Skip to content

Commit

Permalink
When dragging in rectangle select mode use a crosshair mouse cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
kovidgoyal committed Feb 23, 2025
1 parent 1effdd8 commit 2a71492
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 61 deletions.
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ Detailed list of changes

- hints/unicode_input kittens: Do not lose keypresses that are sent very rapidly via an automation tool immediately after the kitten is launched (:iss:`7089`)

- When dragging in rectangle select mode use a crosshair mouse cursor configurable via :opt:`pointer_shape_when_dragging`


0.37.0 [2024-10-30]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion gen/cursors.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def main(args: list[str]=sys.argv) -> None:
patch_file('glfw/x11_window.c', 'glfw to xc mapping', '\n'.join(f' {x}' for x in glfw_xfont_map))
patch_file('kitty/data-types.h', 'mouse shapes', '\n'.join(f' {x},' for x in enum_to_glfw_map))
patch_file(
'kitty/options/definition.py', 'pointer shape names', '\n'.join(f' {x!r},' for x in kitty_to_enum_map),
'kitty/options/utils.py', 'pointer shape names', '\n'.join(f' {x!r},' for x in kitty_to_enum_map),
start_marker='# ', end_marker='',
)
patch_file('kitty/options/to-c.h', 'pointer shapes', '\n'.join(
Expand Down
2 changes: 1 addition & 1 deletion kitty/glfw.c
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ set_glfw_mouse_pointer_shape_in_window(GLFWwindow *w, MouseShape type) {
case NO_DROP_POINTER: set_glfw_mouse_cursor(w, GLFW_NO_DROP_CURSOR); break;
case GRAB_POINTER: set_glfw_mouse_cursor(w, GLFW_GRAB_CURSOR); break;
case GRABBING_POINTER: set_glfw_mouse_cursor(w, GLFW_GRABBING_CURSOR); break;
/* end enum to glfw */
/* end enum to glfw */
}
}

Expand Down
12 changes: 7 additions & 5 deletions kitty/mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,11 @@ cell_for_pos(Window *w, unsigned int *x, unsigned int *y, bool *in_left_half_of_
#define HANDLER(name) static void name(Window UNUSED *w, int UNUSED button, int UNUSED modifiers, unsigned int UNUSED window_idx)

static void
set_mouse_cursor_when_dragging(void) {
if (mouse_cursor_shape != OPT(pointer_shape_when_dragging)) {
mouse_cursor_shape = OPT(pointer_shape_when_dragging);
set_mouse_cursor_when_dragging(Screen *screen) {
MouseShape expected_shape = OPT(pointer_shape_when_dragging);
if (screen && screen->selections.count && screen->selections.items[0].rectangle_select) expected_shape = OPT(pointer_shape_when_dragging_rectangle);
if (mouse_cursor_shape != expected_shape) {
mouse_cursor_shape = expected_shape;
set_mouse_cursor(mouse_cursor_shape);
}
}
Expand All @@ -276,7 +278,7 @@ update_drag(Window *w) {
if (screen && screen->selections.in_progress) {
screen_update_selection(screen, w->mouse_pos.cell_x, w->mouse_pos.cell_y, w->mouse_pos.in_left_half_of_cell, (SelectionUpdate){0});
}
set_mouse_cursor_when_dragging();
set_mouse_cursor_when_dragging(screen);
}

static bool
Expand Down Expand Up @@ -759,7 +761,7 @@ mouse_selection(Window *w, int code, int button) {
extend_selection(w, false, false);
break;
}
set_mouse_cursor_when_dragging();
set_mouse_cursor_when_dragging(screen);
#undef S
}

Expand Down
45 changes: 4 additions & 41 deletions kitty/options/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from kitty.conf.types import Action, Definition
from kitty.constants import website_url
from kitty.options.utils import pointer_shape_names

definition = Definition(
'kitty',
Expand Down Expand Up @@ -679,43 +680,6 @@
'''
)

pointer_shape_names = (
# start pointer shape names (auto generated by gen-key-constants.py do not edit)
'arrow',
'beam',
'text',
'pointer',
'hand',
'help',
'wait',
'progress',
'crosshair',
'cell',
'vertical-text',
'move',
'e-resize',
'ne-resize',
'nw-resize',
'n-resize',
'se-resize',
'sw-resize',
's-resize',
'w-resize',
'ew-resize',
'ns-resize',
'nesw-resize',
'nwse-resize',
'zoom-in',
'zoom-out',
'alias',
'copy',
'not-allowed',
'no-drop',
'grab',
'grabbing',
# end pointer shape names
)

opt('pointer_shape_when_grabbed', 'arrow',
choices=pointer_shape_names, ctype='pointer_shape',
long_text='''
Expand All @@ -731,10 +695,9 @@
'''
)

opt('pointer_shape_when_dragging', 'beam',
choices=pointer_shape_names, ctype='pointer_shape',
long_text='''
The default shape of the mouse pointer when dragging across text.
opt('pointer_shape_when_dragging', 'beam crosshair', option_type='pointer_shape_when_dragging', ctype='!dragging_pointer_shape', long_text='''
The default shape of the mouse pointer when dragging across text. The optional second value
sets the shape when dragging in rectangular selection mode.
'''
)

Expand Down
13 changes: 4 additions & 9 deletions kitty/options/parse.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion kitty/options/to-c-generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions kitty/options/to-c.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,12 @@ pointer_shape(PyObject *shape_name) {
return TEXT_POINTER;
}

static inline void
dragging_pointer_shape(PyObject *parts, Options *opts) {
opts->pointer_shape_when_dragging = pointer_shape(PyTuple_GET_ITEM(parts, 0));
opts->pointer_shape_when_dragging_rectangle = pointer_shape(PyTuple_GET_ITEM(parts, 1));
}

static inline int
macos_colorspace(PyObject *csname) {
if (PyUnicode_CompareWithASCIIString(csname, "srgb") == 0) return 1;
Expand Down
3 changes: 1 addition & 2 deletions kitty/options/types.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions kitty/options/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1581,6 +1581,55 @@ def visual_bell_duration(spec: str) -> tuple[float, EasingFunction, EasingFuncti
return parse_animation(spec, interval=0.)


pointer_shape_names = (
# start pointer shape names (auto generated by gen-key-constants.py do not edit)
'arrow',
'beam',
'text',
'pointer',
'hand',
'help',
'wait',
'progress',
'crosshair',
'cell',
'vertical-text',
'move',
'e-resize',
'ne-resize',
'nw-resize',
'n-resize',
'se-resize',
'sw-resize',
's-resize',
'w-resize',
'ew-resize',
'ns-resize',
'nesw-resize',
'nwse-resize',
'zoom-in',
'zoom-out',
'alias',
'copy',
'not-allowed',
'no-drop',
'grab',
'grabbing',
# end pointer shape names
)


def pointer_shape_when_dragging(spec: str) -> tuple[str, str]:
parts = spec.split(maxsplit=1)
first = parts[0]
if first not in pointer_shape_names:
raise ValueError(f'{first} is not a valid pointer shape name')
second = parts[1] if len(parts) > 1 else first
if second not in pointer_shape_names:
raise ValueError(f'{second} is not a valid pointer shape name')
return first, second


def transparent_background_colors(spec: str) -> tuple[tuple[Color, float], ...]:
if not spec:
return ()
Expand Down
2 changes: 1 addition & 1 deletion kitty/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ typedef struct {
struct { monotonic_t on_end, on_pause; } resize_debounce_time;
MouseShape pointer_shape_when_grabbed;
MouseShape default_pointer_shape;
MouseShape pointer_shape_when_dragging;
MouseShape pointer_shape_when_dragging, pointer_shape_when_dragging_rectangle;
struct {
UrlPrefix *values;
size_t num, max_prefix_len;
Expand Down

0 comments on commit 2a71492

Please sign in to comment.