diff options
author | 2015-08-16 14:50:01 -0500 | |
---|---|---|
committer | 2015-08-16 14:50:01 -0500 | |
commit | 0a0fe18fd6126941b3518652c935da1d81249a19 (patch) | |
tree | ef28e8f2078de30a9a68059b8ce7ff20c12121fc /sway/workspace.c | |
parent | Fix key handling from wlc (diff) | |
download | sway-0a0fe18fd6126941b3518652c935da1d81249a19.tar.gz sway-0a0fe18fd6126941b3518652c935da1d81249a19.tar.zst sway-0a0fe18fd6126941b3518652c935da1d81249a19.zip |
Added in workspace next/prev and workspace output_next/prev
Diffstat (limited to 'sway/workspace.c')
-rw-r--r-- | sway/workspace.c | 88 |
1 files changed, 88 insertions, 0 deletions
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) { |