Add a new option :opt:pointer_shape_when_grabbed that allows you to control the mouse pointer shape when the terminal programs grabs the pointer

Fixes #1808
This commit is contained in:
Kovid Goyal 2019-07-19 19:34:32 +05:30
parent 4e427d05b7
commit 87ed774cb4
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
5 changed files with 33 additions and 3 deletions

View File

@ -14,6 +14,10 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
- Document the kitty remote control protocol (:iss:`1646`) - Document the kitty remote control protocol (:iss:`1646`)
- Add a new option :opt:`pointer_shape_when_grabbed` that allows you to control
the mouse pointer shape when the terminal programs grabs the pointer
(:iss:`1808`)
- Add an option :opt:`terminal_select_modifiers` to control which modifiers - Add an option :opt:`terminal_select_modifiers` to control which modifiers
are used to override mouse selection even when a terminal application has are used to override mouse selection even when a terminal application has
grabbed the mouse (:iss:`1774`) grabbed the mouse (:iss:`1774`)

View File

@ -472,6 +472,10 @@ o('focus_follows_mouse', False, long_text=_('''
Set the active window to the window under the mouse when Set the active window to the window under the mouse when
moving the mouse around''')) moving the mouse around'''))
o('pointer_shape_when_grabbed', 'arrow', option_type=choices('arrow', 'beam', 'hand'), long_text=('''
The shape of the mouse pointer when the program running in the terminal grabs the mouse.
'''))
# }}} # }}}
g('performance') # {{{ g('performance') # {{{

View File

@ -243,6 +243,11 @@ get_url_sentinel(Line *line, index_type url_start) {
return sentinel; return sentinel;
} }
static inline void
set_mouse_cursor_for_screen(Screen *screen) {
mouse_cursor_shape = screen->modes.mouse_tracking_mode == NO_TRACKING ? BEAM : OPT(pointer_shape_when_grabbed);
}
static inline void static inline void
detect_url(Screen *screen, unsigned int x, unsigned int y) { detect_url(Screen *screen, unsigned int x, unsigned int y) {
bool has_url = false; bool has_url = false;
@ -261,7 +266,7 @@ detect_url(Screen *screen, unsigned int x, unsigned int y) {
extend_url(screen, line, &url_end, &y_extended, sentinel); extend_url(screen, line, &url_end, &y_extended, sentinel);
screen_mark_url(screen, url_start, y, url_end, y_extended); screen_mark_url(screen, url_start, y, url_end, y_extended);
} else { } else {
mouse_cursor_shape = BEAM; set_mouse_cursor_for_screen(screen);
screen_mark_url(screen, 0, 0, 0, 0); screen_mark_url(screen, 0, 0, 0, 0);
} }
} }
@ -491,9 +496,12 @@ focus_in_event() {
bool in_tab_bar; bool in_tab_bar;
unsigned int window_idx = 0; unsigned int window_idx = 0;
mouse_cursor_shape = BEAM; mouse_cursor_shape = BEAM;
set_mouse_cursor(BEAM);
Window *w = window_for_event(&window_idx, &in_tab_bar); Window *w = window_for_event(&window_idx, &in_tab_bar);
if (w && w->render_data.screen) screen_mark_url(w->render_data.screen, 0, 0, 0, 0); if (w && w->render_data.screen) {
screen_mark_url(w->render_data.screen, 0, 0, 0, 0);
set_mouse_cursor_for_screen(w->render_data.screen);
}
set_mouse_cursor(mouse_cursor_shape);
} }
void void

View File

@ -324,6 +324,18 @@ convert_mods(PyObject *obj) {
return resolve_mods(PyLong_AsLong(obj)); return resolve_mods(PyLong_AsLong(obj));
} }
static MouseShape
pointer_shape(PyObject *shape_name) {
const char *name = PyUnicode_AsUTF8(shape_name);
switch(name[0]) {
case 'a': return ARROW;
case 'h': return HAND;
case 'b': return BEAM;
default: break;
}
return BEAM;
}
static inline void static inline void
set_special_keys(PyObject *dict) { set_special_keys(PyObject *dict) {
dict_iter(dict) { dict_iter(dict) {
@ -410,6 +422,7 @@ PYWRAP1(set_options) {
S(tab_bar_min_tabs, PyLong_AsUnsignedLong); S(tab_bar_min_tabs, PyLong_AsUnsignedLong);
S(disable_ligatures, PyLong_AsLong); S(disable_ligatures, PyLong_AsLong);
S(resize_draw_strategy, PyLong_AsLong); S(resize_draw_strategy, PyLong_AsLong);
S(pointer_shape_when_grabbed, pointer_shape);
GA(tab_bar_style); GA(tab_bar_style);
global_state.tab_bar_hidden = PyUnicode_CompareWithASCIIString(ret, "hidden") == 0 ? true: false; global_state.tab_bar_hidden = PyUnicode_CompareWithASCIIString(ret, "hidden") == 0 ? true: false;

View File

@ -44,6 +44,7 @@ typedef struct {
bool window_alert_on_bell; bool window_alert_on_bell;
bool debug_keyboard; bool debug_keyboard;
double resize_debounce_time; double resize_debounce_time;
MouseShape pointer_shape_when_grabbed;
} Options; } Options;
typedef struct { typedef struct {