Fix storage for GLFW_MOD_KITTY

This commit is contained in:
Kovid Goyal 2022-08-12 09:58:50 +05:30
parent af48547d8b
commit f3329fcd34
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
5 changed files with 11 additions and 7 deletions

1
glfw/glfw3.h vendored
View File

@ -512,6 +512,7 @@ typedef enum {
* GLFW_LOCK_KEY_MODS input mode is set.
*/
#define GLFW_MOD_NUM_LOCK 0x0080
#define GLFW_MOD_LAST GLFW_MOD_NUM_LOCK
#define GLFW_LOCK_MASK (GLFW_MOD_NUM_LOCK | GLFW_MOD_CAPS_LOCK)
/*! @} */

View File

@ -19,7 +19,7 @@
// Required minimum OpenGL version
#define OPENGL_REQUIRED_VERSION_MAJOR 3
#define OPENGL_REQUIRED_VERSION_MINOR 3
#define GLFW_MOD_KITTY 1024
#define GLFW_MOD_KITTY (GLFW_MOD_LAST * 2)
#define UNUSED __attribute__ ((unused))
#define PYNOARG PyObject *__a1 UNUSED, PyObject *__a2 UNUSED
#define EXPORTED __attribute__ ((visibility ("default")))

1
kitty/glfw-wrapper.h generated
View File

@ -250,6 +250,7 @@ typedef enum {
* GLFW_LOCK_KEY_MODS input mode is set.
*/
#define GLFW_MOD_NUM_LOCK 0x0080
#define GLFW_MOD_LAST GLFW_MOD_NUM_LOCK
#define GLFW_LOCK_MASK (GLFW_MOD_NUM_LOCK | GLFW_MOD_CAPS_LOCK)
/*! @} */

View File

@ -286,12 +286,14 @@ static PyMethodDef module_methods[] = {
// SingleKey {{{
#define KEY_BITS 21
#define MOD_BITS 10
#if 1 << (MOD_BITS-1) < GLFW_MOD_KITTY
#error "Not enough mod bits"
#endif
typedef union Key {
struct {
uint32_t key : KEY_BITS;
uint32_t mods : MOD_BITS;
uint32_t is_native: 1;
uint32_t key : KEY_BITS;
};
uint32_t val;
} Key;
@ -316,7 +318,7 @@ SingleKey_new(PyTypeObject *type, PyObject *args, PyObject *kw) {
uint32_t k = (uint32_t)key;
self->key.key = k & BIT_MASK(uint32_t, KEY_BITS);
}
self->key.mods = mods;
self->key.mods = mods & BIT_MASK(u_int32_t, MOD_BITS);
if (is_native) self->key.is_native = 1u;
}
return (PyObject*)self;

View File

@ -534,8 +534,8 @@ class TestDataTypes(BaseTest):
q('a\x1b[12;34:43mbc', 'abc')
def test_SingleKey(self):
from kitty.fast_data_types import SingleKey, GLFW_MOD_NUM_LOCK, GLFW_MOD_SHIFT
for m in (GLFW_MOD_NUM_LOCK, GLFW_MOD_SHIFT):
from kitty.fast_data_types import SingleKey, GLFW_MOD_KITTY, GLFW_MOD_SHIFT
for m in (GLFW_MOD_KITTY, GLFW_MOD_SHIFT):
s = SingleKey(mods=m)
self.ae(s.mods, m)
self.ae(tuple(iter(SingleKey())), (0, False, -1))
@ -545,4 +545,4 @@ class TestDataTypes(BaseTest):
self.ae(repr(SingleKey(key=23, mods=2)), 'SingleKey(mods=2, key=23)')
self.ae(repr(SingleKey(key=23)), 'SingleKey(key=23)')
self.ae(repr(SingleKey(key=23)._replace(mods=2)), 'SingleKey(mods=2, key=23)')
self.ae(repr(SingleKey(key=23)._replace(key=-1, mods=2)), 'SingleKey(mods=2)')
self.ae(repr(SingleKey(key=23)._replace(key=-1, mods=GLFW_MOD_KITTY)), f'SingleKey(mods={GLFW_MOD_KITTY})')