From 00db22e44f796f0ac007dc59440453d6ba7a177f Mon Sep 17 00:00:00 2001 From: Mikhail Kshevetskiy Date: Thu, 27 May 2021 02:11:11 +0300 Subject: [PATCH] focus: add basic follow mouse support --- include/config/rcxml.h | 2 ++ include/labwc.h | 1 + src/config/rcxml.c | 5 +++++ src/cursor.c | 9 +++++++++ src/desktop.c | 23 +++++++++++++++++++++++ 5 files changed, 40 insertions(+) diff --git a/include/config/rcxml.h b/include/config/rcxml.h index b682a1c3..188ea5bd 100644 --- a/include/config/rcxml.h +++ b/include/config/rcxml.h @@ -9,6 +9,8 @@ struct rcxml { bool xdg_shell_server_side_deco; + bool focus_follow_mouse; + bool raise_on_focus; char *theme_name; int corner_radius; char *font_name_activewindow; diff --git a/include/labwc.h b/include/labwc.h index fa0bac02..6f55bce7 100644 --- a/include/labwc.h +++ b/include/labwc.h @@ -296,6 +296,7 @@ void view_for_each_surface(struct view *view, void view_for_each_popup_surface(struct view *view, wlr_surface_iterator_func_t iterator, void *data); +void desktop_set_focus_view_only(struct seat *seat, struct view *view); void desktop_focus_view(struct seat *seat, struct view *view); /** diff --git a/src/config/rcxml.c b/src/config/rcxml.c index 5271317a..0362b73a 100644 --- a/src/config/rcxml.c +++ b/src/config/rcxml.c @@ -138,6 +138,11 @@ entry(xmlNode *node, char *nodename, char *content) fill_font(nodename, content, font_place); } else if (!strcmp(nodename, "size.font.theme")) { fill_font(nodename, content, font_place); + } else if (!strcasecmp(nodename, "FollowMouse.focus")) { + rc.focus_follow_mouse = get_bool(content); + } else if (!strcasecmp(nodename, "RaisemOnFocus.focus")) { + rc.focus_follow_mouse = true; + rc.raise_on_focus = get_bool(content); } } diff --git a/src/cursor.c b/src/cursor.c index 2c4fdb13..5790150f 100644 --- a/src/cursor.c +++ b/src/cursor.c @@ -152,6 +152,15 @@ process_cursor_motion(struct server *server, uint32_t time) uint32_t resize_edges = get_resize_edges( view, server->seat.cursor->x, server->seat.cursor->y); switch (resize_edges) { + case 0: + if (rc.focus_follow_mouse){ + if (rc.raise_on_focus){ + desktop_focus_view(&server->seat, view); + } else { + desktop_set_focus_view_only(&server->seat, view); + } + } + break; case WLR_EDGE_TOP: cursor_name = "top_side"; break; diff --git a/src/desktop.c b/src/desktop.c index 21521423..6fce6c7c 100644 --- a/src/desktop.c +++ b/src/desktop.c @@ -69,6 +69,25 @@ set_activated(struct wlr_surface *surface, bool activated) } } +void +desktop_set_focus_view_only(struct seat *seat, struct view *view) +{ + if (!view || view->minimized || !view->mapped) { + return; + } + struct wlr_surface *prev_surface; + prev_surface = seat->seat->keyboard_state.focused_surface; + if (prev_surface == view->surface) { + /* Don't re-focus an already focused surface. */ + return; + } + if (prev_surface) { + set_activated(prev_surface, false); + } + set_activated(view->surface, true); + seat_focus_surface(seat, view->surface); +} + void desktop_focus_view(struct seat *seat, struct view *view) { @@ -85,6 +104,10 @@ desktop_focus_view(struct seat *seat, struct view *view) prev_surface = seat->seat->keyboard_state.focused_surface; if (prev_surface == view->surface) { /* Don't re-focus an already focused surface. */ + move_to_front(view); +#if HAVE_XWAYLAND + move_xwayland_sub_views_to_front(view); +#endif return; } if (prev_surface) {