From: Consolatis <35009135+Consolatis@users.noreply.github.com> Date: Wed, 6 Jul 2022 15:04:21 +0000 (+0200) Subject: SnapToRegion: Add view_snap_to_region() X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=9d3e309a22d06c9c5f8a45c6f62fde3e908edabc;p=proto%2Flabwc.git SnapToRegion: Add view_snap_to_region() --- diff --git a/include/view.h b/include/view.h index 3ee49a67..b9c09793 100644 --- a/include/view.h +++ b/include/view.h @@ -50,6 +50,7 @@ struct view { bool minimized; bool maximized; uint32_t tiled; /* private, enum view_edge in src/view.c */ + struct region *tiled_region; struct wlr_output *fullscreen; /* geometry of the wlr_surface contained within the view */ @@ -134,6 +135,8 @@ void view_discover_output(struct view *view); void view_move_to_edge(struct view *view, const char *direction); void view_snap_to_edge(struct view *view, const char *direction, bool store_natural_geometry); +void view_snap_to_region(struct view *view, struct region *region, + bool store_natural_geometry); const char *view_get_string_prop(struct view *view, const char *prop); void view_update_title(struct view *view); void view_update_app_id(struct view *view); diff --git a/src/view.c b/src/view.c index c53e16a3..7e14756a 100644 --- a/src/view.c +++ b/src/view.c @@ -5,6 +5,7 @@ #include "common/scene-helpers.h" #include "labwc.h" #include "menu/menu.h" +#include "regions.h" #include "ssd.h" #include "view.h" #include "workspaces.h" @@ -293,7 +294,7 @@ void view_store_natural_geometry(struct view *view) { assert(view); - if (view->maximized || view->tiled) { + if (view->maximized || view->tiled || view->tiled_region) { /* Do not overwrite the stored geometry with special cases */ return; } @@ -341,6 +342,30 @@ view_apply_natural_geometry(struct view *view) } } +static void +view_apply_region_geometry(struct view *view) +{ + assert(view); + assert(view->tiled_region); + + /* Create a copy of the original region geometry */ + struct wlr_box geo = view->tiled_region->geo; + + /* And adjust for current view */ + struct border margin = ssd_get_margin(view->ssd); + geo.x += margin.left; + geo.y += margin.top; + geo.width -= margin.left + margin.right; + geo.height -= margin.top + margin.bottom; + + if (view->w == geo.width && view->h == geo.height) { + /* move horizontally/vertically without changing size */ + view_move(view, geo.x, geo.y); + } else { + view_move_resize(view, geo); + } +} + static void view_apply_tiled_geometry(struct view *view, struct output *output) { @@ -419,6 +444,8 @@ view_apply_special_geometry(struct view *view) view_apply_maximized_geometry(view); } else if (view->tiled) { view_apply_tiled_geometry(view, NULL); + } else if (view->tiled_region) { + view_apply_region_geometry(view); } else { return false; } @@ -461,6 +488,7 @@ view_set_untiled(struct view *view) { assert(view); view->tiled = VIEW_EDGE_INVALID; + view->tiled_region = NULL; } void @@ -859,6 +887,27 @@ view_snap_to_edge(struct view *view, const char *direction, view_apply_tiled_geometry(view, output); } +void +view_snap_to_region(struct view *view, struct region *region, + bool store_natural_geometry) +{ + assert(view); + assert(region); + if (view->fullscreen) { + return; + } + if (view->maximized) { + /* Unmaximize + keep using existing natural_geometry */ + view_maximize(view, false, /*store_natural_geometry*/ false); + } else if (store_natural_geometry) { + /* store current geometry as new natural_geometry */ + view_store_natural_geometry(view); + } + view_set_untiled(view); + view->tiled_region = region; + view_apply_region_geometry(view); +} + const char * view_get_string_prop(struct view *view, const char *prop) {