]> git.mdlowis.com Git - proto/labwc.git/commitdiff
SnapToRegion: Add view_snap_to_region()
authorConsolatis <35009135+Consolatis@users.noreply.github.com>
Wed, 6 Jul 2022 15:04:21 +0000 (17:04 +0200)
committerConsolatis <35009135+Consolatis@users.noreply.github.com>
Wed, 11 Jan 2023 17:52:24 +0000 (18:52 +0100)
include/view.h
src/view.c

index 3ee49a6719cee721183fa7887da515b36abf4331..b9c09793f380f05370c2ffdf3f8eafd9867d7fdb 100644 (file)
@@ -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);
index c53e16a35d688d51efaf0a2586efb9c635fa0ee7..7e14756a92de366d5e73dd659ddbb3b332b34f5a 100644 (file)
@@ -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)
 {