aboutsummaryrefslogtreecommitdiff
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) {
swayc_t *workspace_by_name(const char *name) {
struct sway_seat *seat = input_manager_current_seat(input_manager);
swayc_t *current_workspace = NULL, *current_output = NULL;
- if (seat->focus) {
- current_workspace = swayc_parent_by_type(seat->focus, C_WORKSPACE);
- current_output = swayc_parent_by_type(seat->focus, C_OUTPUT);
+ swayc_t *focus = sway_seat_get_focus(seat);
+ if (focus) {
+ current_workspace = swayc_parent_by_type(focus, C_WORKSPACE);
+ current_output = swayc_parent_by_type(focus, C_OUTPUT);
}
if (strcmp(name, "prev") == 0) {
return workspace_prev(current_workspace);
@@ -102,7 +103,8 @@ swayc_t *workspace_create(const char *name) {
}
// Otherwise create a new one
struct sway_seat *seat = input_manager_current_seat(input_manager);
- parent = seat->focus;
+ swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container);
+ parent = focus;
parent = swayc_parent_by_type(parent, C_OUTPUT);
return new_workspace(parent, name);
}
@@ -118,9 +120,15 @@ swayc_t *workspace_output_prev_next_impl(swayc_t *output, bool next) {
return NULL;
}
+ struct sway_seat *seat = input_manager_current_seat(input_manager);
+ swayc_t *focus = sway_seat_get_focus_inactive(seat, output);
+ swayc_t *workspace = (focus->type == C_WORKSPACE ?
+ focus :
+ swayc_parent_by_type(focus, C_WORKSPACE));
+
int i;
for (i = 0; i < output->children->length; i++) {
- if (output->children->items[i] == output->focused) {
+ if (output->children->items[i] == workspace) {
return output->children->items[
wrap(i + (next ? 1 : -1), output->children->length)];
}
@@ -193,12 +201,13 @@ bool workspace_switch(swayc_t *workspace) {
return false;
}
struct sway_seat *seat = input_manager_current_seat(input_manager);
- if (!seat || !seat->focus) {
+ swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container);
+ if (!seat || !focus) {
return false;
}
- swayc_t *active_ws = seat->focus;
+ swayc_t *active_ws = focus;
if (active_ws->type != C_WORKSPACE) {
- swayc_parent_by_type(seat->focus, C_WORKSPACE);
+ swayc_parent_by_type(focus, C_WORKSPACE);
}
if (config->auto_back_and_forth
@@ -222,16 +231,12 @@ bool workspace_switch(swayc_t *workspace) {
// TODO: Deal with sticky containers
wlr_log(L_DEBUG, "Switching to workspace %p:%s", workspace, workspace->name);
- // TODO FOCUS: Focus the last view this seat had focused on this workspace
- if (workspace->children->length) {
- // TODO FOCUS: This is really fucking stupid
- sway_seat_set_focus(seat, workspace->children->items[0]);
- } else {
- sway_seat_set_focus(seat, workspace);
+ swayc_t *next = sway_seat_get_focus_inactive(seat, workspace);
+ if (next == NULL) {
+ next = workspace;
}
+ sway_seat_set_focus(seat, next);
swayc_t *output = swayc_parent_by_type(workspace, C_OUTPUT);
- // TODO FOCUS: take a look at this
- output->focused = workspace;
arrange_windows(output, -1, -1);
return true;
}