]> git.sur5r.net Git - i3/i3/blobdiff - src/workspace.c
ipc: also send workspace event when initializing a workspace for an output
[i3/i3] / src / workspace.c
index 70b034ab068725e8ec35093792d6689513f0843e..8d76272925ff8ff5b3d9eb754ffac2147d252072 100644 (file)
@@ -28,6 +28,7 @@
 #include "client.h"
 #include "log.h"
 #include "ewmh.h"
+#include "ipc.h"
 
 /*
  * Returns a pointer to the workspace with the given number (starting at 0),
@@ -57,6 +58,8 @@ Workspace *workspace_get(int number) {
                 workspace_set_name(ws, NULL);
 
                 TAILQ_INSERT_TAIL(workspaces, ws, workspaces);
+
+                ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"init\"}");
         }
         DLOG("done\n");
 
@@ -84,13 +87,13 @@ void workspace_set_name(Workspace *ws, const char *name) {
                 errx(1, "asprintf() failed");
 
         FREE(ws->name);
+        FREE(ws->utf8_name);
 
         ws->name = convert_utf8_to_ucs2(label, &(ws->name_len));
         if (config.font != NULL)
                 ws->text_width = predict_text_width(global_conn, config.font, ws->name, ws->name_len);
         else ws->text_width = 0;
-
-        free(label);
+        ws->utf8_name = label;
 }
 
 /*
@@ -144,6 +147,15 @@ void workspace_show(xcb_connection_t *conn, int workspace) {
                 if ((old_client != NULL) && !old_client->dock)
                         redecorate_window(conn, old_client);
                 else xcb_flush(conn);
+
+                /* We need to check if a global fullscreen-client is blocking
+                 * the t_ws and if necessary switch that to local fullscreen */
+                Client* client = c_ws->fullscreen_client;
+                if (client != NULL && client->workspace != c_ws) {
+                        if (c_ws->fullscreen_client->workspace != c_ws)
+                                c_ws->fullscreen_client = NULL;
+                        client_enter_fullscreen(conn, client, false);
+                }
         }
 
         /* Check if we need to change something or if we’re already there */
@@ -156,6 +168,8 @@ void workspace_show(xcb_connection_t *conn, int workspace) {
                         xcb_flush(conn);
                 }
 
+                ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"focus\"}");
+
                 return;
         }
 
@@ -169,6 +183,8 @@ void workspace_show(xcb_connection_t *conn, int workspace) {
         current_col = c_ws->current_col;
         DLOG("new current row = %d, current col = %d\n", current_row, current_col);
 
+        ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"focus\"}");
+
         workspace_map_clients(conn, c_ws);
 
         /* POTENTIAL TO IMPROVE HERE: due to the call to _map_clients first and
@@ -204,9 +220,10 @@ void workspace_show(xcb_connection_t *conn, int workspace) {
  * output 1 and you just plugged in output 1).
  *
  */
-void workspace_assign_to(Workspace *ws, Output *output) {
+void workspace_assign_to(Workspace *ws, Output *output, bool hide_it) {
         Client *client;
         bool empty = true;
+        bool visible = workspace_is_visible(ws);
 
         ws->output = output;
 
@@ -228,14 +245,14 @@ void workspace_assign_to(Workspace *ws, Output *output) {
         render_workspace(global_conn, output, ws);
 
         /* …unless we want to see them at the moment, we should hide that workspace */
-        if (workspace_is_visible(ws))
+        if (visible && !hide_it)
                 return;
 
         workspace_unmap_clients(global_conn, ws);
 
         if (c_ws == ws) {
-                DLOG("Need to adjust c_ws...\n");
-                c_ws = output->current_workspace;
+                DLOG("Need to adjust output->current_workspace...\n");
+                output->current_workspace = c_ws;
         }
 }
 
@@ -268,7 +285,7 @@ void workspace_initialize(Workspace *ws, Output *output, bool recheck) {
         if (old_output != NULL && ws->output == old_output)
                 return;
 
-        workspace_assign_to(ws, ws->output);
+        workspace_assign_to(ws, ws->output, false);
 }
 
 /*
@@ -276,7 +293,7 @@ void workspace_initialize(Workspace *ws, Output *output, bool recheck) {
  * the preferred_output setting of every workspace (workspace assignments).
  *
  */
-Workspace *get_first_workspace_for_screen(Output *output) {
+Workspace *get_first_workspace_for_output(Output *output) {
         Workspace *result = NULL;
 
         Workspace *ws;
@@ -335,7 +352,7 @@ void workspace_map_clients(xcb_connection_t *conn, Workspace *ws) {
         /* Map all stack windows, if any */
         struct Stack_Window *stack_win;
         SLIST_FOREACH(stack_win, &stack_wins, stack_windows)
-                if (stack_win->container->workspace == ws)
+                if (stack_win->container->workspace == ws && stack_win->rect.height > 0)
                         xcb_map_window(conn, stack_win->window);
 
         ignore_enter_notify_forall(conn, ws, false);
@@ -443,7 +460,8 @@ int workspace_height(Workspace *ws) {
                 height -= client->desired_height;
 
         /* Space for the internal bar */
-        height -= (font->height + 6);
+        if (!config.disable_workspace_bar)
+                height -= (font->height + 6);
 
         return height;
 }