Implement floating

This commit is contained in:
Ryan Dwyer 2018-05-24 22:30:44 +10:00
parent 1132efe42e
commit 1f2e399ade
21 changed files with 572 additions and 169 deletions

View file

@ -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;
}