From 303e4baa58cbeaa348eed1c651925c37b7580cd9 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 30 Jul 2021 08:30:57 +0530 Subject: [PATCH] Add GLFW API to set WM_COMMAND Also have create_os_window take keyword arguments --- glfw/glfw.py | 1 + glfw/x11_window.c | 7 +++++++ kitty/glfw-wrapper.c | 3 +++ kitty/glfw-wrapper.h | 4 ++++ kitty/glfw.c | 8 +++++--- 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/glfw/glfw.py b/glfw/glfw.py index bdc6bf4c4..256d831c4 100755 --- a/glfw/glfw.py +++ b/glfw/glfw.py @@ -222,6 +222,7 @@ def generate_wrappers(glfw_header: str) -> None: unsigned long long glfwDBusUserNotify(const char *app_name, const char* icon, const char *summary, const char *body, \ const char *action_text, int32_t timeout, GLFWDBusnotificationcreatedfun callback, void *data) void glfwDBusSetUserNotificationHandler(GLFWDBusnotificationactivatedfun handler) + int glfwSetX11LaunchCommand(GLFWwindow *handle, char **argv, int argc) '''.splitlines(): if line: functions.append(Function(line.strip(), check_fail=False)) diff --git a/glfw/x11_window.c b/glfw/x11_window.c index 76815292c..9f80bb670 100644 --- a/glfw/x11_window.c +++ b/glfw/x11_window.c @@ -3122,3 +3122,10 @@ GLFWAPI unsigned long long glfwDBusUserNotify(const char *app_name, const char* GLFWAPI void glfwDBusSetUserNotificationHandler(GLFWDBusnotificationactivatedfun handler) { glfw_dbus_set_user_notification_activated_handler(handler); } + +GLFWAPI int glfwSetX11LaunchCommand(GLFWwindow *handle, char **argv, int argc) +{ + _GLFW_REQUIRE_INIT_OR_RETURN(0); + _GLFWwindow* window = (_GLFWwindow*) handle; + return XSetCommand(_glfw.x11.display, window->x11.handle, argv, argc); +} diff --git a/kitty/glfw-wrapper.c b/kitty/glfw-wrapper.c index ad47a3f4d..4db98fd90 100644 --- a/kitty/glfw-wrapper.c +++ b/kitty/glfw-wrapper.c @@ -441,6 +441,9 @@ load_glfw(const char* path) { *(void **) (&glfwDBusSetUserNotificationHandler_impl) = dlsym(handle, "glfwDBusSetUserNotificationHandler"); if (glfwDBusSetUserNotificationHandler_impl == NULL) dlerror(); // clear error indicator + *(void **) (&glfwSetX11LaunchCommand_impl) = dlsym(handle, "glfwSetX11LaunchCommand"); + if (glfwSetX11LaunchCommand_impl == NULL) dlerror(); // clear error indicator + return NULL; } diff --git a/kitty/glfw-wrapper.h b/kitty/glfw-wrapper.h index 74a7a7fab..6f8ce2c87 100644 --- a/kitty/glfw-wrapper.h +++ b/kitty/glfw-wrapper.h @@ -2168,4 +2168,8 @@ typedef void (*glfwDBusSetUserNotificationHandler_func)(GLFWDBusnotificationacti GFW_EXTERN glfwDBusSetUserNotificationHandler_func glfwDBusSetUserNotificationHandler_impl; #define glfwDBusSetUserNotificationHandler glfwDBusSetUserNotificationHandler_impl +typedef int (*glfwSetX11LaunchCommand_func)(GLFWwindow*, char**, int); +GFW_EXTERN glfwSetX11LaunchCommand_func glfwSetX11LaunchCommand_impl; +#define glfwSetX11LaunchCommand glfwSetX11LaunchCommand_impl + const char* load_glfw(const char* path); diff --git a/kitty/glfw.c b/kitty/glfw.c index 374d7fc8d..7f74131a2 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -622,11 +622,13 @@ native_window_handle(GLFWwindow *w) { } static PyObject* -create_os_window(PyObject UNUSED *self, PyObject *args) { +create_os_window(PyObject UNUSED *self, PyObject *args, PyObject *kw) { int x = -1, y = -1; char *title, *wm_class_class, *wm_class_name; PyObject *load_programs = NULL, *get_window_size, *pre_show_callback; - if (!PyArg_ParseTuple(args, "OOsss|Oii", &get_window_size, &pre_show_callback, &title, &wm_class_name, &wm_class_class, &load_programs, &x, &y)) return NULL; + static const char* kwlist[] = {"get_window_size", "pre_show_callback", "title", "wm_class_name", "wm_class_class", "load_programs", "x", "y", NULL}; + if (!PyArg_ParseTupleAndKeywords(args, kw, "OOsss|Oii", (char**)kwlist, + &get_window_size, &pre_show_callback, &title, &wm_class_name, &wm_class_class, &load_programs, &x, &y)) return NULL; static bool is_first_window = true; if (is_first_window) { @@ -1431,7 +1433,7 @@ stop_main_loop(void) { static PyMethodDef module_methods[] = { METHODB(set_custom_cursor, METH_VARARGS), - METHODB(create_os_window, METH_VARARGS), + {"create_os_window", (PyCFunction)(void (*) (void))(create_os_window), METH_VARARGS | METH_KEYWORDS, NULL}, METHODB(set_default_window_icon, METH_VARARGS), METHODB(get_clipboard_string, METH_NOARGS), METHODB(get_content_scale_for_window, METH_NOARGS),