2015-07-22 10:43:25 -04: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-pointer-gesture-swipe.h"
|
|
|
|
|
2015-07-22 10:43:25 -04:00
|
|
|
#include <glib.h>
|
|
|
|
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "wayland/meta-wayland-pointer.h"
|
|
|
|
#include "wayland/meta-wayland-seat.h"
|
|
|
|
#include "wayland/meta-wayland-surface.h"
|
|
|
|
|
2015-11-09 02:28:14 -05:00
|
|
|
#include "pointer-gestures-unstable-v1-server-protocol.h"
|
2015-07-22 10:43:25 -04:00
|
|
|
|
|
|
|
static void
|
|
|
|
handle_swipe_begin (MetaWaylandPointer *pointer,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
MetaWaylandPointerClient *pointer_client;
|
2016-09-12 11:20:36 -04:00
|
|
|
MetaWaylandSeat *seat;
|
2015-07-22 10:43:25 -04:00
|
|
|
struct wl_resource *resource;
|
|
|
|
uint32_t serial, fingers;
|
|
|
|
|
|
|
|
pointer_client = pointer->focus_client;
|
2016-09-12 11:20:36 -04:00
|
|
|
seat = meta_wayland_pointer_get_seat (pointer);
|
|
|
|
serial = wl_display_next_serial (seat->wl_display);
|
2016-05-03 07:31:11 -04:00
|
|
|
fingers = clutter_event_get_touchpad_gesture_finger_count (event);
|
2015-07-22 10:43:25 -04:00
|
|
|
|
2022-09-23 09:53:19 -04:00
|
|
|
pointer_client->active_touchpad_gesture = event->type;
|
|
|
|
|
2015-07-22 10:43:25 -04:00
|
|
|
wl_resource_for_each (resource, &pointer_client->swipe_gesture_resources)
|
|
|
|
{
|
2015-11-09 02:28:14 -05:00
|
|
|
zwp_pointer_gesture_swipe_v1_send_begin (resource, serial,
|
|
|
|
clutter_event_get_time (event),
|
|
|
|
pointer->focus_surface->resource,
|
|
|
|
fingers);
|
2015-07-22 10:43:25 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_swipe_update (MetaWaylandPointer *pointer,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
MetaWaylandPointerClient *pointer_client;
|
|
|
|
struct wl_resource *resource;
|
|
|
|
gdouble dx, dy;
|
|
|
|
|
|
|
|
pointer_client = pointer->focus_client;
|
|
|
|
clutter_event_get_gesture_motion_delta (event, &dx, &dy);
|
|
|
|
|
|
|
|
wl_resource_for_each (resource, &pointer_client->swipe_gesture_resources)
|
|
|
|
{
|
2015-11-09 02:28:14 -05:00
|
|
|
zwp_pointer_gesture_swipe_v1_send_update (resource,
|
|
|
|
clutter_event_get_time (event),
|
|
|
|
wl_fixed_from_double (dx),
|
|
|
|
wl_fixed_from_double (dy));
|
2015-07-22 10:43:25 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-23 09:52:20 -04:00
|
|
|
static void
|
|
|
|
broadcast_end (MetaWaylandPointer *pointer,
|
|
|
|
uint32_t serial,
|
|
|
|
uint32_t time,
|
|
|
|
gboolean cancelled)
|
|
|
|
{
|
|
|
|
MetaWaylandPointerClient *pointer_client;
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
|
|
pointer_client = pointer->focus_client;
|
|
|
|
|
|
|
|
wl_resource_for_each (resource, &pointer_client->swipe_gesture_resources)
|
|
|
|
{
|
|
|
|
zwp_pointer_gesture_swipe_v1_send_end (resource, serial,
|
|
|
|
time, cancelled);
|
|
|
|
}
|
2022-09-23 09:53:19 -04:00
|
|
|
|
|
|
|
pointer_client->active_touchpad_gesture = CLUTTER_NOTHING;
|
2022-09-23 09:52:20 -04:00
|
|
|
}
|
|
|
|
|
2015-07-22 10:43:25 -04:00
|
|
|
static void
|
|
|
|
handle_swipe_end (MetaWaylandPointer *pointer,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
2016-09-12 11:20:36 -04:00
|
|
|
MetaWaylandSeat *seat;
|
2015-07-22 10:43:25 -04:00
|
|
|
gboolean cancelled = FALSE;
|
|
|
|
uint32_t serial;
|
|
|
|
|
2016-09-12 11:20:36 -04:00
|
|
|
seat = meta_wayland_pointer_get_seat (pointer);
|
|
|
|
serial = wl_display_next_serial (seat->wl_display);
|
2015-07-22 10:43:25 -04:00
|
|
|
|
|
|
|
if (event->touchpad_swipe.phase == CLUTTER_TOUCHPAD_GESTURE_PHASE_CANCEL)
|
|
|
|
cancelled = TRUE;
|
|
|
|
|
2022-09-23 09:52:20 -04:00
|
|
|
broadcast_end (pointer, serial,
|
|
|
|
clutter_event_get_time (event),
|
|
|
|
cancelled);
|
2015-07-22 10:43:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
meta_wayland_pointer_gesture_swipe_handle_event (MetaWaylandPointer *pointer,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
if (event->type != CLUTTER_TOUCHPAD_SWIPE)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!pointer->focus_client)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
switch (event->touchpad_swipe.phase)
|
|
|
|
{
|
|
|
|
case CLUTTER_TOUCHPAD_GESTURE_PHASE_BEGIN:
|
|
|
|
handle_swipe_begin (pointer, event);
|
|
|
|
break;
|
|
|
|
case CLUTTER_TOUCHPAD_GESTURE_PHASE_UPDATE:
|
|
|
|
handle_swipe_update (pointer, event);
|
|
|
|
break;
|
|
|
|
case CLUTTER_TOUCHPAD_GESTURE_PHASE_END:
|
2021-05-07 02:17:15 -04:00
|
|
|
case CLUTTER_TOUCHPAD_GESTURE_PHASE_CANCEL:
|
2015-07-22 10:43:25 -04:00
|
|
|
handle_swipe_end (pointer, event);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pointer_gesture_swipe_release (struct wl_client *client,
|
|
|
|
struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
wl_resource_destroy (resource);
|
|
|
|
}
|
|
|
|
|
2015-11-09 02:28:14 -05:00
|
|
|
static const struct zwp_pointer_gesture_swipe_v1_interface pointer_gesture_swipe_interface = {
|
2015-07-22 10:43:25 -04:00
|
|
|
pointer_gesture_swipe_release
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_wayland_pointer_gesture_swipe_create_new_resource (MetaWaylandPointer *pointer,
|
|
|
|
struct wl_client *client,
|
|
|
|
struct wl_resource *pointer_resource,
|
|
|
|
uint32_t id)
|
|
|
|
{
|
|
|
|
MetaWaylandPointerClient *pointer_client;
|
|
|
|
struct wl_resource *res;
|
|
|
|
|
2015-11-09 02:28:14 -05:00
|
|
|
res = wl_resource_create (client, &zwp_pointer_gesture_swipe_v1_interface,
|
2015-07-22 10:43:25 -04:00
|
|
|
wl_resource_get_version (pointer_resource), id);
|
|
|
|
wl_resource_set_implementation (res, &pointer_gesture_swipe_interface, pointer,
|
|
|
|
meta_wayland_pointer_unbind_pointer_client_resource);
|
2022-11-06 00:38:22 -04:00
|
|
|
|
|
|
|
if (pointer)
|
|
|
|
{
|
|
|
|
pointer_client = meta_wayland_pointer_get_pointer_client (pointer, client);
|
|
|
|
g_return_if_fail (pointer_client != NULL);
|
|
|
|
|
|
|
|
wl_list_insert (&pointer_client->swipe_gesture_resources,
|
|
|
|
wl_resource_get_link (res));
|
|
|
|
}
|
2015-07-22 10:43:25 -04:00
|
|
|
}
|
2022-09-23 09:55:27 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
meta_wayland_pointer_gesture_swipe_cancel (MetaWaylandPointer *pointer,
|
|
|
|
uint32_t serial)
|
|
|
|
{
|
|
|
|
broadcast_end (pointer, serial,
|
|
|
|
us2ms (g_get_monotonic_time ()),
|
|
|
|
TRUE);
|
|
|
|
}
|