From ab960ea12d3e1e3489898b663f8d678ece8b2409 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 31 Aug 2018 07:50:51 +0530 Subject: [PATCH] Linux: Fix slow startup on some systems caused by GLFW searching for joysticks. Since kitty does not use joysticks, disable joystick support. Fixes #830 --- docs/changelog.rst | 5 +++++ glfw/glfw3.h | 1 + glfw/init.c | 4 ++++ glfw/internal.h | 1 + glfw/wl_init.c | 6 ++++-- glfw/x11_init.c | 11 +++++++---- kitty/glfw-wrapper.h | 1 + kitty/glfw.c | 3 +++ 8 files changed, 26 insertions(+), 6 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 01126bd2a..1bd76f616 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -70,6 +70,11 @@ Changelog - macOS: Fix control+tab key combination not working (:iss:`801`) +- Linux: Fix slow startup on some systems caused by GLFW searching for + joysticks. Since kitty does not use joysticks, disable joystick support. + (:iss:`830`) + + 0.11.3 [2018-07-10] ------------------------------ diff --git a/glfw/glfw3.h b/glfw/glfw3.h index 936d44760..b144bd431 100644 --- a/glfw/glfw3.h +++ b/glfw/glfw3.h @@ -1058,6 +1058,7 @@ extern "C" { * @{ */ #define GLFW_JOYSTICK_HAT_BUTTONS 0x00050001 #define GLFW_DEBUG_KEYBOARD 0x00050002 +#define GLFW_ENABLE_JOYSTICKS 0x00050003 #define GLFW_COCOA_CHDIR_RESOURCES 0x00051001 #define GLFW_COCOA_MENUBAR 0x00051002 diff --git a/glfw/init.c b/glfw/init.c index a152df749..3b7d8dc36 100644 --- a/glfw/init.c +++ b/glfw/init.c @@ -52,6 +52,7 @@ static _GLFWinitconfig _glfwInitHints = { GLFW_TRUE, // hat buttons GLFW_FALSE, // debug keyboard + GLFW_TRUE, // enable joystick { GLFW_TRUE, // macOS menu bar GLFW_TRUE // macOS bundle chdir @@ -254,6 +255,9 @@ GLFWAPI void glfwInitHint(int hint, int value) { switch (hint) { + case GLFW_ENABLE_JOYSTICKS: + _glfwInitHints.enableJoysticks = value; + return; case GLFW_JOYSTICK_HAT_BUTTONS: _glfwInitHints.hatButtons = value; return; diff --git a/glfw/internal.h b/glfw/internal.h index 62171e728..e3360bbbd 100644 --- a/glfw/internal.h +++ b/glfw/internal.h @@ -244,6 +244,7 @@ struct _GLFWinitconfig { GLFWbool hatButtons; GLFWbool debugKeyboard; + GLFWbool enableJoysticks; struct { GLFWbool menubar; GLFWbool chdir; diff --git a/glfw/wl_init.c b/glfw/wl_init.c index a4981e1da..43deab03d 100644 --- a/glfw/wl_init.c +++ b/glfw/wl_init.c @@ -688,8 +688,10 @@ int _glfwPlatformInit(void) wl_display_roundtrip(_glfw.wl.display); #ifdef __linux__ - if (!_glfwInitJoysticksLinux()) - return GLFW_FALSE; + if (_glfw.hints.init.enableJoysticks) { + if (!_glfwInitJoysticksLinux()) + return GLFW_FALSE; + } #endif _glfwInitTimerPOSIX(); diff --git a/glfw/x11_init.c b/glfw/x11_init.c index decc2f4d6..558d94a9a 100644 --- a/glfw/x11_init.c +++ b/glfw/x11_init.c @@ -659,10 +659,13 @@ int _glfwPlatformInit(void) _glfw.x11.hiddenCursorHandle = createHiddenCursor(); #if defined(__linux__) - if (!_glfwInitJoysticksLinux()) - return GLFW_FALSE; - if (_glfw.linjs.inotify > 0) - addWatch(&_glfw.x11.eventLoopData, "joystick", _glfw.linjs.inotify, POLLIN, 1, NULL, NULL); + if (_glfw.hints.init.enableJoysticks) { + printf("1111111111\n"); + if (!_glfwInitJoysticksLinux()) + return GLFW_FALSE; + if (_glfw.linjs.inotify > 0) + addWatch(&_glfw.x11.eventLoopData, "joystick", _glfw.linjs.inotify, POLLIN, 1, NULL, NULL); + } #endif _glfwInitTimerPOSIX(); diff --git a/kitty/glfw-wrapper.h b/kitty/glfw-wrapper.h index c228c7602..c7617aa70 100644 --- a/kitty/glfw-wrapper.h +++ b/kitty/glfw-wrapper.h @@ -819,6 +819,7 @@ typedef int (* GLFWapplicationshouldhandlereopenfun)(int); * @{ */ #define GLFW_JOYSTICK_HAT_BUTTONS 0x00050001 #define GLFW_DEBUG_KEYBOARD 0x00050002 +#define GLFW_ENABLE_JOYSTICKS 0x00050003 #define GLFW_COCOA_CHDIR_RESOURCES 0x00051001 #define GLFW_COCOA_MENUBAR 0x00051002 diff --git a/kitty/glfw.c b/kitty/glfw.c index c7ed4697c..d33dc1286 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -593,6 +593,9 @@ glfw_init(PyObject UNUSED *self, PyObject *args) { if (err) { PyErr_SetString(PyExc_RuntimeError, err); return NULL; } glfwSetErrorCallback(error_callback); glfwInitHint(GLFW_DEBUG_KEYBOARD, debug_keyboard); + // Joysticks cause slow startup on some linux systems, see + // https://github.com/kovidgoyal/kitty/issues/830 + glfwInitHint(GLFW_ENABLE_JOYSTICKS, 0); global_state.opts.debug_keyboard = debug_keyboard != 0; #ifdef __APPLE__ glfwInitHint(GLFW_COCOA_CHDIR_RESOURCES, 0);