]> git.mdlowis.com Git - proto/labwc.git/commitdiff
desktop: refactor desktop_focus_view()
authorJohan Malm <jgm323@gmail.com>
Thu, 8 Oct 2020 19:08:41 +0000 (20:08 +0100)
committerJohan Malm <jgm323@gmail.com>
Thu, 8 Oct 2020 19:08:41 +0000 (20:08 +0100)
include/labwc.h
src/cursor.c
src/desktop.c
src/keyboard.c
src/xdg.c
src/xwayland.c

index 8d7c5eb7765e385f65136a766057e1a7d0943e4b..df9e80121eada5e38b506e863512505327700915 100644 (file)
@@ -221,7 +221,7 @@ void view_unminimize(struct view *view);
 void view_for_each_surface(struct view *view,
        wlr_surface_iterator_func_t iterator, void *user_data);
 
-void desktop_focus_view(struct view *view);
+void desktop_focus_view(struct seat *seat, struct view *view);
 
 /**
  * desktop_next_view - return next view
index c99319155e4e5a5e9059560bd4345241b0c4e97b..ab909e2426cf94b921d70e7fa318130911ac9bf6 100644 (file)
@@ -248,7 +248,7 @@ cursor_button(struct wl_listener *listener, void *data)
                server->cursor_mode = LAB_CURSOR_PASSTHROUGH;
        } else {
                /* Focus that client if the button was _pressed_ */
-               desktop_focus_view(view);
+               desktop_focus_view(&server->seat, view);
                switch (view_area) {
                case LAB_DECO_BUTTON_CLOSE:
                        view->impl->close(view);
index 1f0db9db39cb615095470ec636f908d829fc0068..371432f864daac8498bc0529da00112a7e3d1fd4 100644 (file)
@@ -64,43 +64,31 @@ set_activated(struct wlr_surface *surface, bool activated)
        }
 }
 
-static void
-focus_view(struct view *view)
-{
-       struct server *server = view->server;
-       struct wlr_seat *wlr_seat = server->seat.seat;
-       struct wlr_surface *prev_surface;
-       prev_surface = wlr_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);
-       }
-
-       move_to_front(view);
-       set_activated(view->surface, true);
-
-       struct wlr_keyboard *kb = &server->seat.keyboard_group->keyboard;
-       wlr_seat_keyboard_notify_enter(wlr_seat, view->surface, kb->keycodes,
-               kb->num_keycodes, &kb->modifiers);
-
-       move_xwayland_sub_views_to_front(view);
-}
-
 void
-desktop_focus_view(struct view *view)
+desktop_focus_view(struct seat *seat, struct view *view)
 {
        if (!view) {
-               seat_focus_surface(view->server->seat.seat, NULL);
+               seat_focus_surface(seat->seat, NULL);
                return;
        }
        if (view->minimized) {
-               /* this will unmap and focus */
+               /* this will unmap and then focus */
                view_unminimize(view);
+               return;
        } else if (view->mapped) {
-               focus_view(view);
+               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);
+               }
+               move_to_front(view);
+               set_activated(view->surface, true);
+               seat_focus_surface(seat->seat, view->surface);
+               move_xwayland_sub_views_to_front(view);
        }
 }
 
@@ -187,7 +175,7 @@ desktop_focus_next_mapped_view(struct view *current)
 {
        assert(current);
        struct view *view = desktop_next_mapped_view(current);
-       desktop_focus_view(view);
+       desktop_focus_view(&current->server->seat, view);
 }
 
 static bool
index 496d328becb645552d6f418694c8114085757792..45d6418485a8ac2929122f3a06b6ba4b82cc51f0 100644 (file)
@@ -52,7 +52,7 @@ keyboard_key_notify(struct wl_listener *listener, void *data)
                if ((syms[0] == XKB_KEY_Alt_L) &&
                    event->state == WLR_KEY_RELEASED) {
                        /* end cycle */
-                       desktop_focus_view(server->cycle_view);
+                       desktop_focus_view(&server->seat, server->cycle_view);
                        server->cycle_view = NULL;
                } else if (event->state == WLR_KEY_PRESSED) {
                        /* cycle to next */
index e48e4985d496310f1babe3be5bfb592b1c88289f..265dff56aa4f75c9ca09e2a321a314462aa3bccd 100644 (file)
--- a/src/xdg.c
+++ b/src/xdg.c
@@ -195,7 +195,7 @@ xdg_toplevel_view_map(struct view *view)
                      &view->commit);
        view->commit.notify = handle_commit;
 
-       desktop_focus_view(view);
+       desktop_focus_view(&view->server->seat, view);
 }
 
 static void
index 413a5815f49abafe98e23f4fd84ed6d3624b120a..174e6db60f6d75755fae74568b2b4006a9a901a6 100644 (file)
@@ -112,7 +112,7 @@ map(struct view *view)
                      &view->commit);
        view->commit.notify = handle_commit;
 
-       desktop_focus_view(view);
+       desktop_focus_view(&view->server->seat, view);
 }
 
 static void