From a9bc9962f4d4497e4632ce6fc1c1c41380089b64 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 2 May 2025 08:37:49 +0530 Subject: [PATCH] X11: add support for --output-name --- glfw/x11_window.c | 21 +++++++++++++++++++-- kitty/simple_cli_definitions.py | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/glfw/x11_window.c b/glfw/x11_window.c index b00c3796a..576eda080 100644 --- a/glfw/x11_window.c +++ b/glfw/x11_window.c @@ -538,13 +538,28 @@ typedef struct WindowGeometry { strut_type struts[12]; } WindowGeometry; +#define config (window->x11.layer_shell.config) + +static _GLFWmonitor* +find_monitor_by_name(const char* name) { + if (!name || !name[0]) return (_GLFWmonitor*)glfwGetPrimaryMonitor();; + for (int i = 0; i < _glfw.monitorCount; i++) { + _GLFWmonitor *m = _glfw.monitors[i]; + if (strcmp(m->name, name) == 0) return m; + } + return (_GLFWmonitor*)glfwGetPrimaryMonitor();; +} + + static WindowGeometry calculate_layer_geometry(_GLFWwindow *window) { + _GLFWmonitor *monitor = find_monitor_by_name(config.output_name); MonitorGeometry mg = _glfwPlatformGetMonitorGeometry((_GLFWmonitor*)glfwGetPrimaryMonitor()); WindowGeometry ans = {0}; + debug_rendering("Monitor: %s full: %dx%d@%dx%d workarea: %dx%d@%dx%d\n", monitor->name, + mg.full.width, mg.full.height, mg.full.x, mg.full.y, mg.workarea.width, mg.workarea.height, mg.workarea.x, mg.workarea.y); ans.width = mg.full.width; ans.height = mg.full.height; ans.x = mg.full.x; ans.y = mg.full.y; -#define config (window->x11.layer_shell.config) ans.needs_strut = config.type == GLFW_LAYER_SHELL_PANEL; if (config.type == GLFW_LAYER_SHELL_BACKGROUND) { ans.x += config.requested_left_margin; ans.y += config.requested_top_margin; @@ -556,7 +571,6 @@ calculate_layer_geometry(_GLFWwindow *window) { _glfwPlatformGetWindowContentScale(window, &xscale, &yscale); unsigned cell_width, cell_height; double left_edge_spacing, top_edge_spacing, right_edge_spacing, bottom_edge_spacing; config.size_callback((GLFWwindow*)window, xscale, yscale, &cell_width, &cell_height, &left_edge_spacing, &top_edge_spacing, &right_edge_spacing, &bottom_edge_spacing); - debug_rendering("Calculating layer size at scale: %f cell size: (%u, %u) \n", xscale, cell_width, cell_height) double spacing_x = left_edge_spacing + right_edge_spacing; double spacing_y = top_edge_spacing + bottom_edge_spacing; double xsz = config.x_size_in_pixels ? (unsigned)(config.x_size_in_pixels * xscale) : (cell_width * config.x_size_in_cells); @@ -600,6 +614,8 @@ calculate_layer_geometry(_GLFWwindow *window) { ans.width = m.width - config.requested_right_margin - config.requested_left_margin; break; } + debug_rendering("Calculating layer geometry at scale: %f cell size: (%u, %u) -> %dx%d@%dx%d needs_strut: %d\n", + xscale, cell_width, cell_height, ans.width, ans.height, ans.x, ans.y, ans.needs_strut) return ans; } @@ -720,6 +736,7 @@ static bool createNativeWindow(_GLFWwindow* window, _glfwGrabErrorHandlerX11(); window->x11.parent = _glfw.x11.root; + debug_rendering("Creating window with geometry: %dx%d@%dx%d\n", wg.width, wg.height, wg.x, wg.y); window->x11.handle = XCreateWindow(_glfw.x11.display, _glfw.x11.root, wg.x, wg.y, // Position diff --git a/kitty/simple_cli_definitions.py b/kitty/simple_cli_definitions.py index cbac502fb..7c3a7c1f9 100644 --- a/kitty/simple_cli_definitions.py +++ b/kitty/simple_cli_definitions.py @@ -631,7 +631,7 @@ Syntax: :italic:`name=value`. For example: :option:`kitty +kitten panel -o` font --output-name -On Wayland, the panel can only be displayed on a single monitor (output) at a time. This allows +On Wayland or X11, the panel can only be displayed on a single monitor (output) at a time. This allows you to specify which output is used, by name. If not specified the compositor will choose an output automatically, typically the last output the user interacted with or the primary monitor.