summaryrefslogtreecommitdiffstats
path: root/sway/workspace.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/workspace.c')
-rw-r--r--sway/workspace.c77
1 files changed, 11 insertions, 66 deletions
diff --git a/sway/workspace.c b/sway/workspace.c
index 05a669fe..d436da8e 100644
--- a/sway/workspace.c
+++ b/sway/workspace.c
@@ -31,7 +31,7 @@ char *workspace_next_name(void) {
31 char* target = malloc(strlen(args->items[1]) + 1); 31 char* target = malloc(strlen(args->items[1]) + 1);
32 strcpy(target, args->items[1]); 32 strcpy(target, args->items[1]);
33 while (*target == ' ' || *target == '\t') 33 while (*target == ' ' || *target == '\t')
34 target++; 34 target++;
35 35
36 // Make sure that the command references an actual workspace 36 // Make sure that the command references an actual workspace
37 // not a command about workspaces 37 // not a command about workspaces
@@ -42,11 +42,15 @@ char *workspace_next_name(void) {
42 strcmp(target, "number") == 0 || 42 strcmp(target, "number") == 0 ||
43 strcmp(target, "back_and_forth") == 0 || 43 strcmp(target, "back_and_forth") == 0 ||
44 strcmp(target, "current") == 0) 44 strcmp(target, "current") == 0)
45 {
46 list_free(args);
45 continue; 47 continue;
46 48 }
47 //Make sure that the workspace doesn't already exist 49
50 // Make sure that the workspace doesn't already exist
48 if (workspace_find_by_name(target)) { 51 if (workspace_find_by_name(target)) {
49 continue; 52 list_free(args);
53 continue;
50 } 54 }
51 55
52 list_free(args); 56 list_free(args);
@@ -54,6 +58,7 @@ char *workspace_next_name(void) {
54 sway_log(L_DEBUG, "Workspace: Found free name %s", target); 58 sway_log(L_DEBUG, "Workspace: Found free name %s", target);
55 return target; 59 return target;
56 } 60 }
61 list_free(args);
57 } 62 }
58 // As a fall back, get the current number of active workspaces 63 // As a fall back, get the current number of active workspaces
59 // and return that + 1 for the next workspace's name 64 // and return that + 1 for the next workspace's name
@@ -70,14 +75,12 @@ char *workspace_next_name(void) {
70 75
71swayc_t *workspace_create(const char* name) { 76swayc_t *workspace_create(const char* name) {
72 swayc_t *parent = get_focused_container(&root_container); 77 swayc_t *parent = get_focused_container(&root_container);
73 while (parent->type != C_OUTPUT) { 78 parent = swayc_parent_by_type(parent, C_OUTPUT);
74 parent = parent->parent;
75 }
76 return new_workspace(parent, name); 79 return new_workspace(parent, name);
77} 80}
78 81
79bool workspace_by_name(swayc_t *view, void *data) { 82bool workspace_by_name(swayc_t *view, void *data) {
80 return (view->type == C_WORKSPACE) && 83 return (view->type == C_WORKSPACE) &&
81 (strcasecmp(view->name, (char *) data) == 0); 84 (strcasecmp(view->name, (char *) data) == 0);
82} 85}
83 86
@@ -180,62 +183,4 @@ void workspace_switch(swayc_t *workspace) {
180 sway_log(L_DEBUG, "Switching to workspace %p:%s", workspace, workspace->name); 183 sway_log(L_DEBUG, "Switching to workspace %p:%s", workspace, workspace->name);
181 set_focused_container(get_focused_view(workspace)); 184 set_focused_container(get_focused_view(workspace));
182 arrange_windows(workspace, -1, -1); 185 arrange_windows(workspace, -1, -1);
183 active_workspace = workspace;
184}
185
186/* XXX:DEBUG:XXX */
187static void container_log(const swayc_t *c) {
188 fprintf(stderr, "focus:%c|",
189 c->is_focused ? 'F' : //Focused
190 c == active_workspace ? 'W' : //active workspace
191 c == &root_container ? 'R' : //root
192 'X');//not any others
193 fprintf(stderr,"(%p)",c);
194 fprintf(stderr,"(p:%p)",c->parent);
195 fprintf(stderr,"(f:%p)",c->focused);
196 fprintf(stderr,"(h:%ld)",c->handle);
197 fprintf(stderr,"Type:");
198 fprintf(stderr,
199 c->type == C_ROOT ? "Root|" :
200 c->type == C_OUTPUT ? "Output|" :
201 c->type == C_WORKSPACE ? "Workspace|" :
202 c->type == C_CONTAINER ? "Container|" :
203 c->type == C_VIEW ? "View|" : "Unknown|");
204 fprintf(stderr,"layout:");
205 fprintf(stderr,
206 c->layout == L_NONE ? "NONE|" :
207 c->layout == L_HORIZ ? "Horiz|":
208 c->layout == L_VERT ? "Vert|":
209 c->layout == L_STACKED ? "Stacked|":
210 c->layout == L_FLOATING ? "Floating|":
211 "Unknown|");
212 fprintf(stderr, "w:%d|h:%d|", c->width, c->height);
213 fprintf(stderr, "x:%d|y:%d|", c->x, c->y);
214 fprintf(stderr, "vis:%c|", c->visible?'t':'f');
215 fprintf(stderr, "wgt:%d|", c->weight);
216 fprintf(stderr, "name:%.16s|", c->name);
217 fprintf(stderr, "children:%d\n",c->children?c->children->length:0);
218}
219void layout_log(const swayc_t *c, int depth) {
220 int i, d;
221 int e = c->children ? c->children->length : 0;
222 container_log(c);
223 if (e) {
224 for (i = 0; i < e; ++i) {
225 fputc('|',stderr);
226 for (d = 0; d < depth; ++d) fputc('-', stderr);
227 layout_log(c->children->items[i], depth + 1);
228 }
229 }
230 if (c->type == C_WORKSPACE) {
231 e = c->floating?c->floating->length:0;
232 if (e) {
233 for (i = 0; i < e; ++i) {
234 fputc('|',stderr);
235 for (d = 0; d < depth; ++d) fputc('-', stderr);
236 layout_log(c->floating->items[i], depth + 1);
237 }
238 }
239 }
240} 186}
241/* XXX:DEBUG:XXX */