From 9188d6a66443a79656518a73e5784929767a70eb Mon Sep 17 00:00:00 2001 From: alex-huff Date: Fri, 7 Mar 2025 11:11:07 -0600 Subject: [PATCH 1/3] Wayland: added --edge=center option for panel kitten --- glfw/glfw3.h | 2 +- glfw/wl_window.c | 5 ++++- kittens/panel/main.py | 25 ++++++++++++++----------- kitty/fast_data_types.pyi | 1 + kitty/glfw-wrapper.h | 2 +- kitty/glfw.c | 13 +++++++++---- kitty/os_window_size.py | 2 +- 7 files changed, 31 insertions(+), 19 deletions(-) diff --git a/glfw/glfw3.h b/glfw/glfw3.h index f9119231d..c887460c4 100644 --- a/glfw/glfw3.h +++ b/glfw/glfw3.h @@ -1302,7 +1302,7 @@ typedef struct GLFWkeyevent typedef enum { GLFW_LAYER_SHELL_NONE, GLFW_LAYER_SHELL_BACKGROUND, GLFW_LAYER_SHELL_PANEL, GLFW_LAYER_SHELL_TOP, GLFW_LAYER_SHELL_OVERLAY } GLFWLayerShellType; -typedef enum { GLFW_EDGE_TOP, GLFW_EDGE_BOTTOM, GLFW_EDGE_LEFT, GLFW_EDGE_RIGHT, GLFW_EDGE_NONE } GLFWEdge; +typedef enum { GLFW_EDGE_TOP, GLFW_EDGE_BOTTOM, GLFW_EDGE_LEFT, GLFW_EDGE_RIGHT, GLFW_EDGE_CENTER, GLFW_EDGE_NONE } GLFWEdge; typedef enum { GLFW_FOCUS_NOT_ALLOWED, GLFW_FOCUS_EXCLUSIVE, GLFW_FOCUS_ON_DEMAND} GLFWFocusPolicy; diff --git a/glfw/wl_window.c b/glfw/wl_window.c index f4b25c0b4..5a377d1d5 100644 --- a/glfw/wl_window.c +++ b/glfw/wl_window.c @@ -1009,8 +1009,11 @@ layer_set_properties(_GLFWwindow *window) { panel_width = window->wl.width; if (!window->wl.layer_shell.config.override_exclusive_zone) exclusive_zone = window->wl.width; break; + case GLFW_EDGE_CENTER: + which_anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT | ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM; + break; case GLFW_EDGE_NONE: - which_anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP; // None is anchored to "top left" + which_anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP; panel_width = window->wl.width; panel_height = window->wl.height; break; diff --git a/kittens/panel/main.py b/kittens/panel/main.py index 806180dcb..6fac9399a 100644 --- a/kittens/panel/main.py +++ b/kittens/panel/main.py @@ -9,11 +9,12 @@ from kitty.cli_stub import PanelCLIOptions from kitty.constants import appname, is_macos, is_wayland from kitty.fast_data_types import ( + GLFW_EDGE_TOP, GLFW_EDGE_BOTTOM, GLFW_EDGE_LEFT, - GLFW_EDGE_NONE, GLFW_EDGE_RIGHT, - GLFW_EDGE_TOP, + GLFW_EDGE_CENTER, + GLFW_EDGE_NONE, GLFW_FOCUS_EXCLUSIVE, GLFW_FOCUS_NOT_ALLOWED, GLFW_FOCUS_ON_DEMAND, @@ -32,13 +33,13 @@ --lines type=int default=1 -The number of lines shown in the panel. Ignored for background and vertical panels. +The number of lines shown in the panel. Ignored for background, centered, and vertical panels. --columns type=int default=1 -The number of columns shown in the panel. Ignored for background and horizontal panels. +The number of columns shown in the panel. Ignored for background, centered, and horizontal panels. --margin-top @@ -70,7 +71,7 @@ --edge -choices=top,bottom,left,right,background,none +choices=top,bottom,left,right,background,center,none default=top Which edge of the screen to place the panel on. Note that some window managers (such as i3) do not support placing docked windows on the left and right edges. @@ -78,8 +79,10 @@ is only supported on Wayland, not X11 and note that when using sway if you set a background in your sway config it will cover the background drawn using this kitten. -The value :code:`none` anchors the panel to the top left corner by default -and the panel should be placed using margins parameters, works only on Wayland. +The value :code:`center` anchors the panel to all sides and covers the entire +display by default. The panel can be shrinked using the margin parameters. +The value :code:`none` anchors the panel to the top left corner and should be +placed using the margin parameters, works only on Wayland. --layer @@ -131,8 +134,8 @@ default=-1 On a Wayland compositor that supports the wlr layer shell protocol, request a given exclusive zone for the panel. Please refer to the wlr layer shell documentation for more details on the meaning of exclusive and its value. -If :option:`--edge` is set to anything else than :code:`none`, this flag will not have any effect unless -the flag :option:`--override-exclusive-zone` is also set. +If :option:`--edge` is set to anything else than :code:`center` or :code:`none`, this flag will not have any +effect unless the flag :option:`--override-exclusive-zone` is also set. If :option:`--edge` is set to :code:`background`, this option has no effect. @@ -215,7 +218,7 @@ def initial_window_size(cell_width: int, cell_height: int, dpi_x: float, dpi_y: spacing = es('top') + es('bottom') window_height = int(cell_height * args.lines / yscale + (dpi_y / 72) * spacing + 1) window_width = monitor_width - elif args.edge == 'background': + elif args.edge in {'background', 'center'}: window_width, window_height = monitor_width, monitor_height else: spacing = es('left') + es('right') @@ -233,7 +236,7 @@ def layer_shell_config(opts: PanelCLIOptions) -> LayerShellConfig: 'overlay': GLFW_LAYER_SHELL_OVERLAY}.get(opts.layer, GLFW_LAYER_SHELL_PANEL) ltype = GLFW_LAYER_SHELL_BACKGROUND if opts.edge == 'background' else ltype edge = { - 'top': GLFW_EDGE_TOP, 'bottom': GLFW_EDGE_BOTTOM, 'left': GLFW_EDGE_LEFT, 'right': GLFW_EDGE_RIGHT, 'none': GLFW_EDGE_NONE + 'top': GLFW_EDGE_TOP, 'bottom': GLFW_EDGE_BOTTOM, 'left': GLFW_EDGE_LEFT, 'right': GLFW_EDGE_RIGHT, 'center': GLFW_EDGE_CENTER, 'none': GLFW_EDGE_NONE }.get(opts.edge, GLFW_EDGE_TOP) focus_policy = { 'not-allowed': GLFW_FOCUS_NOT_ALLOWED, 'exclusive': GLFW_FOCUS_EXCLUSIVE, 'on-demand': GLFW_FOCUS_ON_DEMAND diff --git a/kitty/fast_data_types.pyi b/kitty/fast_data_types.pyi index 6a77edefe..8c9d9bbec 100644 --- a/kitty/fast_data_types.pyi +++ b/kitty/fast_data_types.pyi @@ -23,6 +23,7 @@ GLFW_EDGE_TOP: int GLFW_EDGE_BOTTOM: int GLFW_EDGE_LEFT: int GLFW_EDGE_RIGHT: int +GLFW_EDGE_CENTER: int GLFW_EDGE_NONE: int GLFW_FOCUS_NOT_ALLOWED: int GLFW_FOCUS_EXCLUSIVE: int diff --git a/kitty/glfw-wrapper.h b/kitty/glfw-wrapper.h index 543e5d00f..c9c23d94f 100644 --- a/kitty/glfw-wrapper.h +++ b/kitty/glfw-wrapper.h @@ -1040,7 +1040,7 @@ typedef struct GLFWkeyevent typedef enum { GLFW_LAYER_SHELL_NONE, GLFW_LAYER_SHELL_BACKGROUND, GLFW_LAYER_SHELL_PANEL, GLFW_LAYER_SHELL_TOP, GLFW_LAYER_SHELL_OVERLAY } GLFWLayerShellType; -typedef enum { GLFW_EDGE_TOP, GLFW_EDGE_BOTTOM, GLFW_EDGE_LEFT, GLFW_EDGE_RIGHT, GLFW_EDGE_NONE } GLFWEdge; +typedef enum { GLFW_EDGE_TOP, GLFW_EDGE_BOTTOM, GLFW_EDGE_LEFT, GLFW_EDGE_RIGHT, GLFW_EDGE_CENTER, GLFW_EDGE_NONE } GLFWEdge; typedef enum { GLFW_FOCUS_NOT_ALLOWED, GLFW_FOCUS_EXCLUSIVE, GLFW_FOCUS_ON_DEMAND} GLFWFocusPolicy; diff --git a/kitty/glfw.c b/kitty/glfw.c index 7c505b454..35de14ea2 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -1041,7 +1041,9 @@ edge_spacing(GLFWEdge which) { case GLFW_EDGE_BOTTOM: edge = "bottom"; break; case GLFW_EDGE_LEFT: edge = "left"; break; case GLFW_EDGE_RIGHT: edge = "right"; break; - case GLFW_EDGE_NONE: edge = "left"; break; // GLFW_EDGE_NONE is considered as "top left" + case GLFW_EDGE_CENTER: + case GLFW_EDGE_NONE: + return 0; } if (!edge_spacing_func) { log_error("Attempt to call edge_spacing() without first setting edge_spacing_func"); @@ -1080,11 +1082,14 @@ calculate_layer_shell_window_size( spacing *= ydpi / 72.; spacing += (fonts_data->fcm.cell_height * config->y_size_in_cells) / yscale; *height = (uint32_t)(1. + spacing); + } else if (config->edge == GLFW_EDGE_CENTER) { + if (!*width) *width = monitor_width; + if (!*height) *height = monitor_height; } else { - double spacing_x = edge_spacing(GLFW_EDGE_LEFT); + double spacing_x = edge_spacing(GLFW_EDGE_LEFT) + edge_spacing(GLFW_EDGE_RIGHT); spacing_x *= xdpi / 72.; spacing_x += (fonts_data->fcm.cell_width * config->x_size_in_cells) / xscale; - double spacing_y = edge_spacing(GLFW_EDGE_TOP); + double spacing_y = edge_spacing(GLFW_EDGE_TOP) + edge_spacing(GLFW_EDGE_BOTTOM); spacing_y *= ydpi / 72.; spacing_y += (fonts_data->fcm.cell_height * config->y_size_in_cells) / yscale; *width = (uint32_t)(1. + spacing_x); @@ -2382,7 +2387,7 @@ init_glfw(PyObject *m) { ADDC(GLFW_PRIMARY_SELECTION); ADDC(GLFW_CLIPBOARD); ADDC(GLFW_LAYER_SHELL_NONE); ADDC(GLFW_LAYER_SHELL_PANEL); ADDC(GLFW_LAYER_SHELL_BACKGROUND); ADDC(GLFW_LAYER_SHELL_TOP); ADDC(GLFW_LAYER_SHELL_OVERLAY); ADDC(GLFW_FOCUS_NOT_ALLOWED); ADDC(GLFW_FOCUS_EXCLUSIVE); ADDC(GLFW_FOCUS_ON_DEMAND); - ADDC(GLFW_EDGE_TOP); ADDC(GLFW_EDGE_BOTTOM); ADDC(GLFW_EDGE_LEFT); ADDC(GLFW_EDGE_RIGHT); ADDC(GLFW_EDGE_NONE) + ADDC(GLFW_EDGE_TOP); ADDC(GLFW_EDGE_BOTTOM); ADDC(GLFW_EDGE_LEFT); ADDC(GLFW_EDGE_RIGHT); ADDC(GLFW_EDGE_CENTER); ADDC(GLFW_EDGE_NONE) ADDC(GLFW_COLOR_SCHEME_NO_PREFERENCE); ADDC(GLFW_COLOR_SCHEME_DARK); ADDC(GLFW_COLOR_SCHEME_LIGHT); /* start glfw functional keys (auto generated by gen-key-constants.py do not edit) */ diff --git a/kitty/os_window_size.py b/kitty/os_window_size.py index 5a9c7ef7f..20f78145f 100644 --- a/kitty/os_window_size.py +++ b/kitty/os_window_size.py @@ -38,7 +38,7 @@ def sanitize_window_size(x: Any) -> int: return max(20, min(ans, 50000)) -def edge_spacing(which: EdgeLiteral, opts:WindowSizeData | Options | None = None) -> float: +def edge_spacing(which: EdgeLiteral, opts: WindowSizeData | Options | None = None) -> float: if opts is None: opts = get_options() margin: float = getattr(opts.single_window_margin_width, which) From 537000dfc01309e81056a211428ebe424bdd8b0b Mon Sep 17 00:00:00 2001 From: alex-huff Date: Fri, 7 Mar 2025 11:18:18 -0600 Subject: [PATCH 2/3] ... --- kittens/panel/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kittens/panel/main.py b/kittens/panel/main.py index 6fac9399a..1339a39f0 100644 --- a/kittens/panel/main.py +++ b/kittens/panel/main.py @@ -9,12 +9,12 @@ from kitty.cli_stub import PanelCLIOptions from kitty.constants import appname, is_macos, is_wayland from kitty.fast_data_types import ( - GLFW_EDGE_TOP, GLFW_EDGE_BOTTOM, - GLFW_EDGE_LEFT, - GLFW_EDGE_RIGHT, GLFW_EDGE_CENTER, + GLFW_EDGE_LEFT, GLFW_EDGE_NONE, + GLFW_EDGE_RIGHT, + GLFW_EDGE_TOP, GLFW_FOCUS_EXCLUSIVE, GLFW_FOCUS_NOT_ALLOWED, GLFW_FOCUS_ON_DEMAND, From 3555569c0989ced2134af1470c8399443ac526c9 Mon Sep 17 00:00:00 2001 From: alex-huff Date: Fri, 7 Mar 2025 11:26:49 -0600 Subject: [PATCH 3/3] ... --- kitty/glfw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kitty/glfw.c b/kitty/glfw.c index 35de14ea2..5bd31e7d6 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -2387,7 +2387,7 @@ init_glfw(PyObject *m) { ADDC(GLFW_PRIMARY_SELECTION); ADDC(GLFW_CLIPBOARD); ADDC(GLFW_LAYER_SHELL_NONE); ADDC(GLFW_LAYER_SHELL_PANEL); ADDC(GLFW_LAYER_SHELL_BACKGROUND); ADDC(GLFW_LAYER_SHELL_TOP); ADDC(GLFW_LAYER_SHELL_OVERLAY); ADDC(GLFW_FOCUS_NOT_ALLOWED); ADDC(GLFW_FOCUS_EXCLUSIVE); ADDC(GLFW_FOCUS_ON_DEMAND); - ADDC(GLFW_EDGE_TOP); ADDC(GLFW_EDGE_BOTTOM); ADDC(GLFW_EDGE_LEFT); ADDC(GLFW_EDGE_RIGHT); ADDC(GLFW_EDGE_CENTER); ADDC(GLFW_EDGE_NONE) + ADDC(GLFW_EDGE_TOP); ADDC(GLFW_EDGE_BOTTOM); ADDC(GLFW_EDGE_LEFT); ADDC(GLFW_EDGE_RIGHT); ADDC(GLFW_EDGE_CENTER); ADDC(GLFW_EDGE_NONE); ADDC(GLFW_COLOR_SCHEME_NO_PREFERENCE); ADDC(GLFW_COLOR_SCHEME_DARK); ADDC(GLFW_COLOR_SCHEME_LIGHT); /* start glfw functional keys (auto generated by gen-key-constants.py do not edit) */