diff options
Diffstat (limited to 'sway/tree/view.c')
-rw-r--r-- | sway/tree/view.c | 60 |
1 files changed, 49 insertions, 11 deletions
diff --git a/sway/tree/view.c b/sway/tree/view.c index e0aa6c0c..26e1a108 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c | |||
@@ -1,5 +1,6 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <wayland-server.h> | 2 | #include <wayland-server.h> |
3 | #include <wlr/render/wlr_renderer.h> | ||
3 | #include <wlr/types/wlr_output_layout.h> | 4 | #include <wlr/types/wlr_output_layout.h> |
4 | #include "log.h" | 5 | #include "log.h" |
5 | #include "sway/criteria.h" | 6 | #include "sway/criteria.h" |
@@ -73,6 +74,51 @@ void view_configure(struct sway_view *view, double ox, double oy, int width, | |||
73 | } | 74 | } |
74 | } | 75 | } |
75 | 76 | ||
77 | /** | ||
78 | * Configure the view's position and size based on the swayc's position and | ||
79 | * size, taking borders into consideration. | ||
80 | */ | ||
81 | void view_autoconfigure(struct sway_view *view) { | ||
82 | if (!sway_assert(view->swayc, | ||
83 | "Called view_autoconfigure() on a view without a swayc")) { | ||
84 | return; | ||
85 | } | ||
86 | |||
87 | if (view->is_fullscreen) { | ||
88 | struct sway_container *output = container_parent(view->swayc, C_OUTPUT); | ||
89 | view_configure(view, 0, 0, output->width, output->height); | ||
90 | view->x = view->y = 0; | ||
91 | return; | ||
92 | } | ||
93 | |||
94 | double x, y, width, height; | ||
95 | switch (view->border) { | ||
96 | case B_NONE: | ||
97 | x = view->swayc->x; | ||
98 | y = view->swayc->y; | ||
99 | width = view->swayc->width; | ||
100 | height = view->swayc->height; | ||
101 | break; | ||
102 | case B_PIXEL: | ||
103 | x = view->swayc->x + view->border_thickness; | ||
104 | y = view->swayc->y + view->border_thickness; | ||
105 | width = view->swayc->width - view->border_thickness * 2; | ||
106 | height = view->swayc->height - view->border_thickness * 2; | ||
107 | break; | ||
108 | case B_NORMAL: | ||
109 | // TODO: Size the title bar by checking the font | ||
110 | x = view->swayc->x + view->border_thickness; | ||
111 | y = view->swayc->y + 20; | ||
112 | width = view->swayc->width - view->border_thickness * 2; | ||
113 | height = view->swayc->height - view->border_thickness - 20; | ||
114 | break; | ||
115 | } | ||
116 | |||
117 | view->x = x; | ||
118 | view->y = y; | ||
119 | view_configure(view, x, y, width, height); | ||
120 | } | ||
121 | |||
76 | void view_set_activated(struct sway_view *view, bool activated) { | 122 | void view_set_activated(struct sway_view *view, bool activated) { |
77 | if (view->impl->set_activated) { | 123 | if (view->impl->set_activated) { |
78 | view->impl->set_activated(view, activated); | 124 | view->impl->set_activated(view, activated); |
@@ -262,6 +308,8 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { | |||
262 | 308 | ||
263 | view->surface = wlr_surface; | 309 | view->surface = wlr_surface; |
264 | view->swayc = cont; | 310 | view->swayc = cont; |
311 | view->border = config->border; | ||
312 | view->border_thickness = config->border_thickness; | ||
265 | 313 | ||
266 | view_init_subsurfaces(view, wlr_surface); | 314 | view_init_subsurfaces(view, wlr_surface); |
267 | wl_signal_add(&wlr_surface->events.new_subsurface, | 315 | wl_signal_add(&wlr_surface->events.new_subsurface, |
@@ -305,23 +353,13 @@ void view_unmap(struct sway_view *view) { | |||
305 | arrange_children_of(parent); | 353 | arrange_children_of(parent); |
306 | } | 354 | } |
307 | 355 | ||
308 | void view_update_position(struct sway_view *view, double ox, double oy) { | ||
309 | if (view->swayc->x == ox && view->swayc->y == oy) { | ||
310 | return; | ||
311 | } | ||
312 | |||
313 | view_damage(view, true); | ||
314 | view->swayc->x = ox; | ||
315 | view->swayc->y = oy; | ||
316 | view_damage(view, true); | ||
317 | } | ||
318 | |||
319 | void view_update_size(struct sway_view *view, int width, int height) { | 356 | void view_update_size(struct sway_view *view, int width, int height) { |
320 | if (view->width == width && view->height == height) { | 357 | if (view->width == width && view->height == height) { |
321 | return; | 358 | return; |
322 | } | 359 | } |
323 | 360 | ||
324 | view_damage(view, true); | 361 | view_damage(view, true); |
362 | // Should we update the swayc width/height here too? | ||
325 | view->width = width; | 363 | view->width = width; |
326 | view->height = height; | 364 | view->height = height; |
327 | view_damage(view, true); | 365 | view_damage(view, true); |