Skip to content

Commit 6282a46

Browse files
committed
A new centered panel type that is sized
1 parent 6afe3cb commit 6282a46

File tree

10 files changed

+32
-12
lines changed

10 files changed

+32
-12
lines changed

docs/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ Detailed list of changes
121121

122122
- A new setting :opt:`remember_window_position` to optionally use the position of the last closed kitty OS Window as the position of the first kitty OS Window when running a new kitty instance (:pull:`8601`)
123123

124+
- Panel kitten: A new ``center-sized`` value for :option:`--edge <kitty +kitten panel --edge>` to allow easily creating sized and centered panels
125+
124126

125127
0.42.0 [2025-05-11]
126128
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

glfw/cocoa_window.m

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,6 +2031,11 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window)
20312031
x += width - panel_width + 1.;
20322032
width = panel_width;
20332033
break;
2034+
case GLFW_EDGE_CENTER_SIZED:
2035+
x += (width - panel_width) / 2;
2036+
y += (height - panel_height) / 2;
2037+
width = panel_width; height = panel_height;
2038+
break;
20342039
default: // top left
20352040
y += height - panel_height + 1.;
20362041
height = panel_height; width = panel_width;
@@ -2040,8 +2045,10 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window)
20402045
if (height < 1.) height = NSWidth(screen.visibleFrame);
20412046
}
20422047

2043-
x += config.requested_left_margin; width -= config.requested_left_margin + config.requested_right_margin;
2044-
y += config.requested_bottom_margin; height -= config.requested_top_margin + config.requested_bottom_margin;
2048+
if (config.edge != GLFW_EDGE_CENTER_SIZED) {
2049+
x += config.requested_left_margin; width -= config.requested_left_margin + config.requested_right_margin;
2050+
y += config.requested_bottom_margin; height -= config.requested_top_margin + config.requested_bottom_margin;
2051+
}
20452052

20462053
[nswindow setAnimationBehavior:animation_behavior];
20472054
[nswindow setLevel:level];

glfw/glfw3.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1302,7 +1302,7 @@ typedef struct GLFWkeyevent
13021302

13031303
typedef enum { GLFW_LAYER_SHELL_NONE, GLFW_LAYER_SHELL_BACKGROUND, GLFW_LAYER_SHELL_PANEL, GLFW_LAYER_SHELL_TOP, GLFW_LAYER_SHELL_OVERLAY } GLFWLayerShellType;
13041304

1305-
typedef enum { GLFW_EDGE_TOP, GLFW_EDGE_BOTTOM, GLFW_EDGE_LEFT, GLFW_EDGE_RIGHT, GLFW_EDGE_CENTER, GLFW_EDGE_NONE } GLFWEdge;
1305+
typedef enum { GLFW_EDGE_TOP, GLFW_EDGE_BOTTOM, GLFW_EDGE_LEFT, GLFW_EDGE_RIGHT, GLFW_EDGE_CENTER, GLFW_EDGE_NONE, GLFW_EDGE_CENTER_SIZED } GLFWEdge;
13061306

13071307
typedef enum { GLFW_FOCUS_NOT_ALLOWED, GLFW_FOCUS_EXCLUSIVE, GLFW_FOCUS_ON_DEMAND} GLFWFocusPolicy;
13081308

glfw/wl_window.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,12 +1028,13 @@ layer_set_properties(const _GLFWwindow *window, bool during_creation, uint32_t w
10281028
if (!config.override_exclusive_zone) exclusive_zone = width;
10291029
break;
10301030
case GLFW_EDGE_CENTER:
1031-
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;
1031+
break;
1032+
case GLFW_EDGE_CENTER_SIZED:
1033+
panel_width = width; panel_height = height;
10321034
break;
10331035
case GLFW_EDGE_NONE:
10341036
which_anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP;
1035-
panel_width = width;
1036-
panel_height = height;
1037+
panel_width = width; panel_height = height;
10371038
break;
10381039
}
10391040
}

