Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Commit

Permalink
workspace_get: Remove useless argument
Browse files Browse the repository at this point in the history
Also reworks the structure a bit
  • Loading branch information
orestisfl committed Oct 18, 2020
1 parent 9b295fb commit 9d2c855
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 62 deletions.
5 changes: 1 addition & 4 deletions include/workspace.h
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/commands.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/con.c
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/handlers.c
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/manage.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/scratchpad.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
84 changes: 36 additions & 48 deletions src/workspace.c
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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));
}

/*
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 9d2c855

Please sign in to comment.