From 33f0ac83c1e5e247dc46caf33f36a534b2c0a836 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 6 Sep 2018 06:54:04 +0530 Subject: [PATCH] Wayland: Allow using the --class to set the app id Fixes #862 --- docs/changelog.rst | 3 +++ glfw/glfw3.h | 2 ++ glfw/internal.h | 3 +++ glfw/window.c | 4 ++++ glfw/wl_platform.h | 1 + glfw/wl_window.c | 3 +++ kitty/cli.py | 2 +- kitty/glfw-wrapper.h | 2 ++ kitty/glfw.c | 1 + 9 files changed, 20 insertions(+), 1 deletion(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 72388da86..ddfbb5654 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -29,6 +29,9 @@ Changelog - Fix a regression in 0.12.0 that broke resizing of layouts (:iss:`860`) +- Wayland: Allow using the :option:`kitty --class` command line flag + to set the app id (:iss:`862`) + 0.12.0 [2018-09-01] ------------------------------ diff --git a/glfw/glfw3.h b/glfw/glfw3.h index 948b40f9b..0dc05cf34 100644 --- a/glfw/glfw3.h +++ b/glfw/glfw3.h @@ -984,6 +984,8 @@ extern "C" { #define GLFW_X11_CLASS_NAME 0x00024001 #define GLFW_X11_INSTANCE_NAME 0x00024002 + +#define GLFW_WAYLAND_APP_ID 0x00025001 /*! @} */ #define GLFW_NO_API 0 diff --git a/glfw/internal.h b/glfw/internal.h index efdcf9c66..80f53c200 100644 --- a/glfw/internal.h +++ b/glfw/internal.h @@ -282,6 +282,9 @@ struct _GLFWwndconfig char className[256]; char instanceName[256]; } x11; + struct { + char appId[256]; + } wl; }; // Context configuration diff --git a/glfw/window.c b/glfw/window.c index 4c731b101..10c510e15 100644 --- a/glfw/window.c +++ b/glfw/window.c @@ -460,6 +460,10 @@ GLFWAPI void glfwWindowHintString(int hint, const char* value) strncpy(_glfw.hints.window.x11.instanceName, value, sizeof(_glfw.hints.window.x11.instanceName) - 1); return; + case GLFW_WAYLAND_APP_ID: + strncpy(_glfw.hints.window.wl.appId, value, + sizeof(_glfw.hints.window.wl.appId) - 1); + return; } _glfwInputError(GLFW_INVALID_ENUM, "Invalid window hint string 0x%08X", hint); diff --git a/glfw/wl_platform.h b/glfw/wl_platform.h index c2976f0fa..c0e0b5291 100644 --- a/glfw/wl_platform.h +++ b/glfw/wl_platform.h @@ -149,6 +149,7 @@ typedef struct _GLFWwindowWayland double cursorPosX, cursorPosY; char* title; + char appId[256]; // We need to track the monitors the window spans on to calculate the // optimal scaling factor. diff --git a/glfw/wl_window.c b/glfw/wl_window.c index dad0321de..8a2d934a3 100644 --- a/glfw/wl_window.c +++ b/glfw/wl_window.c @@ -693,6 +693,8 @@ static GLFWbool createXdgSurface(_GLFWwindow* window) { setIdleInhibitor(window, GLFW_FALSE); } + if (strlen(window->wl.appId)) + xdg_toplevel_set_app_id(window->wl.xdg.toplevel, window->wl.appId); wl_surface_commit(window->wl.surface); wl_display_roundtrip(_glfw.wl.display); @@ -769,6 +771,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, { window->wl.justCreated = GLFW_TRUE; window->wl.transparent = fbconfig->transparent; + strncpy(window->wl.appId, wndconfig->wl.appId, sizeof(window->wl.appId)); if (!createSurface(window, wndconfig)) return GLFW_FALSE; diff --git a/kitty/cli.py b/kitty/cli.py index 2dd546703..dd861f181 100644 --- a/kitty/cli.py +++ b/kitty/cli.py @@ -464,7 +464,7 @@ def options_spec(): dest=cls default={appname} condition=not is_macos -Set the class part of the :italic:`WM_CLASS` window property +Set the class part of the :italic:`WM_CLASS` window property. On Wayland, it sets the app id. --name diff --git a/kitty/glfw-wrapper.h b/kitty/glfw-wrapper.h index 251e496f4..986ba529a 100644 --- a/kitty/glfw-wrapper.h +++ b/kitty/glfw-wrapper.h @@ -745,6 +745,8 @@ typedef int (* GLFWapplicationshouldhandlereopenfun)(int); #define GLFW_X11_CLASS_NAME 0x00024001 #define GLFW_X11_INSTANCE_NAME 0x00024002 + +#define GLFW_WAYLAND_APP_ID 0x00025001 /*! @} */ #define GLFW_NO_API 0 diff --git a/kitty/glfw.c b/kitty/glfw.c index d33dc1286..658d59c1a 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -409,6 +409,7 @@ create_os_window(PyObject UNUSED *self, PyObject *args) { #ifndef __APPLE__ glfwWindowHintString(GLFW_X11_INSTANCE_NAME, wm_class_name); glfwWindowHintString(GLFW_X11_CLASS_NAME, wm_class_class); + glfwWindowHintString(GLFW_WAYLAND_APP_ID, wm_class_class); if (OPT(x11_hide_window_decorations)) { glfwWindowHint(GLFW_DECORATED, GLFW_FALSE); }