X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fworkspace.c;h=8104aa89fc35d6da21765408718255e5d06a0473;hb=36583ec6ee7ada36764a492fdaae158a5cdd04c3;hp=d5875f99cf61a7bcdb9a48af2e67206cc3b71747;hpb=7f89c716891c8e8c01d9289d6ceb668d742864b1;p=i3%2Fi3 diff --git a/src/workspace.c b/src/workspace.c index d5875f99..8104aa89 100644 --- a/src/workspace.c +++ b/src/workspace.c @@ -17,40 +17,27 @@ * memory and initializing the data structures correctly). * */ -Con *workspace_get(const char *num) { - Con *output, *workspace = NULL, *current, *child; +Con *workspace_get(const char *num, bool *created) { + Con *output, *workspace = NULL, *child; /* 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 (current->type != CT_CON) + TAILQ_FOREACH(output, &(croot->nodes_head), nodes) + TAILQ_FOREACH(child, &(output_get_content(output)->nodes_head), nodes) { + if (strcasecmp(child->name, num) != 0) continue; - TAILQ_FOREACH(child, &(current->nodes_head), nodes) { - if (strcasecmp(child->name, num) != 0) - continue; - - workspace = child; - break; - } + workspace = child; + break; } - } LOG("getting ws %s\n", num); if (workspace == NULL) { LOG("need to create this one\n"); output = con_get_output(focused); - Con *child, *content = NULL; - TAILQ_FOREACH(child, &(output->nodes_head), nodes) { - if (child->type == CT_CON) { - content = child; - break; - } - } - assert(content != NULL); - LOG("got output %p with child %p\n", output, content); + Con *content = output_get_content(output); + LOG("got output %p with content %p\n", output, content); /* We need to attach this container after setting its type. con_attach * will handle CT_WORKSPACEs differently */ workspace = con_new(NULL); @@ -72,13 +59,27 @@ Con *workspace_get(const char *num) { workspace->num = -1; else workspace->num = parsed_num; LOG("num = %d\n", workspace->num); - workspace->orientation = HORIZ; + + /* If default_orientation is set to NO_ORIENTATION we + * determine workspace orientation from workspace size. + * Otherwise we just set the orientation to default_orientation. */ + if (config.default_orientation == NO_ORIENTATION) { + workspace->orientation = (output->rect.height > output->rect.width) ? VERT : HORIZ; + DLOG("Auto orientation. Output resolution set to (%d,%d), setting orientation to %d.\n", + workspace->rect.width, workspace->rect.height, workspace->orientation); + } else { + workspace->orientation = config.default_orientation; + } + con_attach(workspace, content, false); ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"init\"}"); + if (created != NULL) + *created = true; + } + else if (created != NULL) { + *created = false; } - - //ewmh_update_workarea(); return workspace; } @@ -212,9 +213,10 @@ static void workspace_reassign_sticky(Con *con) { * */ void workspace_show(const char *num) { - Con *workspace, *current, *old; + Con *workspace, *current, *old = NULL; - workspace = workspace_get(num); + bool changed_num_workspaces; + workspace = workspace_get(num, &changed_num_workspaces); /* disable fullscreen for the other workspaces and get the workspace we are * currently on. */ @@ -223,19 +225,15 @@ void workspace_show(const char *num) { old = current; current->fullscreen_mode = CF_NONE; } - - /* Check if the the currently focused con is on the same Output as the - * workspace we chose as 'old'. If not, use the workspace of the currently - * focused con */ - Con *ws = con_get_workspace(focused); - if (ws && ws->parent != old->parent) - old = ws; + assert(old != NULL); /* enable fullscreen for the target workspace. If it happens to be the * same one we are currently on anyways, we can stop here. */ workspace->fullscreen_mode = CF_OUTPUT; - if (workspace == old) + if (workspace == con_get_workspace(focused)) { + DLOG("Not switching, already there.\n"); return; + } workspace_reassign_sticky(workspace); @@ -248,6 +246,7 @@ void workspace_show(const char *num) { LOG("Closing old workspace (%p / %s), it is empty\n", old, old->name); tree_close(old, false, false); ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"empty\"}"); + changed_num_workspaces = true; } } @@ -255,6 +254,11 @@ void workspace_show(const char *num) { workspace->fullscreen_mode = CF_OUTPUT; LOG("focused now = %p / %s\n", focused, focused->name); + /* Update the EWMH hints */ + if (changed_num_workspaces) + ewmh_update_workarea(); + ewmh_update_current_desktop(); + ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"focus\"}"); #if 0 @@ -466,7 +470,7 @@ Workspace *get_first_workspace_for_output(Output *output) { int last_ws = 0; TAILQ_FOREACH(ws, workspaces, workspaces) last_ws = ws->num; - result = workspace_get(last_ws + 1); + result = workspace_get(last_ws + 1, NULL); } workspace_initialize(result, output, false);