]> git.mdlowis.com Git - proto/labwc.git/commitdiff
focus: add basic follow mouse support
authorMikhail Kshevetskiy <mikhail.kshevetskiy@gmail.com>
Wed, 26 May 2021 23:11:11 +0000 (02:11 +0300)
committerJohan Malm <johanmalm@users.noreply.github.com>
Fri, 28 May 2021 20:25:19 +0000 (21:25 +0100)
include/config/rcxml.h
include/labwc.h
src/config/rcxml.c
src/cursor.c
src/desktop.c

index b682a1c300737b1e503bf464ca0460217db890a7..188ea5bd1ebebcf93e3e36ae27046ca32c806a2e 100644 (file)
@@ -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;
index fa0bac02f377a4ae5cd3ab60737b4f90f8fe0fec..6f55bce7061936997c6e964860595d21b26c9b1b 100644 (file)
@@ -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);
 
 /**
index 5271317aa3981c34e46ea5806920bc8660a0ad64..0362b73a7c9303f9fec33ee3588dfd46ee5e61dc 100644 (file)
@@ -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);
        }
 }
 
index 2c4fdb1393fa6e8bff961bfd5aece56aaa1e571b..5790150f102719aa5a00dbc1f69360722b0fab2d 100644 (file)
@@ -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;
index 21521423c3b3ff203a0608de950294c45571c72d..6fce6c7c3c91a501431d6b5cd951fcc00c6cb776 100644 (file)
@@ -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) {