From 630ba30e3c60cfe3f1018b4a1701f0c2a0f6da9a Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Mon, 30 Apr 2018 21:24:13 +1000 Subject: Implement borders Implements rendering of borders. Title text is still to do. Implements the following configuration directives: * client.focused * client.focused_inactive * client.unfocused * client.urgent * border * default_border --- sway/tree/view.c | 60 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 11 deletions(-) (limited to 'sway/tree/view.c') diff --git a/sway/tree/view.c b/sway/tree/view.c index 519c3c78..26902c23 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -1,5 +1,6 @@ #include #include +#include #include #include "log.h" #include "sway/criteria.h" @@ -73,6 +74,51 @@ void view_configure(struct sway_view *view, double ox, double oy, int width, } } +/** + * Configure the view's position and size based on the swayc's position and + * size, taking borders into consideration. + */ +void view_autoconfigure(struct sway_view *view) { + if (!sway_assert(view->swayc, + "Called view_autoconfigure() on a view without a swayc")) { + return; + } + + if (view->is_fullscreen) { + struct sway_container *output = container_parent(view->swayc, C_OUTPUT); + view_configure(view, 0, 0, output->width, output->height); + view->x = view->y = 0; + return; + } + + double x, y, width, height; + switch (view->border) { + case B_NONE: + x = view->swayc->x; + y = view->swayc->y; + width = view->swayc->width; + height = view->swayc->height; + break; + case B_PIXEL: + x = view->swayc->x + view->border_thickness; + y = view->swayc->y + view->border_thickness; + width = view->swayc->width - view->border_thickness * 2; + height = view->swayc->height - view->border_thickness * 2; + break; + case B_NORMAL: + // TODO: Size the title bar by checking the font + x = view->swayc->x + view->border_thickness; + y = view->swayc->y + 20; + width = view->swayc->width - view->border_thickness * 2; + height = view->swayc->height - view->border_thickness - 20; + break; + } + + view->x = x; + view->y = y; + view_configure(view, x, y, width, height); +} + void view_set_activated(struct sway_view *view, bool activated) { if (view->impl->set_activated) { view->impl->set_activated(view, activated); @@ -262,6 +308,8 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { view->surface = wlr_surface; view->swayc = cont; + view->border = config->border; + view->border_thickness = config->border_thickness; view_init_subsurfaces(view, wlr_surface); wl_signal_add(&wlr_surface->events.new_subsurface, @@ -309,23 +357,13 @@ void view_unmap(struct sway_view *view) { } } -void view_update_position(struct sway_view *view, double ox, double oy) { - if (view->swayc->x == ox && view->swayc->y == oy) { - return; - } - - view_damage(view, true); - view->swayc->x = ox; - view->swayc->y = oy; - view_damage(view, true); -} - void view_update_size(struct sway_view *view, int width, int height) { if (view->width == width && view->height == height) { return; } view_damage(view, true); + // Should we update the swayc width/height here too? view->width = width; view->height = height; view_damage(view, true); -- cgit v1.2.3 From fa5de2876e3e8db4966d3404f01ba9600204d75b Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 1 May 2018 17:36:12 +1000 Subject: Move docblock and fix indenting of switch/case. --- sway/tree/view.c | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) (limited to 'sway/tree/view.c') diff --git a/sway/tree/view.c b/sway/tree/view.c index 26902c23..4903b3a4 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -74,10 +74,6 @@ void view_configure(struct sway_view *view, double ox, double oy, int width, } } -/** - * Configure the view's position and size based on the swayc's position and - * size, taking borders into consideration. - */ void view_autoconfigure(struct sway_view *view) { if (!sway_assert(view->swayc, "Called view_autoconfigure() on a view without a swayc")) { @@ -93,25 +89,25 @@ void view_autoconfigure(struct sway_view *view) { double x, y, width, height; switch (view->border) { - case B_NONE: - x = view->swayc->x; - y = view->swayc->y; - width = view->swayc->width; - height = view->swayc->height; - break; - case B_PIXEL: - x = view->swayc->x + view->border_thickness; - y = view->swayc->y + view->border_thickness; - width = view->swayc->width - view->border_thickness * 2; - height = view->swayc->height - view->border_thickness * 2; - break; - case B_NORMAL: - // TODO: Size the title bar by checking the font - x = view->swayc->x + view->border_thickness; - y = view->swayc->y + 20; - width = view->swayc->width - view->border_thickness * 2; - height = view->swayc->height - view->border_thickness - 20; - break; + case B_NONE: + x = view->swayc->x; + y = view->swayc->y; + width = view->swayc->width; + height = view->swayc->height; + break; + case B_PIXEL: + x = view->swayc->x + view->border_thickness; + y = view->swayc->y + view->border_thickness; + width = view->swayc->width - view->border_thickness * 2; + height = view->swayc->height - view->border_thickness * 2; + break; + case B_NORMAL: + // TODO: Size the title bar by checking the font + x = view->swayc->x + view->border_thickness; + y = view->swayc->y + 20; + width = view->swayc->width - view->border_thickness * 2; + height = view->swayc->height - view->border_thickness - 20; + break; } view->x = x; -- cgit v1.2.3 From 83952c52019ceee95e9293398bdc5f723db773eb Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 1 May 2018 19:59:36 +1000 Subject: Restore view_update_position() --- sway/tree/view.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'sway/tree/view.c') diff --git a/sway/tree/view.c b/sway/tree/view.c index 4903b3a4..05a9b277 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -353,6 +353,19 @@ void view_unmap(struct sway_view *view) { } } +void view_update_position(struct sway_view *view, double ox, double oy) { + if (view->swayc->x == ox && view->swayc->y == oy) { + return; + } + + // TODO: Only allow this if the view is floating (this function will only be + // called in response to wayland clients wanting to reposition themselves). + view_damage(view, true); + view->swayc->x = ox; + view->swayc->y = oy; + view_damage(view, true); +} + void view_update_size(struct sway_view *view, int width, int height) { if (view->width == width && view->height == height) { return; -- cgit v1.2.3