2013-05-03 13:51:22 -04:00
|
|
|
/*
|
|
|
|
* Wayland Support
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Intel Corporation
|
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright © 2008 Kristian Høgsberg
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
* documentation for any purpose is hereby granted without fee, provided that
|
|
|
|
* the above copyright notice appear in all copies and that both that copyright
|
|
|
|
* notice and this permission notice appear in supporting documentation, and
|
|
|
|
* that the name of the copyright holders not be used in advertising or
|
|
|
|
* publicity pertaining to distribution of the software without specific,
|
|
|
|
* written prior permission. The copyright holders make no representations
|
|
|
|
* about the suitability of this software for any purpose. It is provided "as
|
|
|
|
* is" without express or implied warranty.
|
|
|
|
*
|
|
|
|
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
|
|
|
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
|
|
|
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
|
|
|
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
|
|
|
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
|
|
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
|
|
|
* OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* The file is based on src/input.c from Weston */
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2013-09-11 08:06:05 -04:00
|
|
|
#include <linux/input.h>
|
2018-07-10 04:36:24 -04:00
|
|
|
#include <string.h>
|
2013-08-23 07:57:58 -04:00
|
|
|
|
2015-07-17 11:16:39 -04:00
|
|
|
#include "backends/meta-backend-private.h"
|
|
|
|
#include "backends/meta-cursor-renderer.h"
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "backends/meta-cursor-tracker-private.h"
|
|
|
|
#include "backends/meta-cursor.h"
|
|
|
|
#include "clutter/clutter.h"
|
|
|
|
#include "cogl/cogl.h"
|
|
|
|
#include "compositor/meta-surface-actor-wayland.h"
|
|
|
|
#include "meta/meta-cursor-tracker.h"
|
2021-07-05 09:50:06 -04:00
|
|
|
#include "wayland/meta-cursor-sprite-wayland.h"
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "wayland/meta-wayland-buffer.h"
|
|
|
|
#include "wayland/meta-wayland-cursor-surface.h"
|
|
|
|
#include "wayland/meta-wayland-pointer.h"
|
|
|
|
#include "wayland/meta-wayland-popup.h"
|
|
|
|
#include "wayland/meta-wayland-private.h"
|
|
|
|
#include "wayland/meta-wayland-seat.h"
|
|
|
|
#include "wayland/meta-wayland-surface.h"
|
|
|
|
#include "wayland/meta-xwayland.h"
|
2015-06-02 04:26:34 -04:00
|
|
|
|
2015-11-17 12:01:08 -05:00
|
|
|
#ifdef HAVE_NATIVE_BACKEND
|
|
|
|
#include "backends/native/meta-backend-native.h"
|
|
|
|
#endif
|
|
|
|
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "relative-pointer-unstable-v1-server-protocol.h"
|
2013-07-17 04:44:29 -04:00
|
|
|
|
2014-04-17 18:16:49 -04:00
|
|
|
#define DEFAULT_AXIS_STEP_DISTANCE wl_fixed_from_int (10)
|
|
|
|
|
2018-12-19 03:04:25 -05:00
|
|
|
enum
|
|
|
|
{
|
2016-04-01 09:07:59 -04:00
|
|
|
FOCUS_SURFACE_CHANGED,
|
|
|
|
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL];
|
|
|
|
|
2016-09-12 11:17:28 -04:00
|
|
|
G_DEFINE_TYPE (MetaWaylandPointer, meta_wayland_pointer,
|
|
|
|
META_TYPE_WAYLAND_INPUT_DEVICE)
|
2016-04-01 04:39:30 -04:00
|
|
|
|
2017-05-31 05:27:52 -04:00
|
|
|
static void
|
|
|
|
meta_wayland_pointer_set_current (MetaWaylandPointer *pointer,
|
|
|
|
MetaWaylandSurface *surface);
|
|
|
|
|
2016-09-21 02:30:15 -04:00
|
|
|
static void
|
|
|
|
meta_wayland_pointer_reset_grab (MetaWaylandPointer *pointer);
|
|
|
|
|
2016-09-21 02:33:47 -04:00
|
|
|
static void
|
|
|
|
meta_wayland_pointer_cancel_grab (MetaWaylandPointer *pointer);
|
|
|
|
|
2015-08-09 09:24:16 -04:00
|
|
|
static MetaWaylandPointerClient *
|
|
|
|
meta_wayland_pointer_client_new (void)
|
|
|
|
{
|
|
|
|
MetaWaylandPointerClient *pointer_client;
|
|
|
|
|
2020-10-19 13:57:57 -04:00
|
|
|
pointer_client = g_new0 (MetaWaylandPointerClient, 1);
|
2015-08-09 09:24:16 -04:00
|
|
|
wl_list_init (&pointer_client->pointer_resources);
|
2015-07-22 10:43:25 -04:00
|
|
|
wl_list_init (&pointer_client->swipe_gesture_resources);
|
2015-07-22 10:46:55 -04:00
|
|
|
wl_list_init (&pointer_client->pinch_gesture_resources);
|
2021-04-18 14:24:52 -04:00
|
|
|
wl_list_init (&pointer_client->hold_gesture_resources);
|
2015-06-02 04:26:34 -04:00
|
|
|
wl_list_init (&pointer_client->relative_pointer_resources);
|
2015-08-09 09:24:16 -04:00
|
|
|
|
|
|
|
return pointer_client;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
wayland: Avoid a race in wl_seat capabilities
The way wl_seat capabilities work, by notifying clients of capabilities
changes, and clients consequently requesting the relevant interface
objects (pointer, keyboard, touch) is inherently racy.
On quick VT changes for example, capabilities on the seat will be added
and removed, and by the time the client receives the capability change
notification and requests the relevant keyboard, pointer or touch,
another VT switch might have occurred and the wl_pointer, wl_keyboard or
wl_touch already destroyed, leading to a protocol error which kills the
client.
To avoid this, create the objects when requested regardless of the
capabilities.
Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/1797
Related: https://bugzilla.gnome.org/show_bug.cgi?id=790932
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/77>
2017-11-28 04:54:08 -05:00
|
|
|
meta_wayland_pointer_make_resources_inert (MetaWaylandPointerClient *pointer_client)
|
2015-08-09 09:24:16 -04:00
|
|
|
{
|
2015-08-14 08:46:27 -04:00
|
|
|
struct wl_resource *resource, *next;
|
2015-08-09 09:24:16 -04:00
|
|
|
|
|
|
|
/* Since we make every wl_pointer resource defunct when we stop advertising
|
|
|
|
* the pointer capability on the wl_seat, we need to make sure all the
|
|
|
|
* resources in the pointer client instance gets removed.
|
|
|
|
*/
|
2015-08-14 08:46:27 -04:00
|
|
|
wl_resource_for_each_safe (resource, next, &pointer_client->pointer_resources)
|
2015-08-09 09:24:16 -04:00
|
|
|
{
|
|
|
|
wl_list_remove (wl_resource_get_link (resource));
|
|
|
|
wl_list_init (wl_resource_get_link (resource));
|
2021-04-12 08:54:15 -04:00
|
|
|
wl_resource_set_user_data (resource, NULL);
|
2015-08-09 09:24:16 -04:00
|
|
|
}
|
2015-08-14 08:46:27 -04:00
|
|
|
wl_resource_for_each_safe (resource, next, &pointer_client->swipe_gesture_resources)
|
2015-07-22 10:43:25 -04:00
|
|
|
{
|
|
|
|
wl_list_remove (wl_resource_get_link (resource));
|
|
|
|
wl_list_init (wl_resource_get_link (resource));
|
2021-04-12 08:54:15 -04:00
|
|
|
wl_resource_set_user_data (resource, NULL);
|
2015-07-22 10:43:25 -04:00
|
|
|
}
|
2015-08-14 08:46:27 -04:00
|
|
|
wl_resource_for_each_safe (resource, next, &pointer_client->pinch_gesture_resources)
|
2015-07-22 10:46:55 -04:00
|
|
|
{
|
|
|
|
wl_list_remove (wl_resource_get_link (resource));
|
|
|
|
wl_list_init (wl_resource_get_link (resource));
|
2021-04-12 08:54:15 -04:00
|
|
|
wl_resource_set_user_data (resource, NULL);
|
2015-07-22 10:46:55 -04:00
|
|
|
}
|
2021-04-18 14:24:52 -04:00
|
|
|
wl_resource_for_each_safe (resource, next, &pointer_client->hold_gesture_resources)
|
|
|
|
{
|
|
|
|
wl_list_remove (wl_resource_get_link (resource));
|
|
|
|
wl_list_init (wl_resource_get_link (resource));
|
|
|
|
}
|
2015-06-02 04:26:34 -04:00
|
|
|
wl_resource_for_each_safe (resource, next, &pointer_client->relative_pointer_resources)
|
|
|
|
{
|
|
|
|
wl_list_remove (wl_resource_get_link (resource));
|
|
|
|
wl_list_init (wl_resource_get_link (resource));
|
2021-04-12 08:54:15 -04:00
|
|
|
wl_resource_set_user_data (resource, NULL);
|
2015-06-02 04:26:34 -04:00
|
|
|
}
|
wayland: Avoid a race in wl_seat capabilities
The way wl_seat capabilities work, by notifying clients of capabilities
changes, and clients consequently requesting the relevant interface
objects (pointer, keyboard, touch) is inherently racy.
On quick VT changes for example, capabilities on the seat will be added
and removed, and by the time the client receives the capability change
notification and requests the relevant keyboard, pointer or touch,
another VT switch might have occurred and the wl_pointer, wl_keyboard or
wl_touch already destroyed, leading to a protocol error which kills the
client.
To avoid this, create the objects when requested regardless of the
capabilities.
Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/1797
Related: https://bugzilla.gnome.org/show_bug.cgi?id=790932
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/77>
2017-11-28 04:54:08 -05:00
|
|
|
}
|
2015-08-09 09:24:16 -04:00
|
|
|
|
wayland: Avoid a race in wl_seat capabilities
The way wl_seat capabilities work, by notifying clients of capabilities
changes, and clients consequently requesting the relevant interface
objects (pointer, keyboard, touch) is inherently racy.
On quick VT changes for example, capabilities on the seat will be added
and removed, and by the time the client receives the capability change
notification and requests the relevant keyboard, pointer or touch,
another VT switch might have occurred and the wl_pointer, wl_keyboard or
wl_touch already destroyed, leading to a protocol error which kills the
client.
To avoid this, create the objects when requested regardless of the
capabilities.
Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/1797
Related: https://bugzilla.gnome.org/show_bug.cgi?id=790932
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/77>
2017-11-28 04:54:08 -05:00
|
|
|
static void
|
|
|
|
meta_wayland_pointer_client_free (MetaWaylandPointerClient *pointer_client)
|
|
|
|
{
|
|
|
|
meta_wayland_pointer_make_resources_inert (pointer_client);
|
2020-10-19 13:57:57 -04:00
|
|
|
g_free (pointer_client);
|
2015-08-09 09:24:16 -04:00
|
|
|
}
|
|
|
|
|
wayland: Avoid a race in wl_seat capabilities
The way wl_seat capabilities work, by notifying clients of capabilities
changes, and clients consequently requesting the relevant interface
objects (pointer, keyboard, touch) is inherently racy.
On quick VT changes for example, capabilities on the seat will be added
and removed, and by the time the client receives the capability change
notification and requests the relevant keyboard, pointer or touch,
another VT switch might have occurred and the wl_pointer, wl_keyboard or
wl_touch already destroyed, leading to a protocol error which kills the
client.
To avoid this, create the objects when requested regardless of the
capabilities.
Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/1797
Related: https://bugzilla.gnome.org/show_bug.cgi?id=790932
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/77>
2017-11-28 04:54:08 -05:00
|
|
|
static void
|
|
|
|
make_resources_inert_foreach (gpointer key,
|
|
|
|
gpointer value,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
MetaWaylandPointerClient *pointer_client = value;
|
|
|
|
|
|
|
|
meta_wayland_pointer_make_resources_inert (pointer_client);
|
|
|
|
}
|
|
|
|
|
2015-08-09 09:24:16 -04:00
|
|
|
static gboolean
|
|
|
|
meta_wayland_pointer_client_is_empty (MetaWaylandPointerClient *pointer_client)
|
|
|
|
{
|
2015-07-22 10:43:25 -04:00
|
|
|
return (wl_list_empty (&pointer_client->pointer_resources) &&
|
2015-07-22 10:46:55 -04:00
|
|
|
wl_list_empty (&pointer_client->swipe_gesture_resources) &&
|
2015-06-02 04:26:34 -04:00
|
|
|
wl_list_empty (&pointer_client->pinch_gesture_resources) &&
|
2021-04-18 14:24:52 -04:00
|
|
|
wl_list_empty (&pointer_client->hold_gesture_resources) &&
|
2015-06-02 04:26:34 -04:00
|
|
|
wl_list_empty (&pointer_client->relative_pointer_resources));
|
2015-08-09 09:24:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
MetaWaylandPointerClient *
|
|
|
|
meta_wayland_pointer_get_pointer_client (MetaWaylandPointer *pointer,
|
|
|
|
struct wl_client *client)
|
|
|
|
{
|
|
|
|
return g_hash_table_lookup (pointer->pointer_clients, client);
|
|
|
|
}
|
|
|
|
|
|
|
|
static MetaWaylandPointerClient *
|
|
|
|
meta_wayland_pointer_ensure_pointer_client (MetaWaylandPointer *pointer,
|
|
|
|
struct wl_client *client)
|
|
|
|
{
|
|
|
|
MetaWaylandPointerClient *pointer_client;
|
|
|
|
|
|
|
|
pointer_client = meta_wayland_pointer_get_pointer_client (pointer, client);
|
|
|
|
if (pointer_client)
|
|
|
|
return pointer_client;
|
|
|
|
|
|
|
|
pointer_client = meta_wayland_pointer_client_new ();
|
|
|
|
g_hash_table_insert (pointer->pointer_clients, client, pointer_client);
|
|
|
|
|
|
|
|
if (!pointer->focus_client &&
|
|
|
|
pointer->focus_surface &&
|
|
|
|
wl_resource_get_client (pointer->focus_surface->resource) == client)
|
|
|
|
pointer->focus_client = pointer_client;
|
|
|
|
|
|
|
|
return pointer_client;
|
|
|
|
}
|
|
|
|
|
2014-04-17 17:16:17 -04:00
|
|
|
static void
|
2015-08-09 09:24:16 -04:00
|
|
|
meta_wayland_pointer_cleanup_pointer_client (MetaWaylandPointer *pointer,
|
|
|
|
MetaWaylandPointerClient *pointer_client,
|
|
|
|
struct wl_client *client)
|
2014-04-17 17:16:17 -04:00
|
|
|
{
|
2015-08-09 09:24:16 -04:00
|
|
|
if (meta_wayland_pointer_client_is_empty (pointer_client))
|
|
|
|
{
|
|
|
|
if (pointer->focus_client == pointer_client)
|
|
|
|
pointer->focus_client = NULL;
|
|
|
|
g_hash_table_remove (pointer->pointer_clients, client);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_wayland_pointer_unbind_pointer_client_resource (struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
MetaWaylandPointer *pointer = wl_resource_get_user_data (resource);
|
|
|
|
MetaWaylandPointerClient *pointer_client;
|
|
|
|
struct wl_client *client = wl_resource_get_client (resource);
|
|
|
|
|
2021-04-12 08:54:15 -04:00
|
|
|
pointer = wl_resource_get_user_data (resource);
|
|
|
|
if (!pointer)
|
|
|
|
return;
|
|
|
|
|
2014-04-17 17:16:17 -04:00
|
|
|
wl_list_remove (wl_resource_get_link (resource));
|
2015-08-09 09:24:16 -04:00
|
|
|
|
|
|
|
pointer_client = meta_wayland_pointer_get_pointer_client (pointer, client);
|
|
|
|
if (!pointer_client)
|
|
|
|
{
|
|
|
|
/* This happens if all pointer devices were unplugged and no new resources
|
|
|
|
* were created by the client.
|
|
|
|
*
|
|
|
|
* If this is a resource that was previously made defunct, pointer_client
|
|
|
|
* be non-NULL but it is harmless since the below cleanup call will be
|
|
|
|
* prevented from removing the pointer client because of valid resources.
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
meta_wayland_pointer_cleanup_pointer_client (pointer,
|
|
|
|
pointer_client,
|
|
|
|
client);
|
2014-04-17 17:16:17 -04:00
|
|
|
}
|
|
|
|
|
2021-09-03 17:49:46 -04:00
|
|
|
static MetaWindow *
|
|
|
|
surface_get_effective_window (MetaWaylandSurface *surface)
|
|
|
|
{
|
|
|
|
MetaWaylandSurface *toplevel;
|
|
|
|
|
|
|
|
toplevel = meta_wayland_surface_get_toplevel (surface);
|
|
|
|
if (!toplevel)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return meta_wayland_surface_get_window (toplevel);
|
|
|
|
}
|
|
|
|
|
2014-11-26 18:22:01 -05:00
|
|
|
static void
|
|
|
|
sync_focus_surface (MetaWaylandPointer *pointer)
|
|
|
|
{
|
|
|
|
MetaDisplay *display = meta_get_display ();
|
2019-02-16 16:48:17 -05:00
|
|
|
MetaBackend *backend = meta_get_backend ();
|
|
|
|
MetaCursorTracker *cursor_tracker = meta_backend_get_cursor_tracker (backend);
|
2020-02-19 15:19:19 -05:00
|
|
|
ClutterBackend *clutter_backend = clutter_get_default_backend ();
|
|
|
|
ClutterSeat *clutter_seat = clutter_backend_get_default_seat (clutter_backend);
|
2021-11-17 17:31:11 -05:00
|
|
|
ClutterStage *stage = CLUTTER_STAGE (meta_backend_get_stage (backend));
|
2019-02-16 16:48:17 -05:00
|
|
|
|
2021-11-17 17:31:11 -05:00
|
|
|
if (clutter_stage_get_grab_actor (stage) != NULL ||
|
|
|
|
(!meta_cursor_tracker_get_pointer_visible (cursor_tracker) &&
|
|
|
|
!clutter_seat_is_unfocus_inhibited (clutter_seat)))
|
2019-02-16 16:48:17 -05:00
|
|
|
{
|
|
|
|
meta_wayland_pointer_set_focus (pointer, NULL);
|
|
|
|
return;
|
|
|
|
}
|
2014-11-26 18:22:01 -05:00
|
|
|
|
|
|
|
switch (display->event_route)
|
|
|
|
{
|
|
|
|
case META_EVENT_ROUTE_WINDOW_OP:
|
|
|
|
case META_EVENT_ROUTE_COMPOSITOR_GRAB:
|
2015-01-19 14:27:27 -05:00
|
|
|
case META_EVENT_ROUTE_FRAME_BUTTON:
|
2014-11-26 18:22:01 -05:00
|
|
|
/* The compositor has a grab, so remove our focus... */
|
|
|
|
meta_wayland_pointer_set_focus (pointer, NULL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case META_EVENT_ROUTE_NORMAL:
|
|
|
|
case META_EVENT_ROUTE_WAYLAND_POPUP:
|
|
|
|
{
|
|
|
|
const MetaWaylandPointerGrabInterface *interface = pointer->grab->interface;
|
|
|
|
interface->focus (pointer->grab, pointer->current);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-09-08 08:32:50 -04:00
|
|
|
static void
|
2016-01-19 05:50:27 -05:00
|
|
|
meta_wayland_pointer_send_frame (MetaWaylandPointer *pointer,
|
|
|
|
struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
if (wl_resource_get_version (resource) >= WL_POINTER_AXIS_SOURCE_SINCE_VERSION)
|
|
|
|
wl_pointer_send_frame (resource);
|
|
|
|
}
|
|
|
|
|
2016-09-06 00:45:01 -04:00
|
|
|
void
|
2016-01-19 05:50:27 -05:00
|
|
|
meta_wayland_pointer_broadcast_frame (MetaWaylandPointer *pointer)
|
2015-09-08 08:32:50 -04:00
|
|
|
{
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
|
|
if (!pointer->focus_client)
|
|
|
|
return;
|
|
|
|
|
|
|
|
wl_resource_for_each (resource, &pointer->focus_client->pointer_resources)
|
|
|
|
{
|
2016-01-19 05:50:27 -05:00
|
|
|
meta_wayland_pointer_send_frame (pointer, resource);
|
2015-09-08 08:32:50 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-17 00:10:52 -04:00
|
|
|
void
|
2015-06-02 04:26:34 -04:00
|
|
|
meta_wayland_pointer_send_relative_motion (MetaWaylandPointer *pointer,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
struct wl_resource *resource;
|
|
|
|
double dx, dy;
|
|
|
|
double dx_unaccel, dy_unaccel;
|
|
|
|
uint64_t time_us;
|
|
|
|
uint32_t time_us_hi;
|
|
|
|
uint32_t time_us_lo;
|
|
|
|
wl_fixed_t dxf, dyf;
|
|
|
|
wl_fixed_t dx_unaccelf, dy_unaccelf;
|
|
|
|
|
|
|
|
if (!pointer->focus_client)
|
|
|
|
return;
|
|
|
|
|
2020-12-08 07:18:06 -05:00
|
|
|
if (!clutter_event_get_relative_motion (event,
|
|
|
|
&dx, &dy,
|
|
|
|
&dx_unaccel, &dy_unaccel))
|
2015-06-02 04:26:34 -04:00
|
|
|
return;
|
|
|
|
|
2020-12-08 07:18:06 -05:00
|
|
|
time_us = clutter_event_get_time_us (event);
|
2015-06-02 04:26:34 -04:00
|
|
|
if (time_us == 0)
|
|
|
|
time_us = clutter_event_get_time (event) * 1000ULL;
|
|
|
|
time_us_hi = (uint32_t) (time_us >> 32);
|
|
|
|
time_us_lo = (uint32_t) time_us;
|
|
|
|
dxf = wl_fixed_from_double (dx);
|
|
|
|
dyf = wl_fixed_from_double (dy);
|
|
|
|
dx_unaccelf = wl_fixed_from_double (dx_unaccel);
|
|
|
|
dy_unaccelf = wl_fixed_from_double (dy_unaccel);
|
|
|
|
|
|
|
|
wl_resource_for_each (resource,
|
|
|
|
&pointer->focus_client->relative_pointer_resources)
|
|
|
|
{
|
|
|
|
zwp_relative_pointer_v1_send_relative_motion (resource,
|
|
|
|
time_us_hi,
|
|
|
|
time_us_lo,
|
|
|
|
dxf,
|
|
|
|
dyf,
|
|
|
|
dx_unaccelf,
|
|
|
|
dy_unaccelf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-11 04:34:15 -05:00
|
|
|
void
|
|
|
|
meta_wayland_pointer_send_motion (MetaWaylandPointer *pointer,
|
|
|
|
const ClutterEvent *event)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
|
|
|
struct wl_resource *resource;
|
2015-08-09 09:24:16 -04:00
|
|
|
uint32_t time;
|
2015-07-07 01:47:19 -04:00
|
|
|
float sx, sy;
|
2013-05-03 13:51:22 -04:00
|
|
|
|
2015-08-09 09:24:16 -04:00
|
|
|
if (!pointer->focus_client)
|
|
|
|
return;
|
2013-09-11 08:06:05 -04:00
|
|
|
|
2015-08-09 09:24:16 -04:00
|
|
|
time = clutter_event_get_time (event);
|
2015-07-07 01:47:19 -04:00
|
|
|
meta_wayland_surface_get_relative_coordinates (pointer->focus_surface,
|
|
|
|
event->motion.x,
|
|
|
|
event->motion.y,
|
2015-08-09 09:24:16 -04:00
|
|
|
&sx, &sy);
|
|
|
|
|
|
|
|
wl_resource_for_each (resource, &pointer->focus_client->pointer_resources)
|
|
|
|
{
|
2015-07-07 01:47:19 -04:00
|
|
|
wl_pointer_send_motion (resource, time,
|
|
|
|
wl_fixed_from_double (sx),
|
|
|
|
wl_fixed_from_double (sy));
|
2013-09-11 08:06:05 -04:00
|
|
|
}
|
2015-09-08 08:32:50 -04:00
|
|
|
|
2015-06-02 04:26:34 -04:00
|
|
|
meta_wayland_pointer_send_relative_motion (pointer, event);
|
|
|
|
|
2016-01-19 05:50:27 -05:00
|
|
|
meta_wayland_pointer_broadcast_frame (pointer);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
2015-02-11 04:34:15 -05:00
|
|
|
void
|
|
|
|
meta_wayland_pointer_send_button (MetaWaylandPointer *pointer,
|
|
|
|
const ClutterEvent *event)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
|
|
|
struct wl_resource *resource;
|
2013-09-11 08:06:05 -04:00
|
|
|
ClutterEventType event_type;
|
|
|
|
|
|
|
|
event_type = clutter_event_type (event);
|
2013-05-03 13:51:22 -04:00
|
|
|
|
2015-08-09 09:24:16 -04:00
|
|
|
if (pointer->focus_client &&
|
|
|
|
!wl_list_empty (&pointer->focus_client->pointer_resources))
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
2016-09-21 00:30:09 -04:00
|
|
|
MetaWaylandInputDevice *input_device =
|
|
|
|
META_WAYLAND_INPUT_DEVICE (pointer);
|
2015-08-09 09:24:16 -04:00
|
|
|
uint32_t time;
|
2013-09-11 08:06:05 -04:00
|
|
|
uint32_t button;
|
|
|
|
uint32_t serial;
|
|
|
|
|
2020-12-08 06:28:01 -05:00
|
|
|
button = clutter_event_get_event_code (event);
|
2015-11-17 12:01:08 -05:00
|
|
|
time = clutter_event_get_time (event);
|
2016-09-21 00:30:09 -04:00
|
|
|
serial = meta_wayland_input_device_next_serial (input_device);
|
2014-09-17 19:51:27 -04:00
|
|
|
|
2015-08-09 09:24:16 -04:00
|
|
|
wl_resource_for_each (resource, &pointer->focus_client->pointer_resources)
|
2014-09-17 19:51:27 -04:00
|
|
|
{
|
|
|
|
wl_pointer_send_button (resource, serial,
|
2015-08-09 09:24:16 -04:00
|
|
|
time, button,
|
2014-09-17 19:51:27 -04:00
|
|
|
event_type == CLUTTER_BUTTON_PRESS ? 1 : 0);
|
|
|
|
}
|
2015-09-08 08:32:50 -04:00
|
|
|
|
2016-01-19 05:50:27 -05:00
|
|
|
meta_wayland_pointer_broadcast_frame (pointer);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
2013-09-11 08:06:05 -04:00
|
|
|
if (pointer->button_count == 0 && event_type == CLUTTER_BUTTON_RELEASE)
|
2014-11-26 18:22:01 -05:00
|
|
|
sync_focus_surface (pointer);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
2015-02-11 04:34:15 -05:00
|
|
|
static void
|
|
|
|
default_grab_focus (MetaWaylandPointerGrab *grab,
|
|
|
|
MetaWaylandSurface *surface)
|
|
|
|
{
|
|
|
|
MetaWaylandPointer *pointer = grab->pointer;
|
2016-09-21 01:41:11 -04:00
|
|
|
MetaWaylandSeat *seat = meta_wayland_pointer_get_seat (pointer);
|
2016-10-13 11:03:36 -04:00
|
|
|
MetaDisplay *display = meta_get_display ();
|
2019-09-12 13:18:44 -04:00
|
|
|
MetaBackend *backend = meta_get_backend ();
|
|
|
|
MetaCursorTracker *cursor_tracker = meta_backend_get_cursor_tracker (backend);
|
2020-02-19 15:19:19 -05:00
|
|
|
ClutterBackend *clutter_backend = clutter_get_default_backend ();
|
|
|
|
ClutterSeat *clutter_seat = clutter_backend_get_default_seat (clutter_backend);
|
2021-11-17 17:31:11 -05:00
|
|
|
ClutterStage *stage = CLUTTER_STAGE (meta_backend_get_stage (backend));
|
2019-09-12 13:18:44 -04:00
|
|
|
|
|
|
|
if (!meta_wayland_seat_has_pointer (seat))
|
|
|
|
return;
|
|
|
|
|
2021-11-17 17:31:11 -05:00
|
|
|
if (clutter_stage_get_grab_actor (stage) != NULL)
|
|
|
|
return;
|
|
|
|
|
2020-02-19 15:19:19 -05:00
|
|
|
if (!meta_cursor_tracker_get_pointer_visible (cursor_tracker) &&
|
|
|
|
!clutter_seat_is_unfocus_inhibited (clutter_seat))
|
2019-09-12 13:18:44 -04:00
|
|
|
return;
|
2015-02-11 04:34:15 -05:00
|
|
|
|
|
|
|
if (pointer->button_count > 0)
|
|
|
|
return;
|
|
|
|
|
2016-10-13 11:03:36 -04:00
|
|
|
switch (display->event_route)
|
|
|
|
{
|
|
|
|
case META_EVENT_ROUTE_WINDOW_OP:
|
|
|
|
case META_EVENT_ROUTE_COMPOSITOR_GRAB:
|
|
|
|
case META_EVENT_ROUTE_FRAME_BUTTON:
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case META_EVENT_ROUTE_NORMAL:
|
|
|
|
case META_EVENT_ROUTE_WAYLAND_POPUP:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-09-03 17:49:46 -04:00
|
|
|
if (surface)
|
|
|
|
{
|
|
|
|
MetaWindow *window = NULL;
|
|
|
|
|
|
|
|
window = surface_get_effective_window (surface);
|
|
|
|
|
|
|
|
/* Avoid focusing a non-alive surface */
|
|
|
|
if (!window || !meta_window_get_alive (window))
|
|
|
|
surface = NULL;
|
|
|
|
}
|
|
|
|
|
2019-09-12 13:18:44 -04:00
|
|
|
meta_wayland_pointer_set_focus (pointer, surface);
|
2015-02-11 04:34:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
default_grab_motion (MetaWaylandPointerGrab *grab,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
MetaWaylandPointer *pointer = grab->pointer;
|
|
|
|
|
|
|
|
meta_wayland_pointer_send_motion (pointer, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
default_grab_button (MetaWaylandPointerGrab *grab,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
MetaWaylandPointer *pointer = grab->pointer;
|
|
|
|
|
|
|
|
meta_wayland_pointer_send_button (pointer, event);
|
|
|
|
}
|
|
|
|
|
2013-05-03 13:51:22 -04:00
|
|
|
static const MetaWaylandPointerGrabInterface default_pointer_grab_interface = {
|
|
|
|
default_grab_focus,
|
|
|
|
default_grab_motion,
|
|
|
|
default_grab_button
|
|
|
|
};
|
|
|
|
|
2015-07-17 11:28:31 -04:00
|
|
|
static void
|
|
|
|
meta_wayland_pointer_on_cursor_changed (MetaCursorTracker *cursor_tracker,
|
|
|
|
MetaWaylandPointer *pointer)
|
|
|
|
{
|
|
|
|
if (pointer->cursor_surface)
|
|
|
|
meta_wayland_surface_update_outputs (pointer->cursor_surface);
|
|
|
|
}
|
|
|
|
|
2013-05-03 13:51:22 -04:00
|
|
|
void
|
2016-09-12 11:20:36 -04:00
|
|
|
meta_wayland_pointer_enable (MetaWaylandPointer *pointer)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
2016-11-29 07:30:22 -05:00
|
|
|
MetaBackend *backend = meta_get_backend ();
|
|
|
|
MetaCursorTracker *cursor_tracker = meta_backend_get_cursor_tracker (backend);
|
2019-10-04 08:01:19 -04:00
|
|
|
ClutterSeat *clutter_seat;
|
2013-08-23 07:57:58 -04:00
|
|
|
|
2014-04-18 10:15:40 -04:00
|
|
|
pointer->cursor_surface = NULL;
|
|
|
|
|
2019-10-04 08:01:19 -04:00
|
|
|
clutter_seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
|
|
|
|
pointer->device = clutter_seat_get_pointer (clutter_seat);
|
2015-07-17 11:28:31 -04:00
|
|
|
|
|
|
|
g_signal_connect (cursor_tracker,
|
|
|
|
"cursor-changed",
|
|
|
|
G_CALLBACK (meta_wayland_pointer_on_cursor_changed),
|
|
|
|
pointer);
|
2019-02-16 16:48:17 -05:00
|
|
|
|
2020-02-19 15:21:29 -05:00
|
|
|
g_signal_connect_swapped (cursor_tracker,
|
|
|
|
"visibility-changed",
|
|
|
|
G_CALLBACK (sync_focus_surface),
|
|
|
|
pointer);
|
2020-02-19 15:19:19 -05:00
|
|
|
|
|
|
|
g_signal_connect_swapped (clutter_seat,
|
|
|
|
"is-unfocus-inhibited-changed",
|
|
|
|
G_CALLBACK (sync_focus_surface),
|
|
|
|
pointer);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-04-01 04:39:30 -04:00
|
|
|
meta_wayland_pointer_disable (MetaWaylandPointer *pointer)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
2016-11-29 07:30:22 -05:00
|
|
|
MetaBackend *backend = meta_get_backend ();
|
|
|
|
MetaCursorTracker *cursor_tracker = meta_backend_get_cursor_tracker (backend);
|
2020-02-19 15:19:19 -05:00
|
|
|
ClutterBackend *clutter_backend = clutter_get_default_backend ();
|
|
|
|
ClutterSeat *clutter_seat = clutter_backend_get_default_seat (clutter_backend);
|
2015-07-17 11:28:31 -04:00
|
|
|
|
wayland: Avoid a race in wl_seat capabilities
The way wl_seat capabilities work, by notifying clients of capabilities
changes, and clients consequently requesting the relevant interface
objects (pointer, keyboard, touch) is inherently racy.
On quick VT changes for example, capabilities on the seat will be added
and removed, and by the time the client receives the capability change
notification and requests the relevant keyboard, pointer or touch,
another VT switch might have occurred and the wl_pointer, wl_keyboard or
wl_touch already destroyed, leading to a protocol error which kills the
client.
To avoid this, create the objects when requested regardless of the
capabilities.
Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/1797
Related: https://bugzilla.gnome.org/show_bug.cgi?id=790932
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/77>
2017-11-28 04:54:08 -05:00
|
|
|
g_hash_table_foreach (pointer->pointer_clients,
|
|
|
|
make_resources_inert_foreach,
|
|
|
|
NULL);
|
|
|
|
|
2015-07-17 11:28:31 -04:00
|
|
|
g_signal_handlers_disconnect_by_func (cursor_tracker,
|
|
|
|
(gpointer) meta_wayland_pointer_on_cursor_changed,
|
|
|
|
pointer);
|
|
|
|
|
2019-02-16 16:48:17 -05:00
|
|
|
g_signal_handlers_disconnect_by_func (cursor_tracker,
|
2020-02-19 15:21:29 -05:00
|
|
|
sync_focus_surface,
|
2019-02-16 16:48:17 -05:00
|
|
|
pointer);
|
|
|
|
|
2020-02-19 15:19:19 -05:00
|
|
|
g_signal_handlers_disconnect_by_func (clutter_seat,
|
|
|
|
sync_focus_surface,
|
|
|
|
pointer);
|
|
|
|
|
2019-11-15 19:25:52 -05:00
|
|
|
if (pointer->cursor_surface)
|
2015-10-21 10:36:44 -04:00
|
|
|
{
|
2019-11-15 19:25:52 -05:00
|
|
|
g_clear_signal_handler (&pointer->cursor_surface_destroy_id,
|
|
|
|
pointer->cursor_surface);
|
2015-10-21 10:36:44 -04:00
|
|
|
}
|
|
|
|
|
2016-09-21 02:33:47 -04:00
|
|
|
meta_wayland_pointer_cancel_grab (pointer);
|
2016-09-21 02:30:15 -04:00
|
|
|
meta_wayland_pointer_reset_grab (pointer);
|
2016-09-21 01:42:59 -04:00
|
|
|
meta_wayland_pointer_set_focus (pointer, NULL);
|
2017-05-31 05:27:52 -04:00
|
|
|
meta_wayland_pointer_set_current (pointer, NULL);
|
2014-09-05 21:00:09 -04:00
|
|
|
|
2015-07-17 11:16:39 -04:00
|
|
|
pointer->cursor_surface = NULL;
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
2014-04-17 17:52:11 -04:00
|
|
|
static int
|
|
|
|
count_buttons (const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
static gint maskmap[5] =
|
|
|
|
{
|
|
|
|
CLUTTER_BUTTON1_MASK, CLUTTER_BUTTON2_MASK, CLUTTER_BUTTON3_MASK,
|
|
|
|
CLUTTER_BUTTON4_MASK, CLUTTER_BUTTON5_MASK
|
|
|
|
};
|
|
|
|
ClutterModifierType mod_mask;
|
|
|
|
int i, count;
|
|
|
|
|
|
|
|
mod_mask = clutter_event_get_state (event);
|
|
|
|
count = 0;
|
|
|
|
for (i = 0; i < 5; i++)
|
|
|
|
{
|
|
|
|
if (mod_mask & maskmap[i])
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2017-05-31 05:27:52 -04:00
|
|
|
static void
|
|
|
|
current_surface_destroyed (MetaWaylandSurface *surface,
|
|
|
|
MetaWaylandPointer *pointer)
|
|
|
|
{
|
|
|
|
meta_wayland_pointer_set_current (pointer, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_pointer_set_current (MetaWaylandPointer *pointer,
|
|
|
|
MetaWaylandSurface *surface)
|
|
|
|
{
|
|
|
|
if (pointer->current)
|
|
|
|
{
|
2019-11-15 19:25:52 -05:00
|
|
|
g_clear_signal_handler (&pointer->current_surface_destroyed_handler_id,
|
|
|
|
pointer->current);
|
2017-05-31 05:27:52 -04:00
|
|
|
pointer->current = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (surface)
|
|
|
|
{
|
|
|
|
pointer->current = surface;
|
|
|
|
pointer->current_surface_destroyed_handler_id =
|
|
|
|
g_signal_connect (surface, "destroy",
|
|
|
|
G_CALLBACK (current_surface_destroyed),
|
|
|
|
pointer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-17 18:16:49 -04:00
|
|
|
static void
|
|
|
|
repick_for_event (MetaWaylandPointer *pointer,
|
|
|
|
const ClutterEvent *for_event)
|
|
|
|
{
|
2015-02-06 12:44:08 -05:00
|
|
|
ClutterActor *actor;
|
2017-05-31 05:27:52 -04:00
|
|
|
MetaWaylandSurface *surface;
|
2014-04-17 18:16:49 -04:00
|
|
|
|
2020-12-22 11:41:09 -05:00
|
|
|
if (clutter_event_type (for_event) == CLUTTER_LEAVE)
|
2020-12-22 11:24:31 -05:00
|
|
|
actor = clutter_event_get_related (for_event);
|
2014-04-17 18:16:49 -04:00
|
|
|
else
|
2020-12-22 11:41:09 -05:00
|
|
|
actor = clutter_event_get_source (for_event);
|
2014-04-17 18:16:49 -04:00
|
|
|
|
2014-04-18 18:51:17 -04:00
|
|
|
if (META_IS_SURFACE_ACTOR_WAYLAND (actor))
|
2017-05-31 05:27:52 -04:00
|
|
|
{
|
|
|
|
MetaSurfaceActorWayland *actor_wayland =
|
|
|
|
META_SURFACE_ACTOR_WAYLAND (actor);
|
|
|
|
|
|
|
|
surface = meta_surface_actor_wayland_get_surface (actor_wayland);
|
|
|
|
}
|
2014-04-18 18:46:15 -04:00
|
|
|
else
|
2017-05-31 05:27:52 -04:00
|
|
|
{
|
|
|
|
surface = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
meta_wayland_pointer_set_current (pointer, surface);
|
2014-04-18 18:38:20 -04:00
|
|
|
|
2014-04-18 18:53:38 -04:00
|
|
|
sync_focus_surface (pointer);
|
2014-11-22 20:06:21 -05:00
|
|
|
meta_wayland_pointer_update_cursor_surface (pointer);
|
2014-04-17 18:16:49 -04:00
|
|
|
}
|
|
|
|
|
2014-04-20 10:59:49 -04:00
|
|
|
void
|
|
|
|
meta_wayland_pointer_update (MetaWaylandPointer *pointer,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
2020-12-28 13:06:27 -05:00
|
|
|
if ((event->type == CLUTTER_MOTION ||
|
|
|
|
event->type == CLUTTER_ENTER ||
|
2020-12-28 12:38:51 -05:00
|
|
|
event->type == CLUTTER_LEAVE) &&
|
|
|
|
!clutter_event_get_event_sequence (event))
|
2020-12-23 06:33:00 -05:00
|
|
|
repick_for_event (pointer, event);
|
2014-04-20 10:59:49 -04:00
|
|
|
|
2017-07-24 11:29:37 -04:00
|
|
|
if (event->type == CLUTTER_MOTION ||
|
|
|
|
event->type == CLUTTER_BUTTON_PRESS ||
|
|
|
|
event->type == CLUTTER_BUTTON_RELEASE)
|
|
|
|
{
|
|
|
|
pointer->button_count = count_buttons (event);
|
|
|
|
}
|
2014-04-20 10:59:49 -04:00
|
|
|
}
|
|
|
|
|
2014-04-17 18:16:49 -04:00
|
|
|
static void
|
|
|
|
notify_motion (MetaWaylandPointer *pointer,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
pointer->grab->interface->motion (pointer->grab, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_motion_event (MetaWaylandPointer *pointer,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
notify_motion (pointer, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_button_event (MetaWaylandPointer *pointer,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
gboolean implicit_grab;
|
|
|
|
|
|
|
|
implicit_grab = (event->type == CLUTTER_BUTTON_PRESS) && (pointer->button_count == 1);
|
|
|
|
if (implicit_grab)
|
|
|
|
{
|
|
|
|
pointer->grab_button = clutter_event_get_button (event);
|
|
|
|
pointer->grab_time = clutter_event_get_time (event);
|
2014-04-18 10:27:48 -04:00
|
|
|
clutter_event_get_coords (event, &pointer->grab_x, &pointer->grab_y);
|
2014-04-17 18:16:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pointer->grab->interface->button (pointer->grab, event);
|
|
|
|
|
|
|
|
if (implicit_grab)
|
2016-09-12 11:20:36 -04:00
|
|
|
{
|
|
|
|
MetaWaylandSeat *seat = meta_wayland_pointer_get_seat (pointer);
|
|
|
|
|
|
|
|
pointer->grab_serial = wl_display_get_serial (seat->wl_display);
|
|
|
|
}
|
2014-04-17 18:16:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_scroll_event (MetaWaylandPointer *pointer,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
struct wl_resource *resource;
|
|
|
|
wl_fixed_t x_value = 0, y_value = 0;
|
2015-09-08 08:32:50 -04:00
|
|
|
int x_discrete = 0, y_discrete = 0;
|
|
|
|
enum wl_pointer_axis_source source = -1;
|
2021-09-20 13:53:39 -04:00
|
|
|
MetaWaylandPointerClient *client;
|
2014-04-17 18:16:49 -04:00
|
|
|
|
|
|
|
if (clutter_event_is_pointer_emulated (event))
|
|
|
|
return;
|
|
|
|
|
2021-09-20 13:53:39 -04:00
|
|
|
client = pointer->focus_client;
|
|
|
|
if (!client)
|
|
|
|
return;
|
|
|
|
|
2015-09-08 08:32:50 -04:00
|
|
|
switch (event->scroll.scroll_source)
|
|
|
|
{
|
|
|
|
case CLUTTER_SCROLL_SOURCE_WHEEL:
|
|
|
|
source = WL_POINTER_AXIS_SOURCE_WHEEL;
|
|
|
|
break;
|
|
|
|
case CLUTTER_SCROLL_SOURCE_FINGER:
|
|
|
|
source = WL_POINTER_AXIS_SOURCE_FINGER;
|
|
|
|
break;
|
|
|
|
case CLUTTER_SCROLL_SOURCE_CONTINUOUS:
|
|
|
|
source = WL_POINTER_AXIS_SOURCE_CONTINUOUS;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
source = WL_POINTER_AXIS_SOURCE_WHEEL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-04-17 18:16:49 -04:00
|
|
|
switch (clutter_event_get_scroll_direction (event))
|
|
|
|
{
|
|
|
|
case CLUTTER_SCROLL_UP:
|
|
|
|
y_value = -DEFAULT_AXIS_STEP_DISTANCE;
|
2015-09-08 08:32:50 -04:00
|
|
|
y_discrete = -1;
|
2014-04-17 18:16:49 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CLUTTER_SCROLL_DOWN:
|
|
|
|
y_value = DEFAULT_AXIS_STEP_DISTANCE;
|
2015-09-08 08:32:50 -04:00
|
|
|
y_discrete = 1;
|
2014-04-17 18:16:49 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CLUTTER_SCROLL_LEFT:
|
|
|
|
x_value = -DEFAULT_AXIS_STEP_DISTANCE;
|
2015-09-08 08:32:50 -04:00
|
|
|
x_discrete = -1;
|
2014-04-17 18:16:49 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CLUTTER_SCROLL_RIGHT:
|
|
|
|
x_value = DEFAULT_AXIS_STEP_DISTANCE;
|
2015-09-08 08:32:50 -04:00
|
|
|
x_discrete = 1;
|
2014-04-17 18:16:49 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CLUTTER_SCROLL_SMOOTH:
|
|
|
|
{
|
|
|
|
double dx, dy;
|
2014-05-03 15:06:08 -04:00
|
|
|
/* Clutter smooth scroll events are in discrete steps (1 step = 1.0 long
|
|
|
|
* vector along one axis). To convert to smooth scroll events that are
|
|
|
|
* in pointer motion event space, multiply the vector with the 10. */
|
|
|
|
const double factor = 10.0;
|
2014-04-17 18:16:49 -04:00
|
|
|
clutter_event_get_scroll_delta (event, &dx, &dy);
|
2014-05-03 15:06:08 -04:00
|
|
|
x_value = wl_fixed_from_double (dx) * factor;
|
|
|
|
y_value = wl_fixed_from_double (dy) * factor;
|
2014-04-17 18:16:49 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-09-20 13:53:39 -04:00
|
|
|
wl_resource_for_each (resource, &client->pointer_resources)
|
2014-04-17 18:16:49 -04:00
|
|
|
{
|
2021-09-20 13:53:39 -04:00
|
|
|
int client_version = wl_resource_get_version (resource);
|
|
|
|
|
|
|
|
if (client_version >= WL_POINTER_AXIS_SOURCE_SINCE_VERSION)
|
|
|
|
wl_pointer_send_axis_source (resource, source);
|
|
|
|
|
|
|
|
/* X axis */
|
|
|
|
if (x_discrete != 0 &&
|
|
|
|
client_version >= WL_POINTER_AXIS_DISCRETE_SINCE_VERSION)
|
|
|
|
wl_pointer_send_axis_discrete (resource,
|
|
|
|
WL_POINTER_AXIS_HORIZONTAL_SCROLL,
|
|
|
|
x_discrete);
|
|
|
|
|
|
|
|
if (x_value)
|
|
|
|
wl_pointer_send_axis (resource, clutter_event_get_time (event),
|
|
|
|
WL_POINTER_AXIS_HORIZONTAL_SCROLL, x_value);
|
|
|
|
|
|
|
|
if ((event->scroll.finish_flags & CLUTTER_SCROLL_FINISHED_HORIZONTAL) &&
|
|
|
|
client_version >= WL_POINTER_AXIS_STOP_SINCE_VERSION)
|
|
|
|
wl_pointer_send_axis_stop (resource,
|
|
|
|
clutter_event_get_time (event),
|
|
|
|
WL_POINTER_AXIS_HORIZONTAL_SCROLL);
|
|
|
|
/* Y axis */
|
|
|
|
if (y_discrete != 0 &&
|
|
|
|
client_version >= WL_POINTER_AXIS_DISCRETE_SINCE_VERSION)
|
|
|
|
wl_pointer_send_axis_discrete (resource,
|
|
|
|
WL_POINTER_AXIS_VERTICAL_SCROLL,
|
|
|
|
y_discrete);
|
|
|
|
|
|
|
|
if (y_value)
|
|
|
|
wl_pointer_send_axis (resource, clutter_event_get_time (event),
|
|
|
|
WL_POINTER_AXIS_VERTICAL_SCROLL, y_value);
|
|
|
|
|
|
|
|
if ((event->scroll.finish_flags & CLUTTER_SCROLL_FINISHED_VERTICAL) &&
|
|
|
|
client_version >= WL_POINTER_AXIS_STOP_SINCE_VERSION)
|
|
|
|
wl_pointer_send_axis_stop (resource,
|
|
|
|
clutter_event_get_time (event),
|
|
|
|
WL_POINTER_AXIS_VERTICAL_SCROLL);
|
2014-04-17 18:16:49 -04:00
|
|
|
}
|
2021-09-20 13:53:39 -04:00
|
|
|
|
|
|
|
meta_wayland_pointer_broadcast_frame (pointer);
|
2014-04-17 18:16:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
meta_wayland_pointer_handle_event (MetaWaylandPointer *pointer,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
switch (event->type)
|
|
|
|
{
|
|
|
|
case CLUTTER_MOTION:
|
|
|
|
handle_motion_event (pointer, event);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CLUTTER_BUTTON_PRESS:
|
|
|
|
case CLUTTER_BUTTON_RELEASE:
|
|
|
|
handle_button_event (pointer, event);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CLUTTER_SCROLL:
|
|
|
|
handle_scroll_event (pointer, event);
|
|
|
|
break;
|
|
|
|
|
2015-07-22 10:43:25 -04:00
|
|
|
case CLUTTER_TOUCHPAD_SWIPE:
|
|
|
|
meta_wayland_pointer_gesture_swipe_handle_event (pointer, event);
|
|
|
|
break;
|
|
|
|
|
2015-07-22 10:46:55 -04:00
|
|
|
case CLUTTER_TOUCHPAD_PINCH:
|
|
|
|
meta_wayland_pointer_gesture_pinch_handle_event (pointer, event);
|
|
|
|
break;
|
|
|
|
|
2021-04-18 14:24:52 -04:00
|
|
|
case CLUTTER_TOUCHPAD_HOLD:
|
|
|
|
meta_wayland_pointer_gesture_hold_handle_event (pointer, event);
|
|
|
|
break;
|
|
|
|
|
2014-04-17 18:16:49 -04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-09-05 19:29:24 -04:00
|
|
|
static void
|
2015-09-16 23:13:51 -04:00
|
|
|
meta_wayland_pointer_send_enter (MetaWaylandPointer *pointer,
|
|
|
|
struct wl_resource *pointer_resource,
|
|
|
|
uint32_t serial,
|
|
|
|
MetaWaylandSurface *surface)
|
2014-09-05 19:29:24 -04:00
|
|
|
{
|
|
|
|
wl_fixed_t sx, sy;
|
|
|
|
|
2015-09-16 23:13:51 -04:00
|
|
|
meta_wayland_pointer_get_relative_coordinates (pointer, surface, &sx, &sy);
|
|
|
|
wl_pointer_send_enter (pointer_resource,
|
|
|
|
serial,
|
|
|
|
surface->resource,
|
|
|
|
sx, sy);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_pointer_send_leave (MetaWaylandPointer *pointer,
|
|
|
|
struct wl_resource *pointer_resource,
|
|
|
|
uint32_t serial,
|
|
|
|
MetaWaylandSurface *surface)
|
|
|
|
{
|
|
|
|
wl_pointer_send_leave (pointer_resource, serial, surface->resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_pointer_broadcast_enter (MetaWaylandPointer *pointer,
|
|
|
|
uint32_t serial,
|
|
|
|
MetaWaylandSurface *surface)
|
|
|
|
{
|
|
|
|
struct wl_resource *pointer_resource;
|
|
|
|
|
|
|
|
wl_resource_for_each (pointer_resource,
|
|
|
|
&pointer->focus_client->pointer_resources)
|
|
|
|
meta_wayland_pointer_send_enter (pointer, pointer_resource,
|
|
|
|
serial, surface);
|
2015-09-08 08:32:50 -04:00
|
|
|
|
2016-01-19 05:50:27 -05:00
|
|
|
meta_wayland_pointer_broadcast_frame (pointer);
|
2015-09-16 23:13:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_pointer_broadcast_leave (MetaWaylandPointer *pointer,
|
|
|
|
uint32_t serial,
|
|
|
|
MetaWaylandSurface *surface)
|
|
|
|
{
|
|
|
|
struct wl_resource *pointer_resource;
|
|
|
|
|
|
|
|
wl_resource_for_each (pointer_resource,
|
|
|
|
&pointer->focus_client->pointer_resources)
|
|
|
|
meta_wayland_pointer_send_leave (pointer, pointer_resource,
|
|
|
|
serial, surface);
|
2015-09-08 08:32:50 -04:00
|
|
|
|
2016-01-19 05:50:27 -05:00
|
|
|
meta_wayland_pointer_broadcast_frame (pointer);
|
2014-09-05 19:29:24 -04:00
|
|
|
}
|
|
|
|
|
2017-05-31 05:24:07 -04:00
|
|
|
static void
|
|
|
|
focus_surface_destroyed (MetaWaylandSurface *surface,
|
|
|
|
MetaWaylandPointer *pointer)
|
|
|
|
{
|
|
|
|
meta_wayland_pointer_set_focus (pointer, NULL);
|
|
|
|
}
|
|
|
|
|
2021-09-03 17:49:46 -04:00
|
|
|
static void
|
|
|
|
focus_surface_alive_notify (MetaWindow *window,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
MetaWaylandPointer *pointer)
|
|
|
|
{
|
|
|
|
if (!meta_window_get_alive (window))
|
|
|
|
meta_wayland_pointer_set_focus (pointer, NULL);
|
|
|
|
sync_focus_surface (pointer);
|
|
|
|
}
|
|
|
|
|
2013-05-03 13:51:22 -04:00
|
|
|
void
|
|
|
|
meta_wayland_pointer_set_focus (MetaWaylandPointer *pointer,
|
2013-09-11 08:06:05 -04:00
|
|
|
MetaWaylandSurface *surface)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
2016-09-21 00:30:09 -04:00
|
|
|
MetaWaylandInputDevice *input_device = META_WAYLAND_INPUT_DEVICE (pointer);
|
2019-09-12 13:17:06 -04:00
|
|
|
MetaBackend *backend = meta_get_backend ();
|
|
|
|
MetaCursorTracker *cursor_tracker = meta_backend_get_cursor_tracker (backend);
|
2020-02-19 15:19:19 -05:00
|
|
|
ClutterBackend *clutter_backend = clutter_get_default_backend ();
|
|
|
|
ClutterSeat *clutter_seat = clutter_backend_get_default_seat (clutter_backend);
|
2021-09-03 17:49:46 -04:00
|
|
|
MetaWindow *toplevel_window;
|
2019-09-12 13:17:06 -04:00
|
|
|
|
|
|
|
g_return_if_fail (meta_cursor_tracker_get_pointer_visible (cursor_tracker) ||
|
2020-02-19 15:19:19 -05:00
|
|
|
clutter_seat_is_unfocus_inhibited (clutter_seat) ||
|
|
|
|
surface == NULL);
|
2014-09-05 21:00:09 -04:00
|
|
|
|
2014-09-05 19:29:24 -04:00
|
|
|
if (pointer->focus_surface == surface)
|
2013-11-19 20:20:13 -05:00
|
|
|
return;
|
|
|
|
|
2014-09-16 20:55:27 -04:00
|
|
|
if (pointer->focus_surface != NULL)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
2015-08-09 09:24:16 -04:00
|
|
|
uint32_t serial;
|
2014-04-16 15:11:10 -04:00
|
|
|
|
2016-09-21 00:30:09 -04:00
|
|
|
serial = meta_wayland_input_device_next_serial (input_device);
|
2014-01-31 18:18:59 -05:00
|
|
|
|
2015-08-09 09:24:16 -04:00
|
|
|
if (pointer->focus_client)
|
|
|
|
{
|
2015-09-16 23:13:51 -04:00
|
|
|
meta_wayland_pointer_broadcast_leave (pointer,
|
|
|
|
serial,
|
|
|
|
pointer->focus_surface);
|
2015-08-09 09:24:16 -04:00
|
|
|
pointer->focus_client = NULL;
|
2014-02-18 23:16:54 -05:00
|
|
|
}
|
2014-02-19 07:56:56 -05:00
|
|
|
|
2021-09-03 17:49:46 -04:00
|
|
|
toplevel_window = surface_get_effective_window (pointer->focus_surface);
|
|
|
|
if (toplevel_window)
|
|
|
|
{
|
|
|
|
g_clear_signal_handler (&pointer->focus_surface_alive_notify_id,
|
|
|
|
toplevel_window);
|
|
|
|
}
|
|
|
|
|
2019-11-15 19:25:52 -05:00
|
|
|
g_clear_signal_handler (&pointer->focus_surface_destroyed_handler_id,
|
|
|
|
pointer->focus_surface);
|
2014-02-19 07:56:56 -05:00
|
|
|
pointer->focus_surface = NULL;
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
2014-02-18 23:16:54 -05:00
|
|
|
if (surface != NULL)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
2020-12-22 11:33:03 -05:00
|
|
|
ClutterStage *stage = CLUTTER_STAGE (meta_backend_get_stage (backend));
|
2015-08-09 09:24:16 -04:00
|
|
|
struct wl_client *client = wl_resource_get_client (surface->resource);
|
2019-02-20 09:53:44 -05:00
|
|
|
graphene_point_t pos;
|
2019-10-09 03:37:04 -04:00
|
|
|
MetaWindow *focus_window;
|
2014-04-16 15:11:10 -04:00
|
|
|
|
2014-02-18 23:16:54 -05:00
|
|
|
pointer->focus_surface = surface;
|
2017-05-31 05:24:07 -04:00
|
|
|
|
|
|
|
pointer->focus_surface_destroyed_handler_id =
|
|
|
|
g_signal_connect_after (pointer->focus_surface, "destroy",
|
|
|
|
G_CALLBACK (focus_surface_destroyed),
|
|
|
|
pointer);
|
2013-09-11 08:06:05 -04:00
|
|
|
|
2020-12-22 11:33:03 -05:00
|
|
|
clutter_stage_get_device_coords (stage, pointer->device, NULL, &pos);
|
2014-04-18 10:27:48 -04:00
|
|
|
|
2019-10-09 03:37:04 -04:00
|
|
|
focus_window = meta_wayland_surface_get_window (pointer->focus_surface);
|
|
|
|
if (focus_window)
|
|
|
|
meta_window_handle_enter (focus_window,
|
2014-10-20 12:41:22 -04:00
|
|
|
/* XXX -- can we reliably get a timestamp for setting focus? */
|
|
|
|
clutter_get_current_event_time (),
|
|
|
|
pos.x, pos.y);
|
2014-04-16 14:47:06 -04:00
|
|
|
|
2021-09-03 17:49:46 -04:00
|
|
|
toplevel_window = surface_get_effective_window (pointer->focus_surface);
|
|
|
|
if (toplevel_window)
|
|
|
|
{
|
|
|
|
pointer->focus_surface_alive_notify_id =
|
|
|
|
g_signal_connect (toplevel_window, "notify::is-alive",
|
|
|
|
G_CALLBACK (focus_surface_alive_notify),
|
|
|
|
pointer);
|
|
|
|
}
|
|
|
|
|
2015-08-09 09:24:16 -04:00
|
|
|
pointer->focus_client =
|
|
|
|
meta_wayland_pointer_get_pointer_client (pointer, client);
|
|
|
|
if (pointer->focus_client)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
2016-09-21 00:30:09 -04:00
|
|
|
pointer->focus_serial =
|
|
|
|
meta_wayland_input_device_next_serial (input_device);
|
2015-09-16 23:13:51 -04:00
|
|
|
meta_wayland_pointer_broadcast_enter (pointer,
|
|
|
|
pointer->focus_serial,
|
|
|
|
pointer->focus_surface);
|
2014-02-18 23:16:54 -05:00
|
|
|
}
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
2014-10-06 18:41:13 -04:00
|
|
|
|
|
|
|
meta_wayland_pointer_update_cursor_surface (pointer);
|
2016-04-01 09:07:59 -04:00
|
|
|
|
|
|
|
g_signal_emit (pointer, signals[FOCUS_SURFACE_CHANGED], 0);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_wayland_pointer_start_grab (MetaWaylandPointer *pointer,
|
|
|
|
MetaWaylandPointerGrab *grab)
|
|
|
|
{
|
|
|
|
const MetaWaylandPointerGrabInterface *interface;
|
|
|
|
|
2016-09-21 02:33:47 -04:00
|
|
|
meta_wayland_pointer_cancel_grab (pointer);
|
|
|
|
|
2013-05-03 13:51:22 -04:00
|
|
|
pointer->grab = grab;
|
|
|
|
interface = pointer->grab->interface;
|
|
|
|
grab->pointer = pointer;
|
|
|
|
|
2016-03-09 10:37:41 -05:00
|
|
|
interface->focus (pointer->grab, pointer->current);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
2016-09-21 02:30:15 -04:00
|
|
|
static void
|
|
|
|
meta_wayland_pointer_reset_grab (MetaWaylandPointer *pointer)
|
|
|
|
{
|
|
|
|
pointer->grab = &pointer->default_grab;
|
|
|
|
}
|
|
|
|
|
2013-05-03 13:51:22 -04:00
|
|
|
void
|
|
|
|
meta_wayland_pointer_end_grab (MetaWaylandPointer *pointer)
|
|
|
|
{
|
|
|
|
const MetaWaylandPointerGrabInterface *interface;
|
|
|
|
|
|
|
|
pointer->grab = &pointer->default_grab;
|
|
|
|
interface = pointer->grab->interface;
|
2014-03-16 11:50:38 -04:00
|
|
|
interface->focus (pointer->grab, pointer->current);
|
2014-10-06 19:19:19 -04:00
|
|
|
|
|
|
|
meta_wayland_pointer_update_cursor_surface (pointer);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
2016-09-21 02:33:47 -04:00
|
|
|
static void
|
|
|
|
meta_wayland_pointer_cancel_grab (MetaWaylandPointer *pointer)
|
|
|
|
{
|
|
|
|
if (pointer->grab->interface->cancel)
|
|
|
|
pointer->grab->interface->cancel (pointer->grab);
|
|
|
|
}
|
|
|
|
|
2015-02-11 04:34:15 -05:00
|
|
|
void
|
2013-09-10 09:53:31 -04:00
|
|
|
meta_wayland_pointer_end_popup_grab (MetaWaylandPointer *pointer)
|
|
|
|
{
|
2015-02-11 04:34:15 -05:00
|
|
|
MetaWaylandPopupGrab *popup_grab = (MetaWaylandPopupGrab*)pointer->grab;
|
2014-03-10 15:00:59 -04:00
|
|
|
|
2015-02-11 04:34:15 -05:00
|
|
|
meta_wayland_popup_grab_destroy (popup_grab);
|
2013-09-10 09:53:31 -04:00
|
|
|
}
|
|
|
|
|
2015-02-11 22:13:55 -05:00
|
|
|
MetaWaylandPopup *
|
2016-01-21 04:01:08 -05:00
|
|
|
meta_wayland_pointer_start_popup_grab (MetaWaylandPointer *pointer,
|
|
|
|
MetaWaylandPopupSurface *popup_surface)
|
2013-09-10 09:53:31 -04:00
|
|
|
{
|
2013-09-11 08:06:05 -04:00
|
|
|
MetaWaylandPopupGrab *grab;
|
2013-09-10 09:53:31 -04:00
|
|
|
|
2015-02-11 04:34:15 -05:00
|
|
|
if (pointer->grab != &pointer->default_grab &&
|
|
|
|
!meta_wayland_pointer_grab_is_popup_grab (pointer->grab))
|
2015-02-11 22:13:55 -05:00
|
|
|
return NULL;
|
2013-09-11 08:53:48 -04:00
|
|
|
|
|
|
|
if (pointer->grab == &pointer->default_grab)
|
2016-01-21 04:01:08 -05:00
|
|
|
grab = meta_wayland_popup_grab_create (pointer, popup_surface);
|
2013-09-11 08:53:48 -04:00
|
|
|
else
|
|
|
|
grab = (MetaWaylandPopupGrab*)pointer->grab;
|
2013-09-10 09:53:31 -04:00
|
|
|
|
2016-01-21 04:01:08 -05:00
|
|
|
return meta_wayland_popup_create (popup_surface, grab);
|
2013-09-10 09:53:31 -04:00
|
|
|
}
|
2013-09-11 08:06:05 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
meta_wayland_pointer_get_relative_coordinates (MetaWaylandPointer *pointer,
|
|
|
|
MetaWaylandSurface *surface,
|
|
|
|
wl_fixed_t *sx,
|
|
|
|
wl_fixed_t *sy)
|
|
|
|
{
|
2020-12-22 11:33:03 -05:00
|
|
|
MetaBackend *backend = meta_get_backend ();
|
|
|
|
ClutterStage *stage = CLUTTER_STAGE (meta_backend_get_stage (backend));
|
2013-09-11 08:06:05 -04:00
|
|
|
float xf = 0.0f, yf = 0.0f;
|
2019-02-20 09:53:44 -05:00
|
|
|
graphene_point_t pos;
|
2013-09-11 08:06:05 -04:00
|
|
|
|
2020-12-22 11:33:03 -05:00
|
|
|
clutter_stage_get_device_coords (stage, pointer->device, NULL, &pos);
|
2015-06-16 22:16:02 -04:00
|
|
|
meta_wayland_surface_get_relative_coordinates (surface, pos.x, pos.y, &xf, &yf);
|
2013-09-11 08:06:05 -04:00
|
|
|
|
2015-06-16 22:16:02 -04:00
|
|
|
*sx = wl_fixed_from_double (xf);
|
|
|
|
*sy = wl_fixed_from_double (yf);
|
2013-09-11 08:06:05 -04:00
|
|
|
}
|
2014-03-16 15:32:52 -04:00
|
|
|
|
2015-10-21 10:36:44 -04:00
|
|
|
void
|
2014-04-17 16:54:30 -04:00
|
|
|
meta_wayland_pointer_update_cursor_surface (MetaWaylandPointer *pointer)
|
|
|
|
{
|
2016-11-29 07:30:22 -05:00
|
|
|
MetaBackend *backend = meta_get_backend ();
|
|
|
|
MetaCursorTracker *cursor_tracker = meta_backend_get_cursor_tracker (backend);
|
2014-04-17 16:54:30 -04:00
|
|
|
|
2014-10-06 18:41:13 -04:00
|
|
|
if (pointer->current)
|
2014-04-17 16:54:30 -04:00
|
|
|
{
|
2015-07-17 11:16:39 -04:00
|
|
|
MetaCursorSprite *cursor_sprite = NULL;
|
2014-04-17 16:54:30 -04:00
|
|
|
|
2015-07-17 11:16:39 -04:00
|
|
|
if (pointer->cursor_surface)
|
2014-10-06 18:41:13 -04:00
|
|
|
{
|
2018-04-19 15:51:31 -04:00
|
|
|
MetaWaylandCursorSurface *cursor_surface =
|
|
|
|
META_WAYLAND_CURSOR_SURFACE (pointer->cursor_surface->role);
|
2015-07-17 11:16:39 -04:00
|
|
|
|
2018-04-19 15:51:31 -04:00
|
|
|
cursor_sprite = meta_wayland_cursor_surface_get_sprite (cursor_surface);
|
2014-10-06 18:41:13 -04:00
|
|
|
}
|
2014-04-17 16:54:30 -04:00
|
|
|
|
2015-07-17 03:29:42 -04:00
|
|
|
meta_cursor_tracker_set_window_cursor (cursor_tracker, cursor_sprite);
|
2014-10-06 18:41:13 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-07-17 03:29:42 -04:00
|
|
|
meta_cursor_tracker_unset_window_cursor (cursor_tracker);
|
2014-10-06 18:41:13 -04:00
|
|
|
}
|
2014-04-17 16:54:30 -04:00
|
|
|
}
|
2014-04-17 17:00:59 -04:00
|
|
|
|
2015-07-17 11:16:39 -04:00
|
|
|
static void
|
2015-10-21 10:36:44 -04:00
|
|
|
ensure_update_cursor_surface (MetaWaylandPointer *pointer,
|
|
|
|
MetaWaylandSurface *surface)
|
2015-07-17 11:16:39 -04:00
|
|
|
{
|
2015-10-21 10:36:44 -04:00
|
|
|
if (pointer->cursor_surface != surface)
|
|
|
|
return;
|
2015-07-17 11:16:39 -04:00
|
|
|
|
2015-10-21 10:36:44 -04:00
|
|
|
pointer->cursor_surface = NULL;
|
|
|
|
meta_wayland_pointer_update_cursor_surface (pointer);
|
2015-07-17 11:16:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_pointer_set_cursor_surface (MetaWaylandPointer *pointer,
|
|
|
|
MetaWaylandSurface *cursor_surface)
|
|
|
|
{
|
2015-07-17 11:28:31 -04:00
|
|
|
MetaWaylandSurface *prev_cursor_surface;
|
|
|
|
|
|
|
|
prev_cursor_surface = pointer->cursor_surface;
|
2015-10-21 10:36:44 -04:00
|
|
|
|
|
|
|
if (prev_cursor_surface == cursor_surface)
|
|
|
|
return;
|
|
|
|
|
2015-07-17 11:16:39 -04:00
|
|
|
pointer->cursor_surface = cursor_surface;
|
2015-07-17 11:28:31 -04:00
|
|
|
|
2015-10-21 10:36:44 -04:00
|
|
|
if (prev_cursor_surface)
|
|
|
|
{
|
|
|
|
meta_wayland_surface_update_outputs (prev_cursor_surface);
|
2019-11-15 19:25:52 -05:00
|
|
|
g_clear_signal_handler (&pointer->cursor_surface_destroy_id,
|
|
|
|
prev_cursor_surface);
|
2015-10-21 10:36:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cursor_surface)
|
2015-07-17 11:28:31 -04:00
|
|
|
{
|
2015-10-21 10:36:44 -04:00
|
|
|
pointer->cursor_surface_destroy_id =
|
|
|
|
g_signal_connect_swapped (cursor_surface, "destroy",
|
|
|
|
G_CALLBACK (ensure_update_cursor_surface),
|
|
|
|
pointer);
|
2015-07-17 11:28:31 -04:00
|
|
|
}
|
2015-10-21 10:36:44 -04:00
|
|
|
|
|
|
|
meta_wayland_pointer_update_cursor_surface (pointer);
|
2015-07-17 11:16:39 -04:00
|
|
|
}
|
|
|
|
|
2014-04-17 17:16:17 -04:00
|
|
|
static void
|
2014-04-17 18:16:49 -04:00
|
|
|
pointer_set_cursor (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t serial,
|
|
|
|
struct wl_resource *surface_resource,
|
2015-07-17 11:16:39 -04:00
|
|
|
int32_t hot_x, int32_t hot_y)
|
2014-04-17 18:16:49 -04:00
|
|
|
{
|
2021-04-12 08:54:15 -04:00
|
|
|
MetaWaylandPointer *pointer;
|
2014-04-17 18:16:49 -04:00
|
|
|
MetaWaylandSurface *surface;
|
|
|
|
|
2021-04-12 08:54:15 -04:00
|
|
|
pointer = wl_resource_get_user_data (resource);
|
|
|
|
if (!pointer)
|
|
|
|
return;
|
|
|
|
|
2014-04-17 18:16:49 -04:00
|
|
|
surface = (surface_resource ? wl_resource_get_user_data (surface_resource) : NULL);
|
|
|
|
|
|
|
|
if (pointer->focus_surface == NULL)
|
|
|
|
return;
|
|
|
|
if (wl_resource_get_client (pointer->focus_surface->resource) != client)
|
|
|
|
return;
|
|
|
|
if (pointer->focus_serial - serial > G_MAXUINT32 / 2)
|
|
|
|
return;
|
|
|
|
|
2015-07-08 04:14:00 -04:00
|
|
|
if (surface &&
|
|
|
|
!meta_wayland_surface_assign_role (surface,
|
2018-04-19 15:51:31 -04:00
|
|
|
META_TYPE_WAYLAND_CURSOR_SURFACE,
|
2016-01-28 04:14:06 -05:00
|
|
|
NULL))
|
2015-02-06 03:12:21 -05:00
|
|
|
{
|
2015-07-08 04:14:00 -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;
|
2015-02-06 03:12:21 -05:00
|
|
|
}
|
|
|
|
|
2015-07-17 11:16:39 -04:00
|
|
|
if (surface)
|
|
|
|
{
|
2020-07-10 17:31:26 -04:00
|
|
|
ClutterBackend *clutter_backend = clutter_get_default_backend ();
|
|
|
|
ClutterSeat *clutter_seat =
|
|
|
|
clutter_backend_get_default_seat (clutter_backend);
|
|
|
|
ClutterInputDevice *device = clutter_seat_get_pointer (clutter_seat);
|
2015-10-21 10:36:44 -04:00
|
|
|
MetaCursorRenderer *cursor_renderer =
|
2020-07-10 17:31:26 -04:00
|
|
|
meta_backend_get_cursor_renderer_for_device (meta_get_backend (),
|
|
|
|
device);
|
2018-04-19 15:51:31 -04:00
|
|
|
MetaWaylandCursorSurface *cursor_surface;
|
2021-07-05 09:50:06 -04:00
|
|
|
MetaCursorSprite *cursor_sprite;
|
2015-07-17 11:16:39 -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,
|
|
|
|
cursor_renderer);
|
|
|
|
meta_wayland_cursor_surface_set_hotspot (cursor_surface,
|
|
|
|
hot_x, hot_y);
|
2021-07-05 09:50:06 -04:00
|
|
|
|
|
|
|
cursor_sprite = meta_wayland_cursor_surface_get_sprite (cursor_surface);
|
|
|
|
meta_cursor_sprite_invalidate (cursor_sprite);
|
2015-07-17 11:16:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
meta_wayland_pointer_set_cursor_surface (pointer, surface);
|
2014-04-17 18:16:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-04-17 17:16:17 -04:00
|
|
|
pointer_release (struct wl_client *client,
|
|
|
|
struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
wl_resource_destroy (resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_pointer_interface pointer_interface = {
|
|
|
|
pointer_set_cursor,
|
|
|
|
pointer_release,
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_wayland_pointer_create_new_resource (MetaWaylandPointer *pointer,
|
|
|
|
struct wl_client *client,
|
|
|
|
struct wl_resource *seat_resource,
|
|
|
|
uint32_t id)
|
|
|
|
{
|
2016-09-21 01:50:55 -04:00
|
|
|
struct wl_resource *resource;
|
2015-08-09 09:24:16 -04:00
|
|
|
MetaWaylandPointerClient *pointer_client;
|
2014-04-17 17:16:17 -04:00
|
|
|
|
2016-09-21 01:50:55 -04:00
|
|
|
resource = wl_resource_create (client, &wl_pointer_interface,
|
|
|
|
wl_resource_get_version (seat_resource), id);
|
|
|
|
wl_resource_set_implementation (resource, &pointer_interface, pointer,
|
2015-08-09 09:24:16 -04:00
|
|
|
meta_wayland_pointer_unbind_pointer_client_resource);
|
2014-04-17 17:16:17 -04:00
|
|
|
|
2015-08-09 09:24:16 -04:00
|
|
|
pointer_client = meta_wayland_pointer_ensure_pointer_client (pointer, client);
|
|
|
|
|
|
|
|
wl_list_insert (&pointer_client->pointer_resources,
|
2016-09-21 01:50:55 -04:00
|
|
|
wl_resource_get_link (resource));
|
2015-08-09 09:24:16 -04:00
|
|
|
|
|
|
|
if (pointer->focus_client == pointer_client)
|
2016-01-19 05:51:36 -05:00
|
|
|
{
|
2016-09-21 01:50:55 -04:00
|
|
|
meta_wayland_pointer_send_enter (pointer, resource,
|
2016-01-19 05:51:36 -05:00
|
|
|
pointer->focus_serial,
|
|
|
|
pointer->focus_surface);
|
2016-09-21 01:50:55 -04:00
|
|
|
meta_wayland_pointer_send_frame (pointer, resource);
|
2016-01-19 05:51:36 -05:00
|
|
|
}
|
2014-04-17 17:00:59 -04:00
|
|
|
}
|
2014-05-22 10:57:02 -04:00
|
|
|
|
2017-06-02 00:41:56 -04:00
|
|
|
static gboolean
|
|
|
|
pointer_can_grab_surface (MetaWaylandPointer *pointer,
|
|
|
|
MetaWaylandSurface *surface)
|
|
|
|
{
|
2019-12-06 12:22:47 -05:00
|
|
|
MetaWaylandSurface *subsurface;
|
2017-06-02 00:41:56 -04:00
|
|
|
|
|
|
|
if (pointer->focus_surface == surface)
|
|
|
|
return TRUE;
|
|
|
|
|
2019-12-06 12:22:47 -05:00
|
|
|
META_WAYLAND_SURFACE_FOREACH_SUBSURFACE (surface, subsurface)
|
2017-06-02 00:41:56 -04:00
|
|
|
{
|
|
|
|
if (pointer_can_grab_surface (pointer, subsurface))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-05-22 10:57:02 -04:00
|
|
|
gboolean
|
|
|
|
meta_wayland_pointer_can_grab_surface (MetaWaylandPointer *pointer,
|
|
|
|
MetaWaylandSurface *surface,
|
|
|
|
uint32_t serial)
|
|
|
|
{
|
2016-04-04 12:07:42 -04:00
|
|
|
return (pointer->grab_serial == serial &&
|
2017-06-02 00:41:56 -04:00
|
|
|
pointer_can_grab_surface (pointer, surface));
|
2014-05-22 10:57:02 -04:00
|
|
|
}
|
2015-02-10 08:11:17 -05:00
|
|
|
|
|
|
|
gboolean
|
|
|
|
meta_wayland_pointer_can_popup (MetaWaylandPointer *pointer, uint32_t serial)
|
|
|
|
{
|
|
|
|
return pointer->grab_serial == serial;
|
|
|
|
}
|
2015-02-11 22:20:52 -05:00
|
|
|
|
|
|
|
MetaWaylandSurface *
|
|
|
|
meta_wayland_pointer_get_top_popup (MetaWaylandPointer *pointer)
|
|
|
|
{
|
|
|
|
MetaWaylandPopupGrab *grab;
|
|
|
|
|
|
|
|
if (!meta_wayland_pointer_grab_is_popup_grab (pointer->grab))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
grab = (MetaWaylandPopupGrab*)pointer->grab;
|
|
|
|
return meta_wayland_popup_grab_get_top_popup(grab);
|
|
|
|
}
|
2015-07-17 10:02:15 -04:00
|
|
|
|
2015-06-02 04:26:34 -04:00
|
|
|
static void
|
|
|
|
relative_pointer_destroy (struct wl_client *client,
|
|
|
|
struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
wl_resource_destroy (resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct zwp_relative_pointer_v1_interface relative_pointer_interface = {
|
|
|
|
relative_pointer_destroy
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
relative_pointer_manager_destroy (struct wl_client *client,
|
|
|
|
struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
wl_resource_destroy (resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
relative_pointer_manager_get_relative_pointer (struct wl_client *client,
|
2016-09-21 01:50:55 -04:00
|
|
|
struct wl_resource *manager_resource,
|
2015-06-02 04:26:34 -04:00
|
|
|
uint32_t id,
|
|
|
|
struct wl_resource *pointer_resource)
|
|
|
|
{
|
|
|
|
MetaWaylandPointer *pointer = wl_resource_get_user_data (pointer_resource);
|
2016-09-21 01:50:55 -04:00
|
|
|
struct wl_resource *resource;
|
2015-06-02 04:26:34 -04:00
|
|
|
MetaWaylandPointerClient *pointer_client;
|
|
|
|
|
2016-09-21 01:50:55 -04:00
|
|
|
resource = wl_resource_create (client, &zwp_relative_pointer_v1_interface,
|
|
|
|
wl_resource_get_version (manager_resource),
|
|
|
|
id);
|
|
|
|
if (!resource)
|
2015-06-02 04:26:34 -04:00
|
|
|
{
|
|
|
|
wl_client_post_no_memory (client);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-21 01:50:55 -04:00
|
|
|
wl_resource_set_implementation (resource, &relative_pointer_interface,
|
2015-06-02 04:26:34 -04:00
|
|
|
pointer,
|
|
|
|
meta_wayland_pointer_unbind_pointer_client_resource);
|
|
|
|
|
|
|
|
pointer_client = meta_wayland_pointer_ensure_pointer_client (pointer, client);
|
|
|
|
|
|
|
|
wl_list_insert (&pointer_client->relative_pointer_resources,
|
2016-09-21 01:50:55 -04:00
|
|
|
wl_resource_get_link (resource));
|
2015-06-02 04:26:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct zwp_relative_pointer_manager_v1_interface relative_pointer_manager = {
|
|
|
|
relative_pointer_manager_destroy,
|
|
|
|
relative_pointer_manager_get_relative_pointer,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
bind_relative_pointer_manager (struct wl_client *client,
|
|
|
|
void *data,
|
|
|
|
uint32_t version,
|
|
|
|
uint32_t id)
|
|
|
|
{
|
|
|
|
MetaWaylandCompositor *compositor = data;
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
|
|
resource = wl_resource_create (client,
|
|
|
|
&zwp_relative_pointer_manager_v1_interface,
|
|
|
|
1, id);
|
|
|
|
|
|
|
|
if (version != 1)
|
|
|
|
wl_resource_post_error (resource,
|
|
|
|
WL_DISPLAY_ERROR_INVALID_OBJECT,
|
|
|
|
"bound invalid version %u of "
|
|
|
|
"wp_relative_pointer_manager",
|
|
|
|
version);
|
|
|
|
|
|
|
|
wl_resource_set_implementation (resource, &relative_pointer_manager,
|
|
|
|
compositor,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_wayland_relative_pointer_init (MetaWaylandCompositor *compositor)
|
|
|
|
{
|
|
|
|
/* Relative pointer events are currently only supported by the native backend
|
|
|
|
* so lets just advertise the extension when the native backend is used.
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_NATIVE_BACKEND
|
|
|
|
if (!META_IS_BACKEND_NATIVE (meta_get_backend ()))
|
|
|
|
return;
|
|
|
|
#else
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!wl_global_create (compositor->wayland_display,
|
|
|
|
&zwp_relative_pointer_manager_v1_interface, 1,
|
|
|
|
compositor, bind_relative_pointer_manager))
|
|
|
|
g_error ("Could not create relative pointer manager global");
|
|
|
|
}
|
|
|
|
|
2015-06-17 00:10:52 -04:00
|
|
|
MetaWaylandSeat *
|
|
|
|
meta_wayland_pointer_get_seat (MetaWaylandPointer *pointer)
|
|
|
|
{
|
2016-09-12 11:20:36 -04:00
|
|
|
MetaWaylandInputDevice *input_device = META_WAYLAND_INPUT_DEVICE (pointer);
|
|
|
|
|
|
|
|
return meta_wayland_input_device_get_seat (input_device);
|
2016-04-01 04:39:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_pointer_init (MetaWaylandPointer *pointer)
|
|
|
|
{
|
2016-09-12 11:22:23 -04:00
|
|
|
pointer->default_grab.interface = &default_pointer_grab_interface;
|
|
|
|
pointer->default_grab.pointer = pointer;
|
|
|
|
pointer->grab = &pointer->default_grab;
|
wayland: Avoid a race in wl_seat capabilities
The way wl_seat capabilities work, by notifying clients of capabilities
changes, and clients consequently requesting the relevant interface
objects (pointer, keyboard, touch) is inherently racy.
On quick VT changes for example, capabilities on the seat will be added
and removed, and by the time the client receives the capability change
notification and requests the relevant keyboard, pointer or touch,
another VT switch might have occurred and the wl_pointer, wl_keyboard or
wl_touch already destroyed, leading to a protocol error which kills the
client.
To avoid this, create the objects when requested regardless of the
capabilities.
Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/1797
Related: https://bugzilla.gnome.org/show_bug.cgi?id=790932
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/77>
2017-11-28 04:54:08 -05:00
|
|
|
pointer->pointer_clients =
|
|
|
|
g_hash_table_new_full (NULL, NULL, NULL,
|
|
|
|
(GDestroyNotify) meta_wayland_pointer_client_free);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_pointer_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
MetaWaylandPointer *pointer = META_WAYLAND_POINTER (object);
|
|
|
|
|
|
|
|
g_clear_pointer (&pointer->pointer_clients, g_hash_table_unref);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (meta_wayland_pointer_parent_class)->finalize (object);
|
2016-04-01 04:39:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_pointer_class_init (MetaWaylandPointerClass *klass)
|
|
|
|
{
|
wayland: Avoid a race in wl_seat capabilities
The way wl_seat capabilities work, by notifying clients of capabilities
changes, and clients consequently requesting the relevant interface
objects (pointer, keyboard, touch) is inherently racy.
On quick VT changes for example, capabilities on the seat will be added
and removed, and by the time the client receives the capability change
notification and requests the relevant keyboard, pointer or touch,
another VT switch might have occurred and the wl_pointer, wl_keyboard or
wl_touch already destroyed, leading to a protocol error which kills the
client.
To avoid this, create the objects when requested regardless of the
capabilities.
Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/1797
Related: https://bugzilla.gnome.org/show_bug.cgi?id=790932
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/77>
2017-11-28 04:54:08 -05:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->finalize = meta_wayland_pointer_finalize;
|
|
|
|
|
2016-04-01 09:07:59 -04:00
|
|
|
signals[FOCUS_SURFACE_CHANGED] = g_signal_new ("focus-surface-changed",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
0,
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE, 0);
|
2015-06-17 00:10:52 -04:00
|
|
|
}
|