workspace_get: Remove useless argument

Also reworks the structure a bit
This commit is contained in:
Orestis Floros 2020-04-17 00:59:55 +02:00
parent 9b295fbb57
commit 9d2c855fcd
No known key found for this signature in database
GPG Key ID: A09DBD7D3222C1C3
7 changed files with 50 additions and 65 deletions

View File

@ -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 * creating the workspace if necessary (by allocating the necessary amount of
* memory and initializing the data structures correctly). * 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 * Extracts workspace names from keybindings (e.g. web from bindsym $mod+1

View File

@ -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); LOG("should move window to workspace %s\n", name);
/* get the workspace */ /* get the workspace */
Con *ws = workspace_get(name, NULL); Con *ws = workspace_get(name);
if (no_auto_back_and_forth == NULL) { if (no_auto_back_and_forth == NULL) {
ws = maybe_auto_back_and_forth_workspace(ws); 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); Con *ws = get_existing_workspace_by_num(parsed_num);
if (!ws) { if (!ws) {
ws = workspace_get(which, NULL); ws = workspace_get(which);
} }
if (no_auto_back_and_forth == NULL) { if (no_auto_back_and_forth == NULL) {
@ -1399,7 +1399,7 @@ void cmd_focus(I3_CMD) {
CMD_FOCUS_WARN_CHILDREN; CMD_FOCUS_WARN_CHILDREN;
Con *__i3_scratch = workspace_get("__i3_scratch", NULL); Con *__i3_scratch = workspace_get("__i3_scratch");
owindow *current; owindow *current;
TAILQ_FOREACH (current, &owindows, owindows) { TAILQ_FOREACH (current, &owindows, owindows) {
Con *ws = con_get_workspace(current->con); Con *ws = con_get_workspace(current->con);

View File

@ -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. */ /* 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"); DLOG("target container is in the scratchpad, moving container to scratchpad.\n");
scratchpad_move(con); scratchpad_move(con);
return true; return true;

View File

@ -727,7 +727,7 @@ static void handle_client_message(xcb_client_message_event_t *event) {
return; 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"); DLOG("Workspace is internal but not scratchpad, ignoring _NET_ACTIVE_WINDOW\n");
return; return;
} }

View File

@ -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 /* A_TO_WORKSPACE type assignment or fallback from A_TO_WORKSPACE_NUMBER
* when the target workspace number does not exist yet. */ * when the target workspace number does not exist yet. */
if (!assigned_ws) { 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); 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) { } else if (startup_ws) {
/* If it was started on a specific workspace, we want to open it there. */ /* 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); 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); DLOG("focused on ws %s: %p / %s\n", startup_ws, nc, nc->name);
if (nc->type == CT_WORKSPACE) if (nc->type == CT_WORKSPACE)
nc = tree_open_con(nc, cwindow); nc = tree_open_con(nc, cwindow);

View File

@ -32,7 +32,7 @@ void scratchpad_move(Con *con) {
} }
DLOG("should move con %p to __i3_scratch\n", 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) { if (con_get_workspace(con) == __i3_scratch) {
DLOG("This window is already on __i3_scratch.\n"); DLOG("This window is already on __i3_scratch.\n");
return; return;
@ -84,7 +84,7 @@ void scratchpad_move(Con *con) {
*/ */
bool scratchpad_show(Con *con) { bool scratchpad_show(Con *con) {
DLOG("should show scratchpad window %p\n", 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; Con *floating;
/* If this was 'scratchpad show' without criteria, we check if the /* 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) { 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); Con *__i3_output = con_get_output(__i3_scratch);
DLOG("Current resolution: (%d, %d) %d x %d\n", DLOG("Current resolution: (%d, %d) %d x %d\n",
__i3_output->rect.x, __i3_output->rect.y, __i3_output->rect.x, __i3_output->rect.y,

View File

@ -122,52 +122,45 @@ bool output_triggers_assignment(Output *output, struct Workspace_Assignment *ass
* memory and initializing the data structures correctly). * 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); Con *workspace = get_existing_workspace_by_name(num);
if (workspace) {
if (workspace == NULL) { return workspace;
LOG("Creating new workspace \"%s\"\n", num);
/* We set workspace->num to the number if this workspaces name begins
* with a positive number. Otherwise its a named ws and num will be
* -1. */
long parsed_num = ws_name_to_number(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);
}
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;
} }
LOG("Creating new workspace \"%s\"\n", num);
/* We set workspace->num to the number if this workspaces name begins with
* a positive number. Otherwise its a named ws and num will be 1. */
const long parsed_num = ws_name_to_number(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);
}
/* 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; return workspace;
} }
@ -552,9 +545,7 @@ void workspace_show(Con *workspace) {
* *
*/ */
void workspace_show_by_name(const char *num) { void workspace_show_by_name(const char *num) {
Con *workspace; workspace_show(workspace_get(num));
workspace = workspace_get(num, NULL);
workspace_show(workspace);
} }
/* /*
@ -821,10 +812,7 @@ Con *workspace_back_and_forth_get(void) {
return NULL; return NULL;
} }
Con *workspace; return workspace_get(previous_workspace_name);
workspace = workspace_get(previous_workspace_name, NULL);
return workspace;
} }
static bool get_urgency_flag(Con *con) { 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 */ /* so create the workspace referenced to by this assignment */
DLOG("Creating workspace from assignment %s.\n", assignment->name); DLOG("Creating workspace from assignment %s.\n", assignment->name);
workspace_get(assignment->name, NULL); workspace_get(assignment->name);
used_assignment = true; used_assignment = true;
break; break;
} }