The focus_follows_mouse option now also works across top-level kitty OS windows

Fixes #772
This commit is contained in:
Kovid Goyal
2018-07-30 21:26:20 +05:30
parent 78def6e6bf
commit 9af3081f45
8 changed files with 48 additions and 8 deletions

View File

@@ -36,7 +36,10 @@ Changelog
file is text (:pull:`752`) file is text (:pull:`752`)
- kitty @ new-window: Add a new option :option:`kitty @ new-window --window-type` - kitty @ new-window: Add a new option :option:`kitty @ new-window --window-type`
to create top-level OS windows. (:iss:`770`) to create top-level OS windows (:iss:`770`)
- The :opt:`focus_follows_mouse` option now also works across top-level kitty OS windows
(:iss:`754`)
0.11.3 [2018-07-10] 0.11.3 [2018-07-10]

View File

@@ -739,7 +739,7 @@ static GLFWapplicationshouldhandlereopenfun handle_reopen_callback = NULL;
} }
const NSTrackingAreaOptions options = NSTrackingMouseEnteredAndExited | const NSTrackingAreaOptions options = NSTrackingMouseEnteredAndExited |
NSTrackingActiveInKeyWindow | NSTrackingActiveAlways |
NSTrackingEnabledDuringMouseDrag | NSTrackingEnabledDuringMouseDrag |
NSTrackingCursorUpdate | NSTrackingCursorUpdate |
NSTrackingInVisibleRect | NSTrackingInVisibleRect |
@@ -1083,7 +1083,7 @@ is_ascii_control_char(char x) {
} }
- (void)loadMainMenu - (void)loadMainMenu
{ // removed by Kovid as it generated compiler warnings { // removed by Kovid as it generated compiler warnings
} }
@end @end

View File

