summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOrestis Floros <orestisflo@gmail.com>2020-04-17 00:59:55 +0200
committerOrestis Floros <orestisflo@gmail.com>2020-10-18 17:28:14 +0200
commit9d2c855fcd33a2b2fbb6f460a4180e84104804d6 (patch)
treea2c5bb34dc55adfc46299f12e232ca1c75ce3abd
parent9b295fbb57662e4f8e77d4c3a661eb19df1a7024 (diff)
downloadi3-9d2c855fcd33a2b2fbb6f460a4180e84104804d6.tar.gz
i3-9d2c855fcd33a2b2fbb6f460a4180e84104804d6.zip
workspace_get: Remove useless argument
Also reworks the structure a bit
-rw-r--r--include/workspace.h5
-rw-r--r--src/commands.c6
-rw-r--r--src/con.c2
-rw-r--r--src/handlers.c2
-rw-r--r--src/manage.c4
-rw-r--r--src/scratchpad.c6
-rw-r--r--src/workspace.c84
7 files changed, 47 insertions, 62 deletions
diff --git a/include/workspace.h b/include/workspace.h
index 8ef20215..8158f71b 100644
--- a/include/workspace.h
+++ b/include/workspace.h
@@ -57,11 +57,8 @@ bool output_triggers_assignment(Output *output, struct Workspace_Assignment *ass
* creating the workspace if necessary (by allocating the necessary amount of
* memory and initializing the data structures correctly).
*
- * If created is not NULL, *created will be set to whether or not the
- * workspace has just been created.
- *
*/
-Con *workspace_get(const char *num, bool *created);
+Con *workspace_get(const char *num);
/**
* Extracts workspace names from keybindings (e.g. “web” from “bindsym $mod+1
diff --git a/src/commands.c b/src/commands.c
index 3f8c2695..a9c90b9a 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -359,7 +359,7 @@ void cmd_move_con_to_workspace_name(I3_CMD, const char *name, const char *no_aut
LOG("should move window to workspace %s\n", name);
/* get the workspace */
- Con *ws = workspace_get(name, NULL);
+ Con *ws = workspace_get(name);
if (no_auto_back_and_forth == NULL) {
ws = maybe_auto_back_and_forth_workspace(ws);
@@ -390,7 +390,7 @@ void cmd_move_con_to_workspace_number(I3_CMD, const char *which, const char *no_
Con *ws = get_existing_workspace_by_num(parsed_num);
if (!ws) {
- ws = workspace_get(which, NULL);
+ ws = workspace_get(which);
}
if (no_auto_back_and_forth == NULL) {
@@ -1399,7 +1399,7 @@ void cmd_focus(I3_CMD) {
CMD_FOCUS_WARN_CHILDREN;
- Con *__i3_scratch = workspace_get("__i3_scratch", NULL);
+ Con *__i3_scratch = workspace_get("__i3_scratch");
owindow *current;
TAILQ_FOREACH (current, &owindows, owindows) {
Con *ws = con_get_workspace(current->con);
diff --git a/src/con.c b/src/con.c
index 3621c662..19685073 100644
--- a/src/con.c
+++ b/src/con.c
@@ -1370,7 +1370,7 @@ bool con_move_to_mark(Con *con, const char *mark) {
}
/* For target containers in the scratchpad, we just send the window to the scratchpad. */
- if (con_get_workspace(target) == workspace_get("__i3_scratch", NULL)) {
+ if (con_get_workspace(target) == workspace_get("__i3_scratch")) {
DLOG("target container is in the scratchpad, moving container to scratchpad.\n");
scratchpad_move(con);
return true;
diff --git a/src/handlers.c b/src/handlers.c
index b74e589d..eba5fe29 100644
--- a/src/handlers.c
+++ b/src/handlers.c
@@ -727,7 +727,7 @@ static void handle_client_message(xcb_client_message_event_t *event) {
return;
}
- if (con_is_internal(ws) && ws != workspace_get("__i3_scratch", NULL)) {
+ if (con_is_internal(ws) && ws != workspace_get("__i3_scratch")) {
DLOG("Workspace is internal but not scratchpad, ignoring _NET_ACTIVE_WINDOW\n");
return;
}
diff --git a/src/manage.c b/src/manage.c
index 50fec469..13e67d94 100644
--- a/src/manage.c
+++ b/src/manage.c
@@ -291,7 +291,7 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki
/* A_TO_WORKSPACE type assignment or fallback from A_TO_WORKSPACE_NUMBER
* when the target workspace number does not exist yet. */
if (!assigned_ws) {
- assigned_ws = workspace_get(assignment->dest.workspace, NULL);
+ assigned_ws = workspace_get(assignment->dest.workspace);
}
nc = con_descend_tiling_focused(assigned_ws);
@@ -322,7 +322,7 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki
} else if (startup_ws) {
/* If it was started on a specific workspace, we want to open it there. */
DLOG("Using workspace on which this application was started (%s)\n", startup_ws);
- nc = con_descend_tiling_focused(workspace_get(startup_ws, NULL));
+ nc = con_descend_tiling_focused(workspace_get(startup_ws));
DLOG("focused on ws %s: %p / %s\n", startup_ws, nc, nc->name);
if (nc->type == CT_WORKSPACE)
nc = tree_open_con(nc, cwindow);
diff --git a/src/scratchpad.c b/src/scratchpad.c
index e8d70be7..24cde612 100644
--- a/src/scratchpad.c
+++ b/src/scratchpad.c
@@ -32,7 +32,7 @@ void scratchpad_move(Con *con) {
}
DLOG("should move con %p to __i3_scratch\n", con);
- Con *__i3_scratch = workspace_get("__i3_scratch", NULL);
+ Con *__i3_scratch = workspace_get("__i3_scratch");
if (con_get_workspace(con) == __i3_scratch) {
DLOG("This window is already on __i3_scratch.\n");
return;
@@ -84,7 +84,7 @@ void scratchpad_move(Con *con) {
*/
bool scratchpad_show(Con *con) {
DLOG("should show scratchpad window %p\n", con);
- Con *__i3_scratch = workspace_get("__i3_scratch", NULL);
+ Con *__i3_scratch = workspace_get("__i3_scratch");
Con *floating;
/* If this was 'scratchpad show' without criteria, we check if the
@@ -245,7 +245,7 @@ static int _lcm(const int m, const int n) {
*
*/
void scratchpad_fix_resolution(void) {
- Con *__i3_scratch = workspace_get("__i3_scratch", NULL);
+ Con *__i3_scratch = workspace_get("__i3_scratch");
Con *__i3_output = con_get_output(__i3_scratch);
DLOG("Current resolution: (%d, %d) %d x %d\n",
__i3_output->rect.x, __i3_output->rect.y,
diff --git a/src/workspace.c b/src/workspace.c
index f48599c7..406d35ad 100644
--- a/src/workspace.c
+++ b/src/workspace.c
@@ -122,52 +122,45 @@ bool output_triggers_assignment(Output *output, struct Workspace_Assignment *ass
* memory and initializing the data structures correctly).
*
*/
-Con *workspace_get(const char *num, bool *created) {
+Con *workspace_get(const char *num) {
Con *workspace = get_existing_workspace_by_name(num);
+ if (workspace) {
+ return workspace;
+ }
- if (workspace == NULL) {
- LOG("Creating new workspace \"%s\"\n", num);
-
- /* We set workspace->num to the number if this workspace’s name begins
- * with a positive number. Otherwise it’s a named ws and num will be
- * -1. */
- long parsed_num = ws_name_to_number(num);
+ LOG("Creating new workspace \"%s\"\n", num);
- Con *output = get_assigned_output(num, parsed_num);
- /* if an assignment is not found, we create this workspace on the current output */
- if (!output) {
- output = con_get_output(focused);
- }
+ /* We set workspace->num to the number if this workspace’s name begins with
+ * a positive number. Otherwise it’s a named ws and num will be 1. */
+ const long parsed_num = ws_name_to_number(num);
- 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, NULL);
- char *name;
- sasprintf(&name, "[i3 con] workspace %s", num);
- x_set_name(workspace, name);
- free(name);
- workspace->type = CT_WORKSPACE;
- FREE(workspace->name);
- workspace->name = sstrdup(num);
- workspace->workspace_layout = config.default_layout;
- workspace->num = parsed_num;
- LOG("num = %d\n", workspace->num);
-
- workspace->parent = content;
- _workspace_apply_default_orientation(workspace);
-
- con_attach(workspace, content, false);
-
- ipc_send_workspace_event("init", workspace, NULL);
- ewmh_update_desktop_properties();
- if (created != NULL)
- *created = true;
- } else if (created != NULL) {
- *created = false;
+ Con *output = get_assigned_output(num, parsed_num);
+ /* if an assignment is not found, we create this workspace on the current output */
+ if (!output) {
+ output = con_get_output(focused);
}
+ /* No parent because we need to attach this container after setting its
+ * type. con_attach will handle CT_WORKSPACEs differently. */
+ workspace = con_new(NULL, NULL);
+
+ char *name;
+ sasprintf(&name, "[i3 con] workspace %s", num);
+ x_set_name(workspace, name);
+ free(name);
+
+ FREE(workspace->name);
+ workspace->name = sstrdup(num);
+ workspace->workspace_layout = config.default_layout;
+ workspace->num = parsed_num;
+ workspace->type = CT_WORKSPACE;
+
+ con_attach(workspace, output_get_content(output), false);
+ _workspace_apply_default_orientation(workspace);
+
+ ipc_send_workspace_event("init", workspace, NULL);
+ ewmh_update_desktop_properties();
+
return workspace;
}
@@ -552,9 +545,7 @@ void workspace_show(Con *workspace) {
*
*/
void workspace_show_by_name(const char *num) {
- Con *workspace;
- workspace = workspace_get(num, NULL);
- workspace_show(workspace);
+ workspace_show(workspace_get(num));
}
/*
@@ -821,10 +812,7 @@ Con *workspace_back_and_forth_get(void) {
return NULL;
}
- Con *workspace;
- workspace = workspace_get(previous_workspace_name, NULL);
-
- return workspace;
+ return workspace_get(previous_workspace_name);
}
static bool get_urgency_flag(Con *con) {
@@ -1011,7 +999,7 @@ void workspace_move_to_output(Con *ws, Output *output) {
/* so create the workspace referenced to by this assignment */
DLOG("Creating workspace from assignment %s.\n", assignment->name);
- workspace_get(assignment->name, NULL);
+ workspace_get(assignment->name);
used_assignment = true;
break;
}