aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/workspace.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/tree/workspace.c')
-rw-r--r--sway/tree/workspace.c70
1 files changed, 35 insertions, 35 deletions
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c
index 3da3fde6..32e82845 100644
--- a/sway/tree/workspace.c
+++ b/sway/tree/workspace.c
@@ -17,7 +17,7 @@ struct workspace_by_number_data {
17 const char *name; 17 const char *name;
18}; 18};
19 19
20void next_name_map(swayc_t *ws, void *data) { 20void next_name_map(struct sway_container *ws, void *data) {
21 int *count = data; 21 int *count = data;
22 ++count; 22 ++count;
23} 23}
@@ -37,7 +37,7 @@ char *workspace_next_name(const char *output_name) {
37 return name; 37 return name;
38} 38}
39 39
40static bool _workspace_by_number(swayc_t *view, void *data) { 40static bool _workspace_by_number(struct sway_container *view, void *data) {
41 if (view->type != C_WORKSPACE) { 41 if (view->type != C_WORKSPACE) {
42 return false; 42 return false;
43 } 43 }
@@ -46,27 +46,27 @@ static bool _workspace_by_number(swayc_t *view, void *data) {
46 return a == wbnd->len && strncmp(view->name, wbnd->name, a) == 0; 46 return a == wbnd->len && strncmp(view->name, wbnd->name, a) == 0;
47} 47}
48 48
49swayc_t *workspace_by_number(const char* name) { 49struct sway_container *workspace_by_number(const char* name) {
50 struct workspace_by_number_data wbnd = {0, "1234567890", name}; 50 struct workspace_by_number_data wbnd = {0, "1234567890", name};
51 wbnd.len = strspn(name, wbnd.cset); 51 wbnd.len = strspn(name, wbnd.cset);
52 if (wbnd.len <= 0) { 52 if (wbnd.len <= 0) {
53 return NULL; 53 return NULL;
54 } 54 }
55 return swayc_by_test(&root_container, _workspace_by_number, (void *) &wbnd); 55 return sway_container_find(&root_container, _workspace_by_number, (void *) &wbnd);
56} 56}
57 57
58static bool _workspace_by_name(swayc_t *view, void *data) { 58static bool _workspace_by_name(struct sway_container *view, void *data) {
59 return (view->type == C_WORKSPACE) && 59 return (view->type == C_WORKSPACE) &&
60 (strcasecmp(view->name, (char *) data) == 0); 60 (strcasecmp(view->name, (char *) data) == 0);
61} 61}
62 62
63swayc_t *workspace_by_name(const char *name) { 63struct sway_container *workspace_by_name(const char *name) {
64 struct sway_seat *seat = input_manager_current_seat(input_manager); 64 struct sway_seat *seat = input_manager_current_seat(input_manager);
65 swayc_t *current_workspace = NULL, *current_output = NULL; 65 struct sway_container *current_workspace = NULL, *current_output = NULL;
66 swayc_t *focus = sway_seat_get_focus(seat); 66 struct sway_container *focus = sway_seat_get_focus(seat);
67 if (focus) { 67 if (focus) {
68 current_workspace = swayc_parent_by_type(focus, C_WORKSPACE); 68 current_workspace = sway_container_parent(focus, C_WORKSPACE);
69 current_output = swayc_parent_by_type(focus, C_OUTPUT); 69 current_output = sway_container_parent(focus, C_OUTPUT);
70 } 70 }
71 if (strcmp(name, "prev") == 0) { 71 if (strcmp(name, "prev") == 0) {
72 return workspace_prev(current_workspace); 72 return workspace_prev(current_workspace);
@@ -79,12 +79,12 @@ swayc_t *workspace_by_name(const char *name) {
79 } else if (strcmp(name, "current") == 0) { 79 } else if (strcmp(name, "current") == 0) {
80 return current_workspace; 80 return current_workspace;
81 } else { 81 } else {
82 return swayc_by_test(&root_container, _workspace_by_name, (void *) name); 82 return sway_container_find(&root_container, _workspace_by_name, (void *) name);
83 } 83 }
84} 84}
85 85
86swayc_t *workspace_create(const char *name) { 86struct sway_container *workspace_create(const char *name) {
87 swayc_t *parent; 87 struct sway_container *parent;
88 // Search for workspace<->output pair 88 // Search for workspace<->output pair
89 int i, e = config->workspace_outputs->length; 89 int i, e = config->workspace_outputs->length;
90 for (i = 0; i < e; ++i) { 90 for (i = 0; i < e; ++i) {
@@ -95,7 +95,7 @@ swayc_t *workspace_create(const char *name) {
95 for (i = 0; i < e; ++i) { 95 for (i = 0; i < e; ++i) {
96 parent = root_container.children->items[i]; 96 parent = root_container.children->items[i];
97 if (strcmp(parent->name, wso->output) == 0) { 97 if (strcmp(parent->name, wso->output) == 0) {
98 return new_workspace(parent, name); 98 return sway_container_workspace_create(parent, name);
99 } 99 }
100 } 100 }
101 break; 101 break;
@@ -103,10 +103,10 @@ swayc_t *workspace_create(const char *name) {
103 } 103 }
104 // Otherwise create a new one 104 // Otherwise create a new one
105 struct sway_seat *seat = input_manager_current_seat(input_manager); 105 struct sway_seat *seat = input_manager_current_seat(input_manager);
106 swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container); 106 struct sway_container *focus = sway_seat_get_focus_inactive(seat, &root_container);
107 parent = focus; 107 parent = focus;
108 parent = swayc_parent_by_type(parent, C_OUTPUT); 108 parent = sway_container_parent(parent, C_OUTPUT);
109 return new_workspace(parent, name); 109 return sway_container_workspace_create(parent, name);
110} 110}
111 111
112/** 112/**
@@ -114,17 +114,17 @@ swayc_t *workspace_create(const char *name) {
114 * the end and beginning. If next is false, the previous workspace is returned, 114 * the end and beginning. If next is false, the previous workspace is returned,
115 * otherwise the next one is returned. 115 * otherwise the next one is returned.
116 */ 116 */
117swayc_t *workspace_output_prev_next_impl(swayc_t *output, bool next) { 117struct sway_container *workspace_output_prev_next_impl(struct sway_container *output, bool next) {
118 if (!sway_assert(output->type == C_OUTPUT, 118 if (!sway_assert(output->type == C_OUTPUT,
119 "Argument must be an output, is %d", output->type)) { 119 "Argument must be an output, is %d", output->type)) {
120 return NULL; 120 return NULL;
121 } 121 }
122 122
123 struct sway_seat *seat = input_manager_current_seat(input_manager); 123 struct sway_seat *seat = input_manager_current_seat(input_manager);
124 swayc_t *focus = sway_seat_get_focus_inactive(seat, output); 124 struct sway_container *focus = sway_seat_get_focus_inactive(seat, output);
125 swayc_t *workspace = (focus->type == C_WORKSPACE ? 125 struct sway_container *workspace = (focus->type == C_WORKSPACE ?
126 focus : 126 focus :
127 swayc_parent_by_type(focus, C_WORKSPACE)); 127 sway_container_parent(focus, C_WORKSPACE));
128 128
129 int i; 129 int i;
130 for (i = 0; i < output->children->length; i++) { 130 for (i = 0; i < output->children->length; i++) {
@@ -144,13 +144,13 @@ swayc_t *workspace_output_prev_next_impl(swayc_t *output, bool next) {
144 * next is false, the previous workspace is returned, otherwise the next one is 144 * next is false, the previous workspace is returned, otherwise the next one is
145 * returned. 145 * returned.
146 */ 146 */
147swayc_t *workspace_prev_next_impl(swayc_t *workspace, bool next) { 147struct sway_container *workspace_prev_next_impl(struct sway_container *workspace, bool next) {
148 if (!sway_assert(workspace->type == C_WORKSPACE, 148 if (!sway_assert(workspace->type == C_WORKSPACE,
149 "Argument must be a workspace, is %d", workspace->type)) { 149 "Argument must be a workspace, is %d", workspace->type)) {
150 return NULL; 150 return NULL;
151 } 151 }
152 152
153 swayc_t *current_output = workspace->parent; 153 struct sway_container *current_output = workspace->parent;
154 int offset = next ? 1 : -1; 154 int offset = next ? 1 : -1;
155 int start = next ? 0 : 1; 155 int start = next ? 0 : 1;
156 int end; 156 int end;
@@ -170,7 +170,7 @@ swayc_t *workspace_prev_next_impl(swayc_t *workspace, bool next) {
170 int num_outputs = root_container.children->length; 170 int num_outputs = root_container.children->length;
171 for (i = 0; i < num_outputs; i++) { 171 for (i = 0; i < num_outputs; i++) {
172 if (root_container.children->items[i] == current_output) { 172 if (root_container.children->items[i] == current_output) {
173 swayc_t *next_output = root_container.children->items[ 173 struct sway_container *next_output = root_container.children->items[
174 wrap(i + offset, num_outputs)]; 174 wrap(i + offset, num_outputs)];
175 return workspace_output_prev_next_impl(next_output, next); 175 return workspace_output_prev_next_impl(next_output, next);
176 } 176 }
@@ -180,40 +180,40 @@ swayc_t *workspace_prev_next_impl(swayc_t *workspace, bool next) {
180 return NULL; 180 return NULL;
181} 181}
182 182
183swayc_t *workspace_output_next(swayc_t *current) { 183struct sway_container *workspace_output_next(struct sway_container *current) {
184 return workspace_output_prev_next_impl(current, true); 184 return workspace_output_prev_next_impl(current, true);
185} 185}
186 186
187swayc_t *workspace_next(swayc_t *current) { 187struct sway_container *workspace_next(struct sway_container *current) {
188 return workspace_prev_next_impl(current, true); 188 return workspace_prev_next_impl(current, true);
189} 189}
190 190
191swayc_t *workspace_output_prev(swayc_t *current) { 191struct sway_container *workspace_output_prev(struct sway_container *current) {
192 return workspace_output_prev_next_impl(current, false); 192 return workspace_output_prev_next_impl(current, false);
193} 193}
194 194
195swayc_t *workspace_prev(swayc_t *current) { 195struct sway_container *workspace_prev(struct sway_container *current) {
196 return workspace_prev_next_impl(current, false); 196 return workspace_prev_next_impl(current, false);
197} 197}
198 198
199bool workspace_switch(swayc_t *workspace) { 199bool workspace_switch(struct sway_container *workspace) {
200 if (!workspace) { 200 if (!workspace) {
201 return false; 201 return false;
202 } 202 }
203 struct sway_seat *seat = input_manager_current_seat(input_manager); 203 struct sway_seat *seat = input_manager_current_seat(input_manager);
204 swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container); 204 struct sway_container *focus = sway_seat_get_focus_inactive(seat, &root_container);
205 if (!seat || !focus) { 205 if (!seat || !focus) {
206 return false; 206 return false;
207 } 207 }
208 swayc_t *active_ws = focus; 208 struct sway_container *active_ws = focus;
209 if (active_ws->type != C_WORKSPACE) { 209 if (active_ws->type != C_WORKSPACE) {
210 swayc_parent_by_type(focus, C_WORKSPACE); 210 sway_container_parent(focus, C_WORKSPACE);
211 } 211 }
212 212
213 if (config->auto_back_and_forth 213 if (config->auto_back_and_forth
214 && active_ws == workspace 214 && active_ws == workspace
215 && prev_workspace_name) { 215 && prev_workspace_name) {
216 swayc_t *new_ws = workspace_by_name(prev_workspace_name); 216 struct sway_container *new_ws = workspace_by_name(prev_workspace_name);
217 workspace = new_ws ? new_ws : workspace_create(prev_workspace_name); 217 workspace = new_ws ? new_ws : workspace_create(prev_workspace_name);
218 } 218 }
219 219
@@ -231,12 +231,12 @@ bool workspace_switch(swayc_t *workspace) {
231 // TODO: Deal with sticky containers 231 // TODO: Deal with sticky containers
232 232
233 wlr_log(L_DEBUG, "Switching to workspace %p:%s", workspace, workspace->name); 233 wlr_log(L_DEBUG, "Switching to workspace %p:%s", workspace, workspace->name);
234 swayc_t *next = sway_seat_get_focus_inactive(seat, workspace); 234 struct sway_container *next = sway_seat_get_focus_inactive(seat, workspace);
235 if (next == NULL) { 235 if (next == NULL) {
236 next = workspace; 236 next = workspace;
237 } 237 }
238 sway_seat_set_focus(seat, next); 238 sway_seat_set_focus(seat, next);
239 swayc_t *output = swayc_parent_by_type(workspace, C_OUTPUT); 239 struct sway_container *output = sway_container_parent(workspace, C_OUTPUT);
240 arrange_windows(output, -1, -1); 240 arrange_windows(output, -1, -1);
241 return true; 241 return true;
242} 242}