From 2f5b110c411a813c61b664ed711f1a7aa8825401 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 24 Oct 2017 09:29:28 +0530 Subject: [PATCH] Implement an option to have focus follow the mouse Fixes #156 --- kitty/config.py | 1 + kitty/kitty.conf | 3 +++ kitty/mouse.c | 6 ++++++ kitty/state.c | 1 + kitty/state.h | 1 + kitty/window.py | 1 - 6 files changed, 12 insertions(+), 1 deletion(-) diff --git a/kitty/config.py b/kitty/config.py index 4c83e9501..d4de5a07e 100644 --- a/kitty/config.py +++ b/kitty/config.py @@ -240,6 +240,7 @@ type_map = { 'scrollback_in_new_tab': to_bool, 'font_size': to_font_size, 'font_size_delta': positive_float, + 'focus_follows_mouse': to_bool, 'cursor_shape': to_cursor_shape, 'open_url_modifiers': to_open_url_modifiers, 'repaint_delay': positive_int, diff --git a/kitty/kitty.conf b/kitty/kitty.conf index 4e0bcb83a..c46a8aadd 100644 --- a/kitty/kitty.conf +++ b/kitty/kitty.conf @@ -90,6 +90,9 @@ select_by_word_characters :@-./_~?&=%+# # zero to disable mouse cursor hiding. mouse_hide_wait 3.0 +# Set the active window to the window under the mouse when moving the mouse around +focus_follows_mouse no + # The enabled window layouts. A comma separated list of layout names. The special value * means # all layouts. The first listed layout will be used as the startup layout. # For a list of available layouts, see the file layouts.py diff --git a/kitty/mouse.c b/kitty/mouse.c index 6ae8663d9..b327792c5 100644 --- a/kitty/mouse.c +++ b/kitty/mouse.c @@ -164,6 +164,12 @@ detect_url(Window *w, Screen *screen, unsigned int x, unsigned int y) { HANDLER(handle_move_event) { unsigned int x, y; + if (OPT(focus_follows_mouse)) { + Tab *t = global_state.tabs + global_state.active_tab; + if (window_idx != t->active_window) { + call_boss(switch_focus_to, "I", window_idx); + } + } if (!cell_for_pos(w, &x, &y)) return; Screen *screen = w->render_data.screen; detect_url(w, screen, x, y); diff --git a/kitty/state.c b/kitty/state.c index 375c0373e..ec18364c0 100644 --- a/kitty/state.c +++ b/kitty/state.c @@ -151,6 +151,7 @@ PYWRAP1(set_options) { #define S(name, convert) { GA(name); global_state.opts.name = convert(ret); Py_DECREF(ret); if (PyErr_Occurred()) return NULL; } S(visual_bell_duration, PyFloat_AsDouble); S(enable_audio_bell, PyObject_IsTrue); + S(focus_follows_mouse, PyObject_IsTrue); S(cursor_blink_interval, PyFloat_AsDouble); S(cursor_stop_blinking_after, PyFloat_AsDouble); S(cursor_shape, PyLong_AsLong); diff --git a/kitty/state.h b/kitty/state.h index d34374698..21ff8ea7c 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -18,6 +18,7 @@ typedef struct { char_type select_by_word_characters[256]; size_t select_by_word_characters_count; color_type url_color; double repaint_delay, input_delay; + bool focus_follows_mouse; } Options; typedef struct { diff --git a/kitty/window.py b/kitty/window.py index 5fb074857..c38daa59b 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -80,7 +80,6 @@ class Window: self.tab_id = tab.id self.tabref = weakref.ref(tab) self.override_title = None - self.last_mouse_cursor_pos = 0, 0 self.destroyed = False self.click_queue = deque(maxlen=3) self.geometry = WindowGeometry(0, 0, 0, 0, 0, 0)