]> git.corax.cc Git - mwm/commitdiff
workspace: When the focused client is detached, focus on the next one
authorMatthias Kruk <m@m10k.eu>
Fri, 21 May 2021 21:14:33 +0000 (06:14 +0900)
committerMatthias Kruk <m@m10k.eu>
Fri, 21 May 2021 21:14:33 +0000 (06:14 +0900)
When the focused client is detached from a workspace, the focus is moved
to the first client of the workspace. However, from a user point-of-view,
it seems better to move the focus to the next client.
This commit changes the workspace_detach_client() function to shift the
focus to the next client, if the focused client is removed.

workspace.c

index 00fa0b57a3e4c5fbd76d6a34b900d5ec36789239..53172b780f0f0a1e046742e75f11c147122b99a4 100644 (file)
@@ -89,6 +89,7 @@ int workspace_attach_client(struct workspace *workspace, struct client *client)
 
 int workspace_detach_client(struct workspace *workspace, struct client *client)
 {
+       struct client *next;
        int err;
 
 #if MWM_DEBUG
@@ -99,20 +100,42 @@ int workspace_detach_client(struct workspace *workspace, struct client *client)
                return(-EINVAL);
        }
 
+       /* before removing the client, we need to figure out who's getting the focus */
+       err = loop_get_next(&workspace->clients, client, (void**)&next);
+
+       if(err < 0) {
+               /*
+                * At the *very least* we should have gotten a pointer to client itself.
+                * If we didn't even get that, client wasn't on this workspace and we've
+                * encountered a bug.
+                */
+               fprintf(stderr, "%s: BUG: Could not determine next client\n", __func__);
+               fprintf(stderr, "%s: loop_get_next: %s\n", __func__, strerror(-err));
+
+               return(err);
+       }
+
        err = loop_remove(&workspace->clients, client);
 
        if(err < 0) {
+               /*
+                * If client wasn't on this workspace, the branch above should have been
+                * visited. So if we get here, something even nastier is going on.
+                */
+               fprintf(stderr, "%s: BUG: Client %p was not on this workspace.\n",
+                       __func__, (void*)client);
+               fprintf(stderr, "%s: loop_remove: %s\n", __func__, strerror(-err));
+
                return(err);
        }
 
        if(workspace_get_focused_client(workspace) == client) {
-               struct client *first;
-
-               if(loop_get_first(&workspace->clients, (void**)&first) < 0) {
-                       first = NULL;
+               if(next == client) {
+                       /* nothing left to focus on */
+                       next = NULL;
                }
 
-               workspace_focus_client(workspace, first);
+               workspace_focus_client(workspace, next);
        }
 
        workspace_needs_redraw(workspace);