Skip to content

Commit 7536ce5

Browse files
committed
Merge branch 'fix-incremental-os-panel' of https://github.com/alex-huff/kitty
2 parents b401e12 + 0daab6a commit 7536ce5

File tree

4 files changed

+40
-17
lines changed

4 files changed

+40
-17
lines changed

kittens/panel/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import sys
66
from contextlib import suppress
77
from functools import partial
8-
from typing import Iterable, Mapping, Sequence
8+
from typing import Any, Iterable, Mapping, Sequence
99

1010
from kitty.cli import parse_args
1111
from kitty.cli_stub import PanelCLIOptions
@@ -46,7 +46,7 @@ def panel_kitten_options_spec() -> str:
4646
return ans
4747

4848

49-
def parse_panel_args(args: list[str], track_seen_options: set[str] | None = None) -> tuple[PanelCLIOptions, list[str]]:
49+
def parse_panel_args(args: list[str], track_seen_options: dict[str, Any] | None = None) -> tuple[PanelCLIOptions, list[str]]:
5050
return parse_args(
5151
args, panel_kitten_options_spec, usage, help_text, 'kitty +kitten panel',
5252
result_class=PanelCLIOptions, track_seen_options=track_seen_options)

kitty/cli.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -593,22 +593,22 @@ def handle_version(self) -> NoReturn:
593593

594594
def apply_preparsed_cli_flags(
595595
preparsed_from_c: PreparsedCLIFlags, ans: Any, create_oc: Callable[[], Options],
596-
track_seen_options: set[str] | None = None
596+
track_seen_options: dict[str, Any] | None = None
597597
) -> list[str]:
598598
for key, (val, is_seen) in preparsed_from_c[0].items():
599599
if key == 'help' and is_seen and val:
600600
create_oc().handle_help()
601601
elif key == 'version' and is_seen and val:
602602
create_oc().handle_version()
603603
if is_seen and track_seen_options is not None:
604-
track_seen_options.add(key)
604+
track_seen_options[key] = val
605605
setattr(ans, key, val)
606606
return preparsed_from_c[1]
607607

608608

609609
def parse_cmdline_inner(
610610
args: list[str], oc: Options, disabled: OptionSpecSeq, names_map: dict[str, OptionDict],
611-
values_map: dict[str, OptionDict], ans: Any, track_seen_options: set[str] | None = None
611+
values_map: dict[str, OptionDict], ans: Any, track_seen_options: dict[str, Any] | None = None
612612
) -> list[str]:
613613
preparsed = parse_cli_from_spec(args, names_map, values_map)
614614
leftover_args = apply_preparsed_cli_flags(preparsed, ans, lambda: oc, track_seen_options)
@@ -620,7 +620,7 @@ def parse_cmdline_inner(
620620

621621
def parse_cmdline(
622622
oc: Options, disabled: OptionSpecSeq, ans: Any, args: list[str] | None = None,
623-
track_seen_options: set[str] | None = None
623+
track_seen_options: dict[str, Any] | None = None
624624
) -> list[str]:
625625
names_map = oc.names_map.copy()
626626
values_map = oc.values_map.copy()
@@ -677,7 +677,7 @@ def parse_args(
677677
appname: str | None = None,
678678
result_class: type[T] | None = None,
679679
preparsed_from_c: PreparsedCLIFlags | None = None,
680-
track_seen_options: set[str] | None = None,
680+
track_seen_options: dict[str, Any] | None = None,
681681
) -> tuple[T, list[str]]:
682682
if result_class is not None:
683683
ans = result_class()

kitty/launch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ def get_env(opts: LaunchCLIOptions, active_child: Child | None = None, base_env:
443443
return env
444444

445445

446-
def layer_shell_config_from_panel_opts(panel_opts: Iterable[str], track_seen_options: set[str] | None = None) -> LayerShellConfig:
446+
def layer_shell_config_from_panel_opts(panel_opts: Iterable[str], track_seen_options: dict[str, Any] | None = None) -> LayerShellConfig:
447447
from kittens.panel.main import layer_shell_config, parse_panel_args
448448
args = [('' if x.startswith('--') else '--') + x for x in panel_opts]
449449
try:

kitty/rc/resize_os_window.py

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
#!/usr/bin/env python
22
# License: GPLv3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
33

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
511

612
from .base import (
713
MATCH_WINDOW_OPTION,
@@ -73,7 +79,7 @@ class ResizeOSWindow(RemoteCommand):
7379
Treat the specified sizes as increments on the existing window size
7480
instead of absolute sizes. When using :option:`--action`=:code:`os-panel`,
7581
only the specified settings are changed, otherwise non-specified settings
76-
are reset to default.
82+
keep their current value.
7783
7884
7985
--self
@@ -119,23 +125,40 @@ def response_from_kitty(self, boss: Boss, window: Window | None, payload_get: Pa
119125
if not panels:
120126
raise RemoteControlErrorWithoutTraceback('Must specify at least one panel setting')
121127
from kitty.launch import layer_shell_config_from_panel_opts
122-
seen_options: set[str] = set()
128+
seen_options: dict[str, Any] = {}
123129
try:
124130
lsc = layer_shell_config_from_panel_opts(panels, track_seen_options=seen_options)
125131
except Exception as e:
126132
raise RemoteControlErrorWithoutTraceback(
127133
f'Invalid panel options specified: {e}')
128134
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+
}
129150
existing = layer_shell_config_for_os_window(os_window_id)
130151
if existing is None:
131152
raise RemoteControlErrorWithoutTraceback(
132153
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)
139162
if not set_layer_shell_config(os_window_id, lsc):
140163
raise RemoteControlErrorWithoutTraceback(f'Failed to change panel configuration for OS Window {os_window_id}')
141164
elif ac == 'toggle-visibility':

0 commit comments

Comments
 (0)