diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-08-16 16:46:16 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-08-16 16:46:16 -0400 |
commit | 7f4529ec8b6362ef36ce546cfe34d816f1b708f0 (patch) | |
tree | 45de60347ce0fc86e4ac1ee9e814152aee9929c6 | |
parent | Merge pull request #45 from taiyu-len/master (diff) | |
parent | Added in workspace next/prev and workspace output_next/prev (diff) | |
download | sway-7f4529ec8b6362ef36ce546cfe34d816f1b708f0.tar.gz sway-7f4529ec8b6362ef36ce546cfe34d816f1b708f0.tar.zst sway-7f4529ec8b6362ef36ce546cfe34d816f1b708f0.zip |
Merge pull request #44 from Luminarys/master
Added in workspace next/prev and workspace output_next/prev
-rw-r--r-- | include/workspace.h | 4 | ||||
-rw-r--r-- | sway/commands.c | 22 | ||||
-rw-r--r-- | sway/workspace.c | 88 |
3 files changed, 114 insertions, 0 deletions
diff --git a/include/workspace.h b/include/workspace.h index 59a6d526..8ce39bbd 100644 --- a/include/workspace.h +++ b/include/workspace.h | |||
@@ -11,6 +11,10 @@ char *workspace_next_name(void); | |||
11 | swayc_t *workspace_create(const char*); | 11 | swayc_t *workspace_create(const char*); |
12 | swayc_t *workspace_find_by_name(const char*); | 12 | swayc_t *workspace_find_by_name(const char*); |
13 | void workspace_switch(swayc_t*); | 13 | void workspace_switch(swayc_t*); |
14 | void workspace_output_next(); | ||
15 | void workspace_next(); | ||
16 | void workspace_output_prev(); | ||
17 | void workspace_prev(); | ||
14 | void layout_log(const swayc_t *c, int depth); | 18 | void layout_log(const swayc_t *c, int depth); |
15 | 19 | ||
16 | #endif | 20 | #endif |
diff --git a/sway/commands.c b/sway/commands.c index 842142e2..d4f588de 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -342,6 +342,28 @@ static bool cmd_workspace(struct sway_config *config, int argc, char **argv) { | |||
342 | return false; | 342 | return false; |
343 | } | 343 | } |
344 | 344 | ||
345 | // Handle workspace next/prev | ||
346 | if (strcmp(argv[0], "next") == 0) { | ||
347 | workspace_next(); | ||
348 | return true; | ||
349 | } | ||
350 | |||
351 | if (strcmp(argv[0], "prev") == 0) { | ||
352 | workspace_next(); | ||
353 | return true; | ||
354 | } | ||
355 | |||
356 | // Handle workspace output_next/prev | ||
357 | if (strcmp(argv[0], "output_next") == 0) { | ||
358 | workspace_output_next(); | ||
359 | return true; | ||
360 | } | ||
361 | |||
362 | if (strcmp(argv[0], "output_prev") == 0) { | ||
363 | workspace_output_prev(); | ||
364 | return true; | ||
365 | } | ||
366 | |||
345 | swayc_t *workspace = workspace_find_by_name(argv[0]); | 367 | swayc_t *workspace = workspace_find_by_name(argv[0]); |
346 | if (!workspace) { | 368 | if (!workspace) { |
347 | workspace = workspace_create(argv[0]); | 369 | workspace = workspace_create(argv[0]); |
diff --git a/sway/workspace.c b/sway/workspace.c index 49a1224f..a3238da6 100644 --- a/sway/workspace.c +++ b/sway/workspace.c | |||
@@ -93,6 +93,94 @@ swayc_t *workspace_find_by_name(const char* name) { | |||
93 | return find_container(&root_container, workspace_by_name, (void *) name); | 93 | return find_container(&root_container, workspace_by_name, (void *) name); |
94 | } | 94 | } |
95 | 95 | ||
96 | void workspace_output_next() { | ||
97 | // Get the index of the workspace in the current output, and change the view to index+1 workspace. | ||
98 | // if we're currently focused on the last workspace in the output, switch to the first | ||
99 | swayc_t *current_output = active_workspace->parent; | ||
100 | int i; | ||
101 | for (i = 0; i < current_output->children->length - 1; i++) { | ||
102 | if (strcmp((((swayc_t *)current_output->children->items[i])->name), active_workspace->name) == 0) { | ||
103 | workspace_switch(current_output->children->items[i + 1]); | ||
104 | return; | ||
105 | } | ||
106 | } | ||
107 | workspace_switch(current_output->children->items[0]); | ||
108 | } | ||
109 | |||
110 | void workspace_next() { | ||
111 | // Get the index of the workspace in the current output, and change the view to index+1 workspace. | ||
112 | // if we're currently focused on the last workspace in the output, change focus to there | ||
113 | // and call workspace_output_next(), as long as another output actually exists | ||
114 | swayc_t *current_output = active_workspace->parent; | ||
115 | int i; | ||
116 | for (i = 0; i < current_output->children->length - 1; i++) { | ||
117 | if (strcmp((((swayc_t *)current_output->children->items[i])->name), active_workspace->name) == 0) { | ||
118 | workspace_switch(current_output->children->items[i + 1]); | ||
119 | return; | ||
120 | } | ||
121 | } | ||
122 | if (root_container.children->length > 1) { | ||
123 | for (i = 0; i < root_container.children->length - 1; i++) { | ||
124 | if (root_container.children->items[i] == current_output) { | ||
125 | workspace_switch(((swayc_t *)root_container.children->items[i + 1])->focused); | ||
126 | workspace_output_next(); | ||
127 | return; | ||
128 | } | ||
129 | } | ||
130 | // If we're at the last output, then go to the first | ||
131 | workspace_switch(((swayc_t *)root_container.children->items[0])->focused); | ||
132 | workspace_output_next(); | ||
133 | return; | ||
134 | } else { | ||
135 | workspace_switch(current_output->children->items[0]); | ||
136 | } | ||
137 | } | ||
138 | |||
139 | void workspace_output_prev() { | ||
140 | // Get the index of the workspace in the current output, and change the view to index+1 workspace | ||
141 | // if we're currently focused on the first workspace in the output, do nothing and return false | ||
142 | swayc_t *current_output = active_workspace->parent; | ||
143 | int i; | ||
144 | for (i = 1; i < current_output->children->length; i++) { | ||
145 | if (strcmp((((swayc_t *)current_output->children->items[i])->name), active_workspace->name) == 0) { | ||
146 | workspace_switch(current_output->children->items[i - 1]); | ||
147 | return; | ||
148 | } | ||
149 | } | ||
150 | workspace_switch(current_output->children->items[current_output->children->length - 1]); | ||
151 | } | ||
152 | |||
153 | void workspace_prev() { | ||
154 | // Get the index of the workspace in the current output, and change the view to index-1 workspace. | ||
155 | // if we're currently focused on the last workspace in the output, change focus to there | ||
156 | // and call workspace_output_next(), as long as another output actually exists | ||
157 | |||
158 | swayc_t *current_output = active_workspace->parent; | ||
159 | int i; | ||
160 | for (i = 1; i < current_output->children->length; i++) { | ||
161 | if (strcmp((((swayc_t *)current_output->children->items[i])->name), active_workspace->name) == 0) { | ||
162 | workspace_switch(current_output->children->items[i - 1]); | ||
163 | return; | ||
164 | } | ||
165 | } | ||
166 | if (root_container.children->length > 1) { | ||
167 | for (i = 1; i < root_container.children->length; i++) { | ||
168 | if (root_container.children->items[i] == current_output) { | ||
169 | workspace_switch(((swayc_t *)root_container.children->items[i - 1])->focused); | ||
170 | workspace_output_next(); | ||
171 | return; | ||
172 | } | ||
173 | } | ||
174 | // If we're at the first output, then go to the last | ||
175 | workspace_switch(((swayc_t *)root_container.children->items[root_container.children->length-1])->focused); | ||
176 | workspace_output_next(); | ||
177 | return; | ||
178 | } else { | ||
179 | workspace_switch(current_output->children->items[current_output->children->length - 1]); | ||
180 | } | ||
181 | |||
182 | } | ||
183 | |||
96 | void workspace_switch(swayc_t *workspace) { | 184 | void workspace_switch(swayc_t *workspace) { |
97 | swayc_t *ws_output = workspace->parent; | 185 | swayc_t *ws_output = workspace->parent; |
98 | while (ws_output->type != C_OUTPUT) { | 186 | while (ws_output->type != C_OUTPUT) { |