diff --git a/docs/changelog.rst b/docs/changelog.rst index 7587f9909..ee29f6e81 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -52,6 +52,8 @@ Detailed list of changes - macOS: When running the default shell with the login program fix :file:`~/.hushlogin` not being respected when opening windows not in the home directory (:iss:`6689`) +- ``kitten @ set-background-opacity`` - add a new ``--toggle`` flag to easily switch opacity between the specified value and the default (:iss:`6691`) + 0.30.1 [2023-10-05] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/rc/set_background_opacity.py b/kitty/rc/set_background_opacity.py index c07b34fe9..dfaf9b6b1 100644 --- a/kitty/rc/set_background_opacity.py +++ b/kitty/rc/set_background_opacity.py @@ -29,6 +29,7 @@ class SetBackgroundOpacity(RemoteCommand): match_window/str: Window to change opacity in match_tab/str: Tab to change opacity in all/bool: Boolean indicating operate on all windows + toggle/bool: Boolean indicating if opacity should be toggled between the default and the specified value ''' short_desc = 'Set the background opacity' @@ -41,26 +42,37 @@ class SetBackgroundOpacity(RemoteCommand): options_spec = '''\ --all -a type=bool-set -By default, background opacity are only changed for the currently active window. This option will +By default, background opacity are only changed for the currently active OS window. This option will cause background opacity to be changed in all windows. + +--toggle +type=bool-set +When specified, the background opacity for the matching OS windows will be reset to default if it is currently +equal to the specified value, otherwise it will be set to the specified value. ''' + '\n\n' + MATCH_WINDOW_OPTION + '\n\n' + MATCH_TAB_OPTION.replace('--match -m', '--match-tab -t') args = RemoteCommand.Args(spec='OPACITY', count=1, json_field='opacity', special_parse='parse_opacity(args[0])') def message_to_kitty(self, global_opts: RCOptions, opts: 'CLIOptions', args: ArgsType) -> PayloadType: opacity = max(0.1, min(float(args[0]), 1.0)) return { - 'opacity': opacity, 'match_window': opts.match, - 'all': opts.all, 'match_tab': opts.match_tab + 'opacity': opacity, 'match_window': opts.match, + 'all': opts.all, 'match_tab': opts.match_tab, 'toggle': opts.toggle, } def response_from_kitty(self, boss: Boss, window: Optional[Window], payload_get: PayloadGetType) -> ResponseType: - from kitty.fast_data_types import get_options - if not get_options().dynamic_background_opacity: + from kitty.fast_data_types import background_opacity_of, get_options + opts = get_options() + if not opts.dynamic_background_opacity: raise OpacityError('You must turn on the dynamic_background_opacity option in kitty.conf to be able to set background opacity') windows = self.windows_for_payload(boss, window, payload_get) for os_window_id in {w.os_window_id for w in windows if w}: - boss._set_os_window_background_opacity(os_window_id, payload_get('opacity')) + val: float = payload_get('opacity') + if payload_get('toggle'): + current = background_opacity_of(os_window_id) + if current == val: + val = opts.background_opacity + boss._set_os_window_background_opacity(os_window_id, val) return None