]> git.mdlowis.com Git - proto/labwc.git/commitdiff
dnd: fix focus at end of dnd operation
authorJohan Malm <jgm323@gmail.com>
Mon, 10 Jul 2023 15:56:02 +0000 (16:56 +0100)
committerJohan Malm <johanmalm@users.noreply.github.com>
Mon, 10 Jul 2023 16:17:59 +0000 (17:17 +0100)
By default, leave keyboard-focus with the surface that originally had it
at the end of a dnd operation.  This is consistent with the default
behaviour of openbox and mutter.

If the 'focus/followMouse' option is enabled, then focus on the surface
under the cursor at the end of the dnd operation.

Fixes: issue #976
src/dnd.c

index d2d7c29ef0e6c75b4893bd288f7b151b604d60be..66acdffa5ac33153a058636ecb0bf41b8e8f0815 100644 (file)
--- a/src/dnd.c
+++ b/src/dnd.c
@@ -7,6 +7,7 @@
 #include "cursor.h"
 #include "dnd.h"
 #include "labwc.h"  /* for struct seat */
+#include "view.h"
 
 /* Internal DnD icon handlers */
 static void
@@ -138,15 +139,28 @@ handle_drag_destroy(struct wl_listener *listener, void *data)
        wlr_scene_node_set_enabled(&seat->drag.icons->node, false);
 
        /*
-        * Keyboard focus is not changed during drag, so we need to refocus the
-        * current surface under the cursor.
+        * The default focus behaviour at the end of a dnd operation is that the
+        * window that originally had keyboard-focus retains that focus. This is
+        * consistent with the default behaviour of openbox and mutter.
+        *
+        * However, if the 'focus/followMouse' option is enabled we need to
+        * refocus the current surface under the cursor because keyboard focus
+        * is not changed during drag.
         */
+       if (!rc.focus_follow_mouse) {
+               return;
+       }
+
        struct cursor_context ctx = get_cursor_context(seat->server);
        if (!ctx.surface) {
                return;
        }
        seat_focus_surface(seat, NULL);
        seat_focus_surface(seat, ctx.surface);
+
+       if (ctx.view && rc.raise_on_focus) {
+               view_move_to_front(ctx.view);
+       }
 }
 
 /* Public API */