#include "layout.h"
#include "workspace.h"
#include "client.h"
+#include "log.h"
+#include "ewmh.h"
/*
* Returns a pointer to the workspace with the given number (starting at 0),
*
*/
Workspace *workspace_get(int number) {
- Workspace *ws;
+ Workspace *ws = NULL;
TAILQ_FOREACH(ws, workspaces, workspaces)
if (ws->num == number)
return ws;
/* If we are still there, we could not find the requested workspace. */
int last_ws = TAILQ_LAST(workspaces, workspaces_head)->num;
- LOG("We need to initialize that one, last ws = %d\n", last_ws);
+ DLOG("We need to initialize that one, last ws = %d\n", last_ws);
for (int c = last_ws; c < number; c++) {
- LOG("Creating new ws\n");
+ DLOG("Creating new ws\n");
ws = scalloc(sizeof(Workspace));
- ws->num = number;
+ ws->num = c+1;
TAILQ_INIT(&(ws->floating_clients));
expand_table_cols(ws);
expand_table_rows(ws);
TAILQ_INSERT_TAIL(workspaces, ws, workspaces);
}
- LOG("done\n");
+ DLOG("done\n");
+
+ ewmh_update_workarea();
return ws;
}
/* t_ws (to workspace) is just a convenience pointer to the workspace we’re switching to */
Workspace *t_ws = workspace_get(workspace-1);
- LOG("show_workspace(%d)\n", workspace);
+ DLOG("show_workspace(%d)\n", workspace);
/* Store current_row/current_col */
c_ws->current_row = current_row;
c_ws->current_col = current_col;
/* Check if the workspace has not been used yet */
- workspace_initialize(t_ws, c_ws->screen);
+ workspace_initialize(t_ws, c_ws->screen, false);
if (c_ws->screen != t_ws->screen) {
/* We need to switch to the other screen first */
- LOG("moving over to other screen.\n");
+ DLOG("moving over to other screen.\n");
/* Store the old client */
Client *old_client = CUR_CELL->currently_focused;
current_row = c_ws->current_row;
current_col = c_ws->current_col;
- LOG("new current row = %d, current col = %d\n", current_row, current_col);
+ DLOG("new current row = %d, current col = %d\n", current_row, current_col);
workspace_map_clients(conn, c_ws);
char *rest;
int preferred_screen = strtol(preference, &rest, 10);
- LOG("Getting screen for preference \"%s\" (%d)\n", preference, preferred_screen);
+ DLOG("Getting screen for preference \"%s\" (%d)\n", preference, preferred_screen);
if ((rest == preference) || (preferred_screen >= num_screens)) {
int x = INT_MAX, y = INT_MAX;
x = atoi(preference);
}
- LOG("Looking for screen at %d x %d\n", x, y);
+ DLOG("Looking for screen at %d x %d\n", x, y);
TAILQ_FOREACH(screen, slist, screens)
if ((x == INT_MAX || screen->rect.x == x) &&
(y == INT_MAX || screen->rect.y == y)) {
- LOG("found %p\n", screen);
+ DLOG("found %p\n", screen);
return screen;
}
- LOG("none found\n");
+ DLOG("none found\n");
return NULL;
} else {
int c = 0;
return NULL;
}
+/*
+ * Assigns the given workspace to the given screen by correctly updating its
+ * state and reconfiguring all the clients on this workspace.
+ *
+ * This is called when initializing a screen and when re-assigning it to a
+ * different screen which just got available (if you configured it to be on
+ * screen 1 and you just plugged in screen 1).
+ *
+ */
+void workspace_assign_to(Workspace *ws, i3Screen *screen) {
+ Client *client;
+ bool empty = true;
+
+ ws->screen = screen;
+
+ /* Copy the dimensions from the virtual screen */
+ memcpy(&(ws->rect), &(ws->screen->rect), sizeof(Rect));
+
+ ewmh_update_workarea();
+
+ /* Force reconfiguration for each client on that workspace */
+ FOR_TABLE(ws)
+ CIRCLEQ_FOREACH(client, &(ws->table[cols][rows]->clients), clients) {
+ client->force_reconfigure = true;
+ empty = false;
+ }
+
+ if (empty)
+ return;
+
+ /* Render the workspace to reconfigure the clients. However, they will be visible now, so… */
+ render_workspace(global_conn, screen, ws);
+
+ /* …unless we want to see them at the moment, we should hide that workspace */
+ if (workspace_is_visible(ws))
+ return;
+
+ workspace_unmap_clients(global_conn, ws);
+
+ if (c_ws == ws) {
+ DLOG("Need to adjust c_ws...\n");
+ c_ws = screen->current_workspace;
+ }
+}
+
/*
* Initializes the given workspace if it is not already initialized. The given
* screen is to be understood as a fallback, if the workspace itself either
* the screen is not attached at the moment.
*
*/
-void workspace_initialize(Workspace *ws, i3Screen *screen) {
- if (ws->screen != NULL) {
- LOG("Workspace already initialized\n");
+void workspace_initialize(Workspace *ws, i3Screen *screen, bool recheck) {
+ i3Screen *old_screen;
+
+ if (ws->screen != NULL && !recheck) {
+ DLOG("Workspace already initialized\n");
return;
}
+ old_screen = ws->screen;
+
/* If this workspace has no preferred screen or if the screen it wants
* to be on is not available at the moment, we initialize it with
* the screen which was given */
(ws->screen = get_screen_from_preference(virtual_screens, ws->preferred_screen)) == NULL)
ws->screen = screen;
- /* Copy the dimensions from the virtual screen */
- memcpy(&(ws->rect), &(ws->screen->rect), sizeof(Rect));
+ DLOG("old_screen = %p, ws->screen = %p\n", old_screen, ws->screen);
+ /* If the assignment did not change, we do not need to update anything */
+ if (old_screen != NULL && ws->screen == old_screen)
+ return;
+
+ workspace_assign_to(ws, ws->screen);
}
/*
}
if (result == NULL) {
- LOG("No existing free workspace found to assign, creating a new one\n");
+ DLOG("No existing free workspace found to assign, creating a new one\n");
Workspace *ws;
int last_ws = 0;
result = workspace_get(last_ws + 1);
}
- workspace_initialize(result, screen);
+ workspace_initialize(result, screen, false);
return result;
}
int unmapped_clients = 0;
FOR_TABLE(u_ws)
CIRCLEQ_FOREACH(client, &(u_ws->table[cols][rows]->clients), clients) {
- LOG("unmapping normal client %p / %p / %p\n", client, client->frame, client->child);
+ DLOG("unmapping normal client %p / %p / %p\n", client, client->frame, client->child);
client_unmap(conn, client);
unmapped_clients++;
}
if (!client_is_floating(client))
continue;
- LOG("unmapping floating client %p / %p / %p\n", client, client->frame, client->child);
+ DLOG("unmapping floating client %p / %p / %p\n", client, client->frame, client->child);
client_unmap(conn, client);
unmapped_clients++;
if (unmapped_clients == 0 && u_ws != c_ws) {
/* Re-assign the workspace of all dock clients which use this workspace */
Client *dock;
- LOG("workspace %p is empty\n", u_ws);
+ DLOG("workspace %p is empty\n", u_ws);
SLIST_FOREACH(dock, &(u_ws->screen->dock_clients), dock_clients) {
if (dock->workspace != u_ws)
continue;
- LOG("Re-assigning dock client to c_ws (%p)\n", c_ws);
+ DLOG("Re-assigning dock client to c_ws (%p)\n", c_ws);
dock->workspace = c_ws;
}
u_ws->screen = NULL;
ws->urgent = false;
}
+
+/*
+ * Returns the width of the workspace.
+ *
+ */
+int workspace_width(Workspace *ws) {
+ return ws->rect.width;
+}
+
+/*
+ * Returns the effective height of the workspace (without the internal bar and
+ * without dock clients).
+ *
+ */
+int workspace_height(Workspace *ws) {
+ int height = ws->rect.height;
+ i3Font *font = load_font(global_conn, config.font);
+
+ /* Reserve space for dock clients */
+ Client *client;
+ SLIST_FOREACH(client, &(ws->screen->dock_clients), dock_clients)
+ height -= client->desired_height;
+
+ /* Space for the internal bar */
+ height -= (font->height + 6);
+
+ return height;
+}