diff --git a/src/Makefile.am b/src/Makefile.am index 9d8e996da..cb8a42a2d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -294,6 +294,8 @@ libmutter_la_SOURCES += \ wayland/meta-wayland-popup.h \ wayland/meta-wayland-seat.c \ wayland/meta-wayland-seat.h \ + wayland/meta-wayland-tablet.c \ + wayland/meta-wayland-tablet.h \ wayland/meta-wayland-touch.c \ wayland/meta-wayland-touch.h \ wayland/meta-wayland-surface.c \ diff --git a/src/wayland/meta-wayland-tablet.c b/src/wayland/meta-wayland-tablet.c new file mode 100644 index 000000000..20d840c9d --- /dev/null +++ b/src/wayland/meta-wayland-tablet.c @@ -0,0 +1,130 @@ +/* + * Wayland Support + * + * Copyright (C) 2015 Red Hat + * + * 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 + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Author: Carlos Garnacho + */ + +#define _GNU_SOURCE + +#include "config.h" + +#include + +#include +#include "tablet-unstable-v1-server-protocol.h" + +#include "meta-surface-actor-wayland.h" +#include "meta-wayland-private.h" +#include "meta-wayland-tablet.h" + +static void +unbind_resource (struct wl_resource *resource) +{ + wl_list_remove (wl_resource_get_link (resource)); +} + +MetaWaylandTablet * +meta_wayland_tablet_new (ClutterInputDevice *device, + MetaWaylandTabletSeat *tablet_seat) +{ + MetaWaylandTablet *tablet; + + tablet = g_slice_new0 (MetaWaylandTablet); + wl_list_init (&tablet->resource_list); + wl_list_init (&tablet->focus_resource_list); + tablet->device = device; + tablet->tablet_seat = tablet_seat; + + return tablet; +} + +void +meta_wayland_tablet_free (MetaWaylandTablet *tablet) +{ + struct wl_resource *resource, *next; + + wl_resource_for_each_safe (resource, next, &tablet->resource_list) + { + zwp_tablet_v1_send_removed (resource); + } + + g_slice_free (MetaWaylandTablet, tablet); +} + +static void +tablet_destroy (struct wl_client *client, + struct wl_resource *resource) +{ + wl_resource_destroy (resource); +} + +static const struct zwp_tablet_v1_interface tablet_interface = { + tablet_destroy +}; + +void +meta_wayland_tablet_notify (MetaWaylandTablet *tablet, + struct wl_resource *resource) +{ + ClutterInputDevice *device = tablet->device; + guint vid, pid; + + zwp_tablet_v1_send_name (resource, clutter_input_device_get_device_name (device)); + + if (sscanf (clutter_input_device_get_vendor_id (device), "%x", &vid) == 1 && + sscanf (clutter_input_device_get_product_id (device), "%x", &pid) == 1) + zwp_tablet_v1_send_id (resource, vid, pid); + + /* FIXME: zwp_tablet_v1.path missing */ + + zwp_tablet_v1_send_done (resource); +} + +struct wl_resource * +meta_wayland_tablet_create_new_resource (MetaWaylandTablet *tablet, + struct wl_client *client, + struct wl_resource *seat_resource, + uint32_t id) +{ + struct wl_resource *resource; + + resource = wl_resource_create (client, &zwp_tablet_v1_interface, + wl_resource_get_version (seat_resource), id); + wl_resource_set_implementation (resource, &tablet_interface, + tablet, unbind_resource); + wl_resource_set_user_data (resource, tablet); + wl_list_insert (&tablet->resource_list, wl_resource_get_link (resource)); + + return resource; +} + +struct wl_resource * +meta_wayland_tablet_lookup_resource (MetaWaylandTablet *tablet, + struct wl_client *client) +{ + struct wl_resource *resource; + + resource = wl_resource_find_for_client (&tablet->resource_list, client); + + if (!resource) + resource = wl_resource_find_for_client (&tablet->focus_resource_list, client); + + return resource; +} diff --git a/src/wayland/meta-wayland-tablet.h b/src/wayland/meta-wayland-tablet.h new file mode 100644 index 000000000..18295f49d --- /dev/null +++ b/src/wayland/meta-wayland-tablet.h @@ -0,0 +1,59 @@ +/* + * Wayland Support + * + * Copyright (C) 2015 Red Hat + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + * + * Author: Carlos Garnacho + */ + +#ifndef META_WAYLAND_TABLET_H +#define META_WAYLAND_TABLET_H + +#include + +#include + +#include "meta-wayland-types.h" +#include "meta-cursor-renderer.h" + +struct _MetaWaylandTablet +{ + MetaWaylandTabletSeat *tablet_seat; + ClutterInputDevice *device; + + struct wl_list resource_list; + struct wl_list focus_resource_list; + + MetaWaylandSurface *current; +}; + +MetaWaylandTablet * meta_wayland_tablet_new (ClutterInputDevice *device, + MetaWaylandTabletSeat *tablet_seat); +void meta_wayland_tablet_free (MetaWaylandTablet *tablet); + +struct wl_resource * + meta_wayland_tablet_create_new_resource (MetaWaylandTablet *tablet, + struct wl_client *client, + struct wl_resource *seat_resource, + uint32_t id); +struct wl_resource * + meta_wayland_tablet_lookup_resource (MetaWaylandTablet *tablet, + struct wl_client *client); + +void meta_wayland_tablet_notify (MetaWaylandTablet *tablet, + struct wl_resource *resource); + +#endif /* META_WAYLAND_TABLET_H */ diff --git a/src/wayland/meta-wayland-types.h b/src/wayland/meta-wayland-types.h index b07001c1e..27cfb99dd 100644 --- a/src/wayland/meta-wayland-types.h +++ b/src/wayland/meta-wayland-types.h @@ -37,6 +37,9 @@ typedef struct _MetaWaylandDragDestFuncs MetaWaylandDragDestFuncs; typedef struct _MetaWaylandDataOffer MetaWaylandDataOffer; typedef struct _MetaWaylandDataDevice MetaWaylandDataDevice; +typedef struct _MetaWaylandTabletSeat MetaWaylandTabletSeat; +typedef struct _MetaWaylandTablet MetaWaylandTablet; + typedef struct _MetaWaylandBuffer MetaWaylandBuffer; typedef struct _MetaWaylandRegion MetaWaylandRegion;