]> git.mdlowis.com Git - proto/labwc.git/commitdiff
SnapToRegion: Wire up output and handle usable_area changes
authorConsolatis <35009135+Consolatis@users.noreply.github.com>
Wed, 6 Jul 2022 14:57:25 +0000 (16:57 +0200)
committerConsolatis <35009135+Consolatis@users.noreply.github.com>
Wed, 11 Jan 2023 17:52:24 +0000 (18:52 +0100)
include/labwc.h
src/output.c
src/regions.c

index 1d383d1f167a7a191c48a8cd2680d2ac8b5ff09c..9f728a005fc850ff30543cec1e7fd3140bd65f6c 100644 (file)
@@ -309,6 +309,8 @@ struct output {
        struct wlr_scene_buffer *workspace_osd;
        struct wlr_box usable_area;
 
+       struct wl_list regions;  /* struct region.link */
+
        struct lab_data_buffer *osd_buffer;
 
        struct wl_listener destroy;
index a43bc097f92d87fbb1df239ebde73ccce5e2e8ce..b30ba643cb7e829fc53f6d59bd5940132fd7ee14 100644 (file)
@@ -19,6 +19,7 @@
 #include "labwc.h"
 #include "layers.h"
 #include "node.h"
+#include "regions.h"
 #include "view.h"
 
 static void
@@ -40,6 +41,7 @@ static void
 output_destroy_notify(struct wl_listener *listener, void *data)
 {
        struct output *output = wl_container_of(listener, output, destroy);
+       regions_destroy(&output->regions);
        wl_list_remove(&output->link);
        wl_list_remove(&output->frame.link);
        wl_list_remove(&output->destroy.link);
@@ -148,6 +150,8 @@ new_output_notify(struct wl_listener *listener, void *data)
        output->frame.notify = output_frame_notify;
        wl_signal_add(&wlr_output->events.frame, &output->frame);
 
+       wl_list_init(&output->regions);
+
        /*
         * Create layer-trees (background, bottom, top and overlay) and
         * a layer-popup-tree.
@@ -446,6 +450,7 @@ void
 output_update_usable_area(struct output *output)
 {
        if (update_usable_area(output)) {
+               regions_update(output);
                desktop_arrange_all_views(output->server);
        }
 }
@@ -457,7 +462,12 @@ output_update_all_usable_areas(struct server *server, bool layout_changed)
        struct output *output;
 
        wl_list_for_each(output, &server->outputs, link) {
-               usable_area_changed |= update_usable_area(output);
+               if (update_usable_area(output)) {
+                       usable_area_changed = true;
+                       regions_update(output);
+               } else if (layout_changed) {
+                       regions_update(output);
+               }
        }
        if (usable_area_changed || layout_changed) {
                desktop_arrange_all_views(server);
index 2b8ea87a79e498c1b437e8c530ff341a50c3df70..52d2c5d3e9ec1dcab243ecc262f25b21a01c6d2a 100644 (file)
@@ -8,6 +8,7 @@
 #include <wlr/util/box.h>
 #include <wlr/util/log.h>
 #include "common/graphic-helpers.h"
+#include "common/list.h"
 #include "common/mem.h"
 #include "labwc.h"
 #include "regions.h"
@@ -27,7 +28,34 @@ regions_init(struct server *server, struct seat *seat)
 void
 regions_update(struct output *output)
 {
-       /* To be filled later */
+       assert(output);
+
+       struct region *region;
+       struct wlr_box usable = output_usable_area_in_layout_coords(output);
+
+       /* Initialize regions */
+       if (wl_list_empty(&output->regions)) {
+               wl_list_for_each(region, &rc.regions, link) {
+                       struct region *region_new = znew(*region_new);
+                       /* Create a copy */
+                       region_new->name = xstrdup(region->name);
+                       region_new->percentage = region->percentage;
+                       wl_list_append(&output->regions, &region_new->link);
+               }
+       }
+
+       /* Update regions */
+       struct wlr_box *perc, *geo;
+       wl_list_for_each(region, &output->regions, link) {
+               geo = &region->geo;
+               perc = &region->percentage;
+               geo->x = usable.x + usable.width * perc->x / 100;
+               geo->y = usable.y + usable.height * perc->y / 100;
+               geo->width = usable.width * perc->width / 100;
+               geo->height = usable.height * perc->height / 100;
+               region->center.x = geo->x + geo->width / 2;
+               region->center.y = geo->y + geo->height / 2;
+       }
 }
 
 void