workspace_get: Remove useless argument
Also reworks the structure a bit
Orestis Floros
3 years ago
56 | 56 | * creating the workspace if necessary (by allocating the necessary amount of |
57 | 57 | * memory and initializing the data structures correctly). |
58 | 58 | * |
59 | * If created is not NULL, *created will be set to whether or not the | |
60 | * workspace has just been created. | |
61 | * | |
62 | 59 | */ |
63 | Con *workspace_get(const char *num, bool *created); | |
60 | Con *workspace_get(const char *num); | |
64 | 61 | |
65 | 62 | /** |
66 | 63 | * Extracts workspace names from keybindings (e.g. “web” from “bindsym $mod+1 |
358 | 358 | |
359 | 359 | LOG("should move window to workspace %s\n", name); |
360 | 360 | /* get the workspace */ |
361 | Con *ws = workspace_get(name, NULL); | |
361 | Con *ws = workspace_get(name); | |
362 | 362 | |
363 | 363 | if (no_auto_back_and_forth == NULL) { |
364 | 364 | ws = maybe_auto_back_and_forth_workspace(ws); |
389 | 389 | |
390 | 390 | Con *ws = get_existing_workspace_by_num(parsed_num); |
391 | 391 | if (!ws) { |
392 | ws = workspace_get(which, NULL); | |
392 | ws = workspace_get(which); | |
393 | 393 | } |
394 | 394 | |
395 | 395 | if (no_auto_back_and_forth == NULL) { |
1398 | 1398 | |
1399 | 1399 | CMD_FOCUS_WARN_CHILDREN; |
1400 | 1400 | |
1401 | Con *__i3_scratch = workspace_get("__i3_scratch", NULL); | |
1401 | Con *__i3_scratch = workspace_get("__i3_scratch"); | |
1402 | 1402 | owindow *current; |
1403 | 1403 | TAILQ_FOREACH (current, &owindows, owindows) { |
1404 | 1404 | Con *ws = con_get_workspace(current->con); |
1369 | 1369 | } |
1370 | 1370 | |
1371 | 1371 | /* For target containers in the scratchpad, we just send the window to the scratchpad. */ |
1372 | if (con_get_workspace(target) == workspace_get("__i3_scratch", NULL)) { | |
1372 | if (con_get_workspace(target) == workspace_get("__i3_scratch")) { | |
1373 | 1373 | DLOG("target container is in the scratchpad, moving container to scratchpad.\n"); |
1374 | 1374 | scratchpad_move(con); |
1375 | 1375 | return true; |
726 | 726 | return; |
727 | 727 | } |
728 | 728 | |
729 | if (con_is_internal(ws) && ws != workspace_get("__i3_scratch", NULL)) { | |
729 | if (con_is_internal(ws) && ws != workspace_get("__i3_scratch")) { | |
730 | 730 | DLOG("Workspace is internal but not scratchpad, ignoring _NET_ACTIVE_WINDOW\n"); |
731 | 731 | return; |
732 | 732 | } |
290 | 290 | /* A_TO_WORKSPACE type assignment or fallback from A_TO_WORKSPACE_NUMBER |
291 | 291 | * when the target workspace number does not exist yet. */ |
292 | 292 | if (!assigned_ws) { |
293 | assigned_ws = workspace_get(assignment->dest.workspace, NULL); | |
293 | assigned_ws = workspace_get(assignment->dest.workspace); | |
294 | 294 | } |
295 | 295 | |
296 | 296 | nc = con_descend_tiling_focused(assigned_ws); |
321 | 321 | } else if (startup_ws) { |
322 | 322 | /* If it was started on a specific workspace, we want to open it there. */ |
323 | 323 | DLOG("Using workspace on which this application was started (%s)\n", startup_ws); |
324 | nc = con_descend_tiling_focused(workspace_get(startup_ws, NULL)); | |
324 | nc = con_descend_tiling_focused(workspace_get(startup_ws)); | |
325 | 325 | DLOG("focused on ws %s: %p / %s\n", startup_ws, nc, nc->name); |
326 | 326 | if (nc->type == CT_WORKSPACE) |
327 | 327 | nc = tree_open_con(nc, cwindow); |
31 | 31 | } |
32 | 32 | DLOG("should move con %p to __i3_scratch\n", con); |
33 | 33 | |
34 | Con *__i3_scratch = workspace_get("__i3_scratch", NULL); | |
34 | Con *__i3_scratch = workspace_get("__i3_scratch"); | |
35 | 35 | if (con_get_workspace(con) == __i3_scratch) { |
36 | 36 | DLOG("This window is already on __i3_scratch.\n"); |
37 | 37 | return; |
83 | 83 | */ |
84 | 84 | bool scratchpad_show(Con *con) { |
85 | 85 | DLOG("should show scratchpad window %p\n", con); |
86 | Con *__i3_scratch = workspace_get("__i3_scratch", NULL); | |
86 | Con *__i3_scratch = workspace_get("__i3_scratch"); | |
87 | 87 | Con *floating; |
88 | 88 | |
89 | 89 | /* If this was 'scratchpad show' without criteria, we check if the |
244 | 244 | * |
245 | 245 | */ |
246 | 246 | void scratchpad_fix_resolution(void) { |
247 | Con *__i3_scratch = workspace_get("__i3_scratch", NULL); | |
247 | Con *__i3_scratch = workspace_get("__i3_scratch"); | |
248 | 248 | Con *__i3_output = con_get_output(__i3_scratch); |
249 | 249 | DLOG("Current resolution: (%d, %d) %d x %d\n", |
250 | 250 | __i3_output->rect.x, __i3_output->rect.y, |
121 | 121 | * memory and initializing the data structures correctly). |
122 | 122 | * |
123 | 123 | */ |
124 | Con *workspace_get(const char *num, bool *created) { | |
124 | Con *workspace_get(const char *num) { | |
125 | 125 | Con *workspace = get_existing_workspace_by_name(num); |
126 | ||
127 | if (workspace == NULL) { | |
128 | LOG("Creating new workspace \"%s\"\n", num); | |
129 | ||
130 | /* We set workspace->num to the number if this workspace’s name begins | |
131 | * with a positive number. Otherwise it’s a named ws and num will be | |
132 | * -1. */ | |
133 | long parsed_num = ws_name_to_number(num); | |
134 | ||
135 | Con *output = get_assigned_output(num, parsed_num); | |
136 | /* if an assignment is not found, we create this workspace on the current output */ | |
137 | if (!output) { | |
138 | output = con_get_output(focused); | |
139 | } | |
140 | ||
141 | Con *content = output_get_content(output); | |
142 | LOG("got output %p with content %p\n", output, content); | |
143 | /* We need to attach this container after setting its type. con_attach | |
144 | * will handle CT_WORKSPACEs differently */ | |
145 | workspace = con_new(NULL, NULL); | |
146 | char *name; | |
147 | sasprintf(&name, "[i3 con] workspace %s", num); | |
148 | x_set_name(workspace, name); | |
149 | free(name); | |
150 | workspace->type = CT_WORKSPACE; | |
151 | FREE(workspace->name); | |
152 | workspace->name = sstrdup(num); | |
153 | workspace->workspace_layout = config.default_layout; | |
154 | workspace->num = parsed_num; | |
155 | LOG("num = %d\n", workspace->num); | |
156 | ||
157 | workspace->parent = content; | |
158 | _workspace_apply_default_orientation(workspace); | |
159 | ||
160 | con_attach(workspace, content, false); | |
161 | ||
162 | ipc_send_workspace_event("init", workspace, NULL); | |
163 | ewmh_update_desktop_properties(); | |
164 | if (created != NULL) | |
165 | *created = true; | |
166 | } else if (created != NULL) { | |
167 | *created = false; | |
168 | } | |
126 | if (workspace) { | |
127 | return workspace; | |
128 | } | |
129 | ||
130 | LOG("Creating new workspace \"%s\"\n", num); | |
131 | ||
132 | /* We set workspace->num to the number if this workspace’s name begins with | |
133 | * a positive number. Otherwise it’s a named ws and num will be 1. */ | |
134 | const long parsed_num = ws_name_to_number(num); | |
135 | ||
136 | Con *output = get_assigned_output(num, parsed_num); | |
137 | /* if an assignment is not found, we create this workspace on the current output */ | |
138 | if (!output) { | |
139 | output = con_get_output(focused); | |
140 | } | |
141 | ||
142 | /* No parent because we need to attach this container after setting its | |
143 | * type. con_attach will handle CT_WORKSPACEs differently. */ | |
144 | workspace = con_new(NULL, NULL); | |
145 | ||
146 | char *name; | |
147 | sasprintf(&name, "[i3 con] workspace %s", num); | |
148 | x_set_name(workspace, name); | |
149 | free(name); | |
150 | ||
151 | FREE(workspace->name); | |
152 | workspace->name = sstrdup(num); | |
153 | workspace->workspace_layout = config.default_layout; | |
154 | workspace->num = parsed_num; | |
155 | workspace->type = CT_WORKSPACE; | |
156 | ||
157 | con_attach(workspace, output_get_content(output), false); | |
158 | _workspace_apply_default_orientation(workspace); | |
159 | ||
160 | ipc_send_workspace_event("init", workspace, NULL); | |
161 | ewmh_update_desktop_properties(); | |
169 | 162 | |
170 | 163 | return workspace; |
171 | 164 | } |
551 | 544 | * |
552 | 545 | */ |
553 | 546 | void workspace_show_by_name(const char *num) { |
554 | Con *workspace; | |
555 | workspace = workspace_get(num, NULL); | |
556 | workspace_show(workspace); | |
547 | workspace_show(workspace_get(num)); | |
557 | 548 | } |
558 | 549 | |
559 | 550 | /* |
820 | 811 | return NULL; |
821 | 812 | } |
822 | 813 | |
823 | Con *workspace; | |
824 | workspace = workspace_get(previous_workspace_name, NULL); | |
825 | ||
826 | return workspace; | |
814 | return workspace_get(previous_workspace_name); | |
827 | 815 | } |
828 | 816 | |
829 | 817 | static bool get_urgency_flag(Con *con) { |
1010 | 998 | |
1011 | 999 | /* so create the workspace referenced to by this assignment */ |
1012 | 1000 | DLOG("Creating workspace from assignment %s.\n", assignment->name); |
1013 | workspace_get(assignment->name, NULL); | |
1001 | workspace_get(assignment->name); | |
1014 | 1002 | used_assignment = true; |
1015 | 1003 | break; |
1016 | 1004 | } |