diff --git a/glfw/cocoa_init.m b/glfw/cocoa_init.m index feebbabae..15a4b919f 100644 --- a/glfw/cocoa_init.m +++ b/glfw/cocoa_init.m @@ -69,7 +69,6 @@ static void changeToResourcesDirectory(void) static void createKeyTables(void) { int scancode; - _glfw.ns.debug_keyboard = getenv("GLFW_DEBUG_KEYBOARD") != NULL; memset(_glfw.ns.keycodes, -1, sizeof(_glfw.ns.keycodes)); memset(_glfw.ns.scancodes, -1, sizeof(_glfw.ns.scancodes)); diff --git a/glfw/cocoa_platform.h b/glfw/cocoa_platform.h index a95c2a658..692cc4603 100644 --- a/glfw/cocoa_platform.h +++ b/glfw/cocoa_platform.h @@ -121,7 +121,6 @@ typedef struct _GLFWlibraryNS char keyName[64]; char text[256]; - GLFWbool debug_keyboard; short int keycodes[256]; short int scancodes[GLFW_KEY_LAST + 1]; char* clipboardString; diff --git a/glfw/cocoa_window.m b/glfw/cocoa_window.m index 4f9d112ec..c521c1585 100644 --- a/glfw/cocoa_window.m +++ b/glfw/cocoa_window.m @@ -209,7 +209,7 @@ static int translateFlags(NSUInteger flags) return mods; } -#define debug_key(...) if (_glfw.ns.debug_keyboard) NSLog(__VA_ARGS__) +#define debug_key(...) if (_glfw.hints.init.debugKeyboard) NSLog(__VA_ARGS__) static inline const char* format_mods(int mods) { diff --git a/glfw/glfw3.h b/glfw/glfw3.h index a97c5ade2..edf0745cf 100644 --- a/glfw/glfw3.h +++ b/glfw/glfw3.h @@ -1057,6 +1057,7 @@ extern "C" { /*! @addtogroup init * @{ */ #define GLFW_JOYSTICK_HAT_BUTTONS 0x00050001 +#define GLFW_DEBUG_KEYBOARD 0x00050002 #define GLFW_COCOA_CHDIR_RESOURCES 0x00051001 #define GLFW_COCOA_MENUBAR 0x00051002 diff --git a/glfw/init.c b/glfw/init.c index 9e670d423..7b2ef8533 100644 --- a/glfw/init.c +++ b/glfw/init.c @@ -51,6 +51,7 @@ static GLFWerrorfun _glfwErrorCallback; static _GLFWinitconfig _glfwInitHints = { GLFW_TRUE, // hat buttons + GLFW_FALSE, // debug keyboard { GLFW_TRUE, // macOS menu bar GLFW_TRUE // macOS bundle chdir @@ -255,6 +256,9 @@ GLFWAPI void glfwInitHint(int hint, int value) case GLFW_JOYSTICK_HAT_BUTTONS: _glfwInitHints.hatButtons = value; return; + case GLFW_DEBUG_KEYBOARD: + _glfwInitHints.debugKeyboard = value; + return; case GLFW_COCOA_CHDIR_RESOURCES: _glfwInitHints.ns.chdir = value; return; @@ -311,4 +315,3 @@ GLFWAPI GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cbfun) _GLFW_SWAP_POINTERS(_glfwErrorCallback, cbfun); return cbfun; } - diff --git a/glfw/internal.h b/glfw/internal.h index f0a4be9eb..782c0f2cf 100644 --- a/glfw/internal.h +++ b/glfw/internal.h @@ -242,6 +242,7 @@ struct _GLFWerror struct _GLFWinitconfig { GLFWbool hatButtons; + GLFWbool debugKeyboard; struct { GLFWbool menubar; GLFWbool chdir; diff --git a/glfw/xkb_glfw.c b/glfw/xkb_glfw.c index 98ee95a84..2d19ca05b 100644 --- a/glfw/xkb_glfw.c +++ b/glfw/xkb_glfw.c @@ -30,8 +30,7 @@ #include "internal.h" #include "xkb_glfw.h" -static GLFWbool debug_keyboard = GLFW_FALSE; -#define debug(...) if (debug_keyboard) printf(__VA_ARGS__); +#define debug(...) if (_glfw.hints.init.debugKeyboard) printf(__VA_ARGS__); #define map_key(key) { \ switch(key) { \ @@ -206,7 +205,6 @@ glfw_xkb_release(_GLFWXKBData *xkb) { GLFWbool glfw_xkb_create_context(_GLFWXKBData *xkb) { xkb->context = xkb_context_new(0); - debug_keyboard = getenv("GLFW_DEBUG_KEYBOARD") != NULL; if (!xkb->context) { _glfwInputError(GLFW_PLATFORM_ERROR, diff --git a/kitty/glfw-wrapper.h b/kitty/glfw-wrapper.h index d7eeca7e5..205bebb02 100644 --- a/kitty/glfw-wrapper.h +++ b/kitty/glfw-wrapper.h @@ -818,6 +818,7 @@ typedef int (* GLFWapplicationshouldhandlereopenfun)(int); /*! @addtogroup init * @{ */ #define GLFW_JOYSTICK_HAT_BUTTONS 0x00050001 +#define GLFW_DEBUG_KEYBOARD 0x00050002 #define GLFW_COCOA_CHDIR_RESOURCES 0x00051001 #define GLFW_COCOA_MENUBAR 0x00051002 diff --git a/kitty/glfw.c b/kitty/glfw.c index bf3365250..5ab6e951a 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -558,10 +558,12 @@ error_callback(int error, const char* description) { PyObject* glfw_init(PyObject UNUSED *self, PyObject *args) { const char* path; - if (!PyArg_ParseTuple(args, "s", &path)) return NULL; + int debug_keyboard = 0; + if (!PyArg_ParseTuple(args, "s|p", &path, &debug_keyboard)) return NULL; const char* err = load_glfw(path); if (err) { PyErr_SetString(PyExc_RuntimeError, err); return NULL; } glfwSetErrorCallback(error_callback); + glfwInitHint(GLFW_DEBUG_KEYBOARD, debug_keyboard); #ifdef __APPLE__ glfwInitHint(GLFW_COCOA_CHDIR_RESOURCES, 0); glfwInitHint(GLFW_COCOA_MENUBAR, 0); diff --git a/kitty/main.py b/kitty/main.py index 8eac25ce1..16530bcb7 100644 --- a/kitty/main.py +++ b/kitty/main.py @@ -71,12 +71,8 @@ def load_all_shaders(semi_transparent=0): def init_glfw(debug_keyboard=False): glfw_module = 'cocoa' if is_macos else ('wayland' if is_wayland else 'x11') - if debug_keyboard: - os.environ['GLFW_DEBUG_KEYBOARD'] = '1' - if not glfw_init(glfw_path(glfw_module)): + if not glfw_init(glfw_path(glfw_module), debug_keyboard): raise SystemExit('GLFW initialization failed') - if debug_keyboard: - os.environ.pop('GLFW_DEBUG_KEYBOARD') return glfw_module