2022-07-06 17:37:22 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
|
|
|
|
|
|
#define _POSIX_C_SOURCE 200809L
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <float.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <wlr/types/wlr_scene.h>
|
|
|
|
|
#include <wlr/util/box.h>
|
|
|
|
|
#include <wlr/util/log.h>
|
|
|
|
|
#include "common/graphic-helpers.h"
|
2022-07-06 16:57:25 +02:00
|
|
|
#include "common/list.h"
|
2022-07-06 17:37:22 +02:00
|
|
|
#include "common/mem.h"
|
|
|
|
|
#include "labwc.h"
|
|
|
|
|
#include "regions.h"
|
|
|
|
|
|
2022-07-06 17:21:02 +02:00
|
|
|
bool
|
|
|
|
|
regions_available(void)
|
|
|
|
|
{
|
|
|
|
|
return !wl_list_empty(&rc.regions);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 17:37:22 +02:00
|
|
|
void
|
|
|
|
|
regions_init(struct server *server, struct seat *seat)
|
|
|
|
|
{
|
|
|
|
|
/* To be filled later */
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 08:06:48 +02:00
|
|
|
struct region *
|
|
|
|
|
regions_from_name(const char *region_name, struct output *output)
|
|
|
|
|
{
|
|
|
|
|
assert(region_name);
|
|
|
|
|
assert(output);
|
|
|
|
|
struct region *region;
|
|
|
|
|
wl_list_for_each(region, &output->regions, link) {
|
|
|
|
|
if (!strcmp(region->name, region_name)) {
|
|
|
|
|
return region;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 17:37:22 +02:00
|
|
|
void
|
|
|
|
|
regions_update(struct output *output)
|
|
|
|
|
{
|
2022-07-06 16:57:25 +02:00
|
|
|
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, ®ion_new->link);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Update regions */
|
|
|
|
|
struct wlr_box *perc, *geo;
|
|
|
|
|
wl_list_for_each(region, &output->regions, link) {
|
|
|
|
|
geo = ®ion->geo;
|
|
|
|
|
perc = ®ion->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;
|
|
|
|
|
}
|
2022-07-06 17:37:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
regions_destroy(struct wl_list *regions)
|
|
|
|
|
{
|
|
|
|
|
assert(regions);
|
|
|
|
|
struct region *region, *region_tmp;
|
|
|
|
|
wl_list_for_each_safe(region, region_tmp, regions, link) {
|
|
|
|
|
wl_list_remove(®ion->link);
|
|
|
|
|
zfree(region->name);
|
|
|
|
|
zfree(region);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|