From 68649d78dfd05af4cccfcdcbed64924149477af3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 15 Jun 2024 06:12:31 +0530 Subject: [PATCH] Cleanup previous PR --- docs/changelog.rst | 2 ++ kitty/options/definition.py | 14 ++++++-------- kitty/options/parse.py | 6 +++--- kitty/options/to-c-generated.h | 30 +++++++++++++++--------------- kitty/options/types.py | 4 ++-- kitty/options/utils.py | 16 ++++++++-------- kitty/shaders.c | 2 +- kitty/state.h | 3 +-- 8 files changed, 38 insertions(+), 39 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index affbef5f1..7981e411c 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -55,6 +55,8 @@ Detailed list of changes - A new option, :opt:`window_logo_scale` to specify how window logo are scaled with respect to the size of the window containing the logo (:pull:`7534`) +- A new option, :opt:`cursor_shape_unfocused` to specify the shape of the text cursor in unfocused OS windows (:pull:`7544`) + 0.35.1 [2024-05-31] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/options/definition.py b/kitty/options/definition.py index d791c84db..3a54d1130 100644 --- a/kitty/options/definition.py +++ b/kitty/options/definition.py @@ -330,6 +330,12 @@ cursor shape to :code:`beam` at shell prompts. You can avoid this by setting ''' ) +opt('cursor_shape_unfocused', 'hollow', option_type='to_cursor_unfocused_shape', ctype='int', long_text=''' +Defines the text cursor shape when the OS window is not focused. The unfocused +cursor shape can be one of :code:`block`, :code:`beam`, :code:`underline`, +:code:`hollow`. +''') + opt('cursor_beam_thickness', '1.5', option_type='positive_float', ctype='float', long_text='The thickness of the beam cursor (in pts).' @@ -357,14 +363,6 @@ inactivity. Set to zero to never stop blinking. ''' ) -opt('cursor_unfocused_shape', 'hollow', - option_type='to_cursor_unfocused_shape', ctype='int', - long_text=''' -Defines the cursor shape when the terminal window is not focused. The unfocused -cursor shape can be one of :code:`block`, :code:`beam`, :code:`underline`, -:code:`hollow`. -''' - ) egr() # }}} diff --git a/kitty/options/parse.py b/kitty/options/parse.py index b4b21fb95..2c8b7aa4e 100644 --- a/kitty/options/parse.py +++ b/kitty/options/parse.py @@ -920,6 +920,9 @@ class Parser: def cursor_shape(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: ans['cursor_shape'] = to_cursor_shape(val) + def cursor_shape_unfocused(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: + ans['cursor_shape_unfocused'] = to_cursor_unfocused_shape(val) + def cursor_stop_blinking_after(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: ans['cursor_stop_blinking_after'] = positive_float(val) @@ -929,9 +932,6 @@ class Parser: def cursor_underline_thickness(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: ans['cursor_underline_thickness'] = positive_float(val) - def cursor_unfocused_shape(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: - ans['cursor_unfocused_shape'] = to_cursor_unfocused_shape(val) - def default_pointer_shape(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: val = val.lower() if val not in self.choices_for_default_pointer_shape: diff --git a/kitty/options/to-c-generated.h b/kitty/options/to-c-generated.h index d424d327a..6aec2ea6d 100644 --- a/kitty/options/to-c-generated.h +++ b/kitty/options/to-c-generated.h @@ -83,6 +83,19 @@ convert_from_opts_cursor_shape(PyObject *py_opts, Options *opts) { Py_DECREF(ret); } +static void +convert_from_python_cursor_shape_unfocused(PyObject *val, Options *opts) { + opts->cursor_shape_unfocused = PyLong_AsLong(val); +} + +static void +convert_from_opts_cursor_shape_unfocused(PyObject *py_opts, Options *opts) { + PyObject *ret = PyObject_GetAttrString(py_opts, "cursor_shape_unfocused"); + if (ret == NULL) return; + convert_from_python_cursor_shape_unfocused(ret, opts); + Py_DECREF(ret); +} + static void convert_from_python_cursor_beam_thickness(PyObject *val, Options *opts) { opts->cursor_beam_thickness = PyFloat_AsFloat(val); @@ -135,19 +148,6 @@ convert_from_opts_cursor_stop_blinking_after(PyObject *py_opts, Options *opts) { Py_DECREF(ret); } -static void -convert_from_python_cursor_unfocused_shape(PyObject *val, Options *opts) { - opts->cursor_unfocused_shape = PyLong_AsLong(val); -} - -static void -convert_from_opts_cursor_unfocused_shape(PyObject *py_opts, Options *opts) { - PyObject *ret = PyObject_GetAttrString(py_opts, "cursor_unfocused_shape"); - if (ret == NULL) return; - convert_from_python_cursor_unfocused_shape(ret, opts); - Py_DECREF(ret); -} - static void convert_from_python_scrollback_indicator_opacity(PyObject *val, Options *opts) { opts->scrollback_indicator_opacity = PyFloat_AsFloat(val); @@ -1176,6 +1176,8 @@ convert_opts_from_python_opts(PyObject *py_opts, Options *opts) { if (PyErr_Occurred()) return false; convert_from_opts_cursor_shape(py_opts, opts); if (PyErr_Occurred()) return false; + convert_from_opts_cursor_shape_unfocused(py_opts, opts); + if (PyErr_Occurred()) return false; convert_from_opts_cursor_beam_thickness(py_opts, opts); if (PyErr_Occurred()) return false; convert_from_opts_cursor_underline_thickness(py_opts, opts); @@ -1184,8 +1186,6 @@ convert_opts_from_python_opts(PyObject *py_opts, Options *opts) { if (PyErr_Occurred()) return false; convert_from_opts_cursor_stop_blinking_after(py_opts, opts); if (PyErr_Occurred()) return false; - convert_from_opts_cursor_unfocused_shape(py_opts, opts); - if (PyErr_Occurred()) return false; convert_from_opts_scrollback_indicator_opacity(py_opts, opts); if (PyErr_Occurred()) return false; convert_from_opts_scrollback_pager_history_size(py_opts, opts); diff --git a/kitty/options/types.py b/kitty/options/types.py index 39c90a316..b9262c860 100644 --- a/kitty/options/types.py +++ b/kitty/options/types.py @@ -330,10 +330,10 @@ option_names = ( # {{{ 'cursor_beam_thickness', 'cursor_blink_interval', 'cursor_shape', + 'cursor_shape_unfocused', 'cursor_stop_blinking_after', 'cursor_text_color', 'cursor_underline_thickness', - 'cursor_unfocused_shape', 'default_pointer_shape', 'detect_urls', 'dim_opacity', @@ -504,10 +504,10 @@ class Options: cursor_beam_thickness: float = 1.5 cursor_blink_interval: float = -1.0 cursor_shape: int = 1 + cursor_shape_unfocused: int = 0 cursor_stop_blinking_after: float = 15.0 cursor_text_color: typing.Optional[kitty.fast_data_types.Color] = Color(17, 17, 17) cursor_underline_thickness: float = 2.0 - cursor_unfocused_shape: int = 0 default_pointer_shape: choices_for_default_pointer_shape = 'beam' detect_urls: bool = True dim_opacity: float = 0.4 diff --git a/kitty/options/utils.py b/kitty/options/utils.py index 394573df0..3930ad4f3 100644 --- a/kitty/options/utils.py +++ b/kitty/options/utils.py @@ -524,6 +524,13 @@ cshapes = { 'beam': CURSOR_BEAM, 'underline': CURSOR_UNDERLINE } +cshapes_unfocused = { + 'block': CURSOR_BLOCK, + 'beam': CURSOR_BEAM, + 'underline': CURSOR_UNDERLINE, + 'hollow': NO_CURSOR_SHAPE +} + def to_cursor_shape(x: str) -> int: try: @@ -536,19 +543,12 @@ def to_cursor_shape(x: str) -> int: ) -cshapes_unfocused = { - 'block': CURSOR_BLOCK, - 'beam': CURSOR_BEAM, - 'underline': CURSOR_UNDERLINE, - 'hollow': NO_CURSOR_SHAPE -} - def to_cursor_unfocused_shape(x: str) -> int: try: return cshapes_unfocused[x.lower()] except KeyError: raise ValueError( - 'Invalid inactive cursor shape: {} allowed values are {}'.format( + 'Invalid unfocused cursor shape: {} allowed values are {}'.format( x, ', '.join(cshapes_unfocused) ) ) diff --git a/kitty/shaders.c b/kitty/shaders.c index 8805e61ee..9b4f8ebeb 100644 --- a/kitty/shaders.c +++ b/kitty/shaders.c @@ -334,7 +334,7 @@ cell_update_uniform_block(ssize_t vao_idx, Screen *screen, int uniform_buffer, c rd->cursor_fg_sprite_idx = UNDERLINE_IDX; break; } } else { - switch(OPT(cursor_unfocused_shape)) { + switch(OPT(cursor_shape_unfocused)) { default: rd->cursor_fg_sprite_idx = UNFOCUSED_IDX; break; case CURSOR_BEAM: diff --git a/kitty/state.h b/kitty/state.h index 10db4c2cd..a539a88e8 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -38,8 +38,7 @@ typedef struct { double wheel_scroll_multiplier, touch_scroll_multiplier; int wheel_scroll_min_lines; bool enable_audio_bell; - CursorShape cursor_shape; - CursorShape cursor_unfocused_shape; + CursorShape cursor_shape, cursor_shape_unfocused; float cursor_beam_thickness; float cursor_underline_thickness; unsigned int url_style;