API to set layer shell config for existing window

This commit is contained in:
Kovid Goyal
2025-04-22 11:08:13 +05:30
parent db5b691545
commit c1a9873530
10 changed files with 46 additions and 1 deletions

View File

@@ -1903,6 +1903,11 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window)
window->ns.object = nil;
}
bool _glfwPlatformSetLayerShellConfig(_GLFWwindow* window, const GLFWLayerShellConfig *value) {
(void)window; (void)value;
return false;
}
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
{
if (!title) return;

1
glfw/glfw3.h vendored
View File

@@ -2873,6 +2873,7 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, const char* title, G
GLFWAPI bool glfwToggleFullscreen(GLFWwindow *window, unsigned int flags);
GLFWAPI bool glfwIsFullscreen(GLFWwindow *window, unsigned int flags);
GLFWAPI bool glfwAreSwapsAllowed(const GLFWwindow* window);
GLFWAPI bool glfwSetLayerShellConfig(GLFWwindow* handle, const GLFWLayerShellConfig *value);
/*! @brief Destroys the specified window and its context.
*

1
glfw/internal.h vendored
View File

@@ -714,6 +714,7 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window);
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title);
void _glfwPlatformSetWindowIcon(_GLFWwindow* window,
int count, const GLFWimage* images);
bool _glfwPlatformSetLayerShellConfig(_GLFWwindow* window, const GLFWLayerShellConfig *value);
void _glfwPlatformGetWindowPos(_GLFWwindow* window, int* xpos, int* ypos);
void _glfwPlatformSetWindowPos(_GLFWwindow* window, int xpos, int ypos);
void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height);

8
glfw/window.c vendored
View File

@@ -551,6 +551,14 @@ GLFWAPI void glfwSetWindowShouldClose(GLFWwindow* handle, int value)
window->shouldClose = value;
}
GLFWAPI bool glfwSetLayerShellConfig(GLFWwindow* handle, const GLFWLayerShellConfig *value) {
_GLFWwindow* window = (_GLFWwindow*) handle;
assert(window != NULL);
_GLFW_REQUIRE_INIT_OR_RETURN(false);
return _glfwPlatformSetLayerShellConfig(window, value);
}
GLFWAPI void glfwSetWindowTitle(GLFWwindow* handle, const char* title)
{
_GLFWwindow* window = (_GLFWwindow*) handle;

6
glfw/wl_window.c vendored
View File

@@ -1707,6 +1707,12 @@ void _glfwPlatformHideWindow(_GLFWwindow* window)
wl_surface_commit(window->wl.surface);
}
bool _glfwPlatformSetLayerShellConfig(_GLFWwindow* window, const GLFWLayerShellConfig *value) {
if (!is_layer_shell(window)) return false;
window->wl.layer_shell.config = *value;
return true;
}
static void
request_attention(GLFWwindow *window, const char *token, void *data UNUSED) {
if (window && token && token[0] && _glfw.wl.xdg_activation_v1) xdg_activation_v1_activate(_glfw.wl.xdg_activation_v1, token, ((_GLFWwindow*)window)->wl.surface);

5
glfw/x11_window.c vendored
View File

@@ -1963,6 +1963,11 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window)
XFlush(_glfw.x11.display);
}
bool _glfwPlatformSetLayerShellConfig(_GLFWwindow* window, const GLFWLayerShellConfig *value) {
(void)window; (void)value;
return false;
}
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
{
#if defined(X_HAVE_UTF8_STRING)

View File

@@ -1704,7 +1704,8 @@ def get_clipboard_mime(ct: int, mime: Optional[str], callback: Callable[[bytes],
def run_with_activation_token(func: Callable[[str], None]) -> bool: ...
def make_x11_window_a_dock_window(x11_window_id: int, strut: Tuple[int, int, int, int, int, int, int, int, int, int, int, int]) -> None: ...
def toggle_os_window_visibility(os_window_id: int) -> bool: ...
def layer_shell_config_for_os_window(os_window_id: int) -> LayerShellConfig: ...
def layer_shell_config_for_os_window(os_window_id: int) -> dict[str, Any] | None: ...
def set_layer_shell_config(os_window_id: int, cfg: LayerShellConfig) -> bool: ...
def wrapped_kitten_names() -> List[str]: ...
def expand_ansi_c_escapes(test: str) -> str: ...
def update_tab_bar_edge_colors(os_window_id: int) -> bool: ...

3
kitty/glfw-wrapper.c generated
View File

@@ -131,6 +131,9 @@ load_glfw(const char* path) {
*(void **) (&glfwAreSwapsAllowed_impl) = dlsym(handle, "glfwAreSwapsAllowed");
if (glfwAreSwapsAllowed_impl == NULL) fail("Failed to load glfw function glfwAreSwapsAllowed with error: %s", dlerror());
*(void **) (&glfwSetLayerShellConfig_impl) = dlsym(handle, "glfwSetLayerShellConfig");
if (glfwSetLayerShellConfig_impl == NULL) fail("Failed to load glfw function glfwSetLayerShellConfig with error: %s", dlerror());
*(void **) (&glfwDestroyWindow_impl) = dlsym(handle, "glfwDestroyWindow");
if (glfwDestroyWindow_impl == NULL) fail("Failed to load glfw function glfwDestroyWindow with error: %s", dlerror());

4
kitty/glfw-wrapper.h generated
View File

@@ -1868,6 +1868,10 @@ typedef bool (*glfwAreSwapsAllowed_func)(const GLFWwindow*);
GFW_EXTERN glfwAreSwapsAllowed_func glfwAreSwapsAllowed_impl;
#define glfwAreSwapsAllowed glfwAreSwapsAllowed_impl
typedef bool (*glfwSetLayerShellConfig_func)(GLFWwindow*, const GLFWLayerShellConfig*);
GFW_EXTERN glfwSetLayerShellConfig_func glfwSetLayerShellConfig_impl;
#define glfwSetLayerShellConfig glfwSetLayerShellConfig_impl
typedef void (*glfwDestroyWindow_func)(GLFWwindow*);
GFW_EXTERN glfwDestroyWindow_func glfwDestroyWindow_impl;
#define glfwDestroyWindow glfwDestroyWindow_impl

View File

@@ -2475,6 +2475,16 @@ layer_shell_config_for_os_window(PyObject *self UNUSED, PyObject *wid) {
#endif
}
static PyObject*
set_layer_shell_config(PyObject *self UNUSED, PyObject *args) {
unsigned long long wid; PyObject *pylsc;
if (!PyArg_ParseTuple(args, "KO", &wid, &pylsc)) return NULL;
OSWindow *window = os_window_for_id(wid);
if (!window || !window->handle || !window->is_layer_shell) Py_RETURN_FALSE;
GLFWLayerShellConfig lsc = {0};
if (!layer_shell_config_from_python(pylsc, &lsc)) return NULL;
return Py_NewRef(glfwSetLayerShellConfig(window->handle, &lsc) ? Py_True : Py_False);
}
// Boilerplate {{{
@@ -2483,6 +2493,7 @@ static PyMethodDef module_methods[] = {
METHODB(is_css_pointer_name_valid, METH_O),
METHODB(toggle_os_window_visibility, METH_O),
METHODB(layer_shell_config_for_os_window, METH_O),
METHODB(set_layer_shell_config, METH_VARARGS),
METHODB(pointer_name_to_css_name, METH_O),
{"create_os_window", (PyCFunction)(void (*) (void))(create_os_window), METH_VARARGS | METH_KEYWORDS, NULL},
METHODB(set_default_window_icon, METH_VARARGS),