diff options
Diffstat (limited to 'sway/tree/root.c')
-rw-r--r-- | sway/tree/root.c | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/sway/tree/root.c b/sway/tree/root.c index 544d666a..e1624863 100644 --- a/sway/tree/root.c +++ b/sway/tree/root.c | |||
@@ -5,6 +5,7 @@ | |||
5 | #include <wlr/types/wlr_output_layout.h> | 5 | #include <wlr/types/wlr_output_layout.h> |
6 | #include "sway/desktop/transaction.h" | 6 | #include "sway/desktop/transaction.h" |
7 | #include "sway/input/seat.h" | 7 | #include "sway/input/seat.h" |
8 | #include "sway/ipc-server.h" | ||
8 | #include "sway/output.h" | 9 | #include "sway/output.h" |
9 | #include "sway/tree/arrange.h" | 10 | #include "sway/tree/arrange.h" |
10 | #include "sway/tree/container.h" | 11 | #include "sway/tree/container.h" |
@@ -68,13 +69,18 @@ void root_scratchpad_add_container(struct sway_container *con) { | |||
68 | list_add(root->scratchpad, con); | 69 | list_add(root->scratchpad, con); |
69 | 70 | ||
70 | struct sway_seat *seat = input_manager_current_seat(); | 71 | struct sway_seat *seat = input_manager_current_seat(); |
72 | struct sway_node *new_focus = NULL; | ||
71 | if (parent) { | 73 | if (parent) { |
72 | arrange_container(parent); | 74 | arrange_container(parent); |
73 | seat_set_focus(seat, seat_get_focus_inactive(seat, &parent->node)); | 75 | new_focus = seat_get_focus_inactive(seat, &parent->node); |
74 | } else { | 76 | } |
77 | if (!new_focus) { | ||
75 | arrange_workspace(workspace); | 78 | arrange_workspace(workspace); |
76 | seat_set_focus(seat, seat_get_focus_inactive(seat, &workspace->node)); | 79 | new_focus = seat_get_focus_inactive(seat, &workspace->node); |
77 | } | 80 | } |
81 | seat_set_focus(seat, new_focus); | ||
82 | |||
83 | ipc_event_window(con, "move"); | ||
78 | } | 84 | } |
79 | 85 | ||
80 | void root_scratchpad_remove_container(struct sway_container *con) { | 86 | void root_scratchpad_remove_container(struct sway_container *con) { |
@@ -85,45 +91,51 @@ void root_scratchpad_remove_container(struct sway_container *con) { | |||
85 | int index = list_find(root->scratchpad, con); | 91 | int index = list_find(root->scratchpad, con); |
86 | if (index != -1) { | 92 | if (index != -1) { |
87 | list_del(root->scratchpad, index); | 93 | list_del(root->scratchpad, index); |
94 | ipc_event_window(con, "move"); | ||
88 | } | 95 | } |
89 | } | 96 | } |
90 | 97 | ||
91 | void root_scratchpad_show(struct sway_container *con) { | 98 | void root_scratchpad_show(struct sway_container *con) { |
92 | struct sway_seat *seat = input_manager_current_seat(); | 99 | struct sway_seat *seat = input_manager_current_seat(); |
93 | struct sway_workspace *ws = seat_get_focused_workspace(seat); | 100 | struct sway_workspace *new_ws = seat_get_focused_workspace(seat); |
101 | struct sway_workspace *old_ws = con->workspace; | ||
94 | 102 | ||
95 | // If the current con or any of its parents are in fullscreen mode, we | 103 | // If the current con or any of its parents are in fullscreen mode, we |
96 | // first need to disable it before showing the scratchpad con. | 104 | // first need to disable it before showing the scratchpad con. |
97 | if (ws->fullscreen) { | 105 | if (new_ws->fullscreen) { |
98 | container_set_fullscreen(ws->fullscreen, false); | 106 | container_set_fullscreen(new_ws->fullscreen, false); |
99 | } | 107 | } |
100 | 108 | ||
101 | // Show the container | 109 | // Show the container |
102 | if (con->workspace) { | 110 | if (old_ws) { |
103 | container_detach(con); | 111 | container_detach(con); |
104 | } | 112 | } |
105 | workspace_add_floating(ws, con); | 113 | workspace_add_floating(new_ws, con); |
106 | 114 | ||
107 | // Make sure the container's center point overlaps this workspace | 115 | // Make sure the container's center point overlaps this workspace |
108 | double center_lx = con->x + con->width / 2; | 116 | double center_lx = con->x + con->width / 2; |
109 | double center_ly = con->y + con->height / 2; | 117 | double center_ly = con->y + con->height / 2; |
110 | 118 | ||
111 | struct wlr_box workspace_box; | 119 | struct wlr_box workspace_box; |
112 | workspace_get_box(ws, &workspace_box); | 120 | workspace_get_box(new_ws, &workspace_box); |
113 | if (!wlr_box_contains_point(&workspace_box, center_lx, center_ly)) { | 121 | if (!wlr_box_contains_point(&workspace_box, center_lx, center_ly)) { |
114 | // Maybe resize it | 122 | // Maybe resize it |
115 | if (con->width > ws->width || con->height > ws->height) { | 123 | if (con->width > new_ws->width || con->height > new_ws->height) { |
116 | container_init_floating(con); | 124 | container_init_floating(con); |
117 | } | 125 | } |
118 | 126 | ||
119 | // Center it | 127 | // Center it |
120 | double new_lx = ws->x + (ws->width - con->width) / 2; | 128 | double new_lx = new_ws->x + (new_ws->width - con->width) / 2; |
121 | double new_ly = ws->y + (ws->height - con->height) / 2; | 129 | double new_ly = new_ws->y + (new_ws->height - con->height) / 2; |
122 | container_floating_move_to(con, new_lx, new_ly); | 130 | container_floating_move_to(con, new_lx, new_ly); |
123 | } | 131 | } |
124 | 132 | ||
125 | arrange_workspace(ws); | 133 | arrange_workspace(new_ws); |
126 | seat_set_focus(seat, seat_get_focus_inactive(seat, &con->node)); | 134 | seat_set_focus(seat, seat_get_focus_inactive(seat, &con->node)); |
135 | |||
136 | if (new_ws != old_ws) { | ||
137 | ipc_event_window(con, "move"); | ||
138 | } | ||
127 | } | 139 | } |
128 | 140 | ||
129 | void root_scratchpad_hide(struct sway_container *con) { | 141 | void root_scratchpad_hide(struct sway_container *con) { |
@@ -133,10 +145,12 @@ void root_scratchpad_hide(struct sway_container *con) { | |||
133 | 145 | ||
134 | container_detach(con); | 146 | container_detach(con); |
135 | arrange_workspace(ws); | 147 | arrange_workspace(ws); |
136 | if (&con->node == focus) { | 148 | if (&con->node == focus || node_has_ancestor(focus, &con->node)) { |
137 | seat_set_focus(seat, seat_get_focus_inactive(seat, &ws->node)); | 149 | seat_set_focus(seat, seat_get_focus_inactive(seat, &ws->node)); |
138 | } | 150 | } |
139 | list_move_to_end(root->scratchpad, con); | 151 | list_move_to_end(root->scratchpad, con); |
152 | |||
153 | ipc_event_window(con, "move"); | ||
140 | } | 154 | } |
141 | 155 | ||
142 | struct pid_workspace { | 156 | struct pid_workspace { |