mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-22 08:18:08 +02:00
Change mouse_hide_wait to struct, and change mouse_show_* options to optional parameters for struct. mouse_show_* renamed to mouse_unhide_*
This commit is contained in:
@@ -511,43 +511,51 @@ agr('mouse', 'Mouse')
|
||||
|
||||
opt('mouse_hide_wait', '3.0',
|
||||
macos_default='0.0',
|
||||
option_type='float', ctype='time',
|
||||
option_type='mouse_hide_wait', ctype='!mouse_hide_wait',
|
||||
long_text='''
|
||||
Hide mouse cursor after the specified number of seconds of the mouse not being
|
||||
used. Set to zero to disable mouse cursor hiding. Set to a negative value to
|
||||
hide the mouse cursor immediately when typing text. Disabled by default on macOS
|
||||
as getting it to work robustly with the ever-changing sea of bugs that is Cocoa
|
||||
is too much effort.
|
||||
'''
|
||||
)
|
||||
opt('mouse_show_wait', '0.0',
|
||||
option_type='float', ctype='time',
|
||||
long_text='''
|
||||
|
||||
By default, once the cursor is hidden, it is immediately unhidden on any
|
||||
further mouse events.
|
||||
|
||||
Two formats are supported:
|
||||
- "<hide-wait>"
|
||||
- "<hide-wait> <unhide-wait> <unhide-threshold> <scroll-unhide>"
|
||||
|
||||
To change the unhide behavior, the optional parameters <unhide-wait>,
|
||||
<unhide-threshold>, and <scroll-unhide> may be set.
|
||||
|
||||
<unhide-wait>:
|
||||
Waits for the specified number of seconds after mouse events before unhiding the
|
||||
mouse cursor. Set to zero to unhide mouse cursor immediately on mouse activity.
|
||||
This is useful to prevent the mouse cursor from unhiding on accidental swipes on
|
||||
the trackpad.
|
||||
'''
|
||||
)
|
||||
opt('mouse_show_threshold', '40',
|
||||
option_type='positive_int',
|
||||
long_text='''
|
||||
Sets the threshold of mouse activity required to unhide the mouse cursor, when
|
||||
the mouse_show_wait option is non-zero. When mouse_show_wait is zero, this has
|
||||
no effect.
|
||||
|
||||
For example, if mouse_show_threshold is 40 and mouse_show_wait is 2.5, when
|
||||
kitty detects a mouse event, it records the number of mouse events in the next
|
||||
2.5 seconds, and checks if that exceeds 40 * 2.5 = 100. If it does, then the
|
||||
mouse cursor is unhidden, otherwise nothing happens.
|
||||
'''
|
||||
)
|
||||
opt('mouse_scroll_show', 'yes',
|
||||
option_type='to_bool', ctype='bool',
|
||||
long_text='''
|
||||
<unhide-threshold>:
|
||||
Sets the threshold of mouse activity required to unhide the mouse cursor, when
|
||||
the <unhide-wait> option is non-zero. When <unhide-wait> is zero, this has no
|
||||
effect.
|
||||
|
||||
For example, if <unhide-threshold> is 40 and <unhide-wait> is 2.5, when kitty
|
||||
detects a mouse event, it records the number of mouse events in the next 2.5
|
||||
seconds, and checks if that exceeds 40 * 2.5 = 100. If it does, then the mouse
|
||||
cursor is unhidden, otherwise nothing happens.
|
||||
|
||||
<scroll-unhide>:
|
||||
Controls what mouse events may unhide the mouse cursor. If enabled, both scroll
|
||||
and movement events may unhide the cursor. If disabled, only mouse movements can
|
||||
unhide the cursor.
|
||||
|
||||
|
||||
Examples of valid values:
|
||||
- 0.0
|
||||
- 1.0
|
||||
- -1.0
|
||||
- 0.1 3.0 40 yes
|
||||
'''
|
||||
)
|
||||
|
||||
|
||||
13
kitty/options/parse.py
generated
13
kitty/options/parse.py
generated
@@ -14,7 +14,7 @@ from kitty.options.utils import (
|
||||
cursor_trail_decay, deprecated_adjust_line_height, deprecated_hide_window_decorations_aliases,
|
||||
deprecated_macos_show_window_title_in_menubar_alias, deprecated_send_text, disable_ligatures,
|
||||
edge_width, env, filter_notification, font_features, hide_window_decorations, macos_option_as_alt,
|
||||
macos_titlebar_color, menu_map, modify_font, narrow_symbols, notify_on_cmd_finish,
|
||||
macos_titlebar_color, menu_map, modify_font, mouse_hide_wait, narrow_symbols, notify_on_cmd_finish,
|
||||
optional_edge_width, parse_font_spec, parse_map, parse_mouse_map, paste_actions,
|
||||
pointer_shape_when_dragging, remote_control_password, resize_debounce_time, scrollback_lines,
|
||||
scrollback_pager_history_size, shell_integration, store_multiple, symbol_map, tab_activity_symbol,
|
||||
@@ -1137,16 +1137,7 @@ class Parser:
|
||||
ans["modify_font"][k] = v
|
||||
|
||||
def mouse_hide_wait(self, val: str, ans: dict[str, typing.Any]) -> None:
|
||||
ans['mouse_hide_wait'] = float(val)
|
||||
|
||||
def mouse_scroll_show(self, val: str, ans: dict[str, typing.Any]) -> None:
|
||||
ans['mouse_scroll_show'] = to_bool(val)
|
||||
|
||||
def mouse_show_threshold(self, val: str, ans: dict[str, typing.Any]) -> None:
|
||||
ans['mouse_show_threshold'] = positive_int(val)
|
||||
|
||||
def mouse_show_wait(self, val: str, ans: dict[str, typing.Any]) -> None:
|
||||
ans['mouse_show_wait'] = float(val)
|
||||
ans['mouse_hide_wait'] = mouse_hide_wait(val)
|
||||
|
||||
def narrow_symbols(self, val: str, ans: dict[str, typing.Any]) -> None:
|
||||
for k, v in narrow_symbols(val):
|
||||
|
||||
32
kitty/options/to-c-generated.h
generated
32
kitty/options/to-c-generated.h
generated
@@ -319,7 +319,7 @@ convert_from_opts_touch_scroll_multiplier(PyObject *py_opts, Options *opts) {
|
||||
|
||||
static void
|
||||
convert_from_python_mouse_hide_wait(PyObject *val, Options *opts) {
|
||||
opts->mouse_hide_wait = parse_s_double_to_monotonic_t(val);
|
||||
mouse_hide_wait(val, opts);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -330,32 +330,6 @@ convert_from_opts_mouse_hide_wait(PyObject *py_opts, Options *opts) {
|
||||
Py_DECREF(ret);
|
||||
}
|
||||
|
||||
static void
|
||||
convert_from_python_mouse_show_wait(PyObject *val, Options *opts) {
|
||||
opts->mouse_show_wait = parse_s_double_to_monotonic_t(val);
|
||||
}
|
||||
|
||||
static void
|
||||
convert_from_opts_mouse_show_wait(PyObject *py_opts, Options *opts) {
|
||||
PyObject *ret = PyObject_GetAttrString(py_opts, "mouse_show_wait");
|
||||
if (ret == NULL) return;
|
||||
convert_from_python_mouse_show_wait(ret, opts);
|
||||
Py_DECREF(ret);
|
||||
}
|
||||
|
||||
static void
|
||||
convert_from_python_mouse_scroll_show(PyObject *val, Options *opts) {
|
||||
opts->mouse_scroll_show = PyObject_IsTrue(val);
|
||||
}
|
||||
|
||||
static void
|
||||
convert_from_opts_mouse_scroll_show(PyObject *py_opts, Options *opts) {
|
||||
PyObject *ret = PyObject_GetAttrString(py_opts, "mouse_scroll_show");
|
||||
if (ret == NULL) return;
|
||||
convert_from_python_mouse_scroll_show(ret, opts);
|
||||
Py_DECREF(ret);
|
||||
}
|
||||
|
||||
static void
|
||||
convert_from_python_url_color(PyObject *val, Options *opts) {
|
||||
opts->url_color = color_as_int(val);
|
||||
@@ -1253,10 +1227,6 @@ convert_opts_from_python_opts(PyObject *py_opts, Options *opts) {
|
||||
if (PyErr_Occurred()) return false;
|
||||
convert_from_opts_mouse_hide_wait(py_opts, opts);
|
||||
if (PyErr_Occurred()) return false;
|
||||
convert_from_opts_mouse_show_wait(py_opts, opts);
|
||||
if (PyErr_Occurred()) return false;
|
||||
convert_from_opts_mouse_scroll_show(py_opts, opts);
|
||||
if (PyErr_Occurred()) return false;
|
||||
convert_from_opts_url_color(py_opts, opts);
|
||||
if (PyErr_Occurred()) return false;
|
||||
convert_from_opts_url_style(py_opts, opts);
|
||||
|
||||
@@ -197,6 +197,18 @@ visual_bell_duration(PyObject *src, Options *opts) {
|
||||
|
||||
#undef parse_animation
|
||||
|
||||
static inline void
|
||||
mouse_hide_wait(PyObject *val, Options *opts) {
|
||||
if (!PyTuple_Check(val) || PyTuple_GET_SIZE(val) != 4) {
|
||||
PyErr_SetString(PyExc_TypeError, "mouse_hide_wait is not a 4-item tuple");
|
||||
return;
|
||||
}
|
||||
opts->mouse_hide.hide_wait = parse_s_double_to_monotonic_t(PyTuple_GET_ITEM(val, 0));
|
||||
opts->mouse_hide.unhide_wait = parse_s_double_to_monotonic_t(PyTuple_GET_ITEM(val, 1));
|
||||
opts->mouse_hide.unhide_threshold = PyLong_AsLong(PyTuple_GET_ITEM(val, 2));
|
||||
opts->mouse_hide.scroll_unhide = PyObject_IsTrue(PyTuple_GET_ITEM(val, 3));
|
||||
}
|
||||
|
||||
static inline void
|
||||
cursor_trail_decay(PyObject *src, Options *opts) {
|
||||
opts->cursor_trail_decay_fast = PyFloat_AsFloat(PyTuple_GET_ITEM(src, 0));
|
||||
|
||||
10
kitty/options/types.py
generated
10
kitty/options/types.py
generated
@@ -11,7 +11,7 @@ import kitty.fast_data_types
|
||||
from kitty.fonts import FontSpec
|
||||
import kitty.fonts
|
||||
from kitty.options.utils import (
|
||||
AliasMap, KeyDefinition, KeyboardModeMap, MouseMap, MouseMapping, NotifyOnCmdFinish,
|
||||
AliasMap, KeyDefinition, KeyboardModeMap, MouseHideWait, MouseMap, MouseMapping, NotifyOnCmdFinish,
|
||||
TabBarMarginHeight
|
||||
)
|
||||
import kitty.options.utils
|
||||
@@ -396,9 +396,6 @@ option_names = (
|
||||
'modify_font',
|
||||
'mouse_hide_wait',
|
||||
'mouse_map',
|
||||
'mouse_scroll_show',
|
||||
'mouse_show_threshold',
|
||||
'mouse_show_wait',
|
||||
'narrow_symbols',
|
||||
'notify_on_cmd_finish',
|
||||
'open_url_with',
|
||||
@@ -571,10 +568,7 @@ class Options:
|
||||
mark2_foreground: Color = Color(0, 0, 0)
|
||||
mark3_background: Color = Color(242, 116, 188)
|
||||
mark3_foreground: Color = Color(0, 0, 0)
|
||||
mouse_hide_wait: float = 0.0 if is_macos else 3.0
|
||||
mouse_scroll_show: bool = True
|
||||
mouse_show_threshold: int = 40
|
||||
mouse_show_wait: float = 0.0
|
||||
mouse_hide_wait: MouseHideWait = MouseHideWait(hide_wait=0.0, show_wait=0.0, show_threshold=40, scroll_show=True) if is_macos else MouseHideWait(hide_wait=3.0, show_wait=0.0, show_threshold=40, scroll_show=True)
|
||||
notify_on_cmd_finish: NotifyOnCmdFinish = NotifyOnCmdFinish(when='never', duration=5.0, action='notify', cmdline=(), clear_on=('focus', 'next'))
|
||||
open_url_with: list[str] = ['default']
|
||||
paste_actions: frozenset[str] = frozenset({'confirm', 'quote-urls-at-prompt'})
|
||||
|
||||
@@ -1590,6 +1590,24 @@ def cursor_blink_interval(spec: str) -> tuple[float, EasingFunction, EasingFunct
|
||||
return parse_animation(spec)
|
||||
|
||||
|
||||
class MouseHideWait(NamedTuple):
|
||||
hide_wait: float
|
||||
show_wait: float
|
||||
show_threshold: int
|
||||
scroll_show: bool
|
||||
|
||||
|
||||
def mouse_hide_wait(x: str) -> MouseHideWait:
|
||||
parts = x.split(maxsplit=3)
|
||||
if len(parts) != 1 and len(parts) != 4:
|
||||
log_error(f'Invalid mouse_hide_wait: {x}, ignoring')
|
||||
return MouseHideWait(3.0, 0.0, 40, True)
|
||||
if len(parts) == 1:
|
||||
return MouseHideWait(float(parts[0]), 0.0, 40, True)
|
||||
else:
|
||||
return MouseHideWait(float(parts[0]), float(parts[1]), int(parts[2]), to_bool(parts[3]))
|
||||
|
||||
|
||||
def visual_bell_duration(spec: str) -> tuple[float, EasingFunction, EasingFunction]:
|
||||
return parse_animation(spec, interval=0.)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user