diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-06-01 15:41:49 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-01 15:41:49 -0700 |
commit | 96446fdbf748acfdbd4c60fbc0d12e45a27199fe (patch) | |
tree | 6d46cc61a1e7c74efe36565796ccbf8b47e7e4a7 /sway/desktop/xdg_shell.c | |
parent | fd885d5779ef9aa408fa856a66fa7343ce01fa19 (diff) | |
parent | 70c2c504452eccbe5a74bc014e99b5b03db14124 (diff) |
Merge pull request #2027 from RyanDwyer/implement-floating
Implement floating
Diffstat (limited to 'sway/desktop/xdg_shell.c')
-rw-r--r-- | sway/desktop/xdg_shell.c | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c index b2b95fa0..d2b8822c 100644 --- a/sway/desktop/xdg_shell.c +++ b/sway/desktop/xdg_shell.c @@ -87,7 +87,7 @@ static const char *get_string_prop(struct sway_view *view, enum sway_view_prop p } } -static void configure(struct sway_view *view, double ox, double oy, int width, +static void configure(struct sway_view *view, double lx, double ly, int width, int height) { struct sway_xdg_shell_view *xdg_shell_view = xdg_shell_view_from_view(view); @@ -98,6 +98,7 @@ static void configure(struct sway_view *view, double ox, double oy, int width, xdg_shell_view->pending_width = width; xdg_shell_view->pending_height = height; wlr_xdg_toplevel_set_size(view->wlr_xdg_surface, width, height); + view_update_position(view, lx, ly); } static void set_activated(struct sway_view *view, bool activated) { @@ -118,6 +119,14 @@ static void set_fullscreen(struct sway_view *view, bool fullscreen) { wlr_xdg_toplevel_set_fullscreen(surface, fullscreen); } +static bool wants_floating(struct sway_view *view) { + struct wlr_xdg_toplevel_state *state = + &view->wlr_xdg_surface->toplevel->current; + return state->min_width != 0 && state->min_height != 0 + && state->min_width == state->max_width + && state->min_height == state->max_height; +} + static void for_each_surface(struct sway_view *view, wlr_surface_iterator_func_t iterator, void *user_data) { if (xdg_shell_view_from_view(view) == NULL) { @@ -155,6 +164,7 @@ static const struct sway_view_impl view_impl = { .configure = configure, .set_activated = set_activated, .set_fullscreen = set_fullscreen, + .wants_floating = wants_floating, .for_each_surface = for_each_surface, .close = _close, .destroy = destroy, @@ -164,11 +174,18 @@ static void handle_commit(struct wl_listener *listener, void *data) { struct sway_xdg_shell_view *xdg_shell_view = wl_container_of(listener, xdg_shell_view, commit); struct sway_view *view = &xdg_shell_view->view; - // NOTE: We intentionally discard the view's desired width here - // TODO: Store this for restoration when moving to floating plane - // TODO: Let floating views do whatever - view_update_size(view, xdg_shell_view->pending_width, - xdg_shell_view->pending_height); + if (view->swayc && container_is_floating(view->swayc)) { + int width = view->wlr_xdg_surface->geometry.width; + int height = view->wlr_xdg_surface->geometry.height; + if (!width && !height) { + width = view->wlr_xdg_surface->surface->current->width; + height = view->wlr_xdg_surface->surface->current->height; + } + view_update_size(view, width, height); + } else { + view_update_size(view, xdg_shell_view->pending_width, + xdg_shell_view->pending_height); + } view_update_title(view, false); view_damage_from(view); } @@ -196,6 +213,12 @@ static void handle_map(struct wl_listener *listener, void *data) { struct sway_view *view = &xdg_shell_view->view; struct wlr_xdg_surface *xdg_surface = view->wlr_xdg_surface; + view->natural_width = view->wlr_xdg_surface->geometry.width; + view->natural_height = view->wlr_xdg_surface->geometry.height; + if (!view->natural_width && !view->natural_height) { + view->natural_width = view->wlr_xdg_surface->surface->current->width; + view->natural_height = view->wlr_xdg_surface->surface->current->height; + } view_map(view, view->wlr_xdg_surface->surface); xdg_shell_view->commit.notify = handle_commit; |