From 0641ec2d899b2b20d42d3618d6dce691d43fac79 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 23 Mar 2024 12:30:31 +0530 Subject: [PATCH] GLFW API for configuring a window as a layer shell --- glfw/glfw.py | 1 + glfw/glfw3.h | 8 ++++++++ glfw/wl_window.c | 8 ++++++++ kitty/glfw-wrapper.c | 3 +++ kitty/glfw-wrapper.h | 12 ++++++++++++ 5 files changed, 32 insertions(+) diff --git a/glfw/glfw.py b/glfw/glfw.py index 3fca901ea..db4d975a4 100755 --- a/glfw/glfw.py +++ b/glfw/glfw.py @@ -314,6 +314,7 @@ def generate_wrappers(glfw_header: str) -> None: void glfwWaylandRunWithActivationToken(GLFWwindow *handle, GLFWactivationcallback cb, void *cb_data) bool glfwWaylandSetTitlebarColor(GLFWwindow *handle, uint32_t color, bool use_system_color) void glfwWaylandRedrawCSDWindowTitle(GLFWwindow *handle) + GLFWLayerShellConfig* glfwWaylandSetupLayerShellForNextWindow(void) 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) diff --git a/glfw/glfw3.h b/glfw/glfw3.h index e35d1330b..1f412f9a8 100644 --- a/glfw/glfw3.h +++ b/glfw/glfw3.h @@ -1292,6 +1292,14 @@ typedef struct GLFWkeyevent bool fake_event_on_focus_change; } GLFWkeyevent; +typedef enum { GLFW_LAYER_SHELL_NONE, GLFW_LAYER_SHELL_BACKGROUND, GLFW_LAYER_SHELL_PANEL } GLFWLayerShellType; + +typedef struct GLFWLayerShellConfig { + GLFWLayerShellType type; + const char *output_name; + const char *edge; +} GLFWLayerShellConfig; + /*! @brief The function pointer type for error callbacks. * * This is the function pointer type for error callbacks. An error callback diff --git a/glfw/wl_window.c b/glfw/wl_window.c index 380b88a3f..b7b034302 100644 --- a/glfw/wl_window.c +++ b/glfw/wl_window.c @@ -43,6 +43,8 @@ #define debug(...) if (_glfw.hints.init.debugRendering) fprintf(stderr, __VA_ARGS__); +static GLFWLayerShellConfig layer_shell_config_for_next_window = {0}; + static void activation_token_done(void *data, struct xdg_activation_token_v1 *xdg_token, const char *token) { for (size_t i = 0; i < _glfw.wl.activation_requests.sz; i++) { @@ -2425,3 +2427,9 @@ GLFWAPI void glfwWaylandRedrawCSDWindowTitle(GLFWwindow *handle) { _GLFWwindow* window = (_GLFWwindow*) handle; change_csd_title(window); } + + +GLFWAPI GLFWLayerShellConfig* glfwWaylandSetupLayerShellForNextWindow(void) { + memset(&layer_shell_config_for_next_window, 0, sizeof(layer_shell_config_for_next_window)); + return &layer_shell_config_for_next_window; +} diff --git a/kitty/glfw-wrapper.c b/kitty/glfw-wrapper.c index d5159141d..b6c38a7ad 100644 --- a/kitty/glfw-wrapper.c +++ b/kitty/glfw-wrapper.c @@ -479,6 +479,9 @@ load_glfw(const char* path) { *(void **) (&glfwWaylandRedrawCSDWindowTitle_impl) = dlsym(handle, "glfwWaylandRedrawCSDWindowTitle"); if (glfwWaylandRedrawCSDWindowTitle_impl == NULL) dlerror(); // clear error indicator + *(void **) (&glfwWaylandSetupLayerShellForNextWindow_impl) = dlsym(handle, "glfwWaylandSetupLayerShellForNextWindow"); + if (glfwWaylandSetupLayerShellForNextWindow_impl == NULL) dlerror(); // clear error indicator + *(void **) (&glfwDBusUserNotify_impl) = dlsym(handle, "glfwDBusUserNotify"); if (glfwDBusUserNotify_impl == NULL) dlerror(); // clear error indicator diff --git a/kitty/glfw-wrapper.h b/kitty/glfw-wrapper.h index cb44daa7a..b160fbe8d 100644 --- a/kitty/glfw-wrapper.h +++ b/kitty/glfw-wrapper.h @@ -1030,6 +1030,14 @@ typedef struct GLFWkeyevent bool fake_event_on_focus_change; } GLFWkeyevent; +typedef enum { GLFW_LAYER_SHELL_NONE, GLFW_LAYER_SHELL_BACKGROUND, GLFW_LAYER_SHELL_PANEL } GLFWLayerShellType; + +typedef struct GLFWLayerShellConfig { + GLFWLayerShellType type; + const char *output_name; + const char *edge; +} GLFWLayerShellConfig; + /*! @brief The function pointer type for error callbacks. * * This is the function pointer type for error callbacks. An error callback @@ -2293,6 +2301,10 @@ typedef void (*glfwWaylandRedrawCSDWindowTitle_func)(GLFWwindow*); GFW_EXTERN glfwWaylandRedrawCSDWindowTitle_func glfwWaylandRedrawCSDWindowTitle_impl; #define glfwWaylandRedrawCSDWindowTitle glfwWaylandRedrawCSDWindowTitle_impl +typedef GLFWLayerShellConfig* (*glfwWaylandSetupLayerShellForNextWindow_func)(void); +GFW_EXTERN glfwWaylandSetupLayerShellForNextWindow_func glfwWaylandSetupLayerShellForNextWindow_impl; +#define glfwWaylandSetupLayerShellForNextWindow glfwWaylandSetupLayerShellForNextWindow_impl + typedef unsigned long long (*glfwDBusUserNotify_func)(const char*, const char*, const char*, const char*, const char*, int32_t, GLFWDBusnotificationcreatedfun, void*); GFW_EXTERN glfwDBusUserNotify_func glfwDBusUserNotify_impl; #define glfwDBusUserNotify glfwDBusUserNotify_impl