aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Luminarys <kizunanohikari@gmail.com>2015-08-16 14:50:01 -0500
committerLibravatar Luminarys <kizunanohikari@gmail.com>2015-08-16 14:50:01 -0500
commit0a0fe18fd6126941b3518652c935da1d81249a19 (patch)
treeef28e8f2078de30a9a68059b8ce7ff20c12121fc
parentFix key handling from wlc (diff)
downloadsway-0a0fe18fd6126941b3518652c935da1d81249a19.tar.gz
sway-0a0fe18fd6126941b3518652c935da1d81249a19.tar.zst
sway-0a0fe18fd6126941b3518652c935da1d81249a19.zip
Added in workspace next/prev and workspace output_next/prev
-rw-r--r--include/workspace.h4
-rw-r--r--sway/commands.c22
-rw-r--r--sway/workspace.c88
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);
11swayc_t *workspace_create(const char*); 11swayc_t *workspace_create(const char*);
12swayc_t *workspace_find_by_name(const char*); 12swayc_t *workspace_find_by_name(const char*);
13void workspace_switch(swayc_t*); 13void workspace_switch(swayc_t*);
14void workspace_output_next();
15void workspace_next();
16void workspace_output_prev();
17void workspace_prev();
14void layout_log(const swayc_t *c, int depth); 18void 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 5cb661eb..91fadb86 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
96void 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
110void 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
139void 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
153void 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
96void workspace_switch(swayc_t *workspace) { 184void 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) {