diff options
author | Tony Crisci <tony@dubstepdish.com> | 2017-12-10 08:48:44 -0500 |
---|---|---|
committer | Tony Crisci <tony@dubstepdish.com> | 2017-12-10 08:48:44 -0500 |
commit | e69b052a6d88b1c24d5e48ad086480ee04c07c81 (patch) | |
tree | 0c76b0023ef379df124c04ee8dfe9583d49202b0 /sway/tree/container.c | |
parent | working xcursor (diff) | |
download | sway-e69b052a6d88b1c24d5e48ad086480ee04c07c81.tar.gz sway-e69b052a6d88b1c24d5e48ad086480ee04c07c81.tar.zst sway-e69b052a6d88b1c24d5e48ad086480ee04c07c81.zip |
working pointer motion
Diffstat (limited to 'sway/tree/container.c')
-rw-r--r-- | sway/tree/container.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c index e205fbcf..321ef8b1 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -3,6 +3,7 @@ | |||
3 | #include <stdlib.h> | 3 | #include <stdlib.h> |
4 | #include <string.h> | 4 | #include <string.h> |
5 | #include <wlr/types/wlr_output_layout.h> | 5 | #include <wlr/types/wlr_output_layout.h> |
6 | #include <wlr/types/wlr_wl_shell.h> | ||
6 | #include "sway/container.h" | 7 | #include "sway/container.h" |
7 | #include "sway/layout.h" | 8 | #include "sway/layout.h" |
8 | #include "sway/output.h" | 9 | #include "sway/output.h" |
@@ -168,3 +169,62 @@ swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type) { | |||
168 | } while (container && container->type != type); | 169 | } while (container && container->type != type); |
169 | return container; | 170 | return container; |
170 | } | 171 | } |
172 | |||
173 | swayc_t *swayc_at(swayc_t *parent, double lx, double ly, | ||
174 | struct wlr_surface **surface, double *sx, double *sy) { | ||
175 | list_t *queue = create_list(); | ||
176 | list_add(queue, parent); | ||
177 | |||
178 | swayc_t *swayc = NULL; | ||
179 | while (queue->length) { | ||
180 | swayc = queue->items[0]; | ||
181 | list_del(queue, 0); | ||
182 | if (swayc->type == C_VIEW) { | ||
183 | struct sway_view *sview = swayc->sway_view; | ||
184 | swayc_t *soutput = swayc_parent_by_type(swayc, C_OUTPUT); | ||
185 | struct wlr_box *output_box = | ||
186 | wlr_output_layout_get_box(root_container.output_layout, | ||
187 | soutput->sway_output->wlr_output); | ||
188 | double ox = lx - output_box->x; | ||
189 | double oy = ly - output_box->y; | ||
190 | double view_sx = ox - swayc->x; | ||
191 | double view_sy = oy - swayc->y; | ||
192 | int width = swayc->sway_view->surface->current->width; | ||
193 | int height = swayc->sway_view->surface->current->height; | ||
194 | |||
195 | // TODO popups and subsurfaces | ||
196 | switch (sview->type) { | ||
197 | case SWAY_WL_SHELL_VIEW: | ||
198 | break; | ||
199 | case SWAY_XDG_SHELL_V6_VIEW: | ||
200 | // the top left corner of the sway container is the | ||
201 | // coordinate of the top left corner of the window geometry | ||
202 | view_sx += sview->wlr_xdg_surface_v6->geometry->x; | ||
203 | view_sy += sview->wlr_xdg_surface_v6->geometry->y; | ||
204 | break; | ||
205 | case SWAY_XWAYLAND_VIEW: | ||
206 | break; | ||
207 | default: | ||
208 | break; | ||
209 | } | ||
210 | |||
211 | if (view_sx > 0 && view_sx < width && | ||
212 | view_sy > 0 && view_sy < height && | ||
213 | pixman_region32_contains_point( | ||
214 | &sview->surface->current->input, | ||
215 | view_sx, view_sy, NULL)) { | ||
216 | *sx = view_sx; | ||
217 | *sy = view_sy; | ||
218 | *surface = swayc->sway_view->surface; | ||
219 | list_free(queue); | ||
220 | return swayc; | ||
221 | } | ||
222 | } else { | ||
223 | list_cat(queue, swayc->children); | ||
224 | } | ||
225 | } | ||
226 | |||
227 | list_free(queue); | ||
228 | |||
229 | return NULL; | ||
230 | } | ||