Nicer fix for human_repr of keys defined with kitty_mod

This commit is contained in:
Kovid Goyal
2022-08-12 12:37:15 +05:30
parent ce91b6d9d9
commit 63fa0c4e94
4 changed files with 36 additions and 30 deletions
+10
View File
@@ -305,6 +305,7 @@ typedef struct {
PyObject_HEAD
Key key;
bool defined_with_kitty_mod;
} SingleKey;
static inline void
@@ -366,10 +367,18 @@ SingleKey_get_is_native(SingleKey *self, void UNUSED *closure) {
Py_RETURN_FALSE;
}
static PyObject*
SingleKey_defined_with_kitty_mod(SingleKey *self, void UNUSED *closure) {
if (self->defined_with_kitty_mod || (self->key.mods & GLFW_MOD_KITTY)) Py_RETURN_TRUE;
Py_RETURN_FALSE;
}
static PyGetSetDef SingleKey_getsetters[] = {
{"key", (getter)SingleKey_get_key, NULL, "The key as an integer", NULL},
{"mods", (getter)SingleKey_get_mods, NULL, "The modifiers as an integer", NULL},
{"is_native", (getter)SingleKey_get_is_native, NULL, "A bool", NULL},
{"defined_with_kitty_mod", (getter)SingleKey_defined_with_kitty_mod, NULL, "A bool", NULL},
{NULL} /* Sentinel */
};
@@ -421,6 +430,7 @@ SingleKey_resolve_kitty_mod(SingleKey *self, PyObject *km) {
if (!ans) return NULL;
ans->key.val = self->key.val;
ans->key.mods = (ans->key.mods & ~GLFW_MOD_KITTY) | kitty_mod;
ans->defined_with_kitty_mod = true;
return (PyObject*)ans;
}