2014-10-08 03:12:36 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Endless Mobile
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2023-08-07 09:50:23 +00:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2014-10-08 03:12:36 +00:00
|
|
|
*
|
|
|
|
* Written by:
|
|
|
|
* Jasper St. Pierre <jstpierre@mecheye.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2023-07-19 14:59:04 +00:00
|
|
|
#include "mtk/mtk.h"
|
2018-07-10 08:36:24 +00:00
|
|
|
#include "wayland/meta-wayland-region.h"
|
2014-10-08 03:12:36 +00:00
|
|
|
|
2014-10-08 03:23:55 +00:00
|
|
|
struct _MetaWaylandRegion
|
|
|
|
{
|
|
|
|
struct wl_resource *resource;
|
2023-09-04 14:30:38 +00:00
|
|
|
MtkRegion *region;
|
2014-10-08 03:23:55 +00:00
|
|
|
};
|
|
|
|
|
2014-10-08 03:12:36 +00:00
|
|
|
static void
|
|
|
|
wl_region_destroy (struct wl_client *client,
|
|
|
|
struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
wl_resource_destroy (resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2023-09-04 14:30:38 +00:00
|
|
|
wl_region_add (struct wl_client *client,
|
2014-10-08 03:12:36 +00:00
|
|
|
struct wl_resource *resource,
|
2023-09-04 14:30:38 +00:00
|
|
|
gint32 x,
|
|
|
|
gint32 y,
|
|
|
|
gint32 width,
|
|
|
|
gint32 height)
|
2014-10-08 03:12:36 +00:00
|
|
|
{
|
|
|
|
MetaWaylandRegion *region = wl_resource_get_user_data (resource);
|
2023-07-19 14:59:04 +00:00
|
|
|
MtkRectangle rectangle = { x, y, width, height };
|
2014-10-08 03:12:36 +00:00
|
|
|
|
2023-09-04 14:30:38 +00:00
|
|
|
mtk_region_union_rectangle (region->region, &rectangle);
|
2014-10-08 03:12:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2023-09-04 14:30:38 +00:00
|
|
|
wl_region_subtract (struct wl_client *client,
|
2014-10-08 03:12:36 +00:00
|
|
|
struct wl_resource *resource,
|
2023-09-04 14:30:38 +00:00
|
|
|
gint32 x,
|
|
|
|
gint32 y,
|
|
|
|
gint32 width,
|
|
|
|
gint32 height)
|
2014-10-08 03:12:36 +00:00
|
|
|
{
|
|
|
|
MetaWaylandRegion *region = wl_resource_get_user_data (resource);
|
2023-07-19 14:59:04 +00:00
|
|
|
MtkRectangle rectangle = { x, y, width, height };
|
2014-10-08 03:12:36 +00:00
|
|
|
|
2023-09-04 14:30:38 +00:00
|
|
|
mtk_region_subtract_rectangle (region->region, &rectangle);
|
2014-10-08 03:12:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_region_interface meta_wayland_wl_region_interface = {
|
|
|
|
wl_region_destroy,
|
|
|
|
wl_region_add,
|
|
|
|
wl_region_subtract
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
wl_region_destructor (struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
MetaWaylandRegion *region = wl_resource_get_user_data (resource);
|
|
|
|
|
2023-09-04 14:30:38 +00:00
|
|
|
g_clear_pointer (®ion->region, mtk_region_unref);
|
2020-10-19 17:57:57 +00:00
|
|
|
g_free (region);
|
2014-10-08 03:12:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MetaWaylandRegion *
|
|
|
|
meta_wayland_region_create (MetaWaylandCompositor *compositor,
|
|
|
|
struct wl_client *client,
|
|
|
|
struct wl_resource *compositor_resource,
|
|
|
|
guint32 id)
|
|
|
|
{
|
2020-10-19 17:57:57 +00:00
|
|
|
MetaWaylandRegion *region = g_new0 (MetaWaylandRegion, 1);
|
2014-10-08 03:12:36 +00:00
|
|
|
|
|
|
|
region->resource = wl_resource_create (client, &wl_region_interface, wl_resource_get_version (compositor_resource), id);
|
|
|
|
wl_resource_set_implementation (region->resource, &meta_wayland_wl_region_interface, region, wl_region_destructor);
|
|
|
|
|
2023-09-04 14:30:38 +00:00
|
|
|
region->region = mtk_region_create ();
|
2014-10-08 03:12:36 +00:00
|
|
|
|
|
|
|
return region;
|
|
|
|
}
|
2014-10-08 03:23:55 +00:00
|
|
|
|
2023-09-04 14:30:38 +00:00
|
|
|
MtkRegion *
|
2023-09-20 12:33:13 +00:00
|
|
|
meta_wayland_region_peek_region (MetaWaylandRegion *region)
|
2014-10-08 03:23:55 +00:00
|
|
|
{
|
|
|
|
return region->region;
|
|
|
|
}
|