X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fworkspace.c;h=9b5593d6500e073bc88794dd2041a30d1eb871b4;hb=c56867792aa98ccedecfa40ca55e4a1a141a65c4;hp=63e079f90f1ff463861d2ab118878003a6bf496e;hpb=6aa6fa0af02575174f8bc7c41a6c0f3422cd3bba;p=i3%2Fi3 diff --git a/src/workspace.c b/src/workspace.c index 63e079f9..9b5593d6 100644 --- a/src/workspace.c +++ b/src/workspace.c @@ -1,11 +1,8 @@ /* - * vim:ts=8:expandtab + * vim:ts=4:sw=4:expandtab * * i3 - an improved dynamic tiling window manager - * - * © 2009-2010 Michael Stapelberg and contributors - * - * See file LICENSE for license information. + * © 2009-2010 Michael Stapelberg and contributors (see also: LICENSE) * * workspace.c: Functions for modifying workspaces * @@ -14,8 +11,6 @@ #include "all.h" -extern Con *focused; - /* * Returns a pointer to the workspace with the given number (starting at 0), * creating the workspace if necessary (by allocating the necessary amount of @@ -23,35 +18,35 @@ extern Con *focused; * */ Con *workspace_get(const char *num) { - Con *output, *workspace = NULL, *current; - - /* TODO: could that look like this in the future? - GET_MATCHING_NODE(workspace, croot, strcasecmp(current->name, num) != 0); - */ - TAILQ_FOREACH(output, &(croot->nodes_head), nodes) { - TAILQ_FOREACH(current, &(output->nodes_head), nodes) { - if (strcasecmp(current->name, num) != 0) - continue; - - workspace = current; - break; - } + Con *output, *workspace = NULL, *current; + + /* TODO: could that look like this in the future? + GET_MATCHING_NODE(workspace, croot, strcasecmp(current->name, num) != 0); + */ + TAILQ_FOREACH(output, &(croot->nodes_head), nodes) { + TAILQ_FOREACH(current, &(output->nodes_head), nodes) { + if (strcasecmp(current->name, num) != 0) + continue; + + workspace = current; + break; } + } - LOG("should switch to ws %s\n", num); - if (workspace == NULL) { - LOG("need to create this one\n"); - output = con_get_output(focused); - LOG("got output %p\n", output); - workspace = con_new(output); - workspace->name = strdup(num); + LOG("getting ws %s\n", num); + if (workspace == NULL) { + LOG("need to create this one\n"); + output = con_get_output(focused); + LOG("got output %p\n", output); + workspace = con_new(output); + workspace->name = strdup(num); - ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"init\"}"); - } + ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"init\"}"); + } - //ewmh_update_workarea(); + //ewmh_update_workarea(); - return workspace; + return workspace; } #if 0 @@ -101,23 +96,31 @@ bool workspace_is_visible(Workspace *ws) { * */ void workspace_show(const char *num) { - Con *workspace, *current; + Con *workspace, *current, *old; + + old = con_get_workspace(focused); - workspace = workspace_get(num); - workspace->fullscreen_mode = CF_OUTPUT; - /* disable fullscreen */ - TAILQ_FOREACH(current, &(workspace->parent->nodes_head), nodes) - current->fullscreen_mode = CF_NONE; + workspace = workspace_get(num); + workspace->fullscreen_mode = CF_OUTPUT; + /* disable fullscreen */ + TAILQ_FOREACH(current, &(workspace->parent->nodes_head), nodes) + current->fullscreen_mode = CF_NONE; - LOG("switching to %p\n", workspace); - Con *next = workspace; + LOG("switching to %p\n", workspace); + Con *next = workspace; while (!TAILQ_EMPTY(&(next->focus_head))) next = TAILQ_FIRST(&(next->focus_head)); - con_focus(next); - workspace->fullscreen_mode = CF_OUTPUT; - LOG("focused now = %p / %s\n", focused, focused->name); + + if (TAILQ_EMPTY(&(old->nodes_head))) { + LOG("Closing old workspace (%p / %s), it is empty\n", old, old->name); + tree_close(old); + } + + con_focus(next); + workspace->fullscreen_mode = CF_OUTPUT; + LOG("focused now = %p / %s\n", focused, focused->name); #if 0 /* Check if the workspace has not been used yet */