|
1 | 1 | #!/usr/bin/env python |
2 | 2 | # License: GPLv3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net> |
3 | 3 |
|
4 | | -from typing import TYPE_CHECKING |
| 4 | +from typing import TYPE_CHECKING, Any |
| 5 | + |
| 6 | +from kitty.fast_data_types import ( |
| 7 | + GLFW_FOCUS_ON_DEMAND, |
| 8 | + GLFW_LAYER_SHELL_BACKGROUND, |
| 9 | +) |
| 10 | +from kitty.types import LayerShellConfig |
5 | 11 |
|
6 | 12 | from .base import ( |
7 | 13 | MATCH_WINDOW_OPTION, |
@@ -73,7 +79,7 @@ class ResizeOSWindow(RemoteCommand): |
73 | 79 | Treat the specified sizes as increments on the existing window size |
74 | 80 | instead of absolute sizes. When using :option:`--action`=:code:`os-panel`, |
75 | 81 | only the specified settings are changed, otherwise non-specified settings |
76 | | -are reset to default. |
| 82 | +keep their current value. |
77 | 83 |
|
78 | 84 |
|
79 | 85 | --self |
@@ -119,23 +125,40 @@ def response_from_kitty(self, boss: Boss, window: Window | None, payload_get: Pa |
119 | 125 | if not panels: |
120 | 126 | raise RemoteControlErrorWithoutTraceback('Must specify at least one panel setting') |
121 | 127 | from kitty.launch import layer_shell_config_from_panel_opts |
122 | | - seen_options: set[str] = set() |
| 128 | + seen_options: dict[str, Any] = {} |
123 | 129 | try: |
124 | 130 | lsc = layer_shell_config_from_panel_opts(panels, track_seen_options=seen_options) |
125 | 131 | except Exception as e: |
126 | 132 | raise RemoteControlErrorWithoutTraceback( |
127 | 133 | f'Invalid panel options specified: {e}') |
128 | 134 | if payload_get('incremental'): |
| 135 | + cli_option_to_lsc_configs_map = { |
| 136 | + 'lines': ('y_size_in_cells', 'y_size_in_pixels'), |
| 137 | + 'columns': ('x_size_in_cells', 'x_size_in_pixels'), |
| 138 | + 'margin_top': ('requested_top_margin',), |
| 139 | + 'margin_left': ('requested_left_margin',), |
| 140 | + 'margin_bottom': ('requested_bottom_margin',), |
| 141 | + 'margin_right': ('requested_right_margin',), |
| 142 | + 'edge': ('edge',), |
| 143 | + 'layer': ('type',), |
| 144 | + 'output_name': ('output_name',), |
| 145 | + 'focus_policy': ('focus_policy',), |
| 146 | + 'exclusive_zone': ('requested_exclusive_zone',), |
| 147 | + 'override_exclusive_zone': ('override_exclusive_zone',), |
| 148 | + 'hide_on_focus_loss': ('hide_on_focus_loss',) |
| 149 | + } |
129 | 150 | existing = layer_shell_config_for_os_window(os_window_id) |
130 | 151 | if existing is None: |
131 | 152 | raise RemoteControlErrorWithoutTraceback( |
132 | 153 | f'The OS Window {os_window_id} has no panel configuration') |
133 | | - defaults = layer_shell_config_from_panel_opts(()) |
134 | | - replacements = {} |
135 | | - for x in lsc._fields: |
136 | | - if x not in seen_options: |
137 | | - replacements[x] = getattr(defaults, x) |
138 | | - lsc = lsc._replace(**replacements) |
| 154 | + for option in seen_options.keys(): |
| 155 | + for config in cli_option_to_lsc_configs_map[option]: |
| 156 | + existing[config] = getattr(lsc, config) |
| 157 | + if seen_options.get('edge', None) == 'background': |
| 158 | + existing['type'] = GLFW_LAYER_SHELL_BACKGROUND |
| 159 | + if existing['hide_on_focus_loss']: |
| 160 | + existing['focus_policy'] = GLFW_FOCUS_ON_DEMAND |
| 161 | + lsc = LayerShellConfig(**existing) |
139 | 162 | if not set_layer_shell_config(os_window_id, lsc): |
140 | 163 | raise RemoteControlErrorWithoutTraceback(f'Failed to change panel configuration for OS Window {os_window_id}') |
141 | 164 | elif ac == 'toggle-visibility': |
|
0 commit comments