From 1f2e399ade77070a2d0b82856ad9a3eef96b8676 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Thu, 24 May 2018 22:30:44 +1000 Subject: Implement floating --- sway/tree/view.c | 87 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 57 insertions(+), 30 deletions(-) (limited to 'sway/tree/view.c') diff --git a/sway/tree/view.c b/sway/tree/view.c index 26ff1e8d..651a2be6 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -158,21 +158,19 @@ void view_autoconfigure(struct sway_view *view) { view->border_top = view->border_bottom = true; view->border_left = view->border_right = true; - if (view->swayc->layout != L_FLOATING) { - if (config->hide_edge_borders == E_BOTH - || config->hide_edge_borders == E_VERTICAL - || (config->hide_edge_borders == E_SMART && !other_views)) { - view->border_left = view->swayc->x != ws->x; - int right_x = view->swayc->x + view->swayc->width; - view->border_right = right_x != ws->x + ws->width; - } - if (config->hide_edge_borders == E_BOTH - || config->hide_edge_borders == E_HORIZONTAL - || (config->hide_edge_borders == E_SMART && !other_views)) { - view->border_top = view->swayc->y != ws->y; - int bottom_y = view->swayc->y + view->swayc->height; - view->border_bottom = bottom_y != ws->y + ws->height; - } + if (config->hide_edge_borders == E_BOTH + || config->hide_edge_borders == E_VERTICAL + || (config->hide_edge_borders == E_SMART && !other_views)) { + view->border_left = view->swayc->x != ws->x; + int right_x = view->swayc->x + view->swayc->width; + view->border_right = right_x != ws->x + ws->width; + } + if (config->hide_edge_borders == E_BOTH + || config->hide_edge_borders == E_HORIZONTAL + || (config->hide_edge_borders == E_SMART && !other_views)) { + view->border_top = view->swayc->y != ws->y; + int bottom_y = view->swayc->y + view->swayc->height; + view->border_bottom = bottom_y != ws->y + ws->height; } double x, y, width, height; @@ -184,11 +182,11 @@ void view_autoconfigure(struct sway_view *view) { // disable any top border because we'll always have the title bar. if (view->swayc->parent->layout == L_TABBED) { y_offset = container_titlebar_height(); - view->border_top = 0; + view->border_top = false; } else if (view->swayc->parent->layout == L_STACKED) { y_offset = container_titlebar_height() * view->swayc->parent->children->length; - view->border_top = 0; + view->border_top = false; } switch (view->border) { @@ -237,6 +235,12 @@ void view_set_activated(struct sway_view *view, bool activated) { } } +void view_set_maximized(struct sway_view *view, bool maximized) { + if (view->impl->set_maximized) { + view->impl->set_maximized(view, maximized); + } +} + // Set fullscreen, but without IPC events or arranging windows. void view_set_fullscreen_raw(struct sway_view *view, bool fullscreen) { if (view->is_fullscreen == fullscreen) { @@ -452,6 +456,11 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { // TODO: CT_ASSIGN_OUTPUT } } + // If we're about to launch the view into the floating container, then + // launch it as a tiled view in the root of the workspace instead. + if (focus->is_floating) { + focus = focus->parent->parent; + } free(criterias); cont = container_view_create(focus, view); @@ -468,7 +477,12 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { wl_signal_add(&view->swayc->events.reparent, &view->container_reparent); view->container_reparent.notify = view_handle_container_reparent; - arrange_children_of(cont->parent); + if (view->impl->wants_floating && view->impl->wants_floating(view)) { + container_set_floating(view->swayc, true); + } else { + arrange_children_of(cont->parent); + } + input_manager_set_focus(input_manager, cont); if (workspace) { workspace_switch(workspace); @@ -516,16 +530,14 @@ 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) { +void view_update_position(struct sway_view *view, double lx, double ly) { + if (!view->swayc->is_floating) { 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). container_damage_whole(view->swayc); - view->swayc->x = ox; - view->swayc->y = oy; + view->x = lx; + view->y = ly; + container_set_geometry_from_view(view->swayc); container_damage_whole(view->swayc); } @@ -533,15 +545,15 @@ void view_update_size(struct sway_view *view, int width, int height) { if (view->width == width && view->height == height) { return; } - container_damage_whole(view->swayc); - // Should we update the swayc width/height here too? view->width = width; view->height = height; + if (view->swayc->is_floating) { + container_set_geometry_from_view(view->swayc); + } container_damage_whole(view->swayc); } - static void view_subsurface_create(struct sway_view *view, struct wlr_subsurface *subsurface) { struct sway_view_child *child = calloc(1, sizeof(struct sway_view_child)); @@ -888,6 +900,19 @@ bool view_is_visible(struct sway_view *view) { if (!view->swayc) { return false; } + struct sway_container *workspace = + container_parent(view->swayc, C_WORKSPACE); + // Determine if view is nested inside a floating container which is sticky. + // A simple floating view will have this ancestry: + // C_VIEW (is_floating=true) -> floating -> workspace + // A more complex ancestry could be: + // C_VIEW -> C_CONTAINER (tabbed and is_floating) -> floating -> workspace + struct sway_container *floater = view->swayc; + while (floater->parent->type != C_WORKSPACE + && floater->parent->parent->type != C_WORKSPACE) { + floater = floater->parent; + } + bool is_sticky = floater->is_floating && floater->is_sticky; // Check view isn't in a tabbed or stacked container on an inactive tab struct sway_seat *seat = input_manager_current_seat(input_manager); struct sway_container *container = view->swayc; @@ -901,10 +926,12 @@ bool view_is_visible(struct sway_view *view) { container = container->parent; } // Check view isn't hidden by another fullscreen view - struct sway_container *workspace = container; if (workspace->sway_workspace->fullscreen && !view->is_fullscreen) { return false; } // Check the workspace is visible - return workspace_is_visible(workspace); + if (!is_sticky) { + return workspace_is_visible(workspace); + } + return true; } -- cgit v1.2.3 From aaba7642b3e4e9a63aea49412b10221f399b17af Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Fri, 25 May 2018 09:26:23 +1000 Subject: Replace is_floating boolean with function --- sway/tree/view.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'sway/tree/view.c') diff --git a/sway/tree/view.c b/sway/tree/view.c index 651a2be6..8548d9b8 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -458,7 +458,7 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { } // If we're about to launch the view into the floating container, then // launch it as a tiled view in the root of the workspace instead. - if (focus->is_floating) { + if (container_is_floating(focus)) { focus = focus->parent->parent; } free(criterias); @@ -531,7 +531,7 @@ void view_unmap(struct sway_view *view) { } void view_update_position(struct sway_view *view, double lx, double ly) { - if (!view->swayc->is_floating) { + if (!container_is_floating(view->swayc)) { return; } container_damage_whole(view->swayc); @@ -548,7 +548,7 @@ void view_update_size(struct sway_view *view, int width, int height) { container_damage_whole(view->swayc); view->width = width; view->height = height; - if (view->swayc->is_floating) { + if (container_is_floating(view->swayc)) { container_set_geometry_from_view(view->swayc); } container_damage_whole(view->swayc); @@ -904,15 +904,15 @@ bool view_is_visible(struct sway_view *view) { container_parent(view->swayc, C_WORKSPACE); // Determine if view is nested inside a floating container which is sticky. // A simple floating view will have this ancestry: - // C_VIEW (is_floating=true) -> floating -> workspace + // C_VIEW -> floating -> workspace // A more complex ancestry could be: - // C_VIEW -> C_CONTAINER (tabbed and is_floating) -> floating -> workspace + // C_VIEW -> C_CONTAINER (tabbed) -> floating -> workspace struct sway_container *floater = view->swayc; while (floater->parent->type != C_WORKSPACE && floater->parent->parent->type != C_WORKSPACE) { floater = floater->parent; } - bool is_sticky = floater->is_floating && floater->is_sticky; + bool is_sticky = container_is_floating(floater) && floater->is_sticky; // Check view isn't in a tabbed or stacked container on an inactive tab struct sway_seat *seat = input_manager_current_seat(input_manager); struct sway_container *container = view->swayc; -- cgit v1.2.3 From 13a4b0512e25b8da6e16ca1286f8b62fcc24c5cc Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Fri, 25 May 2018 11:15:43 +1000 Subject: Fix unfullscreening a floating view --- sway/tree/view.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'sway/tree/view.c') diff --git a/sway/tree/view.c b/sway/tree/view.c index 8548d9b8..65961dd9 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -126,6 +126,23 @@ void view_configure(struct sway_view *view, double ox, double oy, int width, } } +static void view_autoconfigure_floating(struct sway_view *view) { + struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE); + int max_width = ws->width * 0.6666; + int max_height = ws->height * 0.6666; + int width = + view->natural_width > max_width ? max_width : view->natural_width; + int height = + view->natural_height > max_height ? max_height : view->natural_height; + struct sway_container *output = ws->parent; + int lx = output->x + (ws->width - width) / 2; + int ly = output->y + (ws->height - height) / 2; + + view->border_left = view->border_right = view->border_bottom = true; + view_set_maximized(view, false); + view_configure(view, lx, ly, width, height); +} + void view_autoconfigure(struct sway_view *view) { if (!sway_assert(view->swayc, "Called view_autoconfigure() on a view without a swayc")) { @@ -140,6 +157,11 @@ void view_autoconfigure(struct sway_view *view) { return; } + if (container_is_floating(view->swayc)) { + view_autoconfigure_floating(view); + return; + } + struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE); int other_views = 0; @@ -261,6 +283,8 @@ void view_set_fullscreen_raw(struct sway_view *view, bool fullscreen) { view_set_fullscreen(workspace->sway_workspace->fullscreen, false); } workspace->sway_workspace->fullscreen = view; + view->swayc->saved_x = view->swayc->x; + view->swayc->saved_y = view->swayc->y; view->swayc->saved_width = view->swayc->width; view->swayc->saved_height = view->swayc->height; @@ -283,6 +307,11 @@ void view_set_fullscreen_raw(struct sway_view *view, bool fullscreen) { workspace->sway_workspace->fullscreen = NULL; view->swayc->width = view->swayc->saved_width; view->swayc->height = view->swayc->saved_height; + if (container_is_floating(view->swayc)) { + view->swayc->x = view->swayc->saved_x; + view->swayc->y = view->swayc->saved_y; + view_autoconfigure(view); + } } } -- cgit v1.2.3 From 02de2a6f65c189bf563cca5b4d3fbc11826ea7f7 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 26 May 2018 09:22:10 +1000 Subject: Rename set_maximized functions to set_tiled --- sway/tree/view.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'sway/tree/view.c') diff --git a/sway/tree/view.c b/sway/tree/view.c index 65961dd9..3de9879e 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -139,7 +139,7 @@ static void view_autoconfigure_floating(struct sway_view *view) { int ly = output->y + (ws->height - height) / 2; view->border_left = view->border_right = view->border_bottom = true; - view_set_maximized(view, false); + view_set_tiled(view, false); view_configure(view, lx, ly, width, height); } @@ -257,9 +257,9 @@ void view_set_activated(struct sway_view *view, bool activated) { } } -void view_set_maximized(struct sway_view *view, bool maximized) { - if (view->impl->set_maximized) { - view->impl->set_maximized(view, maximized); +void view_set_tiled(struct sway_view *view, bool tiled) { + if (view->impl->set_tiled) { + view->impl->set_tiled(view, tiled); } } -- cgit v1.2.3 From e4e912ea91a5a36d9f17c1730ffbf29707984399 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 26 May 2018 16:26:10 +1000 Subject: Store swayc coordinates as layout-local --- sway/tree/view.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'sway/tree/view.c') diff --git a/sway/tree/view.c b/sway/tree/view.c index 3de9879e..065d00db 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -119,10 +119,10 @@ const char *view_get_shell(struct sway_view *view) { return "unknown"; } -void view_configure(struct sway_view *view, double ox, double oy, int width, +void view_configure(struct sway_view *view, double lx, double ly, int width, int height) { if (view->impl->configure) { - view->impl->configure(view, ox, oy, width, height); + view->impl->configure(view, lx, ly, width, height); } } @@ -134,9 +134,8 @@ static void view_autoconfigure_floating(struct sway_view *view) { view->natural_width > max_width ? max_width : view->natural_width; int height = view->natural_height > max_height ? max_height : view->natural_height; - struct sway_container *output = ws->parent; - int lx = output->x + (ws->width - width) / 2; - int ly = output->y + (ws->height - height) / 2; + int lx = ws->x + (ws->width - width) / 2; + int ly = ws->y + (ws->height - height) / 2; view->border_left = view->border_right = view->border_bottom = true; view_set_tiled(view, false); @@ -152,8 +151,7 @@ void view_autoconfigure(struct sway_view *view) { struct sway_container *output = container_parent(view->swayc, C_OUTPUT); if (view->is_fullscreen) { - view_configure(view, 0, 0, output->width, output->height); - view->x = view->y = 0; + view_configure(view, output->x, output->y, output->width, output->height); return; } @@ -560,6 +558,9 @@ void view_unmap(struct sway_view *view) { } void view_update_position(struct sway_view *view, double lx, double ly) { + if (view->x == lx && view->y == ly) { + return; + } if (!container_is_floating(view->swayc)) { return; } -- cgit v1.2.3 From 70f5d6fcf3219f122077b7e8d0b43a464f4e3fd4 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 26 May 2018 16:32:24 +1000 Subject: Rename container_set_geometry_from_view --- sway/tree/view.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sway/tree/view.c') diff --git a/sway/tree/view.c b/sway/tree/view.c index 065d00db..30d5c7b4 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -567,7 +567,7 @@ void view_update_position(struct sway_view *view, double lx, double ly) { container_damage_whole(view->swayc); view->x = lx; view->y = ly; - container_set_geometry_from_view(view->swayc); + container_set_geometry_from_floating_view(view->swayc); container_damage_whole(view->swayc); } @@ -579,7 +579,7 @@ void view_update_size(struct sway_view *view, int width, int height) { view->width = width; view->height = height; if (container_is_floating(view->swayc)) { - container_set_geometry_from_view(view->swayc); + container_set_geometry_from_floating_view(view->swayc); } container_damage_whole(view->swayc); } -- cgit v1.2.3 From 97672295ed50d1d6272876c4a3b6b5607cab05c6 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sun, 27 May 2018 23:43:05 +1000 Subject: Don't unmaximize floating views --- sway/tree/view.c | 7 ------- 1 file changed, 7 deletions(-) (limited to 'sway/tree/view.c') diff --git a/sway/tree/view.c b/sway/tree/view.c index 30d5c7b4..6e589611 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -138,7 +138,6 @@ static void view_autoconfigure_floating(struct sway_view *view) { int ly = ws->y + (ws->height - height) / 2; view->border_left = view->border_right = view->border_bottom = true; - view_set_tiled(view, false); view_configure(view, lx, ly, width, height); } @@ -255,12 +254,6 @@ void view_set_activated(struct sway_view *view, bool activated) { } } -void view_set_tiled(struct sway_view *view, bool tiled) { - if (view->impl->set_tiled) { - view->impl->set_tiled(view, tiled); - } -} - // Set fullscreen, but without IPC events or arranging windows. void view_set_fullscreen_raw(struct sway_view *view, bool fullscreen) { if (view->is_fullscreen == fullscreen) { -- cgit v1.2.3 From f24087d1045bbee8642ee0703f6513ae605f2c47 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Mon, 28 May 2018 17:42:56 +1000 Subject: Fix fullscreen position --- sway/tree/view.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'sway/tree/view.c') diff --git a/sway/tree/view.c b/sway/tree/view.c index 6e589611..2eaa5d49 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -554,13 +554,12 @@ void view_update_position(struct sway_view *view, double lx, double ly) { if (view->x == lx && view->y == ly) { return; } - if (!container_is_floating(view->swayc)) { - return; - } container_damage_whole(view->swayc); view->x = lx; view->y = ly; - container_set_geometry_from_floating_view(view->swayc); + if (container_is_floating(view->swayc)) { + container_set_geometry_from_floating_view(view->swayc); + } container_damage_whole(view->swayc); } -- cgit v1.2.3 From a2c1cb9072b990de9181bffeb69e43f9b3030804 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Thu, 31 May 2018 18:21:49 +1000 Subject: Fix mpv damage issue when unfullscreening into floating --- sway/tree/view.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'sway/tree/view.c') diff --git a/sway/tree/view.c b/sway/tree/view.c index 2eaa5d49..3117ded6 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -274,6 +274,10 @@ void view_set_fullscreen_raw(struct sway_view *view, bool fullscreen) { view_set_fullscreen(workspace->sway_workspace->fullscreen, false); } workspace->sway_workspace->fullscreen = view; + view->saved_x = view->x; + view->saved_y = view->y; + view->saved_width = view->width; + view->saved_height = view->height; view->swayc->saved_x = view->swayc->x; view->swayc->saved_y = view->swayc->y; view->swayc->saved_width = view->swayc->width; @@ -296,11 +300,12 @@ void view_set_fullscreen_raw(struct sway_view *view, bool fullscreen) { } } else { workspace->sway_workspace->fullscreen = NULL; - view->swayc->width = view->swayc->saved_width; - view->swayc->height = view->swayc->saved_height; if (container_is_floating(view->swayc)) { - view->swayc->x = view->swayc->saved_x; - view->swayc->y = view->swayc->saved_y; + view_configure(view, view->saved_x, view->saved_y, + view->saved_width, view->saved_height); + } else { + view->swayc->width = view->swayc->saved_width; + view->swayc->height = view->swayc->saved_height; view_autoconfigure(view); } } -- cgit v1.2.3