Codebase list i3-gaps / 9d2c855
workspace_get: Remove useless argument Also reworks the structure a bit Orestis Floros 3 years ago
7 changed file(s) with 51 addition(s) and 66 deletion(s). Raw diff Collapse all Expand all
5656 * creating the workspace if necessary (by allocating the necessary amount of
5757 * memory and initializing the data structures correctly).
5858 *
59 * If created is not NULL, *created will be set to whether or not the
60 * workspace has just been created.
61 *
6259 */
63 Con *workspace_get(const char *num, bool *created);
60 Con *workspace_get(const char *num);
6461
6562 /**
6663 * Extracts workspace names from keybindings (e.g. “web” from “bindsym $mod+1
358358
359359 LOG("should move window to workspace %s\n", name);
360360 /* get the workspace */
361 Con *ws = workspace_get(name, NULL);
361 Con *ws = workspace_get(name);
362362
363363 if (no_auto_back_and_forth == NULL) {
364364 ws = maybe_auto_back_and_forth_workspace(ws);
389389
390390 Con *ws = get_existing_workspace_by_num(parsed_num);
391391 if (!ws) {
392 ws = workspace_get(which, NULL);
392 ws = workspace_get(which);
393393 }
394394
395395 if (no_auto_back_and_forth == NULL) {
13981398
13991399 CMD_FOCUS_WARN_CHILDREN;
14001400
1401 Con *__i3_scratch = workspace_get("__i3_scratch", NULL);
1401 Con *__i3_scratch = workspace_get("__i3_scratch");
14021402 owindow *current;
14031403 TAILQ_FOREACH (current, &owindows, owindows) {
14041404 Con *ws = con_get_workspace(current->con);
13691369 }
13701370
13711371 /* 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")) {
13731373 DLOG("target container is in the scratchpad, moving container to scratchpad.\n");
13741374 scratchpad_move(con);
13751375 return true;
726726 return;
727727 }
728728
729 if (con_is_internal(ws) && ws != workspace_get("__i3_scratch", NULL)) {
729 if (con_is_internal(ws) && ws != workspace_get("__i3_scratch")) {
730730 DLOG("Workspace is internal but not scratchpad, ignoring _NET_ACTIVE_WINDOW\n");
731731 return;
732732 }
290290 /* A_TO_WORKSPACE type assignment or fallback from A_TO_WORKSPACE_NUMBER
291291 * when the target workspace number does not exist yet. */
292292 if (!assigned_ws) {
293 assigned_ws = workspace_get(assignment->dest.workspace, NULL);
293 assigned_ws = workspace_get(assignment->dest.workspace);
294294 }
295295
296296 nc = con_descend_tiling_focused(assigned_ws);
321321 } else if (startup_ws) {
322322 /* If it was started on a specific workspace, we want to open it there. */
323323 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));
325325 DLOG("focused on ws %s: %p / %s\n", startup_ws, nc, nc->name);
326326 if (nc->type == CT_WORKSPACE)
327327 nc = tree_open_con(nc, cwindow);
3131 }
3232 DLOG("should move con %p to __i3_scratch\n", con);
3333
34 Con *__i3_scratch = workspace_get("__i3_scratch", NULL);
34 Con *__i3_scratch = workspace_get("__i3_scratch");
3535 if (con_get_workspace(con) == __i3_scratch) {
3636 DLOG("This window is already on __i3_scratch.\n");
3737 return;
8383 */
8484 bool scratchpad_show(Con *con) {
8585 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");
8787 Con *floating;
8888
8989 /* If this was 'scratchpad show' without criteria, we check if the
244244 *
245245 */
246246 void scratchpad_fix_resolution(void) {
247 Con *__i3_scratch = workspace_get("__i3_scratch", NULL);
247 Con *__i3_scratch = workspace_get("__i3_scratch");
248248 Con *__i3_output = con_get_output(__i3_scratch);
249249 DLOG("Current resolution: (%d, %d) %d x %d\n",
250250 __i3_output->rect.x, __i3_output->rect.y,
121121 * memory and initializing the data structures correctly).
122122 *
123123 */
124 Con *workspace_get(const char *num, bool *created) {
124 Con *workspace_get(const char *num) {
125125 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();
169162
170163 return workspace;
171164 }
551544 *
552545 */
553546 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));
557548 }
558549
559550 /*
820811 return NULL;
821812 }
822813
823 Con *workspace;
824 workspace = workspace_get(previous_workspace_name, NULL);
825
826 return workspace;
814 return workspace_get(previous_workspace_name);
827815 }
828816
829817 static bool get_urgency_flag(Con *con) {
1010998
1011999 /* so create the workspace referenced to by this assignment */
10121000 DLOG("Creating workspace from assignment %s.\n", assignment->name);
1013 workspace_get(assignment->name, NULL);
1001 workspace_get(assignment->name);
10141002 used_assignment = true;
10151003 break;
10161004 }