From a080794e59bfff0f825902e53f2bddc988ffb4f8 Mon Sep 17 00:00:00 2001 From: Deiz Date: Sun, 23 Sep 2012 08:56:56 -0400 Subject: [PATCH] Replace duplicate "__" workspace prefix checks with a single function. --- include/con.h | 6 ++++++ src/con.c | 13 ++++++++++--- src/ipc.c | 2 +- src/render.c | 4 ++-- src/workspace.c | 14 +++++++------- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/include/con.h b/include/con.h index 7bd5b087..b4624373 100644 --- a/include/con.h +++ b/include/con.h @@ -66,6 +66,12 @@ Con *con_parent_with_orientation(Con *con, orientation_t orientation); */ Con *con_get_fullscreen_con(Con *con, int fullscreen_mode); +/** + * Returns true if the container is internal, such as __i3_scratch + * + */ +bool con_is_internal(Con *con); + /** * Returns true if the node is floating. * diff --git a/src/con.c b/src/con.c index 8bc9badc..acc5e8af 100644 --- a/src/con.c +++ b/src/con.c @@ -359,6 +359,14 @@ Con *con_get_fullscreen_con(Con *con, int fullscreen_mode) { return NULL; } +/** + * Returns true if the container is internal, such as __i3_scratch + * + */ +bool con_is_internal(Con *con) { + return (con->name[0] == '_' && con->name[1] == '_'); +} + /* * Returns true if the node is floating. * @@ -692,7 +700,7 @@ void con_move_to_workspace(Con *con, Con *workspace, bool fix_coordinates, bool * calling tree_render(), so for the "real" focus this is a no-op). * We don’t focus the con for i3 pseudo workspaces like __i3_scratch and * we don’t focus when there is a fullscreen con on that workspace. */ - if ((workspace->name[0] != '_' || workspace->name[1] != '_') && + if (!con_is_internal(workspace) && con_get_fullscreen_con(workspace, CF_OUTPUT) == NULL) con_focus(con_descend_focused(con)); @@ -701,8 +709,7 @@ void con_move_to_workspace(Con *con, Con *workspace, bool fix_coordinates, bool * don’t want to focus invisible workspaces */ if (source_output != dest_output && workspace_is_visible(workspace) && - workspace->name[0] != '_' && - workspace->name[1] != '_') { + !con_is_internal(workspace)) { DLOG("Moved to a different output, focusing target\n"); } else { /* Descend focus stack in case focus_next is a workspace which can diff --git a/src/ipc.c b/src/ipc.c index 169c659f..6f8e962d 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -405,7 +405,7 @@ IPC_HANDLER(get_workspaces) { Con *output; TAILQ_FOREACH(output, &(croot->nodes_head), nodes) { - if (output->name[0] == '_' && output->name[1] == '_') + if (con_is_internal(output)) continue; Con *ws; TAILQ_FOREACH(ws, &(output_get_content(output)->nodes_head), nodes) { diff --git a/src/render.c b/src/render.c index 0eda1a97..6f0880d8 100644 --- a/src/render.c +++ b/src/render.c @@ -225,7 +225,7 @@ void render_con(Con *con, bool render_fullscreen) { if (con->layout == L_OUTPUT) { /* Skip i3-internal outputs */ - if (con->name[0] == '_' && con->name[1] == '_') + if (con_is_internal(con)) return; render_l_output(con); } else if (con->type == CT_ROOT) { @@ -240,7 +240,7 @@ void render_con(Con *con, bool render_fullscreen) { * windows/containers so that they overlap on another output. */ DLOG("Rendering floating windows:\n"); TAILQ_FOREACH(output, &(con->nodes_head), nodes) { - if (output->name[0] == '_' && output->name[1] == '_') + if (con_is_internal(output)) continue; /* Get the active workspace of that output */ Con *content = output_get_content(output); diff --git a/src/workspace.c b/src/workspace.c index 71102e5c..3f09ea99 100644 --- a/src/workspace.c +++ b/src/workspace.c @@ -333,7 +333,7 @@ static void _workspace_show(Con *workspace) { Con *current, *old = NULL; /* safe-guard against showing i3-internal workspaces like __i3_scratch */ - if (workspace->name[0] == '_' && workspace->name[1] == '_') + if (con_is_internal(workspace)) return; /* disable fullscreen for the other workspaces and get the workspace we are @@ -462,7 +462,7 @@ Con* workspace_next(void) { /* If currently a numbered workspace, find next numbered workspace. */ TAILQ_FOREACH(output, &(croot->nodes_head), nodes) { /* Skip outputs starting with __, they are internal. */ - if (output->name[0] == '_' && output->name[1] == '_') + if (con_is_internal(output)) continue; NODES_FOREACH(output_get_content(output)) { if (child->type != CT_WORKSPACE) @@ -483,7 +483,7 @@ Con* workspace_next(void) { bool found_current = false; TAILQ_FOREACH(output, &(croot->nodes_head), nodes) { /* Skip outputs starting with __, they are internal. */ - if (output->name[0] == '_' && output->name[1] == '_') + if (con_is_internal(output)) continue; NODES_FOREACH(output_get_content(output)) { if (child->type != CT_WORKSPACE) @@ -502,7 +502,7 @@ Con* workspace_next(void) { if (!next) { TAILQ_FOREACH(output, &(croot->nodes_head), nodes) { /* Skip outputs starting with __, they are internal. */ - if (output->name[0] == '_' && output->name[1] == '_') + if (con_is_internal(output)) continue; NODES_FOREACH(output_get_content(output)) { if (child->type != CT_WORKSPACE) @@ -534,7 +534,7 @@ Con* workspace_prev(void) { /* If numbered workspace, find previous numbered workspace. */ TAILQ_FOREACH_REVERSE(output, &(croot->nodes_head), nodes_head, nodes) { /* Skip outputs starting with __, they are internal. */ - if (output->name[0] == '_' && output->name[1] == '_') + if (con_is_internal(output)) continue; NODES_FOREACH_REVERSE(output_get_content(output)) { if (child->type != CT_WORKSPACE || child->num == -1) @@ -553,7 +553,7 @@ Con* workspace_prev(void) { bool found_current = false; TAILQ_FOREACH_REVERSE(output, &(croot->nodes_head), nodes_head, nodes) { /* Skip outputs starting with __, they are internal. */ - if (output->name[0] == '_' && output->name[1] == '_') + if (con_is_internal(output)) continue; NODES_FOREACH_REVERSE(output_get_content(output)) { if (child->type != CT_WORKSPACE) @@ -572,7 +572,7 @@ Con* workspace_prev(void) { if (!prev) { TAILQ_FOREACH_REVERSE(output, &(croot->nodes_head), nodes_head, nodes) { /* Skip outputs starting with __, they are internal. */ - if (output->name[0] == '_' && output->name[1] == '_') + if (con_is_internal(output)) continue; NODES_FOREACH_REVERSE(output_get_content(output)) { if (child->type != CT_WORKSPACE) -- 2.39.2