]> git.mdlowis.com Git - proto/labwc.git/commitdiff
desktop: simplify interface for view raise/focus
authorJohan Malm <jgm323@gmail.com>
Sat, 16 Oct 2021 18:44:54 +0000 (19:44 +0100)
committerJohan Malm <jgm323@gmail.com>
Sat, 16 Oct 2021 18:44:54 +0000 (19:44 +0100)
Split desktop_focus_view() into the following two functions:
  - desktop_focus_and_activate_view()
  - desktop_raise_view()

Always call view_set_activated() rather than using the private
set_activated(). This keeps the code cleaner and ensures
wlr_foreign_toplevel_handle_v1_set_activated() is called.

include/labwc.h
src/cursor.c
src/desktop.c
src/keyboard.c
src/xdg.c
src/xwayland.c

index 3f1dea66f5115c37e3877751aace85725e06e1e6..27185df2b481d0c42a79d5cdd107f663413fab13 100644 (file)
@@ -340,8 +340,22 @@ void view_update_title(struct view *view);
 
 void foreign_toplevel_handle_create(struct view *view);
 
+/*
+ * desktop.c routines deal with a collection of views
+ *
+ * Definition of a few keywords used in desktop.c
+ *   raise    - Bring view to front.
+ *   focus    - Give keyboard focus to view.
+ *   activate - Set view surface as active so that client window decorations
+ *              are painted to show that the window is active,typically by
+ *              using a different color. Although xdg-shell protocol says you
+ *              cannot assume this means that the window actually has keyboard
+ *              or pointer focus, in this compositor are they called together.
+ */
+
 void desktop_set_focus_view_only(struct seat *seat, struct view *view);
-void desktop_focus_view(struct seat *seat, struct view *view);
+void desktop_raise_view(struct view *view);
+void desktop_focus_and_activate_view(struct seat *seat, struct view *view);
 
 /**
  * desktop_cycle_view - return view to 'cycle' to
index 64749885ff3867035613a08e985a0b0be40e727b..b5dba5c87e926dc45d99861b679968fca8cce9b7 100644 (file)
@@ -182,7 +182,8 @@ process_cursor_motion(struct server *server, uint32_t time)
 
        if (view && rc.focus_follow_mouse) {
                if (rc.raise_on_focus) {
-                       desktop_focus_view(&server->seat, view);
+                       desktop_focus_and_activate_view(&server->seat, view);
+                       desktop_raise_view(view);
                } else {
                        desktop_set_focus_view_only(&server->seat, view);
                }
@@ -384,7 +385,8 @@ cursor_button(struct wl_listener *listener, void *data)
        }
 
        /* Handle _press_ on view */
-       desktop_focus_view(&server->seat, view);
+       desktop_focus_and_activate_view(&server->seat, view);
+       desktop_raise_view(view);
        damage_all_outputs(server);
 
        if (is_double_click(rc.doubleclick_time)
index 934bb3c69088fdcd290b7441362125fcd7b80700..482949aa3dbaa169ae7bc7114981ce496d3b02c3 100644 (file)
@@ -95,7 +95,31 @@ desktop_set_focus_view_only(struct seat *seat, struct view *view)
 }
 
 void
-desktop_focus_view(struct seat *seat, struct view *view)
+desktop_raise_view(struct view *view)
+{
+       if (!view) {
+               return;
+       }
+       move_to_front(view);
+#if HAVE_XWAYLAND
+       move_xwayland_sub_views_to_front(view);
+#endif
+}
+
+static void
+deactivate_all_views(struct server *server)
+{
+       struct view *view;
+       wl_list_for_each (view, &server->views, link) {
+               if (!view->mapped) {
+                       continue;
+               }
+               view_set_activated(view, false);
+       }
+}
+
+void
+desktop_focus_and_activate_view(struct seat *seat, struct view *view)
 {
        if (!view) {
                seat_focus_surface(seat, NULL);
@@ -106,30 +130,28 @@ desktop_focus_view(struct seat *seat, struct view *view)
        }
 
        if (view->minimized) {
-               /* this will unmap and then focus */
+               /*
+                * Unminimizing will map the view which triggers a call to this
+                * function again.
+                */
                view_minimize(view, false);
                return;
-       } else if (view->mapped) {
-               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. */
-                       move_to_front(view);
-#if HAVE_XWAYLAND
-                       move_xwayland_sub_views_to_front(view);
-#endif
-                       return;
-               }
-               if (prev_surface) {
-                       set_activated(prev_surface, false);
-               }
-               move_to_front(view);
-               set_activated(view->surface, true);
-               seat_focus_surface(seat, view->surface);
-#if HAVE_XWAYLAND
-               move_xwayland_sub_views_to_front(view);
-#endif
        }
+       if (!view->mapped) {
+               return;
+       }
+
+       struct wlr_surface *prev_surface;
+       prev_surface = seat->seat->keyboard_state.focused_surface;
+
+       /* Do not re-focus an already focused surface. */
+       if (prev_surface == view->surface) {
+               return;
+       }
+
+       deactivate_all_views(view->server);
+       view_set_activated(view, true);
+       seat_focus_surface(seat, view->surface);
 }
 
 /*
@@ -236,7 +258,8 @@ void
 desktop_focus_topmost_mapped_view(struct server *server)
 {
        struct view *view = topmost_mapped_view(server);
-       desktop_focus_view(&server->seat, view);
+       desktop_focus_and_activate_view(&server->seat, view);
+       desktop_raise_view(view);
 }
 
 static bool
index 1460ba90ad1f21ad6381586356594877a2970d5a..4f7fd253b24422390d088f803bb7e300aa3f56ec 100644 (file)
@@ -43,7 +43,9 @@ keyboard_modifiers_notify(struct wl_listener *listener, void *data)
                if ((event->state == WL_KEYBOARD_KEY_STATE_RELEASED)
                                && !any_modifiers_pressed(device->keyboard))  {
                        /* end cycle */
-                       desktop_focus_view(&server->seat, server->cycle_view);
+                       desktop_focus_and_activate_view(&server->seat,
+                               server->cycle_view);
+                       desktop_raise_view(server->cycle_view);
                        server->cycle_view = NULL;
                }
        }
index 202f285d0bf630720246b62a0710c37d5a2a4deb..e8f9400c481ce51f4ca0ee7edae2d1b05953009b 100644 (file)
--- a/src/xdg.c
+++ b/src/xdg.c
@@ -343,7 +343,8 @@ xdg_toplevel_view_map(struct view *view)
        wl_signal_add(&view->surface->events.new_subsurface,
                &view->new_subsurface);
 
-       desktop_focus_view(&view->server->seat, view);
+       desktop_focus_and_activate_view(&view->server->seat, view);
+       desktop_raise_view(view);
        damage_all_outputs(view->server);
 }
 
index eb730c6e02c65b8908f8161fe44a62aa3b6fabc1..22d548597993cd16487d07d69d29e160bd9feba1 100644 (file)
@@ -208,7 +208,8 @@ map(struct view *view)
                      &view->commit);
        view->commit.notify = handle_commit;
 
-       desktop_focus_view(&view->server->seat, view);
+       desktop_focus_and_activate_view(&view->server->seat, view);
+       desktop_raise_view(view);
        damage_all_outputs(view->server);
 }