diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-04-06 00:14:15 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-06 00:14:15 -0400 |
commit | 3499cc6c8702ed1959ead391f4bb54f7a69fe18a (patch) | |
tree | e993eeb351d7001b24d1449a3f78e43708655ac2 | |
parent | Merge pull request #1751 from emersion/remove-layout-last (diff) | |
parent | Fix wl_output enter/leave events (diff) | |
download | sway-3499cc6c8702ed1959ead391f4bb54f7a69fe18a.tar.gz sway-3499cc6c8702ed1959ead391f4bb54f7a69fe18a.tar.zst sway-3499cc6c8702ed1959ead391f4bb54f7a69fe18a.zip |
Merge pull request #1754 from emersion/fix-output-enter
Fix wl_output enter/leave events
-rw-r--r-- | include/sway/tree/view.h | 1 | ||||
-rw-r--r-- | sway/tree/view.c | 68 |
2 files changed, 38 insertions, 31 deletions
diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index 03d27ceb..6b2d279e 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h | |||
@@ -51,6 +51,7 @@ struct sway_view { | |||
51 | } events; | 51 | } events; |
52 | 52 | ||
53 | struct wl_listener surface_new_subsurface; | 53 | struct wl_listener surface_new_subsurface; |
54 | struct wl_listener container_reparent; | ||
54 | }; | 55 | }; |
55 | 56 | ||
56 | struct sway_xdg_shell_v6_view { | 57 | struct sway_xdg_shell_v6_view { |
diff --git a/sway/tree/view.c b/sway/tree/view.c index d3e3186c..16d48cc9 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c | |||
@@ -102,28 +102,6 @@ static void view_get_layout_box(struct sway_view *view, struct wlr_box *box) { | |||
102 | box->height = view->height; | 102 | box->height = view->height; |
103 | } | 103 | } |
104 | 104 | ||
105 | static void view_update_outputs(struct sway_view *view, | ||
106 | const struct wlr_box *before) { | ||
107 | struct wlr_box box; | ||
108 | view_get_layout_box(view, &box); | ||
109 | |||
110 | struct wlr_output_layout *output_layout = | ||
111 | root_container.sway_root->output_layout; | ||
112 | struct wlr_output_layout_output *layout_output; | ||
113 | wl_list_for_each(layout_output, &output_layout->outputs, link) { | ||
114 | bool intersected = before != NULL && wlr_output_layout_intersects( | ||
115 | output_layout, layout_output->output, before); | ||
116 | bool intersects = wlr_output_layout_intersects(output_layout, | ||
117 | layout_output->output, &box); | ||
118 | if (intersected && !intersects) { | ||
119 | wlr_surface_send_leave(view->surface, layout_output->output); | ||
120 | } | ||
121 | if (!intersected && intersects) { | ||
122 | wlr_surface_send_enter(view->surface, layout_output->output); | ||
123 | } | ||
124 | } | ||
125 | } | ||
126 | |||
127 | static void view_subsurface_create(struct sway_view *view, | 105 | static void view_subsurface_create(struct sway_view *view, |
128 | struct wlr_subsurface *subsurface); | 106 | struct wlr_subsurface *subsurface); |
129 | 107 | ||
@@ -138,6 +116,36 @@ static void view_handle_surface_new_subsurface(struct wl_listener *listener, | |||
138 | view_subsurface_create(view, subsurface); | 116 | view_subsurface_create(view, subsurface); |
139 | } | 117 | } |
140 | 118 | ||
119 | static void view_handle_container_reparent(struct wl_listener *listener, | ||
120 | void *data) { | ||
121 | struct sway_view *view = | ||
122 | wl_container_of(listener, view, container_reparent); | ||
123 | struct sway_container *old_parent = data; | ||
124 | |||
125 | struct sway_container *old_output = old_parent; | ||
126 | if (old_output != NULL && old_output->type != C_OUTPUT) { | ||
127 | old_output = container_parent(old_output, C_OUTPUT); | ||
128 | } | ||
129 | |||
130 | struct sway_container *new_output = view->swayc->parent; | ||
131 | if (new_output != NULL && new_output->type != C_OUTPUT) { | ||
132 | new_output = container_parent(new_output, C_OUTPUT); | ||
133 | } | ||
134 | |||
135 | if (old_output == new_output) { | ||
136 | return; | ||
137 | } | ||
138 | |||
139 | if (old_output != NULL) { | ||
140 | wlr_surface_send_leave(view->surface, | ||
141 | old_output->sway_output->wlr_output); | ||
142 | } | ||
143 | if (new_output != NULL) { | ||
144 | wlr_surface_send_enter(view->surface, | ||
145 | new_output->sway_output->wlr_output); | ||
146 | } | ||
147 | } | ||
148 | |||
141 | void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { | 149 | void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { |
142 | if (!sway_assert(view->surface == NULL, "cannot map mapped view")) { | 150 | if (!sway_assert(view->surface == NULL, "cannot map mapped view")) { |
143 | return; | 151 | return; |
@@ -156,11 +164,14 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { | |||
156 | &view->surface_new_subsurface); | 164 | &view->surface_new_subsurface); |
157 | view->surface_new_subsurface.notify = view_handle_surface_new_subsurface; | 165 | view->surface_new_subsurface.notify = view_handle_surface_new_subsurface; |
158 | 166 | ||
167 | wl_signal_add(&view->swayc->events.reparent, &view->container_reparent); | ||
168 | view->container_reparent.notify = view_handle_container_reparent; | ||
169 | |||
159 | arrange_windows(cont->parent, -1, -1); | 170 | arrange_windows(cont->parent, -1, -1); |
160 | input_manager_set_focus(input_manager, cont); | 171 | input_manager_set_focus(input_manager, cont); |
161 | 172 | ||
162 | view_damage_whole(view); | 173 | view_damage_whole(view); |
163 | view_update_outputs(view, NULL); | 174 | view_handle_container_reparent(&view->container_reparent, NULL); |
164 | } | 175 | } |
165 | 176 | ||
166 | void view_unmap(struct sway_view *view) { | 177 | void view_unmap(struct sway_view *view) { |
@@ -172,9 +183,10 @@ void view_unmap(struct sway_view *view) { | |||
172 | 183 | ||
173 | view_damage_whole(view); | 184 | view_damage_whole(view); |
174 | 185 | ||
175 | struct sway_container *parent = container_destroy(view->swayc); | ||
176 | |||
177 | wl_list_remove(&view->surface_new_subsurface.link); | 186 | wl_list_remove(&view->surface_new_subsurface.link); |
187 | wl_list_remove(&view->container_reparent.link); | ||
188 | |||
189 | struct sway_container *parent = container_destroy(view->swayc); | ||
178 | 190 | ||
179 | view->swayc = NULL; | 191 | view->swayc = NULL; |
180 | view->surface = NULL; | 192 | view->surface = NULL; |
@@ -187,12 +199,9 @@ void view_update_position(struct sway_view *view, double ox, double oy) { | |||
187 | return; | 199 | return; |
188 | } | 200 | } |
189 | 201 | ||
190 | struct wlr_box box; | ||
191 | view_get_layout_box(view, &box); | ||
192 | view_damage_whole(view); | 202 | view_damage_whole(view); |
193 | view->swayc->x = ox; | 203 | view->swayc->x = ox; |
194 | view->swayc->y = oy; | 204 | view->swayc->y = oy; |
195 | view_update_outputs(view, &box); | ||
196 | view_damage_whole(view); | 205 | view_damage_whole(view); |
197 | } | 206 | } |
198 | 207 | ||
@@ -201,12 +210,9 @@ void view_update_size(struct sway_view *view, int width, int height) { | |||
201 | return; | 210 | return; |
202 | } | 211 | } |
203 | 212 | ||
204 | struct wlr_box box; | ||
205 | view_get_layout_box(view, &box); | ||
206 | view_damage_whole(view); | 213 | view_damage_whole(view); |
207 | view->width = width; | 214 | view->width = width; |
208 | view->height = height; | 215 | view->height = height; |
209 | view_update_outputs(view, &box); | ||
210 | view_damage_whole(view); | 216 | view_damage_whole(view); |
211 | } | 217 | } |
212 | 218 | ||