@@ -218,6 +218,12 @@ cocoa_make_window_resizable(void *w, bool resizable) {
return true; return true;
} }
void
cocoa_focus_window(void *w) {
NSWindow *window = (NSWindow*)w;
[window makeKeyWindow];
}
static PyObject* static PyObject*
cocoa_get_lang(PyObject UNUSED *self) { cocoa_get_lang(PyObject UNUSED *self) {
NSString* locale = nil; NSString* locale = nil;

View File

@@ -280,6 +280,7 @@ void colorprofile_push_dynamic_colors(ColorProfile*);
void colorprofile_pop_dynamic_colors(ColorProfile*); void colorprofile_pop_dynamic_colors(ColorProfile*);
void set_mouse_cursor(MouseShape); void set_mouse_cursor(MouseShape);
void enter_event();
void mouse_event(int, int); void mouse_event(int, int);
void focus_in_event(); void focus_in_event();
void wakeup_io_loop(bool); void wakeup_io_loop(bool);

View File

@@ -9,6 +9,7 @@
#include <structmember.h> #include <structmember.h>
#include "glfw-wrapper.h" #include "glfw-wrapper.h"
extern bool cocoa_make_window_resizable(void *w, bool); extern bool cocoa_make_window_resizable(void *w, bool);
extern void cocoa_focus_window(void *w);
extern void cocoa_create_global_menu(void); extern void cocoa_create_global_menu(void);
extern void cocoa_set_hide_from_tasks(void); extern void cocoa_set_hide_from_tasks(void);
extern void cocoa_set_titlebar_color(void *w, color_type color); extern void cocoa_set_titlebar_color(void *w, color_type color);
@@ -138,6 +139,18 @@ key_callback(GLFWwindow *w, int key, int scancode, int action, int mods, const c
global_state.callback_os_window = NULL; global_state.callback_os_window = NULL;
} }
static void
cursor_enter_callback(GLFWwindow *w, int entered) {
if (!set_callback_window(w)) return;
if (entered) {
show_mouse_cursor(w);
double now = monotonic();
global_state.callback_os_window->last_mouse_activity_at = now;
if (is_window_ready_for_callbacks()) enter_event();
}
global_state.callback_os_window = NULL;
}
static void static void
mouse_button_callback(GLFWwindow *w, int button, int action, int mods) { mouse_button_callback(GLFWwindow *w, int button, int action, int mods) {
if (!set_callback_window(w)) return; if (!set_callback_window(w)) return;
@@ -489,6 +502,7 @@ create_os_window(PyObject UNUSED *self, PyObject *args) {
glfwSetFramebufferSizeCallback(glfw_window, framebuffer_size_callback); glfwSetFramebufferSizeCallback(glfw_window, framebuffer_size_callback);
glfwSetWindowContentScaleCallback(glfw_window, dpi_change_callback); glfwSetWindowContentScaleCallback(glfw_window, dpi_change_callback);
glfwSetWindowRefreshCallback(glfw_window, refresh_callback); glfwSetWindowRefreshCallback(glfw_window, refresh_callback);
glfwSetCursorEnterCallback(glfw_window, cursor_enter_callback);
glfwSetMouseButtonCallback(glfw_window, mouse_button_callback); glfwSetMouseButtonCallback(glfw_window, mouse_button_callback);
glfwSetScrollCallback(glfw_window, scroll_callback); glfwSetScrollCallback(glfw_window, scroll_callback);
glfwSetCursorPosCallback(glfw_window, cursor_pos_callback); glfwSetCursorPosCallback(glfw_window, cursor_pos_callback);
@@ -544,8 +558,16 @@ destroy_os_window(OSWindow *w) {
} }
void void
focus_os_window(OSWindow *w) { focus_os_window(OSWindow *w, bool also_raise) {
if (w->handle) glfwFocusWindow(w->handle); if (w->handle) {
#ifdef __APPLE__
if (!also_raise) cocoa_focus_window(glfwGetCocoaWindow(w->handle));
else glfwFocusWindow(w->handle);
#else
(void)also_raise;
glfwFocusWindow(w->handle);
#endif
}
} }
#ifdef __APPLE__ #ifdef __APPLE__

View File

@@ -451,6 +451,13 @@ focus_in_event() {
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);
} }
void
enter_event() {
if (OPT(focus_follows_mouse) && !global_state.callback_os_window->is_focused) {
focus_os_window(global_state.callback_os_window, false);
}
}
void void
mouse_event(int button, int modifiers) { mouse_event(int button, int modifiers) {
MouseShape old_cursor = mouse_cursor_shape; MouseShape old_cursor = mouse_cursor_shape;

View File

@@ -499,9 +499,10 @@ PYWRAP1(mark_os_window_for_close) {
PYWRAP1(focus_os_window) { PYWRAP1(focus_os_window) {
id_type os_window_id; id_type os_window_id;
PA("K", &os_window_id); int also_raise = 1;
PA("K|p", &os_window_id, &also_raise);
WITH_OS_WINDOW(os_window_id) WITH_OS_WINDOW(os_window_id)
if (!os_window->is_focused) focus_os_window(os_window); if (!os_window->is_focused) focus_os_window(os_window, also_raise);
Py_RETURN_TRUE; Py_RETURN_TRUE;
END_WITH_OS_WINDOW END_WITH_OS_WINDOW
Py_RETURN_FALSE; Py_RETURN_FALSE;

View File

@@ -170,7 +170,7 @@ void swap_window_buffers(OSWindow *w);
void make_window_context_current(OSWindow *w); void make_window_context_current(OSWindow *w);
void hide_mouse(OSWindow *w); void hide_mouse(OSWindow *w);
void destroy_os_window(OSWindow *w); void destroy_os_window(OSWindow *w);
void focus_os_window(OSWindow *w); void focus_os_window(OSWindow *w, bool also_raise);
void set_os_window_title(OSWindow *w, const char *title); void set_os_window_title(OSWindow *w, const char *title);
OSWindow* os_window_for_kitty_window(id_type); OSWindow* os_window_for_kitty_window(id_type);
OSWindow* add_os_window(); OSWindow* add_os_window();