diff options
author | emersion <contact@emersion.fr> | 2018-04-19 23:31:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-19 23:31:25 +0100 |
commit | a5719f9f432b5f9378ebd2136f8a2cde46dfb407 (patch) | |
tree | 1735e7c33fe5547acfaa56b893fc0b450c0d9483 /sway/tree | |
parent | 2f0120e458cae47f38a3c09af174bae60964151c (diff) | |
parent | 6afccd07d95582a72e36b49454266ab0cebec7c0 (diff) |
Merge pull request #1817 from RyanDwyer/fullscreen
Implement fullscreen
Diffstat (limited to 'sway/tree')
-rw-r--r-- | sway/tree/container.c | 1 | ||||
-rw-r--r-- | sway/tree/layout.c | 116 | ||||
-rw-r--r-- | sway/tree/view.c | 51 | ||||
-rw-r--r-- | sway/tree/workspace.c | 7 |
4 files changed, 152 insertions, 23 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c index c0067493..f14e9b9a 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -197,6 +197,7 @@ static struct sway_container *container_workspace_destroy( } } + free(workspace->sway_workspace); _container_destroy(workspace); output_damage_whole(output->sway_output); diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 0b637822..7ffc2484 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -82,6 +82,37 @@ static int index_child(const struct sway_container *child) { return i; } +static void container_handle_fullscreen_reparent(struct sway_container *viewcon, + struct sway_container *old_parent) { + if (viewcon->type != C_VIEW || !viewcon->sway_view->is_fullscreen) { + return; + } + struct sway_view *view = viewcon->sway_view; + struct sway_container *old_workspace = old_parent; + if (old_workspace && old_workspace->type != C_WORKSPACE) { + old_workspace = container_parent(old_workspace, C_WORKSPACE); + } + struct sway_container *new_workspace = container_parent(view->swayc, + C_WORKSPACE); + if (old_workspace == new_workspace) { + return; + } + // Unmark the old workspace as fullscreen + if (old_workspace) { + old_workspace->sway_workspace->fullscreen = NULL; + } + + // Mark the new workspace as fullscreen + if (new_workspace->sway_workspace->fullscreen) { + view_set_fullscreen(new_workspace->sway_workspace->fullscreen, false); + } + new_workspace->sway_workspace->fullscreen = view; + // Resize view to new output dimensions + struct sway_output *output = new_workspace->parent->sway_output; + view_configure(view, 0, 0, + output->wlr_output->width, output->wlr_output->height); +} + void container_insert_child(struct sway_container *parent, struct sway_container *child, int i) { struct sway_container *old_parent = child->parent; @@ -91,6 +122,7 @@ void container_insert_child(struct sway_container *parent, wlr_log(L_DEBUG, "Inserting id:%zd at index %d", child->id, i); list_insert(parent->children, i, child); child->parent = parent; + container_handle_fullscreen_reparent(child, old_parent); wl_signal_emit(&child->events.reparent, old_parent); } @@ -106,6 +138,7 @@ struct sway_container *container_add_sibling(struct sway_container *fixed, int i = index_child(fixed); list_insert(parent->children, i + 1, active); active->parent = parent; + container_handle_fullscreen_reparent(active, old_parent); wl_signal_emit(&active->events.reparent, old_parent); return active->parent; } @@ -115,11 +148,18 @@ void container_add_child(struct sway_container *parent, wlr_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)", child, child->type, child->width, child->height, parent, parent->type, parent->width, parent->height); + struct sway_container *old_parent = child->parent; list_add(parent->children, child); + container_handle_fullscreen_reparent(child, old_parent); child->parent = parent; } struct sway_container *container_remove_child(struct sway_container *child) { + if (child->type == C_VIEW && child->sway_view->is_fullscreen) { + struct sway_container *workspace = container_parent(child, C_WORKSPACE); + workspace->sway_workspace->fullscreen = NULL; + } + struct sway_container *parent = child->parent; for (int i = 0; i < parent->children->length; ++i) { if (parent->children->items[i] == child) { @@ -164,6 +204,26 @@ void container_move_to(struct sway_container *container, arrange_windows(old_parent, -1, -1); } arrange_windows(new_parent, -1, -1); + // If view was moved to a fullscreen workspace, refocus the fullscreen view + struct sway_container *new_workspace = container; + if (new_workspace->type != C_WORKSPACE) { + new_workspace = container_parent(new_workspace, C_WORKSPACE); + } + if (new_workspace->sway_workspace->fullscreen) { + struct sway_seat *seat; + struct sway_container *focus, *focus_ws; + wl_list_for_each(seat, &input_manager->seats, link) { + focus = seat_get_focus(seat); + focus_ws = focus; + if (focus_ws->type != C_WORKSPACE) { + focus_ws = container_parent(focus_ws, C_WORKSPACE); + } + seat_set_focus(seat, new_workspace->sway_workspace->fullscreen->swayc); + if (focus_ws != new_workspace) { + seat_set_focus(seat, focus); + } + } + } } static bool sway_dir_to_wlr(enum movement_direction dir, @@ -268,6 +328,11 @@ void container_move(struct sway_container *container, struct sway_container *current = container; struct sway_container *parent = current->parent; + // If moving a fullscreen view, only consider outputs + if (container->type == C_VIEW && container->sway_view->is_fullscreen) { + current = container_parent(container, C_OUTPUT); + } + if (parent != container_flatten(parent)) { // Special case: we were the last one in this container, so flatten it // and leave @@ -568,6 +633,11 @@ void arrange_windows(struct sway_container *container, container->y = y = area->y; wlr_log(L_DEBUG, "Arranging workspace '%s' at %f, %f", container->name, container->x, container->y); + if (container->sway_workspace->fullscreen) { + view_configure(container->sway_workspace->fullscreen, 0, 0, + output->width, output->height); + return; + } } // children are properly handled below break; @@ -816,34 +886,26 @@ static struct sway_container *sway_output_from_wlr(struct wlr_output *output) { struct sway_container *container_get_in_direction( struct sway_container *container, struct sway_seat *seat, enum movement_direction dir) { - if (dir == MOVE_CHILD) { - return seat_get_focus_inactive(seat, container); - } - struct sway_container *parent = container->parent; - if (dir == MOVE_PARENT) { - if (parent->type == C_OUTPUT) { + + if (container->type == C_VIEW && container->sway_view->is_fullscreen) { + if (dir == MOVE_PARENT || dir == MOVE_CHILD) { return NULL; - } else { - return parent; } - } - - // TODO WLR fullscreen - /* - if (container->type == C_VIEW && swayc_is_fullscreen(container)) { - wlr_log(L_DEBUG, "Moving from fullscreen view, skipping to output"); container = container_parent(container, C_OUTPUT); - get_layout_center_position(container, &abs_pos); - struct sway_container *output = - swayc_adjacent_output(container, dir, &abs_pos, true); - return get_swayc_in_output_direction(output, dir); - } - if (container->type == C_WORKSPACE && container->fullscreen) { - sway_log(L_DEBUG, "Moving to fullscreen view"); - return container->fullscreen; + parent = container->parent; + } else { + if (dir == MOVE_CHILD) { + return seat_get_focus_inactive(seat, container); + } + if (dir == MOVE_PARENT) { + if (parent->type == C_OUTPUT) { + return NULL; + } else { + return parent; + } + } } - */ struct sway_container *wrap_candidate = NULL; while (true) { @@ -874,6 +936,14 @@ struct sway_container *container_get_in_direction( if (next == NULL) { return NULL; } + struct sway_container *next_workspace = next; + if (next_workspace->type != C_WORKSPACE) { + next_workspace = container_parent(next_workspace, C_WORKSPACE); + } + sway_assert(next_workspace, "Next container has no workspace"); + if (next_workspace->sway_workspace->fullscreen) { + return next_workspace->sway_workspace->fullscreen->swayc; + } if (next->children && next->children->length) { // TODO consider floating children as well return seat_get_focus_inactive_view(seat, next); diff --git a/sway/tree/view.c b/sway/tree/view.c index 99b44720..b92c7099 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -2,10 +2,12 @@ #include <wayland-server.h> #include <wlr/types/wlr_output_layout.h> #include "log.h" +#include "sway/ipc-server.h" #include "sway/output.h" #include "sway/tree/container.h" #include "sway/tree/layout.h" #include "sway/tree/view.h" +#include "sway/tree/workspace.h" void view_init(struct sway_view *view, enum sway_view_type type, const struct sway_view_impl *impl) { @@ -73,6 +75,50 @@ void view_set_activated(struct sway_view *view, bool activated) { } } +void view_set_fullscreen(struct sway_view *view, bool fullscreen) { + if (view->is_fullscreen == fullscreen) { + return; + } + + struct sway_container *workspace = container_parent(view->swayc, C_WORKSPACE); + struct sway_container *container = container_parent(workspace, C_OUTPUT); + struct sway_output *output = container->sway_output; + + if (view->impl->set_fullscreen) { + view->impl->set_fullscreen(view, fullscreen); + } + + view->is_fullscreen = fullscreen; + + if (fullscreen) { + if (workspace->sway_workspace->fullscreen) { + view_set_fullscreen(workspace->sway_workspace->fullscreen, false); + } + workspace->sway_workspace->fullscreen = view; + + struct sway_seat *seat; + struct sway_container *focus, *focus_ws; + wl_list_for_each(seat, &input_manager->seats, link) { + focus = seat_get_focus(seat); + focus_ws = focus; + if (focus_ws->type != C_WORKSPACE) { + focus_ws = container_parent(focus_ws, C_WORKSPACE); + } + seat_set_focus(seat, view->swayc); + if (focus_ws != workspace) { + seat_set_focus(seat, focus); + } + } + } else { + workspace->sway_workspace->fullscreen = NULL; + } + + arrange_windows(workspace, -1, -1); + output_damage_whole(output); + + ipc_event_window(view->swayc, "fullscreen_mode"); +} + void view_close(struct sway_view *view) { if (view->impl->close) { view->impl->close(view); @@ -197,6 +243,11 @@ void view_unmap(struct sway_view *view) { wl_signal_emit(&view->events.unmap, view); + if (view->is_fullscreen) { + struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE); + ws->sway_workspace->fullscreen = NULL; + } + view_damage(view, true); wl_list_remove(&view->surface_new_subsurface.link); diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 316f01e4..7f3c1903 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -59,6 +59,13 @@ struct sway_container *workspace_create(struct sway_container *output, workspace->layout = container_get_default_layout(output); workspace->workspace_layout = workspace->layout; + struct sway_workspace *swayws = calloc(1, sizeof(struct sway_workspace)); + if (!swayws) { + return NULL; + } + swayws->swayc = workspace; + workspace->sway_workspace = swayws; + container_add_child(output, workspace); container_sort_workspaces(output); container_create_notify(workspace); |