autoformat

This commit is contained in:
Kovid Goyal 2026-08-11 16:48:52 +05:30
parent a18847bcc5
commit 36872d91bb
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
6 changed files with 40 additions and 21 deletions

View file

@ -512,8 +512,7 @@ remap_cocoa_flags(NSUInteger flags) {
const int remapped = _glfwApplyModifierRemap(mods);
if (remapped == mods) return flags;
if (remapped & (GLFW_MOD_HYPER | GLFW_MOD_META)) return flags;
NSUInteger ans = flags & ~(NSUInteger)(NSEventModifierFlagShift | NSEventModifierFlagControl |
NSEventModifierFlagOption | NSEventModifierFlagCommand);
NSUInteger ans = flags & ~(NSUInteger)(NSEventModifierFlagShift | NSEventModifierFlagControl | NSEventModifierFlagOption | NSEventModifierFlagCommand);
if (remapped & GLFW_MOD_SHIFT) ans |= NSEventModifierFlagShift;
if (remapped & GLFW_MOD_CONTROL) ans |= NSEventModifierFlagControl;
if (remapped & GLFW_MOD_ALT) ans |= NSEventModifierFlagOption;
@ -526,7 +525,7 @@ remap_cocoa_flags(NSUInteger flags) {
// the PHYSICAL flags and cannot be recomputed here, so this path is only
// approximately corrected; the UCKeyTranslate() path above, which is the one
// normally taken, uses the remapped flags directly and is exact.
static NSEvent*
static NSEvent *
event_with_remapped_flags(NSEvent *event, NSUInteger flags) {
if (flags == [event modifierFlags]) return event;
NSEvent *ans = [NSEvent keyEventWithType:[event type]

6
glfw/input.c vendored
View file

@ -697,7 +697,8 @@ glfwSetIgnoreOSKeyboardProcessing(bool enabled) {
// Apply the remap_modifier permutation to a GLFW modifier mask. Every source bit
// is translated in the same pass, so a pair of declarations exchanging two
// modifiers is a swap rather than the identity.
int _glfwApplyModifierRemap(int mods) {
int
_glfwApplyModifierRemap(int mods) {
if (!(mods & _glfw.modifierRemapMask)) return mods;
int ans = 0;
for (unsigned i = 0; i < GLFW_MOD_REMAP_SZ; i++) {
@ -707,7 +708,8 @@ int _glfwApplyModifierRemap(int mods) {
return ans;
}
GLFWAPI void glfwSetModifierRemap(const int *table) {
GLFWAPI void
glfwSetModifierRemap(const int *table) {
_glfw.modifierRemapMask = 0;
for (unsigned i = 0; i < GLFW_MOD_REMAP_SZ; i++) {
_glfw.modifierRemap[i] = table ? table[i] : 0;

View file

@ -501,7 +501,8 @@ modifier_to_key(int modifier, bool is_left) {
}
}
static_assert(GLFW_MOD_LAST < (1 << arraysz(((Options*)NULL)->modifier_remap)),
static_assert(
GLFW_MOD_LAST < (1 << arraysz(((Options *)NULL)->modifier_remap)),
"Options.modifier_remap is indexed by modifier bit position, it must cover every GLFW modifier");
#ifdef __APPLE__
@ -512,13 +513,17 @@ static_assert(GLFW_MOD_LAST < (1 << arraysz(((Options*)NULL)->modifier_remap)),
// been remapped away so nothing physical produces it any more.
static bool
invert_modifier_remap(int mods, int *ans) {
if (!OPT(modifier_remap_mask)) { *ans = mods; return true; }
if (!OPT(modifier_remap_mask)) {
*ans = mods;
return true;
}
int consumed = 0, produced = 0;
for (unsigned i = 0; i < arraysz(OPT(modifier_remap)); i++) {
const int dest = OPT(modifier_remap)[i];
if (!dest || (mods & dest) != dest) continue;
if (consumed & dest) return false;
consumed |= dest; produced |= 1 << i;
consumed |= dest;
produced |= 1 << i;
}
const int leftover = mods & ~consumed;
if (leftover & OPT(modifier_remap_mask)) return false;
@ -581,7 +586,7 @@ key_callback(GLFWwindow *w, GLFWkeyevent *ev) {
// on press and the remapped one on release.
if (key_modifier > 0 && (OPT(modifier_remap_mask) & key_modifier)) {
const int dest = OPT(modifier_remap)[__builtin_ctz((unsigned)key_modifier)];
if (dest && !(dest & (dest - 1))) { // only when the destination is a single modifier
if (dest && !(dest & (dest - 1))) { // only when the destination is a single modifier
const uint32_t remapped_key = modifier_to_key(dest, is_left);
if (remapped_key) {
debug_input("\x1b[35mremap_modifier\x1b[m: modifier key 0x%x -> 0x%x\n", ev->key, remapped_key);

View file

@ -558,12 +558,19 @@ static inline void
remap_modifier(PyObject *val, Options *opts) {
memset(opts->modifier_remap, 0, sizeof(opts->modifier_remap));
opts->modifier_remap_mask = 0;
if (!PyDict_Check(val)) { PyErr_SetString(PyExc_TypeError, "remap_modifier must be a dict"); return; }
if (!PyDict_Check(val)) {
PyErr_SetString(PyExc_TypeError, "remap_modifier must be a dict");
return;
}
PyObject *key, *value;
Py_ssize_t pos = 0;
while (PyDict_Next(val, &pos, &key, &value)) {
const long src = PyLong_AsLong(key), dest = PyLong_AsLong(value);
if (PyErr_Occurred()) { PyErr_Print(); PyErr_Clear(); continue; }
if (PyErr_Occurred()) {
PyErr_Print();
PyErr_Clear();
continue;
}
// the parser guarantees a single source bit, but do not trust it in C
if (src <= 0 || (src & (src - 1)) || dest <= 0) continue;
const unsigned idx = (unsigned)__builtin_ctz((unsigned)src);

View file

@ -531,8 +531,7 @@ def remap_modifier(val: str) -> Iterable[tuple[int, int]]:
# carried on an event, so they are rejected here rather than silently
# mangling events later.
remappable = (
defines.GLFW_MOD_SHIFT | defines.GLFW_MOD_ALT | defines.GLFW_MOD_CONTROL |
defines.GLFW_MOD_SUPER | defines.GLFW_MOD_HYPER | defines.GLFW_MOD_META
defines.GLFW_MOD_SHIFT | defines.GLFW_MOD_ALT | defines.GLFW_MOD_CONTROL | defines.GLFW_MOD_SUPER | defines.GLFW_MOD_HYPER | defines.GLFW_MOD_META
)
def bad(msg: str) -> None:

View file

@ -474,17 +474,24 @@ def conf_parsing(self):
# the last declaration for a given source wins, wherever it appears
self.ae(p('remap_modifier ctrl hyper', 'kitty_mod ctrl', 'remap_modifier ctrl super').remap_modifier, {ctrl: sup})
# unrelated options in between do not disturb it
self.ae(p('remap_modifier ctrl hyper', 'font_size 13', 'remap_modifier super alt').remap_modifier,
{ctrl: hyper, sup: to_modifiers('alt')})
self.ae(p('remap_modifier ctrl hyper', 'font_size 13', 'remap_modifier super alt').remap_modifier, {ctrl: hyper, sup: to_modifiers('alt')})
# the destination may name more than one modifier
self.ae(p('remap_modifier ctrl ctrl+shift').remap_modifier, {ctrl: to_modifiers('ctrl+shift')})
# every rejection must be REPORTED, never silently ignored: wrong arity, unknown
# or non-remappable modifier names, a source naming more than one modifier, and
# a mapping that does nothing
for bad in ('remap_modifier ctrl', 'remap_modifier ctrl hyper super', 'remap_modifier ctrl nosuchmod',
'remap_modifier nosuchmod ctrl', 'remap_modifier ctrl+shift hyper',
'remap_modifier ctrl none', 'remap_modifier none ctrl',
'remap_modifier ctrl kitty_mod', 'remap_modifier kitty_mod ctrl',
'remap_modifier caps_lock ctrl', 'remap_modifier ctrl num_lock',
'remap_modifier ctrl ctrl'):
for bad in (
'remap_modifier ctrl',
'remap_modifier ctrl hyper super',
'remap_modifier ctrl nosuchmod',
'remap_modifier nosuchmod ctrl',
'remap_modifier ctrl+shift hyper',
'remap_modifier ctrl none',
'remap_modifier none ctrl',
'remap_modifier ctrl kitty_mod',
'remap_modifier kitty_mod ctrl',
'remap_modifier caps_lock ctrl',
'remap_modifier ctrl num_lock',
'remap_modifier ctrl ctrl',
):
self.ae(p(bad, num_err=1).remap_modifier, {}, f'not rejected: {bad}')