]> git.sur5r.net Git - i3/i3/blobdiff - src/commands.c
Bugfix: Repeatedly try to find screens if none are available (Thanks mxf)
[i3/i3] / src / commands.c
index f15921b49148a3ebd432ebc13cc4293ad2f4828a..275f8f96bb08c931d09842656a91b6e46f848dbe 100644 (file)
@@ -25,6 +25,7 @@
 #include "xinerama.h"
 #include "client.h"
 #include "floating.h"
+#include "xcb.h"
 
 bool focus_window_in_container(xcb_connection_t *conn, Container *container, direction_t direction) {
         /* If this container is empty, we’re done */
@@ -59,10 +60,17 @@ static void focus_thing(xcb_connection_t *conn, direction_t direction, thing_t t
 
         int new_row = current_row,
             new_col = current_col;
-
         Container *container = CUR_CELL;
         Workspace *t_ws = c_ws;
 
+        /* Makes sure new_col and new_row are within bounds of the new workspace */
+        void check_colrow_boundaries() {
+                if (new_col >= t_ws->cols)
+                        new_col = (t_ws->cols - 1);
+                if (new_row >= t_ws->rows)
+                        new_row = (t_ws->rows - 1);
+        }
+
         /* There always is a container. If not, current_col or current_row is wrong */
         assert(container != NULL);
 
@@ -106,6 +114,8 @@ static void focus_thing(xcb_connection_t *conn, direction_t direction, thing_t t
                         new_row = (direction == D_UP ? (t_ws->rows - 1) : 0);
                 }
 
+                check_colrow_boundaries();
+
                 LOG("new_col = %d, new_row = %d\n", new_col, new_row);
                 if (t_ws->table[new_col][new_row]->currently_focused == NULL) {
                         LOG("Cell empty, checking for colspanned client above...\n");
@@ -146,6 +156,8 @@ static void focus_thing(xcb_connection_t *conn, direction_t direction, thing_t t
                         new_col = (direction == D_LEFT ? (t_ws->cols - 1) : 0);
                 }
 
+                check_colrow_boundaries();
+
                 LOG("new_col = %d, new_row = %d\n", new_col, new_row);
                 if (t_ws->table[new_col][new_row]->currently_focused == NULL) {
                         LOG("Cell empty, checking for rowspanned client above...\n");
@@ -163,11 +175,7 @@ static void focus_thing(xcb_connection_t *conn, direction_t direction, thing_t t
                 return;
         }
 
-        /* Bounds checking */
-        if (new_col >= t_ws->cols)
-                new_col = (t_ws->cols - 1);
-        if (new_row >= t_ws->rows)
-                new_row = (t_ws->rows - 1);
+        check_colrow_boundaries();
 
         if (t_ws->table[new_col][new_row]->currently_focused != NULL)
                 set_focus(conn, t_ws->table[new_col][new_row]->currently_focused, true);
@@ -481,8 +489,10 @@ static void move_floating_window_to_workspace(xcb_connection_t *conn, Client *cl
 
         floating_assign_to_workspace(client, t_ws);
 
+        bool target_invisible = t_ws->screen->current_workspace != t_ws->num;
+
         /* If we’re moving it to an invisible screen, we need to unmap it */
-        if (t_ws->screen->current_workspace != t_ws->num) {
+        if (target_invisible) {
                 LOG("This workspace is not visible, unmapping\n");
                 xcb_unmap_window(conn, client->frame);
         } else {
@@ -504,7 +514,8 @@ static void move_floating_window_to_workspace(xcb_connection_t *conn, Client *cl
 
         render_layout(conn);
 
-        set_focus(conn, client, true);
+        if (!target_invisible)
+                set_focus(conn, client, true);
 }
 
 /*
@@ -556,8 +567,6 @@ static void move_current_window_to_workspace(xcb_connection_t *conn, int workspa
         CIRCLEQ_INSERT_TAIL(&(to_container->clients), current_client, clients);
 
         SLIST_INSERT_HEAD(&(to_container->workspace->focus_stack), current_client, focus_clients);
-        if (current_client->fullscreen)
-                t_ws->fullscreen_client = current_client;
         LOG("Moved.\n");
 
         current_client->container = to_container;
@@ -565,16 +574,26 @@ static void move_current_window_to_workspace(xcb_connection_t *conn, int workspa
         container->currently_focused = to_focus;
         to_container->currently_focused = current_client;
 
+        bool target_invisible = (to_container->workspace->screen->current_workspace != to_container->workspace->num);
+
         /* If we’re moving it to an invisible screen, we need to unmap it */
-        if (to_container->workspace->screen->current_workspace != to_container->workspace->num) {
+        if (target_invisible) {
                 LOG("This workspace is not visible, unmapping\n");
                 xcb_unmap_window(conn, current_client->frame);
+        } else {
+                if (current_client->fullscreen) {
+                        LOG("Calling client_enter_fullscreen again\n");
+                        client_enter_fullscreen(conn, current_client);
+                }
         }
 
         /* delete all empty columns/rows */
         cleanup_table(conn, container->workspace);
 
         render_layout(conn);
+
+        if (!target_invisible)
+                set_focus(conn, current_client, true);
 }
 
 /*
@@ -956,7 +975,11 @@ void parse_command(xcb_connection_t *conn, const char *command) {
                 fix_colrowspan(conn, last_focused->workspace);
 
                 render_workspace(conn, last_focused->workspace->screen, last_focused->workspace);
-                xcb_flush(conn);
+
+                /* Re-focus the client because cleanup_table sets the focus to the last
+                 * focused client inside a container only. */
+                set_focus(conn, last_focused, true);
+
                 return;
         }