glfw/x11_window.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,11 @@ calculate_layer_geometry(_GLFWwindow *window) {
606606
ans.width = m.width - config.requested_right_margin - config.requested_left_margin;
607607
ans.struts[s.bottom] = ans.height; ans.struts[s.bottom_end_x] = ans.width;
608608
break;
609+
case GLFW_EDGE_CENTER_SIZED:
610+
ans.needs_strut = false;
611+
ans.x = (m.width - ans.width) / 2;
612+
ans.y = (m.height - ans.height) / 2;
613+
break;
609614
default:
610615
ans.needs_strut = false;
611616
ans.x = m.x + config.requested_left_margin;

kittens/panel/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from kitty.fast_data_types import (
1414
GLFW_EDGE_BOTTOM,
1515
GLFW_EDGE_CENTER,
16+
GLFW_EDGE_CENTER_SIZED,
1617
GLFW_EDGE_LEFT,
1718
GLFW_EDGE_NONE,
1819
GLFW_EDGE_RIGHT,
@@ -66,7 +67,8 @@ def layer_shell_config(opts: PanelCLIOptions) -> LayerShellConfig:
6667
}.get(opts.layer, GLFW_LAYER_SHELL_PANEL)
6768
ltype = GLFW_LAYER_SHELL_BACKGROUND if opts.edge == 'background' else ltype
6869
edge = {
69-
'top': GLFW_EDGE_TOP, 'bottom': GLFW_EDGE_BOTTOM, 'left': GLFW_EDGE_LEFT, 'right': GLFW_EDGE_RIGHT, 'center': GLFW_EDGE_CENTER, 'none': GLFW_EDGE_NONE
70+
'top': GLFW_EDGE_TOP, 'bottom': GLFW_EDGE_BOTTOM, 'left': GLFW_EDGE_LEFT, 'right': GLFW_EDGE_RIGHT,
71+
'center': GLFW_EDGE_CENTER, 'none': GLFW_EDGE_NONE, 'center-sized': GLFW_EDGE_CENTER_SIZED,
7072
}.get(opts.edge, GLFW_EDGE_TOP)
7173
focus_policy = {
7274
'not-allowed': GLFW_FOCUS_NOT_ALLOWED, 'exclusive': GLFW_FOCUS_EXCLUSIVE, 'on-demand': GLFW_FOCUS_ON_DEMAND

kitty/fast_data_types.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ GLFW_EDGE_BOTTOM: int
2525
GLFW_EDGE_LEFT: int
2626
GLFW_EDGE_RIGHT: int
2727
GLFW_EDGE_CENTER: int
28+
GLFW_EDGE_CENTER_SIZED: int
2829
GLFW_EDGE_NONE: int
2930
GLFW_FOCUS_NOT_ALLOWED: int
3031
GLFW_FOCUS_EXCLUSIVE: int

kitty/glfw-wrapper.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

kitty/glfw.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ edge_spacing(GLFWEdge which) {
12311231
case GLFW_EDGE_BOTTOM: edge = "bottom"; break;
12321232
case GLFW_EDGE_LEFT: edge = "left"; break;
12331233
case GLFW_EDGE_RIGHT: edge = "right"; break;
1234-
case GLFW_EDGE_CENTER: case GLFW_EDGE_NONE: return 0;
1234+
case GLFW_EDGE_CENTER: case GLFW_EDGE_NONE: case GLFW_EDGE_CENTER_SIZED: return 0;
12351235
}
12361236
if (!edge_spacing_func) {
12371237
log_error("Attempt to call edge_spacing() without first setting edge_spacing_func");
@@ -2690,6 +2690,7 @@ init_glfw(PyObject *m) {
26902690
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);
26912691
ADDC(GLFW_FOCUS_NOT_ALLOWED); ADDC(GLFW_FOCUS_EXCLUSIVE); ADDC(GLFW_FOCUS_ON_DEMAND);
26922692
ADDC(GLFW_EDGE_TOP); ADDC(GLFW_EDGE_BOTTOM); ADDC(GLFW_EDGE_LEFT); ADDC(GLFW_EDGE_RIGHT); ADDC(GLFW_EDGE_CENTER); ADDC(GLFW_EDGE_NONE);
2693+
ADDC(GLFW_EDGE_CENTER_SIZED);
26932694
ADDC(GLFW_COLOR_SCHEME_NO_PREFERENCE); ADDC(GLFW_COLOR_SCHEME_DARK); ADDC(GLFW_COLOR_SCHEME_LIGHT);
26942695

26952696
/* start glfw functional keys (auto generated by gen-key-constants.py do not edit) */

kitty/simple_cli_definitions.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -601,20 +601,21 @@ def build_panel_cli_spec(defaults: dict[str, str]) -> str:
601601
602602
603603
--edge
604-
choices=top,bottom,left,right,background,center,none
604+
choices=top,bottom,left,right,background,center,center-sized,none
605605
default={edge}
606606
Which edge of the screen to place the panel on. Note that some window managers
607607
(such as i3) do not support placing docked windows on the left and right edges.
608608
The value :code:`background` means make the panel the "desktop wallpaper".
609609
Note that when using sway if you set a background in your sway config it will
610610
cover the background drawn using this kitten.
611-
Additionally, there are two more values: :code:`center` and :code:`none`.
611+
Additionally, there are three more values: :code:`center`, :code:`center-sized` and :code:`none`.
612612
The value :code:`center` anchors the panel to all sides and covers the entire
613613
display (on macOS the part of the display not covered by titlebar and dock).
614614
The panel can be shrunk and placed using the margin parameters.
615615
The value :code:`none` anchors the panel to the top left corner and should be
616616
placed and using the margin parameters. Its size is set by :option:`--lines`
617-
and :option:`--columns`.
617+
and :option:`--columns`. The value :code:`center-sized` is just like :code:`none` except
618+
that the panel is centered instead of in the top left corner and the margins have no effect.
618619
619620
620621
--layer

0 commit comments

Comments
 (0)