X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fworkspace.c;h=670322a9428dbbe0c5cea78ccc3af5468b503856;hb=22be7bc986f51e8dc798fcd5f6bb72e3ed87ba0c;hp=3a5844cb8c1794d1adbe50e6e713046d582739d0;hpb=2252b4f5b956551ad4844deabee0ab38ccc73c99;p=i3%2Fi3 diff --git a/src/workspace.c b/src/workspace.c index 3a5844cb..670322a9 100644 --- a/src/workspace.c +++ b/src/workspace.c @@ -125,6 +125,8 @@ Con *create_workspace_on_output(Output *output, Con *content) { continue; DLOG("relevant command = %s\n", bind->command); char *target = bind->command + strlen("workspace "); + while((*target == ' ' || *target == '\t') && target != '\0') + target++; /* We check if this is the workspace * next/prev/next_on_output/prev_on_output/back_and_forth/number command. * Beware: The workspace names "next", "prev", "next_on_output", @@ -192,17 +194,16 @@ Con *create_workspace_on_output(Output *output, Con *content) { while (exists) { c++; - FREE(ws->name); - sasprintf(&(ws->name), "%d", c); + ws->num = c; current = NULL; TAILQ_FOREACH(out, &(croot->nodes_head), nodes) - GREP_FIRST(current, output_get_content(out), !strcasecmp(child->name, ws->name)); + GREP_FIRST(current, output_get_content(out), child->num == ws->num); exists = (current != NULL); - DLOG("result for ws %s / %d: exists = %d\n", ws->name, c, exists); + DLOG("result for ws %d: exists = %d\n", c, exists); } - ws->num = c; + sasprintf(&(ws->name), "%d", c); } con_attach(ws, content, false); @@ -212,6 +213,7 @@ Con *create_workspace_on_output(Output *output, Con *content) { ws->fullscreen_mode = CF_OUTPUT; + ws->workspace_layout = config.default_layout; _workspace_apply_default_orientation(ws); return ws; @@ -357,15 +359,20 @@ static void _workspace_show(Con *workspace) { /* Remember currently focused workspace for switching back to it later with * the 'workspace back_and_forth' command. * NOTE: We have to duplicate the name as the original will be freed when - * the corresponding workspace is cleaned up. */ - - FREE(previous_workspace_name); - if (current) - previous_workspace_name = sstrdup(current->name); + * the corresponding workspace is cleaned up. + * NOTE: Internal cons such as __i3_scratch (when a scratchpad window is + * focused) are skipped, see bug #868. */ + if (current && !con_is_internal(current)) { + FREE(previous_workspace_name); + if (current) { + previous_workspace_name = sstrdup(current->name); + DLOG("Setting previous_workspace_name = %s\n", previous_workspace_name); + } + } workspace_reassign_sticky(workspace); - LOG("switching to %p\n", workspace); + DLOG("switching to %p / %s\n", workspace, workspace->name); Con *next = con_descend_focused(workspace); /* Memorize current output */ @@ -400,6 +407,9 @@ static void _workspace_show(Con *workspace) { } else con_focus(next); + ipc_send_workspace_focus_event(workspace, current); + + DLOG("old = %p / %s\n", old, (old ? old->name : "(null)")); /* Close old workspace if necessary. This must be done *after* doing * urgency handling, because tree_close() will do a con_focus() on the next * client, which will clear the urgency flag too early. Also, there is no @@ -425,8 +435,6 @@ static void _workspace_show(Con *workspace) { /* Update the EWMH hints */ ewmh_update_current_desktop(); - - ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"focus\"}"); } /* @@ -766,7 +774,6 @@ void ws_force_orientation(Con *ws, orientation_t orientation) { /* 1: create a new split container */ Con *split = con_new(NULL, NULL); split->parent = ws; - split->split = true; /* 2: copy layout from workspace */ split->layout = ws->layout; @@ -818,7 +825,6 @@ Con *workspace_attach_to(Con *ws) { /* 1: create a new split container */ Con *new = con_new(NULL, NULL); new->parent = ws; - new->split = true; /* 2: set the requested layout on the split con */ new->layout = ws->workspace_layout; @@ -829,3 +835,34 @@ Con *workspace_attach_to(Con *ws) { return new; } + +/** + * Creates a new container and re-parents all of children from the given + * workspace into it. + * + * The container inherits the layout from the workspace. + */ +Con *workspace_encapsulate(Con *ws) { + if (TAILQ_EMPTY(&(ws->nodes_head))) { + ELOG("Workspace %p / %s has no children to encapsulate\n", ws, ws->name); + return NULL; + } + + Con *new = con_new(NULL, NULL); + new->parent = ws; + new->layout = ws->layout; + + DLOG("Moving children of workspace %p / %s into container %p\n", + ws, ws->name, new); + + Con *child; + while (!TAILQ_EMPTY(&(ws->nodes_head))) { + child = TAILQ_FIRST(&(ws->nodes_head)); + con_detach(child); + con_attach(child, new, true); + } + + con_attach(new, ws, true); + + return new; +}