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.c37
1 files changed, 21 insertions, 16 deletions
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c
index 23c630b6..861fda4d 100644
--- a/sway/tree/workspace.c
+++ b/sway/tree/workspace.c
@@ -63,9 +63,10 @@ static bool _workspace_by_name(swayc_t *view, void *data) {
63swayc_t *workspace_by_name(const char *name) { 63swayc_t *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 swayc_t *current_workspace = NULL, *current_output = NULL;
66 if (seat->focus) { 66 swayc_t *focus = sway_seat_get_focus(seat);
67 current_workspace = swayc_parent_by_type(seat->focus, C_WORKSPACE); 67 if (focus) {
68 current_output = swayc_parent_by_type(seat->focus, C_OUTPUT); 68 current_workspace = swayc_parent_by_type(focus, C_WORKSPACE);
69 current_output = swayc_parent_by_type(focus, C_OUTPUT);
69 } 70 }
70 if (strcmp(name, "prev") == 0) { 71 if (strcmp(name, "prev") == 0) {
71 return workspace_prev(current_workspace); 72 return workspace_prev(current_workspace);
@@ -102,7 +103,8 @@ swayc_t *workspace_create(const char *name) {
102 } 103 }
103 // Otherwise create a new one 104 // Otherwise create a new one
104 struct sway_seat *seat = input_manager_current_seat(input_manager); 105 struct sway_seat *seat = input_manager_current_seat(input_manager);
105 parent = seat->focus; 106 swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container);
107 parent = focus;
106 parent = swayc_parent_by_type(parent, C_OUTPUT); 108 parent = swayc_parent_by_type(parent, C_OUTPUT);
107 return new_workspace(parent, name); 109 return new_workspace(parent, name);
108} 110}
@@ -118,9 +120,15 @@ swayc_t *workspace_output_prev_next_impl(swayc_t *output, bool next) {
118 return NULL; 120 return NULL;
119 } 121 }
120 122
123 struct sway_seat *seat = input_manager_current_seat(input_manager);
124 swayc_t *focus = sway_seat_get_focus_inactive(seat, output);
125 swayc_t *workspace = (focus->type == C_WORKSPACE ?
126 focus :
127 swayc_parent_by_type(focus, C_WORKSPACE));
128
121 int i; 129 int i;
122 for (i = 0; i < output->children->length; i++) { 130 for (i = 0; i < output->children->length; i++) {
123 if (output->children->items[i] == output->focused) { 131 if (output->children->items[i] == workspace) {
124 return output->children->items[ 132 return output->children->items[
125 wrap(i + (next ? 1 : -1), output->children->length)]; 133 wrap(i + (next ? 1 : -1), output->children->length)];
126 } 134 }
@@ -193,12 +201,13 @@ bool workspace_switch(swayc_t *workspace) {
193 return false; 201 return false;
194 } 202 }
195 struct sway_seat *seat = input_manager_current_seat(input_manager); 203 struct sway_seat *seat = input_manager_current_seat(input_manager);
196 if (!seat || !seat->focus) { 204 swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container);
205 if (!seat || !focus) {
197 return false; 206 return false;
198 } 207 }
199 swayc_t *active_ws = seat->focus; 208 swayc_t *active_ws = focus;
200 if (active_ws->type != C_WORKSPACE) { 209 if (active_ws->type != C_WORKSPACE) {
201 swayc_parent_by_type(seat->focus, C_WORKSPACE); 210 swayc_parent_by_type(focus, C_WORKSPACE);
202 } 211 }
203 212
204 if (config->auto_back_and_forth 213 if (config->auto_back_and_forth
@@ -222,16 +231,12 @@ bool workspace_switch(swayc_t *workspace) {
222 // TODO: Deal with sticky containers 231 // TODO: Deal with sticky containers
223 232
224 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);
225 // TODO FOCUS: Focus the last view this seat had focused on this workspace 234 swayc_t *next = sway_seat_get_focus_inactive(seat, workspace);
226 if (workspace->children->length) { 235 if (next == NULL) {
227 // TODO FOCUS: This is really fucking stupid 236 next = workspace;
228 sway_seat_set_focus(seat, workspace->children->items[0]);
229 } else {
230 sway_seat_set_focus(seat, workspace);
231 } 237 }
238 sway_seat_set_focus(seat, next);
232 swayc_t *output = swayc_parent_by_type(workspace, C_OUTPUT); 239 swayc_t *output = swayc_parent_by_type(workspace, C_OUTPUT);
233 // TODO FOCUS: take a look at this
234 output->focused = workspace;
235 arrange_windows(output, -1, -1); 240 arrange_windows(output, -1, -1);
236 return true; 241 return true;
237} 242}