From 382367506aaa4459529d9fb1b42fdedca7971708 Mon Sep 17 00:00:00 2001 From: Luflosi Date: Wed, 24 Oct 2018 10:44:24 +0200 Subject: [PATCH 1/3] [WIP] Respect the default system click_interval --- kitty/cocoa_window.m | 7 +++++++ kitty/config_data.py | 10 +++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/kitty/cocoa_window.m b/kitty/cocoa_window.m index d3198b399..32372f490 100644 --- a/kitty/cocoa_window.m +++ b/kitty/cocoa_window.m @@ -267,6 +267,12 @@ cocoa_get_lang(PyObject UNUSED *self) { return Py_BuildValue("s", [locale UTF8String]); } +static PyObject* +cocoa_get_double_click_interval(PyObject UNUSED *self) { + double interval = [NSEvent doubleClickInterval]; + return Py_BuildValue("f", interval); +} + void cocoa_set_hide_from_tasks(void) { [NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory]; @@ -300,6 +306,7 @@ cocoa_set_titlebar_color(void *w, color_type titlebar_color) static PyMethodDef module_methods[] = { {"cocoa_get_lang", (PyCFunction)cocoa_get_lang, METH_NOARGS, ""}, + {"cocoa_get_double_click_interval", (PyCFunction)cocoa_get_double_click_interval, METH_NOARGS, ""}, {"cocoa_set_new_window_trigger", (PyCFunction)cocoa_set_new_window_trigger, METH_VARARGS, ""}, {NULL, NULL, 0, NULL} /* Sentinel */ }; diff --git a/kitty/config_data.py b/kitty/config_data.py index 882e32fb4..8f3e3b875 100644 --- a/kitty/config_data.py +++ b/kitty/config_data.py @@ -399,7 +399,15 @@ Characters considered part of a word when double clicking. In addition to these any character that is marked as an alpha-numeric character in the unicode database will be matched.''')) -o('click_interval', 0.5, option_type=positive_float, long_text=_(''' + +def click_interval(x): + if x == 'system': + from .fast_data_types import cocoa_get_double_click_interval + return cocoa_get_double_click_interval() + return positive_float(x) + + +o('click_interval', 'system', option_type=click_interval, long_text=_(''' The interval between successive clicks to detect double/triple clicks (in seconds)''')) From 09183772d3184492c664f0d57b9e1c57780cd831 Mon Sep 17 00:00:00 2001 From: Luflosi Date: Fri, 26 Oct 2018 11:57:33 +0200 Subject: [PATCH 2/3] Respect the default system double-click interval --- glfw/cocoa_window.m | 5 +++++ glfw/glfw3.h | 26 ++++++++++++++++++++++++++ glfw/internal.h | 1 + glfw/null_window.c | 5 +++++ glfw/win32_window.c | 5 +++++ glfw/window.c | 9 +++++++++ glfw/wl_window.c | 5 +++++ glfw/x11_window.c | 5 +++++ kitty/cocoa_window.m | 7 ------- kitty/config_data.py | 3 +-- kitty/glfw-wrapper.c | 3 +++ kitty/glfw-wrapper.h | 4 ++++ kitty/glfw.c | 4 ++++ 13 files changed, 73 insertions(+), 9 deletions(-) diff --git a/glfw/cocoa_window.m b/glfw/cocoa_window.m index 143a8e4e2..ee3740ae8 100644 --- a/glfw/cocoa_window.m +++ b/glfw/cocoa_window.m @@ -1585,6 +1585,11 @@ void _glfwPlatformGetWindowContentScale(_GLFWwindow* window, *yscale = (float) (pixels.size.height / points.size.height); } +double _glfwPlatformGetDoubleClickInterval(_GLFWwindow* window) +{ + return [NSEvent doubleClickInterval]; +} + void _glfwPlatformIconifyWindow(_GLFWwindow* window) { [window->ns.object miniaturize:nil]; diff --git a/glfw/glfw3.h b/glfw/glfw3.h index 0dc05cf34..e728023af 100644 --- a/glfw/glfw3.h +++ b/glfw/glfw3.h @@ -2930,6 +2930,32 @@ GLFWAPI void glfwGetWindowFrameSize(GLFWwindow* window, int* left, int* top, int */ GLFWAPI void glfwGetWindowContentScale(GLFWwindow* window, float* xscale, float* yscale); +/*! @brief Returns the double click time interval. + * + * This function returns the maximum time between clicks to count as a + * double click. + * + * The double click interval is a positive finite number greater than zero, + * where zero means that no click is ever recognized as a double click. If the + * system does not support a double click interval, this function always returns one half. + * + * @return The double click interval. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref double_click + * @sa @ref click_interval + * @sa @ref double_click_interval + * + * @since Added in version 3.3. + * + * @ingroup window + */ +GLFWAPI double glfwGetDoubleClickInterval(GLFWwindow* window); + /*! @brief Returns the opacity of the whole window. * * This function returns the opacity of the window, including any decorations. diff --git a/glfw/internal.h b/glfw/internal.h index b949d306b..6b064c664 100644 --- a/glfw/internal.h +++ b/glfw/internal.h @@ -653,6 +653,7 @@ void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window, int* right, int* bottom); void _glfwPlatformGetWindowContentScale(_GLFWwindow* window, float* xscale, float* yscale); +double _glfwPlatformGetDoubleClickInterval(_GLFWwindow* window); void _glfwPlatformIconifyWindow(_GLFWwindow* window); void _glfwPlatformRestoreWindow(_GLFWwindow* window); void _glfwPlatformMaximizeWindow(_GLFWwindow* window); diff --git a/glfw/null_window.c b/glfw/null_window.c index 82f414934..2823e1775 100644 --- a/glfw/null_window.c +++ b/glfw/null_window.c @@ -148,6 +148,11 @@ void _glfwPlatformGetWindowContentScale(_GLFWwindow* window, *yscale = 1.f; } +double _glfwPlatformGetDoubleClickInterval(_GLFWwindow* window) +{ + return 0.5; +} + void _glfwPlatformIconifyWindow(_GLFWwindow* window) { } diff --git a/glfw/win32_window.c b/glfw/win32_window.c index a1f24e786..0e6cbcecf 100644 --- a/glfw/win32_window.c +++ b/glfw/win32_window.c @@ -1602,6 +1602,11 @@ void _glfwPlatformGetWindowContentScale(_GLFWwindow* window, _glfwGetMonitorContentScaleWin32(handle, xscale, yscale); } +double _glfwPlatformGetDoubleClickInterval(_GLFWwindow* window) +{ + return 0.5; +} + void _glfwPlatformIconifyWindow(_GLFWwindow* window) { ShowWindow(window->win32.handle, SW_MINIMIZE); diff --git a/glfw/window.c b/glfw/window.c index 10c510e15..dcdbef7d0 100644 --- a/glfw/window.c +++ b/glfw/window.c @@ -721,6 +721,15 @@ GLFWAPI void glfwGetWindowContentScale(GLFWwindow* handle, _glfwPlatformGetWindowContentScale(window, xscale, yscale); } +GLFWAPI double glfwGetDoubleClickInterval(GLFWwindow* handle) +{ + _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window != NULL); + + _GLFW_REQUIRE_INIT_OR_RETURN(0.5f); + return _glfwPlatformGetDoubleClickInterval(window); +} + GLFWAPI float glfwGetWindowOpacity(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; diff --git a/glfw/wl_window.c b/glfw/wl_window.c index 295afcfc6..104a52563 100644 --- a/glfw/wl_window.c +++ b/glfw/wl_window.c @@ -1088,6 +1088,11 @@ void _glfwPlatformGetWindowContentScale(_GLFWwindow* window, *yscale = (float) window->wl.scale; } +double _glfwPlatformGetDoubleClickInterval(_GLFWwindow* window) +{ + return 0.5; +} + void _glfwPlatformIconifyWindow(_GLFWwindow* window) { if (_glfw.wl.wmBase) diff --git a/glfw/x11_window.c b/glfw/x11_window.c index a11386d32..c99e1c27e 100644 --- a/glfw/x11_window.c +++ b/glfw/x11_window.c @@ -2100,6 +2100,11 @@ void _glfwPlatformGetWindowContentScale(_GLFWwindow* window, *yscale = _glfw.x11.contentScaleY; } +double _glfwPlatformGetDoubleClickInterval(_GLFWwindow* window) +{ + return 0.5; +} + void _glfwPlatformIconifyWindow(_GLFWwindow* window) { if (window->x11.overrideRedirect) diff --git a/kitty/cocoa_window.m b/kitty/cocoa_window.m index e0a540c5e..fbeb22c46 100644 --- a/kitty/cocoa_window.m +++ b/kitty/cocoa_window.m @@ -261,12 +261,6 @@ cocoa_get_lang(PyObject UNUSED *self) { return Py_BuildValue("s", [locale UTF8String]); } -static PyObject* -cocoa_get_double_click_interval(PyObject UNUSED *self) { - double interval = [NSEvent doubleClickInterval]; - return Py_BuildValue("f", interval); -} - void cocoa_set_hide_from_tasks(void) { [NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory]; @@ -300,7 +294,6 @@ cocoa_set_titlebar_color(void *w, color_type titlebar_color) static PyMethodDef module_methods[] = { {"cocoa_get_lang", (PyCFunction)cocoa_get_lang, METH_NOARGS, ""}, - {"cocoa_get_double_click_interval", (PyCFunction)cocoa_get_double_click_interval, METH_NOARGS, ""}, {"cocoa_set_new_window_trigger", (PyCFunction)cocoa_set_new_window_trigger, METH_VARARGS, ""}, {NULL, NULL, 0, NULL} /* Sentinel */ }; diff --git a/kitty/config_data.py b/kitty/config_data.py index 176852917..932580e6d 100644 --- a/kitty/config_data.py +++ b/kitty/config_data.py @@ -402,8 +402,7 @@ database will be matched.''')) def click_interval(x): if x == 'system': - from .fast_data_types import cocoa_get_double_click_interval - return cocoa_get_double_click_interval() + return -1.0 return positive_float(x) diff --git a/kitty/glfw-wrapper.c b/kitty/glfw-wrapper.c index fc25dda53..cebd854d4 100644 --- a/kitty/glfw-wrapper.c +++ b/kitty/glfw-wrapper.c @@ -131,6 +131,9 @@ load_glfw(const char* path) { *(void **) (&glfwGetWindowContentScale_impl) = dlsym(handle, "glfwGetWindowContentScale"); if (glfwGetWindowContentScale_impl == NULL) fail("Failed to load glfw function glfwGetWindowContentScale with error: %s", dlerror()); + *(void **) (&glfwGetDoubleClickInterval_impl) = dlsym(handle, "glfwGetDoubleClickInterval"); + if (glfwGetDoubleClickInterval_impl == NULL) fail("Failed to load glfw function glfwGetDoubleClickInterval with error: %s", dlerror()); + *(void **) (&glfwGetWindowOpacity_impl) = dlsym(handle, "glfwGetWindowOpacity"); if (glfwGetWindowOpacity_impl == NULL) fail("Failed to load glfw function glfwGetWindowOpacity with error: %s", dlerror()); diff --git a/kitty/glfw-wrapper.h b/kitty/glfw-wrapper.h index b13ee1f54..bf8e42696 100644 --- a/kitty/glfw-wrapper.h +++ b/kitty/glfw-wrapper.h @@ -1544,6 +1544,10 @@ typedef void (*glfwGetWindowContentScale_func)(GLFWwindow*, float*, float*); glfwGetWindowContentScale_func glfwGetWindowContentScale_impl; #define glfwGetWindowContentScale glfwGetWindowContentScale_impl +typedef double (*glfwGetDoubleClickInterval_func)(GLFWwindow*); +glfwGetDoubleClickInterval_func glfwGetDoubleClickInterval_impl; +#define glfwGetDoubleClickInterval glfwGetDoubleClickInterval_impl + typedef float (*glfwGetWindowOpacity_func)(GLFWwindow*); glfwGetWindowOpacity_func glfwGetWindowOpacity_impl; #define glfwGetWindowOpacity glfwGetWindowOpacity_impl diff --git a/kitty/glfw.c b/kitty/glfw.c index d679b0706..ccd45ab6a 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -529,6 +529,10 @@ create_os_window(PyObject UNUSED *self, PyObject *args) { } glfwMakeContextCurrent(glfw_window); if (is_first_window) { + if (OPT(click_interval) < 0) { + OPT(click_interval) = glfwGetDoubleClickInterval(glfw_window); + } + gl_init(); PyObject *ret = PyObject_CallFunction(load_programs, "i", glfwGetWindowAttrib(glfw_window, GLFW_TRANSPARENT_FRAMEBUFFER)); if (ret == NULL) return NULL; From 09daaf1ec37b7e7272bf56ac59362ba098c8c846 Mon Sep 17 00:00:00 2001 From: Luflosi Date: Sat, 27 Oct 2018 17:55:16 +0200 Subject: [PATCH 3/3] Change click_interval default to -1.0 and add help text for negative click_interval values --- kitty/config_data.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/kitty/config_data.py b/kitty/config_data.py index 932580e6d..3cccb3a10 100644 --- a/kitty/config_data.py +++ b/kitty/config_data.py @@ -399,16 +399,9 @@ Characters considered part of a word when double clicking. In addition to these any character that is marked as an alpha-numeric character in the unicode database will be matched.''')) - -def click_interval(x): - if x == 'system': - return -1.0 - return positive_float(x) - - -o('click_interval', 'system', option_type=click_interval, long_text=_(''' -The interval between successive clicks to detect -double/triple clicks (in seconds)''')) +o('click_interval', -1.0, option_type=float, long_text=_(''' +The interval between successive clicks to detect double/triple clicks (in seconds). +Negative numbers will use the system default instead, if available or fallback to 0.5.''')) o('mouse_hide_wait', 3.0, option_type=positive_float, long_text=_(''' Hide mouse cursor after the specified number of seconds