2015-02-04 12:19:08 -05:00
|
|
|
/*
|
|
|
|
* 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 <carlosg@gnome.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "wayland/meta-wayland-tablet-tool.h"
|
2015-02-04 12:19:08 -05:00
|
|
|
|
2018-07-10 04:36:24 -04:00
|
|
|
#include <glib.h>
|
2015-02-04 12:19:08 -05:00
|
|
|
#include <wayland-server.h>
|
2018-07-10 04:36:24 -04:00
|
|
|
|
|
|
|
#include "wayland/meta-wayland-private.h"
|
|
|
|
#include "wayland/meta-wayland-tablet-cursor-surface.h"
|
|
|
|
#include "compositor/meta-surface-actor-wayland.h"
|
|
|
|
#include "wayland/meta-wayland-tablet.h"
|
|
|
|
#include "wayland/meta-wayland-tablet-seat.h"
|
2016-06-22 09:56:08 -04:00
|
|
|
#include "backends/meta-input-settings-private.h"
|
2017-02-10 18:53:42 -05:00
|
|
|
#include "backends/meta-logical-monitor.h"
|
2015-02-04 12:19:08 -05:00
|
|
|
|
2015-10-28 06:50:52 -04:00
|
|
|
#ifdef HAVE_NATIVE_BACKEND
|
2016-06-22 09:56:08 -04:00
|
|
|
#include <linux/input-event-codes.h>
|
2018-07-10 04:36:24 -04:00
|
|
|
|
|
|
|
#include "backends/native/meta-backend-native.h"
|
2019-03-29 17:03:27 -04:00
|
|
|
#include "backends/native/meta-event-native.h"
|
2015-10-28 06:50:52 -04:00
|
|
|
#endif
|
|
|
|
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "tablet-unstable-v2-server-protocol.h"
|
|
|
|
|
2015-10-28 06:50:52 -04:00
|
|
|
#define TABLET_AXIS_MAX 65535
|
|
|
|
|
2015-02-04 12:19:08 -05:00
|
|
|
static void
|
|
|
|
unbind_resource (struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
wl_list_remove (wl_resource_get_link (resource));
|
|
|
|
}
|
|
|
|
|
2015-10-28 06:08:09 -04:00
|
|
|
static void
|
|
|
|
move_resources (struct wl_list *destination,
|
|
|
|
struct wl_list *source)
|
|
|
|
{
|
|
|
|
wl_list_insert_list (destination, source);
|
|
|
|
wl_list_init (source);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
move_resources_for_client (struct wl_list *destination,
|
|
|
|
struct wl_list *source,
|
|
|
|
struct wl_client *client)
|
|
|
|
{
|
|
|
|
struct wl_resource *resource, *tmp;
|
|
|
|
|
|
|
|
wl_resource_for_each_safe (resource, tmp, source)
|
|
|
|
{
|
|
|
|
if (wl_resource_get_client (resource) == client)
|
|
|
|
{
|
|
|
|
wl_list_remove (wl_resource_get_link (resource));
|
|
|
|
wl_list_insert (destination, wl_resource_get_link (resource));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-28 07:55:58 -04:00
|
|
|
static void
|
|
|
|
meta_wayland_tablet_tool_update_cursor_surface (MetaWaylandTabletTool *tool)
|
|
|
|
{
|
|
|
|
MetaCursorSprite *cursor = NULL;
|
|
|
|
|
|
|
|
if (tool->cursor_renderer == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (tool->current && tool->current_tablet)
|
|
|
|
{
|
|
|
|
if (tool->cursor_surface &&
|
|
|
|
meta_wayland_surface_get_buffer (tool->cursor_surface))
|
|
|
|
{
|
2018-04-19 15:51:31 -04:00
|
|
|
MetaWaylandCursorSurface *cursor_surface =
|
|
|
|
META_WAYLAND_CURSOR_SURFACE (tool->cursor_surface->role);
|
2015-10-28 07:55:58 -04:00
|
|
|
|
2018-04-19 15:51:31 -04:00
|
|
|
cursor = meta_wayland_cursor_surface_get_sprite (cursor_surface);
|
2015-10-28 07:55:58 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
cursor = NULL;
|
|
|
|
}
|
|
|
|
else if (tool->current_tablet)
|
2018-04-27 09:43:37 -04:00
|
|
|
cursor = META_CURSOR_SPRITE (tool->default_sprite);
|
2015-10-28 07:55:58 -04:00
|
|
|
else
|
|
|
|
cursor = NULL;
|
|
|
|
|
|
|
|
meta_cursor_renderer_set_cursor (tool->cursor_renderer, cursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_tablet_tool_set_cursor_surface (MetaWaylandTabletTool *tool,
|
|
|
|
MetaWaylandSurface *surface)
|
|
|
|
{
|
|
|
|
if (tool->cursor_surface == surface)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (tool->cursor_surface)
|
2019-04-18 13:21:37 -04:00
|
|
|
{
|
|
|
|
MetaWaylandCursorSurface *cursor_surface;
|
|
|
|
|
|
|
|
cursor_surface = META_WAYLAND_CURSOR_SURFACE (tool->cursor_surface->role);
|
|
|
|
meta_wayland_cursor_surface_set_renderer (cursor_surface, NULL);
|
|
|
|
|
|
|
|
meta_wayland_surface_update_outputs (tool->cursor_surface);
|
|
|
|
wl_list_remove (&tool->cursor_surface_destroy_listener.link);
|
|
|
|
}
|
2015-10-28 07:55:58 -04:00
|
|
|
|
|
|
|
tool->cursor_surface = surface;
|
|
|
|
|
|
|
|
if (tool->cursor_surface)
|
2019-04-18 13:21:37 -04:00
|
|
|
{
|
|
|
|
meta_wayland_surface_update_outputs (tool->cursor_surface);
|
|
|
|
wl_resource_add_destroy_listener (tool->cursor_surface->resource,
|
|
|
|
&tool->cursor_surface_destroy_listener);
|
|
|
|
}
|
2015-10-28 07:55:58 -04:00
|
|
|
|
|
|
|
meta_wayland_tablet_tool_update_cursor_surface (tool);
|
|
|
|
}
|
|
|
|
|
2015-10-28 06:50:52 -04:00
|
|
|
static uint32_t
|
|
|
|
input_device_get_capabilities (ClutterInputDevice *device)
|
|
|
|
{
|
|
|
|
ClutterInputAxis axis;
|
|
|
|
guint32 capabilities = 0, i;
|
|
|
|
|
|
|
|
for (i = 0; i < clutter_input_device_get_n_axes (device); i++)
|
|
|
|
{
|
|
|
|
axis = clutter_input_device_get_axis (device, i);
|
|
|
|
|
|
|
|
switch (axis)
|
|
|
|
{
|
|
|
|
case CLUTTER_INPUT_AXIS_PRESSURE:
|
2016-05-12 08:32:01 -04:00
|
|
|
capabilities |= 1 << ZWP_TABLET_TOOL_V2_CAPABILITY_PRESSURE;
|
2015-10-28 06:50:52 -04:00
|
|
|
break;
|
|
|
|
case CLUTTER_INPUT_AXIS_DISTANCE:
|
2016-05-12 08:32:01 -04:00
|
|
|
capabilities |= 1 << ZWP_TABLET_TOOL_V2_CAPABILITY_DISTANCE;
|
2015-10-28 06:50:52 -04:00
|
|
|
break;
|
|
|
|
case CLUTTER_INPUT_AXIS_XTILT:
|
|
|
|
case CLUTTER_INPUT_AXIS_YTILT:
|
2016-05-12 08:32:01 -04:00
|
|
|
capabilities |= 1 << ZWP_TABLET_TOOL_V2_CAPABILITY_TILT;
|
2015-10-28 06:50:52 -04:00
|
|
|
break;
|
|
|
|
case CLUTTER_INPUT_AXIS_ROTATION:
|
2016-05-12 08:32:01 -04:00
|
|
|
capabilities |= 1 << ZWP_TABLET_TOOL_V2_CAPABILITY_ROTATION;
|
2015-10-28 06:50:52 -04:00
|
|
|
break;
|
|
|
|
case CLUTTER_INPUT_AXIS_WHEEL:
|
2016-05-12 08:32:01 -04:00
|
|
|
capabilities |= 1 << ZWP_TABLET_TOOL_V2_CAPABILITY_WHEEL;
|
2015-10-28 06:50:52 -04:00
|
|
|
break;
|
|
|
|
case CLUTTER_INPUT_AXIS_SLIDER:
|
2016-05-12 08:32:01 -04:00
|
|
|
capabilities |= 1 << ZWP_TABLET_TOOL_V2_CAPABILITY_SLIDER;
|
2015-10-28 06:50:52 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return capabilities;
|
|
|
|
}
|
|
|
|
|
2016-05-12 08:32:01 -04:00
|
|
|
static enum zwp_tablet_tool_v2_type
|
2015-10-28 12:02:16 -04:00
|
|
|
input_device_tool_get_type (ClutterInputDeviceTool *device_tool)
|
|
|
|
{
|
|
|
|
ClutterInputDeviceToolType tool_type;
|
|
|
|
|
|
|
|
tool_type = clutter_input_device_tool_get_tool_type (device_tool);
|
|
|
|
|
|
|
|
switch (tool_type)
|
|
|
|
{
|
|
|
|
case CLUTTER_INPUT_DEVICE_TOOL_NONE:
|
|
|
|
case CLUTTER_INPUT_DEVICE_TOOL_PEN:
|
2016-05-12 08:32:01 -04:00
|
|
|
return ZWP_TABLET_TOOL_V2_TYPE_PEN;
|
2015-10-28 12:02:16 -04:00
|
|
|
case CLUTTER_INPUT_DEVICE_TOOL_ERASER:
|
2016-05-12 08:32:01 -04:00
|
|
|
return ZWP_TABLET_TOOL_V2_TYPE_ERASER;
|
2015-10-28 12:02:16 -04:00
|
|
|
case CLUTTER_INPUT_DEVICE_TOOL_BRUSH:
|
2016-05-12 08:32:01 -04:00
|
|
|
return ZWP_TABLET_TOOL_V2_TYPE_BRUSH;
|
2015-10-28 12:02:16 -04:00
|
|
|
case CLUTTER_INPUT_DEVICE_TOOL_PENCIL:
|
2016-05-12 08:32:01 -04:00
|
|
|
return ZWP_TABLET_TOOL_V2_TYPE_PENCIL;
|
2015-10-28 12:02:16 -04:00
|
|
|
case CLUTTER_INPUT_DEVICE_TOOL_AIRBRUSH:
|
2016-05-12 08:32:01 -04:00
|
|
|
return ZWP_TABLET_TOOL_V2_TYPE_AIRBRUSH;
|
2015-10-28 12:02:16 -04:00
|
|
|
case CLUTTER_INPUT_DEVICE_TOOL_MOUSE:
|
2016-05-12 08:32:01 -04:00
|
|
|
return ZWP_TABLET_TOOL_V2_TYPE_MOUSE;
|
2015-10-28 12:02:16 -04:00
|
|
|
case CLUTTER_INPUT_DEVICE_TOOL_LENS:
|
2016-05-12 08:32:01 -04:00
|
|
|
return ZWP_TABLET_TOOL_V2_TYPE_LENS;
|
2015-10-28 12:02:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_tablet_tool_notify_capabilities (MetaWaylandTabletTool *tool,
|
|
|
|
struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
uint32_t capabilities;
|
|
|
|
|
|
|
|
capabilities = input_device_get_capabilities (tool->device);
|
|
|
|
|
2016-05-12 08:32:01 -04:00
|
|
|
if (capabilities & (1 << ZWP_TABLET_TOOL_V2_CAPABILITY_PRESSURE))
|
|
|
|
zwp_tablet_tool_v2_send_capability (resource,
|
|
|
|
ZWP_TABLET_TOOL_V2_CAPABILITY_PRESSURE);
|
|
|
|
if (capabilities & (1 << ZWP_TABLET_TOOL_V2_CAPABILITY_DISTANCE))
|
|
|
|
zwp_tablet_tool_v2_send_capability (resource,
|
|
|
|
ZWP_TABLET_TOOL_V2_CAPABILITY_DISTANCE);
|
|
|
|
if (capabilities & (1 << ZWP_TABLET_TOOL_V2_CAPABILITY_TILT))
|
|
|
|
zwp_tablet_tool_v2_send_capability (resource,
|
|
|
|
ZWP_TABLET_TOOL_V2_CAPABILITY_TILT);
|
|
|
|
if (capabilities & (1 << ZWP_TABLET_TOOL_V2_CAPABILITY_ROTATION))
|
|
|
|
zwp_tablet_tool_v2_send_capability (resource,
|
|
|
|
ZWP_TABLET_TOOL_V2_CAPABILITY_ROTATION);
|
|
|
|
if (capabilities & (1 << ZWP_TABLET_TOOL_V2_CAPABILITY_SLIDER))
|
|
|
|
zwp_tablet_tool_v2_send_capability (resource,
|
|
|
|
ZWP_TABLET_TOOL_V2_CAPABILITY_SLIDER);
|
|
|
|
if (capabilities & (1 << ZWP_TABLET_TOOL_V2_CAPABILITY_WHEEL))
|
|
|
|
zwp_tablet_tool_v2_send_capability (resource,
|
|
|
|
ZWP_TABLET_TOOL_V2_CAPABILITY_WHEEL);
|
2015-10-28 12:02:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_tablet_tool_notify_details (MetaWaylandTabletTool *tool,
|
|
|
|
struct wl_resource *resource)
|
|
|
|
{
|
2016-05-12 12:02:04 -04:00
|
|
|
guint64 serial, id;
|
2015-10-28 12:02:16 -04:00
|
|
|
|
2016-05-12 08:32:01 -04:00
|
|
|
zwp_tablet_tool_v2_send_type (resource,
|
2015-10-28 12:02:16 -04:00
|
|
|
input_device_tool_get_type (tool->device_tool));
|
|
|
|
|
2016-05-12 12:02:04 -04:00
|
|
|
serial = clutter_input_device_tool_get_serial (tool->device_tool);
|
2016-05-12 08:32:01 -04:00
|
|
|
zwp_tablet_tool_v2_send_hardware_serial (resource, (uint32_t) (serial >> 32),
|
2015-10-28 12:02:16 -04:00
|
|
|
(uint32_t) (serial & G_MAXUINT32));
|
|
|
|
|
2016-05-12 12:02:04 -04:00
|
|
|
id = clutter_input_device_tool_get_id (tool->device_tool);
|
|
|
|
zwp_tablet_tool_v2_send_hardware_id_wacom (resource, (uint32_t) (id >> 32),
|
|
|
|
(uint32_t) (id & G_MAXUINT32));
|
2015-10-28 12:02:16 -04:00
|
|
|
|
2016-05-12 12:02:04 -04:00
|
|
|
meta_wayland_tablet_tool_notify_capabilities (tool, resource);
|
2015-10-28 12:02:16 -04:00
|
|
|
|
2016-05-12 08:32:01 -04:00
|
|
|
zwp_tablet_tool_v2_send_done (resource);
|
2015-10-28 12:02:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_tablet_tool_ensure_resource (MetaWaylandTabletTool *tool,
|
|
|
|
struct wl_client *client)
|
|
|
|
{
|
|
|
|
struct wl_resource *seat_resource, *tool_resource;
|
|
|
|
|
|
|
|
seat_resource = meta_wayland_tablet_seat_lookup_resource (tool->seat, client);
|
|
|
|
|
|
|
|
if (seat_resource &&
|
|
|
|
!meta_wayland_tablet_tool_lookup_resource (tool, client))
|
|
|
|
{
|
|
|
|
tool_resource = meta_wayland_tablet_tool_create_new_resource (tool, client,
|
|
|
|
seat_resource,
|
|
|
|
0);
|
|
|
|
|
|
|
|
meta_wayland_tablet_seat_notify_tool (tool->seat, tool, client);
|
|
|
|
meta_wayland_tablet_tool_notify_details (tool, tool_resource);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-28 06:08:09 -04:00
|
|
|
static void
|
|
|
|
broadcast_proximity_in (MetaWaylandTabletTool *tool)
|
|
|
|
{
|
|
|
|
struct wl_resource *resource, *tablet_resource;
|
|
|
|
struct wl_client *client;
|
|
|
|
|
|
|
|
client = wl_resource_get_client (tool->focus_surface->resource);
|
|
|
|
tablet_resource = meta_wayland_tablet_lookup_resource (tool->current_tablet,
|
|
|
|
client);
|
|
|
|
|
|
|
|
wl_resource_for_each (resource, &tool->focus_resource_list)
|
|
|
|
{
|
2016-05-12 08:32:01 -04:00
|
|
|
zwp_tablet_tool_v2_send_proximity_in (resource, tool->proximity_serial,
|
2015-10-28 06:08:09 -04:00
|
|
|
tablet_resource,
|
|
|
|
tool->focus_surface->resource);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
broadcast_proximity_out (MetaWaylandTabletTool *tool)
|
|
|
|
{
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
|
|
wl_resource_for_each (resource, &tool->focus_resource_list)
|
|
|
|
{
|
2016-05-12 08:32:01 -04:00
|
|
|
zwp_tablet_tool_v2_send_proximity_out (resource);
|
2015-10-28 06:08:09 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
broadcast_frame (MetaWaylandTabletTool *tool,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
struct wl_resource *resource;
|
|
|
|
guint32 _time = event ? clutter_event_get_time (event) : CLUTTER_CURRENT_TIME;
|
|
|
|
|
|
|
|
wl_resource_for_each (resource, &tool->focus_resource_list)
|
|
|
|
{
|
2016-05-12 08:32:01 -04:00
|
|
|
zwp_tablet_tool_v2_send_frame (resource, _time);
|
2015-10-28 06:08:09 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_tablet_tool_set_focus (MetaWaylandTabletTool *tool,
|
|
|
|
MetaWaylandSurface *surface,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
if (tool->focus_surface == surface)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (tool->focus_surface != NULL)
|
|
|
|
{
|
|
|
|
struct wl_list *l;
|
|
|
|
|
|
|
|
l = &tool->focus_resource_list;
|
|
|
|
if (!wl_list_empty (l))
|
|
|
|
{
|
|
|
|
broadcast_proximity_out (tool);
|
|
|
|
broadcast_frame (tool, event);
|
|
|
|
move_resources (&tool->resource_list, &tool->focus_resource_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_list_remove (&tool->focus_surface_destroy_listener.link);
|
|
|
|
tool->focus_surface = NULL;
|
|
|
|
}
|
|
|
|
|
2015-10-28 12:02:16 -04:00
|
|
|
if (surface != NULL && tool->current_tablet)
|
2015-10-28 06:08:09 -04:00
|
|
|
{
|
|
|
|
struct wl_client *client;
|
|
|
|
struct wl_list *l;
|
|
|
|
|
|
|
|
tool->focus_surface = surface;
|
|
|
|
client = wl_resource_get_client (tool->focus_surface->resource);
|
|
|
|
wl_resource_add_destroy_listener (tool->focus_surface->resource,
|
|
|
|
&tool->focus_surface_destroy_listener);
|
|
|
|
|
|
|
|
move_resources_for_client (&tool->focus_resource_list,
|
|
|
|
&tool->resource_list, client);
|
2015-10-28 12:02:16 -04:00
|
|
|
meta_wayland_tablet_tool_ensure_resource (tool, client);
|
2015-10-28 06:08:09 -04:00
|
|
|
|
|
|
|
l = &tool->focus_resource_list;
|
|
|
|
|
|
|
|
if (!wl_list_empty (l))
|
|
|
|
{
|
|
|
|
struct wl_client *client = wl_resource_get_client (tool->focus_surface->resource);
|
|
|
|
struct wl_display *display = wl_client_get_display (client);
|
|
|
|
|
|
|
|
tool->proximity_serial = wl_display_next_serial (display);
|
|
|
|
|
|
|
|
broadcast_proximity_in (tool);
|
|
|
|
broadcast_frame (tool, event);
|
|
|
|
}
|
|
|
|
}
|
2015-10-28 07:55:58 -04:00
|
|
|
|
|
|
|
meta_wayland_tablet_tool_update_cursor_surface (tool);
|
2015-10-28 06:08:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
tablet_tool_handle_focus_surface_destroy (struct wl_listener *listener,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
MetaWaylandTabletTool *tool;
|
|
|
|
|
|
|
|
tool = wl_container_of (listener, tool, focus_surface_destroy_listener);
|
|
|
|
meta_wayland_tablet_tool_set_focus (tool, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2015-10-28 07:55:58 -04:00
|
|
|
static void
|
|
|
|
tablet_tool_handle_cursor_surface_destroy (struct wl_listener *listener,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
MetaWaylandTabletTool *tool;
|
|
|
|
|
|
|
|
tool = wl_container_of (listener, tool, cursor_surface_destroy_listener);
|
|
|
|
meta_wayland_tablet_tool_set_cursor_surface (tool, NULL);
|
|
|
|
}
|
|
|
|
|
2017-02-10 18:53:42 -05:00
|
|
|
static void
|
2018-04-27 09:43:37 -04:00
|
|
|
tool_cursor_prepare_at (MetaCursorSpriteXcursor *sprite_xcursor,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
MetaWaylandTabletTool *tool)
|
2017-02-10 18:53:42 -05:00
|
|
|
{
|
|
|
|
MetaBackend *backend = meta_get_backend ();
|
|
|
|
MetaMonitorManager *monitor_manager =
|
|
|
|
meta_backend_get_monitor_manager (backend);
|
|
|
|
MetaLogicalMonitor *logical_monitor;
|
|
|
|
|
|
|
|
logical_monitor =
|
|
|
|
meta_monitor_manager_get_logical_monitor_at (monitor_manager, x, y);
|
|
|
|
|
|
|
|
/* Reload the cursor texture if the scale has changed. */
|
|
|
|
if (logical_monitor)
|
2019-02-11 21:05:38 -05:00
|
|
|
{
|
|
|
|
MetaCursorSprite *cursor_sprite = META_CURSOR_SPRITE (sprite_xcursor);
|
|
|
|
float ceiled_scale;
|
|
|
|
|
|
|
|
ceiled_scale = ceilf (logical_monitor->scale);
|
|
|
|
meta_cursor_sprite_xcursor_set_theme_scale (sprite_xcursor,
|
|
|
|
(int) ceiled_scale);
|
|
|
|
|
|
|
|
if (meta_is_stage_views_scaled ())
|
|
|
|
meta_cursor_sprite_set_texture_scale (cursor_sprite,
|
|
|
|
1.0 / ceiled_scale);
|
|
|
|
else
|
|
|
|
meta_cursor_sprite_set_texture_scale (cursor_sprite, 1.0);
|
|
|
|
}
|
2017-02-10 18:53:42 -05:00
|
|
|
}
|
|
|
|
|
2015-02-04 12:19:08 -05:00
|
|
|
MetaWaylandTabletTool *
|
|
|
|
meta_wayland_tablet_tool_new (MetaWaylandTabletSeat *seat,
|
|
|
|
ClutterInputDevice *device,
|
|
|
|
ClutterInputDeviceTool *device_tool)
|
|
|
|
{
|
|
|
|
MetaWaylandTabletTool *tool;
|
|
|
|
|
|
|
|
tool = g_slice_new0 (MetaWaylandTabletTool);
|
|
|
|
tool->seat = seat;
|
|
|
|
tool->device = device;
|
|
|
|
tool->device_tool = device_tool;
|
|
|
|
wl_list_init (&tool->resource_list);
|
2015-10-28 06:08:09 -04:00
|
|
|
wl_list_init (&tool->focus_resource_list);
|
|
|
|
|
|
|
|
tool->focus_surface_destroy_listener.notify = tablet_tool_handle_focus_surface_destroy;
|
2015-10-28 07:55:58 -04:00
|
|
|
tool->cursor_surface_destroy_listener.notify = tablet_tool_handle_cursor_surface_destroy;
|
2015-02-04 12:19:08 -05:00
|
|
|
|
2018-04-27 09:43:37 -04:00
|
|
|
tool->default_sprite = meta_cursor_sprite_xcursor_new (META_CURSOR_CROSSHAIR);
|
2017-02-10 18:53:42 -05:00
|
|
|
tool->prepare_at_signal_id =
|
|
|
|
g_signal_connect (tool->default_sprite, "prepare-at",
|
|
|
|
G_CALLBACK (tool_cursor_prepare_at), tool);
|
2017-02-10 18:53:08 -05:00
|
|
|
|
2015-02-04 12:19:08 -05:00
|
|
|
return tool;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_wayland_tablet_tool_free (MetaWaylandTabletTool *tool)
|
|
|
|
{
|
|
|
|
struct wl_resource *resource, *next;
|
|
|
|
|
2015-10-28 06:08:09 -04:00
|
|
|
meta_wayland_tablet_tool_set_focus (tool, NULL, NULL);
|
2015-10-28 07:55:58 -04:00
|
|
|
meta_wayland_tablet_tool_set_cursor_surface (tool, NULL);
|
|
|
|
g_clear_object (&tool->cursor_renderer);
|
2015-10-28 06:08:09 -04:00
|
|
|
|
2015-02-04 12:19:08 -05:00
|
|
|
wl_resource_for_each_safe (resource, next, &tool->resource_list)
|
|
|
|
{
|
2016-05-12 08:32:01 -04:00
|
|
|
zwp_tablet_tool_v2_send_removed (resource);
|
2016-05-10 09:24:41 -04:00
|
|
|
wl_list_remove (wl_resource_get_link (resource));
|
|
|
|
wl_list_init (wl_resource_get_link (resource));
|
2015-02-04 12:19:08 -05:00
|
|
|
}
|
|
|
|
|
2017-02-10 18:53:42 -05:00
|
|
|
g_signal_handler_disconnect (tool->default_sprite, tool->prepare_at_signal_id);
|
2017-02-10 18:53:08 -05:00
|
|
|
g_object_unref (tool->default_sprite);
|
|
|
|
|
2015-02-04 12:19:08 -05:00
|
|
|
g_slice_free (MetaWaylandTabletTool, tool);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
tool_set_cursor (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t serial,
|
|
|
|
struct wl_resource *surface_resource,
|
|
|
|
int32_t hotspot_x,
|
|
|
|
int32_t hotspot_y)
|
|
|
|
{
|
2015-10-28 07:55:58 -04:00
|
|
|
MetaWaylandTabletTool *tool = wl_resource_get_user_data (resource);
|
|
|
|
MetaWaylandSurface *surface;
|
|
|
|
|
|
|
|
surface = (surface_resource ? wl_resource_get_user_data (surface_resource) : NULL);
|
|
|
|
|
|
|
|
if (tool->focus_surface == NULL)
|
|
|
|
return;
|
|
|
|
if (tool->cursor_renderer == NULL)
|
|
|
|
return;
|
|
|
|
if (wl_resource_get_client (tool->focus_surface->resource) != client)
|
|
|
|
return;
|
|
|
|
if (tool->proximity_serial - serial > G_MAXUINT32 / 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (surface &&
|
|
|
|
!meta_wayland_surface_assign_role (surface,
|
2018-04-19 15:51:31 -04:00
|
|
|
META_TYPE_WAYLAND_TABLET_CURSOR_SURFACE,
|
2016-01-28 04:14:06 -05:00
|
|
|
NULL))
|
2015-10-28 07:55:58 -04:00
|
|
|
{
|
|
|
|
wl_resource_post_error (resource, WL_POINTER_ERROR_ROLE,
|
|
|
|
"wl_surface@%d already has a different role",
|
|
|
|
wl_resource_get_id (surface_resource));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (surface)
|
|
|
|
{
|
2018-04-19 15:51:31 -04:00
|
|
|
MetaWaylandCursorSurface *cursor_surface;
|
2015-10-28 07:55:58 -04:00
|
|
|
|
2018-04-19 15:51:31 -04:00
|
|
|
cursor_surface = META_WAYLAND_CURSOR_SURFACE (surface->role);
|
|
|
|
meta_wayland_cursor_surface_set_renderer (cursor_surface,
|
|
|
|
tool->cursor_renderer);
|
|
|
|
meta_wayland_cursor_surface_set_hotspot (cursor_surface,
|
|
|
|
hotspot_x, hotspot_y);
|
2015-10-28 07:55:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
meta_wayland_tablet_tool_set_cursor_surface (tool, surface);
|
2015-02-04 12:19:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
tool_destroy (struct wl_client *client,
|
|
|
|
struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
wl_resource_destroy (resource);
|
|
|
|
}
|
|
|
|
|
2016-05-12 08:32:01 -04:00
|
|
|
static const struct zwp_tablet_tool_v2_interface tool_interface = {
|
2015-02-04 12:19:08 -05:00
|
|
|
tool_set_cursor,
|
|
|
|
tool_destroy
|
|
|
|
};
|
|
|
|
|
2015-10-28 06:08:09 -04:00
|
|
|
static void
|
|
|
|
emit_proximity_in (MetaWaylandTabletTool *tool,
|
|
|
|
struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
struct wl_resource *tablet_resource;
|
|
|
|
struct wl_client *client;
|
|
|
|
|
|
|
|
if (!tool->focus_surface)
|
|
|
|
return;
|
|
|
|
|
|
|
|
client = wl_resource_get_client (resource);
|
|
|
|
tablet_resource = meta_wayland_tablet_lookup_resource (tool->current_tablet,
|
|
|
|
client);
|
|
|
|
|
2016-05-12 08:32:01 -04:00
|
|
|
zwp_tablet_tool_v2_send_proximity_in (resource, tool->proximity_serial,
|
2015-10-28 06:08:09 -04:00
|
|
|
tablet_resource, tool->focus_surface->resource);
|
|
|
|
}
|
|
|
|
|
2015-02-04 12:19:08 -05:00
|
|
|
struct wl_resource *
|
|
|
|
meta_wayland_tablet_tool_create_new_resource (MetaWaylandTabletTool *tool,
|
|
|
|
struct wl_client *client,
|
|
|
|
struct wl_resource *seat_resource,
|
|
|
|
uint32_t id)
|
|
|
|
{
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
2016-05-12 08:32:01 -04:00
|
|
|
resource = wl_resource_create (client, &zwp_tablet_tool_v2_interface,
|
2015-02-04 12:19:08 -05:00
|
|
|
wl_resource_get_version (seat_resource), id);
|
|
|
|
wl_resource_set_implementation (resource, &tool_interface,
|
|
|
|
tool, unbind_resource);
|
|
|
|
wl_resource_set_user_data (resource, tool);
|
2015-10-28 06:08:09 -04:00
|
|
|
|
|
|
|
if (tool->focus_surface &&
|
|
|
|
wl_resource_get_client (tool->focus_surface->resource) == client)
|
|
|
|
{
|
|
|
|
wl_list_insert (&tool->focus_resource_list, wl_resource_get_link (resource));
|
|
|
|
emit_proximity_in (tool, resource);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wl_list_insert (&tool->resource_list, wl_resource_get_link (resource));
|
|
|
|
}
|
2015-02-04 12:19:08 -05:00
|
|
|
|
|
|
|
return resource;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wl_resource *
|
|
|
|
meta_wayland_tablet_tool_lookup_resource (MetaWaylandTabletTool *tool,
|
|
|
|
struct wl_client *client)
|
|
|
|
{
|
2015-10-28 06:08:09 -04:00
|
|
|
struct wl_resource *resource = NULL;
|
|
|
|
|
|
|
|
if (!wl_list_empty (&tool->resource_list))
|
|
|
|
resource = wl_resource_find_for_client (&tool->resource_list, client);
|
|
|
|
|
|
|
|
if (!wl_list_empty (&tool->focus_resource_list))
|
|
|
|
resource = wl_resource_find_for_client (&tool->focus_resource_list, client);
|
|
|
|
|
|
|
|
return resource;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_tablet_tool_account_button (MetaWaylandTabletTool *tool,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
if (event->type == CLUTTER_BUTTON_PRESS)
|
2017-06-23 11:02:21 -04:00
|
|
|
{
|
|
|
|
tool->pressed_buttons |= 1 << (event->button.button - 1);
|
|
|
|
tool->button_count++;
|
|
|
|
}
|
2015-10-28 06:08:09 -04:00
|
|
|
else if (event->type == CLUTTER_BUTTON_RELEASE)
|
2017-06-23 11:02:21 -04:00
|
|
|
{
|
|
|
|
tool->pressed_buttons &= ~(1 << (event->button.button - 1));
|
|
|
|
tool->button_count--;
|
|
|
|
}
|
2015-10-28 06:08:09 -04:00
|
|
|
}
|
2015-02-04 12:19:08 -05:00
|
|
|
|
2015-10-28 06:08:09 -04:00
|
|
|
static void
|
|
|
|
sync_focus_surface (MetaWaylandTabletTool *tool,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
MetaDisplay *display = meta_get_display ();
|
|
|
|
|
|
|
|
switch (display->event_route)
|
|
|
|
{
|
|
|
|
case META_EVENT_ROUTE_WINDOW_OP:
|
|
|
|
case META_EVENT_ROUTE_COMPOSITOR_GRAB:
|
|
|
|
case META_EVENT_ROUTE_FRAME_BUTTON:
|
|
|
|
/* The compositor has a grab, so remove our focus */
|
|
|
|
meta_wayland_tablet_tool_set_focus (tool, NULL, event);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case META_EVENT_ROUTE_NORMAL:
|
|
|
|
case META_EVENT_ROUTE_WAYLAND_POPUP:
|
|
|
|
meta_wayland_tablet_tool_set_focus (tool, tool->current, event);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
repick_for_event (MetaWaylandTabletTool *tool,
|
|
|
|
const ClutterEvent *for_event)
|
|
|
|
{
|
|
|
|
ClutterActor *actor = NULL;
|
|
|
|
|
|
|
|
actor = clutter_event_get_source (for_event);
|
|
|
|
|
|
|
|
if (META_IS_SURFACE_ACTOR_WAYLAND (actor))
|
|
|
|
tool->current = meta_surface_actor_wayland_get_surface (META_SURFACE_ACTOR_WAYLAND (actor));
|
|
|
|
else
|
|
|
|
tool->current = NULL;
|
|
|
|
|
|
|
|
sync_focus_surface (tool, for_event);
|
2015-10-28 07:55:58 -04:00
|
|
|
meta_wayland_tablet_tool_update_cursor_surface (tool);
|
2015-02-04 12:19:08 -05:00
|
|
|
}
|
|
|
|
|
2015-10-28 06:50:52 -04:00
|
|
|
static void
|
|
|
|
meta_wayland_tablet_tool_get_relative_coordinates (MetaWaylandTabletTool *tool,
|
2017-06-30 08:06:26 -04:00
|
|
|
const ClutterEvent *event,
|
2015-10-28 06:50:52 -04:00
|
|
|
MetaWaylandSurface *surface,
|
|
|
|
wl_fixed_t *sx,
|
|
|
|
wl_fixed_t *sy)
|
|
|
|
{
|
2017-06-30 08:06:26 -04:00
|
|
|
float xf, yf;
|
2015-10-28 06:50:52 -04:00
|
|
|
|
2017-06-30 08:06:26 -04:00
|
|
|
clutter_event_get_coords (event, &xf, &yf);
|
2019-07-09 11:36:16 -04:00
|
|
|
meta_wayland_surface_get_relative_coordinates (surface, xf, yf, &xf, &yf);
|
2015-10-28 06:50:52 -04:00
|
|
|
|
2019-10-06 08:52:09 -04:00
|
|
|
*sx = wl_fixed_from_double (xf);
|
|
|
|
*sy = wl_fixed_from_double (yf);
|
2015-10-28 06:50:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
broadcast_motion (MetaWaylandTabletTool *tool,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
struct wl_resource *resource;
|
|
|
|
wl_fixed_t sx, sy;
|
|
|
|
|
2017-06-30 08:06:26 -04:00
|
|
|
meta_wayland_tablet_tool_get_relative_coordinates (tool, event,
|
2015-10-28 06:50:52 -04:00
|
|
|
tool->focus_surface,
|
|
|
|
&sx, &sy);
|
|
|
|
|
|
|
|
wl_resource_for_each (resource, &tool->focus_resource_list)
|
|
|
|
{
|
2016-05-12 08:32:01 -04:00
|
|
|
zwp_tablet_tool_v2_send_motion (resource, sx, sy);
|
2015-10-28 06:50:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
broadcast_down (MetaWaylandTabletTool *tool,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
|
|
tool->down_serial = wl_display_next_serial (tool->seat->manager->wl_display);
|
|
|
|
|
|
|
|
wl_resource_for_each (resource, &tool->focus_resource_list)
|
|
|
|
{
|
2016-05-12 08:32:01 -04:00
|
|
|
zwp_tablet_tool_v2_send_down (resource, tool->down_serial);
|
2015-10-28 06:50:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
broadcast_up (MetaWaylandTabletTool *tool,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
|
|
wl_resource_for_each (resource, &tool->focus_resource_list)
|
|
|
|
{
|
2016-05-12 08:32:01 -04:00
|
|
|
zwp_tablet_tool_v2_send_up (resource);
|
2015-10-28 06:50:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-31 12:43:38 -04:00
|
|
|
static void
|
|
|
|
broadcast_button (MetaWaylandTabletTool *tool,
|
|
|
|
const ClutterEvent *event)
|
2016-06-22 09:56:08 -04:00
|
|
|
{
|
2016-10-31 12:43:38 -04:00
|
|
|
struct wl_resource *resource;
|
|
|
|
guint32 button;
|
2016-06-22 09:56:08 -04:00
|
|
|
|
2016-10-31 12:43:38 -04:00
|
|
|
#ifdef HAVE_NATIVE_BACKEND
|
|
|
|
MetaBackend *backend = meta_get_backend ();
|
|
|
|
if (META_IS_BACKEND_NATIVE (backend))
|
2016-06-22 09:56:08 -04:00
|
|
|
{
|
2019-03-29 17:03:27 -04:00
|
|
|
button = meta_event_native_get_event_code (event);
|
2016-06-22 09:56:08 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
2016-10-31 12:43:38 -04:00
|
|
|
{
|
|
|
|
/* We can't do much better here, there's several
|
|
|
|
* different BTN_ ranges to cover.
|
|
|
|
*/
|
|
|
|
button = event->button.button;
|
2016-06-22 09:56:08 -04:00
|
|
|
}
|
2015-10-28 06:50:52 -04:00
|
|
|
|
|
|
|
tool->button_serial = wl_display_next_serial (tool->seat->manager->wl_display);
|
|
|
|
|
|
|
|
wl_resource_for_each (resource, &tool->focus_resource_list)
|
|
|
|
{
|
2016-05-12 08:32:01 -04:00
|
|
|
zwp_tablet_tool_v2_send_button (resource, tool->button_serial, button,
|
2015-10-28 06:50:52 -04:00
|
|
|
event->type == CLUTTER_BUTTON_PRESS ?
|
2016-05-12 08:32:01 -04:00
|
|
|
ZWP_TABLET_TOOL_V2_BUTTON_STATE_PRESSED :
|
|
|
|
ZWP_TABLET_TOOL_V2_BUTTON_STATE_RELEASED);
|
2015-10-28 06:50:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
broadcast_axis (MetaWaylandTabletTool *tool,
|
|
|
|
const ClutterEvent *event,
|
|
|
|
ClutterInputAxis axis)
|
|
|
|
{
|
|
|
|
struct wl_resource *resource;
|
|
|
|
ClutterInputDevice *source;
|
|
|
|
uint32_t value;
|
|
|
|
gdouble val;
|
|
|
|
|
|
|
|
source = clutter_event_get_source_device (event);
|
|
|
|
|
|
|
|
if (!clutter_input_device_get_axis_value (source, event->motion.axes, axis, &val))
|
|
|
|
return;
|
|
|
|
|
|
|
|
value = val * TABLET_AXIS_MAX;
|
|
|
|
|
|
|
|
wl_resource_for_each (resource, &tool->focus_resource_list)
|
|
|
|
{
|
|
|
|
switch (axis)
|
|
|
|
{
|
|
|
|
case CLUTTER_INPUT_AXIS_PRESSURE:
|
2016-05-12 08:32:01 -04:00
|
|
|
zwp_tablet_tool_v2_send_pressure (resource, value);
|
2015-10-28 06:50:52 -04:00
|
|
|
break;
|
|
|
|
case CLUTTER_INPUT_AXIS_DISTANCE:
|
2016-05-12 08:32:01 -04:00
|
|
|
zwp_tablet_tool_v2_send_distance (resource, value);
|
2015-10-28 06:50:52 -04:00
|
|
|
break;
|
|
|
|
case CLUTTER_INPUT_AXIS_SLIDER:
|
2016-05-12 08:32:01 -04:00
|
|
|
zwp_tablet_tool_v2_send_slider (resource, value);
|
2015-10-28 06:50:52 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
broadcast_tilt (MetaWaylandTabletTool *tool,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
struct wl_resource *resource;
|
|
|
|
ClutterInputDevice *source;
|
|
|
|
gdouble xtilt, ytilt;
|
|
|
|
|
|
|
|
source = clutter_event_get_source_device (event);
|
|
|
|
|
|
|
|
if (!clutter_input_device_get_axis_value (source, event->motion.axes,
|
|
|
|
CLUTTER_INPUT_AXIS_XTILT, &xtilt) ||
|
|
|
|
!clutter_input_device_get_axis_value (source, event->motion.axes,
|
|
|
|
CLUTTER_INPUT_AXIS_YTILT, &ytilt))
|
|
|
|
return;
|
|
|
|
|
|
|
|
wl_resource_for_each (resource, &tool->focus_resource_list)
|
|
|
|
{
|
2016-05-12 08:32:01 -04:00
|
|
|
zwp_tablet_tool_v2_send_tilt (resource,
|
2016-05-12 09:24:03 -04:00
|
|
|
wl_fixed_from_double (xtilt),
|
|
|
|
wl_fixed_from_double (ytilt));
|
2015-10-28 06:50:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
broadcast_rotation (MetaWaylandTabletTool *tool,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
struct wl_resource *resource;
|
|
|
|
ClutterInputDevice *source;
|
|
|
|
gdouble rotation;
|
|
|
|
|
|
|
|
source = clutter_event_get_source_device (event);
|
|
|
|
|
|
|
|
if (!clutter_input_device_get_axis_value (source, event->motion.axes,
|
|
|
|
CLUTTER_INPUT_AXIS_ROTATION,
|
|
|
|
&rotation))
|
|
|
|
return;
|
|
|
|
|
|
|
|
wl_resource_for_each (resource, &tool->focus_resource_list)
|
|
|
|
{
|
2016-05-12 08:32:01 -04:00
|
|
|
zwp_tablet_tool_v2_send_rotation (resource,
|
2016-05-12 09:24:03 -04:00
|
|
|
wl_fixed_from_double (rotation));
|
2015-10-28 06:50:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-12 18:25:10 -04:00
|
|
|
static void
|
|
|
|
broadcast_wheel (MetaWaylandTabletTool *tool,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
struct wl_resource *resource;
|
|
|
|
ClutterInputDevice *source;
|
|
|
|
gdouble angle;
|
|
|
|
gint32 clicks = 0;
|
|
|
|
|
|
|
|
source = clutter_event_get_source_device (event);
|
|
|
|
|
|
|
|
if (!clutter_input_device_get_axis_value (source, event->motion.axes,
|
|
|
|
CLUTTER_INPUT_AXIS_WHEEL,
|
|
|
|
&angle))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* FIXME: Perform proper angle-to-clicks accumulation elsewhere */
|
|
|
|
if (angle > 0.01)
|
|
|
|
clicks = 1;
|
|
|
|
else if (angle < -0.01)
|
|
|
|
clicks = -1;
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
|
|
|
wl_resource_for_each (resource, &tool->focus_resource_list)
|
|
|
|
{
|
|
|
|
zwp_tablet_tool_v2_send_wheel (resource,
|
|
|
|
wl_fixed_from_double (angle),
|
|
|
|
clicks);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-28 06:50:52 -04:00
|
|
|
static void
|
|
|
|
broadcast_axes (MetaWaylandTabletTool *tool,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
ClutterInputDevice *device;
|
|
|
|
guint32 capabilities;
|
|
|
|
|
|
|
|
if (!event->motion.axes)
|
|
|
|
return;
|
|
|
|
|
|
|
|
device = clutter_event_get_source_device (event);
|
|
|
|
capabilities = input_device_get_capabilities (device);
|
|
|
|
|
2016-05-12 08:32:01 -04:00
|
|
|
if (capabilities & (1 << ZWP_TABLET_TOOL_V2_CAPABILITY_PRESSURE))
|
2015-10-28 06:50:52 -04:00
|
|
|
broadcast_axis (tool, event, CLUTTER_INPUT_AXIS_PRESSURE);
|
2016-05-12 08:32:01 -04:00
|
|
|
if (capabilities & (1 << ZWP_TABLET_TOOL_V2_CAPABILITY_DISTANCE))
|
2015-10-28 06:50:52 -04:00
|
|
|
broadcast_axis (tool, event, CLUTTER_INPUT_AXIS_DISTANCE);
|
2016-05-12 08:32:01 -04:00
|
|
|
if (capabilities & (1 << ZWP_TABLET_TOOL_V2_CAPABILITY_TILT))
|
2015-10-28 06:50:52 -04:00
|
|
|
broadcast_tilt (tool, event);
|
2016-05-12 08:32:01 -04:00
|
|
|
if (capabilities & (1 << ZWP_TABLET_TOOL_V2_CAPABILITY_ROTATION))
|
2015-10-28 06:50:52 -04:00
|
|
|
broadcast_rotation (tool, event);
|
2016-05-12 08:32:01 -04:00
|
|
|
if (capabilities & (1 << ZWP_TABLET_TOOL_V2_CAPABILITY_SLIDER))
|
2015-10-28 06:50:52 -04:00
|
|
|
broadcast_axis (tool, event, CLUTTER_INPUT_AXIS_SLIDER);
|
2017-06-12 18:25:10 -04:00
|
|
|
if (capabilities & (1 << ZWP_TABLET_TOOL_V2_CAPABILITY_WHEEL))
|
|
|
|
broadcast_wheel (tool, event);
|
2015-10-28 06:50:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_motion_event (MetaWaylandTabletTool *tool,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
if (!tool->focus_surface)
|
|
|
|
return;
|
|
|
|
|
|
|
|
broadcast_motion (tool, event);
|
|
|
|
broadcast_axes (tool, event);
|
|
|
|
broadcast_frame (tool, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_button_event (MetaWaylandTabletTool *tool,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
if (!tool->focus_surface)
|
|
|
|
return;
|
|
|
|
|
2017-06-23 11:02:21 -04:00
|
|
|
if (event->type == CLUTTER_BUTTON_PRESS && tool->button_count == 1)
|
|
|
|
clutter_event_get_coords (event, &tool->grab_x, &tool->grab_y);
|
|
|
|
|
2015-10-28 06:50:52 -04:00
|
|
|
if (event->type == CLUTTER_BUTTON_PRESS && event->button.button == 1)
|
|
|
|
broadcast_down (tool, event);
|
|
|
|
else if (event->type == CLUTTER_BUTTON_RELEASE && event->button.button == 1)
|
|
|
|
broadcast_up (tool, event);
|
|
|
|
else
|
|
|
|
broadcast_button (tool, event);
|
|
|
|
|
|
|
|
broadcast_frame (tool, event);
|
|
|
|
}
|
|
|
|
|
2015-02-04 12:19:08 -05:00
|
|
|
void
|
|
|
|
meta_wayland_tablet_tool_update (MetaWaylandTabletTool *tool,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
2015-10-28 06:08:09 -04:00
|
|
|
switch (event->type)
|
|
|
|
{
|
|
|
|
case CLUTTER_BUTTON_PRESS:
|
|
|
|
case CLUTTER_BUTTON_RELEASE:
|
|
|
|
meta_wayland_tablet_tool_account_button (tool, event);
|
|
|
|
break;
|
|
|
|
case CLUTTER_MOTION:
|
|
|
|
if (!tool->pressed_buttons)
|
|
|
|
repick_for_event (tool, event);
|
|
|
|
break;
|
|
|
|
case CLUTTER_PROXIMITY_IN:
|
2015-10-28 07:55:58 -04:00
|
|
|
if (!tool->cursor_renderer)
|
|
|
|
tool->cursor_renderer = meta_cursor_renderer_new ();
|
2015-10-28 06:08:09 -04:00
|
|
|
tool->current_tablet =
|
|
|
|
meta_wayland_tablet_seat_lookup_tablet (tool->seat,
|
|
|
|
clutter_event_get_source_device (event));
|
|
|
|
break;
|
2015-10-28 07:55:58 -04:00
|
|
|
case CLUTTER_PROXIMITY_OUT:
|
|
|
|
tool->current_tablet = NULL;
|
2017-07-26 09:24:20 -04:00
|
|
|
meta_wayland_tablet_tool_set_cursor_surface (tool, NULL);
|
2015-10-28 07:55:58 -04:00
|
|
|
meta_wayland_tablet_tool_update_cursor_surface (tool);
|
|
|
|
g_clear_object (&tool->cursor_renderer);
|
|
|
|
break;
|
2015-10-28 06:08:09 -04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2015-02-04 12:19:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
meta_wayland_tablet_tool_handle_event (MetaWaylandTabletTool *tool,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
2015-10-28 06:08:09 -04:00
|
|
|
switch (event->type)
|
|
|
|
{
|
|
|
|
case CLUTTER_PROXIMITY_IN:
|
|
|
|
/* We don't have much info here to make anything useful out of it,
|
|
|
|
* wait until the first motion event so we have both coordinates
|
|
|
|
* and tool.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
case CLUTTER_PROXIMITY_OUT:
|
|
|
|
meta_wayland_tablet_tool_set_focus (tool, NULL, event);
|
|
|
|
break;
|
2015-10-28 06:50:52 -04:00
|
|
|
case CLUTTER_MOTION:
|
|
|
|
handle_motion_event (tool, event);
|
|
|
|
break;
|
|
|
|
case CLUTTER_BUTTON_PRESS:
|
|
|
|
case CLUTTER_BUTTON_RELEASE:
|
|
|
|
handle_button_event (tool, event);
|
|
|
|
break;
|
2015-10-28 06:08:09 -04:00
|
|
|
default:
|
|
|
|
return CLUTTER_EVENT_PROPAGATE;
|
|
|
|
}
|
|
|
|
|
2015-02-04 12:19:08 -05:00
|
|
|
return CLUTTER_EVENT_STOP;
|
|
|
|
}
|
2015-10-28 08:49:19 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
meta_wayland_tablet_tool_set_cursor_position (MetaWaylandTabletTool *tool,
|
2017-06-08 10:13:16 -04:00
|
|
|
float new_x,
|
|
|
|
float new_y)
|
2015-10-28 08:49:19 -04:00
|
|
|
{
|
|
|
|
if (tool->cursor_renderer)
|
|
|
|
meta_cursor_renderer_set_position (tool->cursor_renderer, new_x, new_y);
|
|
|
|
}
|
2017-06-23 11:02:21 -04:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
tablet_tool_can_grab_surface (MetaWaylandTabletTool *tool,
|
|
|
|
MetaWaylandSurface *surface)
|
|
|
|
{
|
2019-06-30 09:18:46 -04:00
|
|
|
GNode *n;
|
2017-06-23 11:02:21 -04:00
|
|
|
|
|
|
|
if (tool->focus_surface == surface)
|
|
|
|
return TRUE;
|
|
|
|
|
2019-06-30 09:18:46 -04:00
|
|
|
for (n = g_node_first_child (surface->subsurface_branch_node);
|
|
|
|
n;
|
|
|
|
n = g_node_next_sibling (n))
|
2017-06-23 11:02:21 -04:00
|
|
|
{
|
2019-06-30 09:18:46 -04:00
|
|
|
MetaWaylandSurface *subsurface = n->data;
|
|
|
|
|
|
|
|
if (G_NODE_IS_LEAF (n))
|
|
|
|
continue;
|
2017-06-23 11:02:21 -04:00
|
|
|
|
|
|
|
if (tablet_tool_can_grab_surface (tool, subsurface))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
meta_wayland_tablet_tool_can_grab_surface (MetaWaylandTabletTool *tool,
|
|
|
|
MetaWaylandSurface *surface,
|
|
|
|
uint32_t serial)
|
|
|
|
{
|
|
|
|
return ((tool->down_serial == serial || tool->button_serial == serial) &&
|
|
|
|
tablet_tool_can_grab_surface (tool, surface));
|
|
|
|
}
|
2019-10-28 13:07:31 -04:00
|
|
|
|
|
|
|
gboolean
|
|
|
|
meta_wayland_tablet_tool_can_popup (MetaWaylandTabletTool *tool,
|
|
|
|
uint32_t serial)
|
|
|
|
{
|
|
|
|
return tool->down_serial == serial || tool->button_serial == serial;
|
|
|
|
}
|