mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-05-13 08:26:56 +00:00
Panel: add options for margin
This commit is contained in:
parent
ce2bcbb92d
commit
5f1c603220
6 changed files with 59 additions and 9 deletions
4
glfw/glfw3.h
vendored
4
glfw/glfw3.h
vendored
|
|
@ -1313,6 +1313,10 @@ typedef struct GLFWLayerShellConfig {
|
|||
GLFWFocusPolicy focus_policy;
|
||||
unsigned x_size_in_cells;
|
||||
unsigned y_size_in_cells;
|
||||
unsigned requested_top_margin;
|
||||
unsigned requested_left_margin;
|
||||
unsigned requested_bottom_margin;
|
||||
unsigned requested_right_margin;
|
||||
void (*size_callback)(GLFWwindow *window, const struct GLFWLayerShellConfig *config, unsigned monitor_width, unsigned monitor_height, uint32_t *width, uint32_t *height);
|
||||
} GLFWLayerShellConfig;
|
||||
|
||||
|
|
|
|||
3
glfw/wl_window.c
vendored
3
glfw/wl_window.c
vendored
|
|
@ -999,6 +999,7 @@ layer_set_properties(_GLFWwindow *window) {
|
|||
exclusive_zone = window->wl.width;
|
||||
break;
|
||||
case GLFW_EDGE_NONE:
|
||||
which_anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM; // None is anchored to "top left"
|
||||
panel_width = window->wl.width;
|
||||
panel_width = window->wl.height;
|
||||
break;
|
||||
|
|
@ -1010,7 +1011,7 @@ layer_set_properties(_GLFWwindow *window) {
|
|||
debug("Compositor will be informed that layer size: %dx%d viewport: %dx%d at next surface commit\n", panel_width, panel_height, window->wl.width, window->wl.height);
|
||||
zwlr_layer_surface_v1_set_anchor(surface, which_anchor);
|
||||
zwlr_layer_surface_v1_set_exclusive_zone(surface, exclusive_zone);
|
||||
zwlr_layer_surface_v1_set_margin(surface, 0, 0, 0, 0);
|
||||
zwlr_layer_surface_v1_set_margin(surface, window->wl.layer_shell.config.requested_top_margin, window->wl.layer_shell.config.requested_right_margin, window->wl.layer_shell.config.requested_bottom_margin, window->wl.layer_shell.config.requested_left_margin);
|
||||
zwlr_layer_surface_v1_set_keyboard_interactivity(surface, focus_policy);
|
||||
#undef surface
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,13 +28,37 @@ OPTIONS = r'''
|
|||
--lines
|
||||
type=int
|
||||
default=1
|
||||
The number of lines shown in the panel if horizontal. Ignored for background panels.
|
||||
The number of lines shown in the panel. Ignored for background and vertical panels.
|
||||
|
||||
|
||||
--columns
|
||||
type=int
|
||||
default=1
|
||||
The number of columns shown in the panel if vertical. Ignored for background panels.
|
||||
The number of columns shown in the panel. Ignored for background and horizontal panels.
|
||||
|
||||
|
||||
--margin-top
|
||||
type=int
|
||||
default=0
|
||||
Request a given top margin to the compositor.
|
||||
|
||||
|
||||
--margin-left
|
||||
type=int
|
||||
default=0
|
||||
Request a given left margin to the compositor.
|
||||
|
||||
|
||||
--margin-bottom
|
||||
type=int
|
||||
default=0
|
||||
Request a given bottom margin to the compositor.
|
||||
|
||||
|
||||
--margin-right
|
||||
type=int
|
||||
default=0
|
||||
Request a given right margin to the compositor.
|
||||
|
||||
|
||||
--edge
|
||||
|
|
@ -45,7 +69,8 @@ Which edge of the screen to place the panel on. Note that some window managers
|
|||
The value :code:`background` means make the panel the "desktop wallpaper". This
|
||||
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.
|
||||
kitten. The value :code:`none` allow free placement of the window
|
||||
when combined with explicit margin parameters.
|
||||
|
||||
|
||||
--layer
|
||||
|
|
@ -53,7 +78,7 @@ choices=background, bottom, top, overlay
|
|||
default=bottom
|
||||
On a compositor that supports the wlr layer shell protocol, specifies the layer
|
||||
on which the panel should be drawn. This parameter is ignored and set to
|
||||
:code:`background` if --edge is set to :code:`background`.
|
||||
:code:`background` if :option:`--edge` is set to :code:`background`.
|
||||
|
||||
|
||||
--config -c
|
||||
|
|
@ -173,7 +198,15 @@ 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}.get(opts.edge, GLFW_EDGE_TOP)
|
||||
return LayerShellConfig(type=ltype, edge=edge, x_size_in_cells=max(1, opts.columns), y_size_in_cells=max(1, opts.lines), output_name=opts.output_name or '')
|
||||
return LayerShellConfig(type=ltype,
|
||||
edge=edge,
|
||||
x_size_in_cells=max(1, opts.columns),
|
||||
y_size_in_cells=max(1, opts.lines),
|
||||
requested_top_margin=max(0, opts.margin-top),
|
||||
requested_left_margin=max(0, opts.margin-left),
|
||||
requested_bottom_margin=max(0, opts.margin-bottom),
|
||||
requested_right_margin=max(0,opts.margin-right),
|
||||
output_name=opts.output_name or '')
|
||||
|
||||
|
||||
def main(sys_args: List[str]) -> None:
|
||||
|
|
|
|||
4
kitty/glfw-wrapper.h
generated
4
kitty/glfw-wrapper.h
generated
|
|
@ -1051,6 +1051,10 @@ typedef struct GLFWLayerShellConfig {
|
|||
GLFWFocusPolicy focus_policy;
|
||||
unsigned x_size_in_cells;
|
||||
unsigned y_size_in_cells;
|
||||
unsigned requested_top_margin;
|
||||
unsigned requested_left_margin;
|
||||
unsigned requested_bottom_margin;
|
||||
unsigned requested_right_margin;
|
||||
void (*size_callback)(GLFWwindow *window, const struct GLFWLayerShellConfig *config, unsigned monitor_width, unsigned monitor_height, uint32_t *width, uint32_t *height);
|
||||
} GLFWLayerShellConfig;
|
||||
|
||||
|
|
|
|||
10
kitty/glfw.c
10
kitty/glfw.c
|
|
@ -1029,7 +1029,7 @@ 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 = "top"; break;
|
||||
case GLFW_EDGE_NONE: edge = "left"; break; // GLFW_EDGE_NONE is considered as "top left"
|
||||
}
|
||||
if (!edge_spacing_func) {
|
||||
log_error("Attempt to call edge_spacing() without first setting edge_spacing_func");
|
||||
|
|
@ -1069,10 +1069,10 @@ calculate_layer_shell_window_size(
|
|||
spacing += (fonts_data->cell_height * config->y_size_in_cells) / yscale;
|
||||
*height = (uint32_t)(1. + spacing);
|
||||
} else {
|
||||
double spacing_x = edge_spacing(GLFW_EDGE_LEFT) + edge_spacing(GLFW_EDGE_RIGHT);
|
||||
double spacing_x = edge_spacing(GLFW_EDGE_LEFT);
|
||||
spacing_x *= xdpi / 72.;
|
||||
spacing_x += (fonts_data->cell_width * config->x_size_in_cells) / xscale;
|
||||
double spacing_y = edge_spacing(GLFW_EDGE_TOP) + edge_spacing(GLFW_EDGE_BOTTOM);
|
||||
double spacing_y = edge_spacing(GLFW_EDGE_TOP);
|
||||
spacing_y *= ydpi / 72.;
|
||||
spacing_y += (fonts_data->cell_height * config->y_size_in_cells) / yscale;
|
||||
*width = (uint32_t)(1. + spacing_x);
|
||||
|
|
@ -1090,6 +1090,10 @@ translate_layer_shell_config(PyObject *p, GLFWLayerShellConfig *ans) {
|
|||
A(focus_policy, PyLong_Check, PyLong_AsLong);
|
||||
A(x_size_in_cells, PyLong_Check, PyLong_AsLong);
|
||||
A(y_size_in_cells, PyLong_Check, PyLong_AsLong);
|
||||
A(requested_top_margin, PyLong_Check, PyLong_AsLong);
|
||||
A(requested_left_margin, PyLong_Check, PyLong_AsLong);
|
||||
A(requested_bottom_margin, PyLong_Check, PyLong_AsLong);
|
||||
A(requested_right_margin, PyLong_Check, PyLong_AsLong);
|
||||
#undef A
|
||||
#define A(attr) { \
|
||||
RAII_PyObject(attr, PyObject_GetAttrString(p, #attr)); if (attr == NULL) return false; \
|
||||
|
|
|
|||
|
|
@ -74,6 +74,10 @@ class LayerShellConfig(NamedTuple):
|
|||
output_name: str = ''
|
||||
x_size_in_cells: int = 0
|
||||
y_size_in_cells: int = 0
|
||||
requested_top_margin: int = 0
|
||||
requested_left_margin: int = 0
|
||||
requested_bottom_margin: int = 0
|
||||
requested_right_margin: int = 0
|
||||
|
||||
|
||||
def mod_to_names(mods: int, has_kitty_mod: bool = False, kitty_mod: int = 0) -> Iterator[str]:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue