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