2014-03-20 19:29:30 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2001 Havoc Pennington
|
|
|
|
* Copyright (C) 2002, 2003, 2004 Red Hat, Inc.
|
|
|
|
* Copyright (C) 2003, 2004 Rob Adams
|
|
|
|
* Copyright (C) 2004-2006 Elijah Newren
|
|
|
|
*
|
|
|
|
* 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "events.h"
|
|
|
|
|
2014-08-05 12:11:59 +00:00
|
|
|
#include <meta/meta-backend.h>
|
|
|
|
|
2014-06-11 20:08:33 +00:00
|
|
|
#include "display-private.h"
|
|
|
|
#include "window-private.h"
|
|
|
|
#include "backends/x11/meta-backend-x11.h"
|
2014-10-09 08:40:26 +00:00
|
|
|
#include "backends/meta-cursor-tracker-private.h"
|
2014-03-20 19:29:30 +00:00
|
|
|
|
2014-06-11 20:08:33 +00:00
|
|
|
#ifdef HAVE_NATIVE_BACKEND
|
|
|
|
#include "backends/native/meta-backend-native.h"
|
|
|
|
#include "backends/native/meta-idle-monitor-native.h"
|
|
|
|
#endif
|
2014-03-20 19:54:16 +00:00
|
|
|
|
2014-08-14 00:19:35 +00:00
|
|
|
#ifdef HAVE_WAYLAND
|
2014-06-11 20:08:33 +00:00
|
|
|
#include "wayland/meta-wayland-private.h"
|
2014-08-14 00:19:35 +00:00
|
|
|
#endif
|
2014-06-11 20:08:33 +00:00
|
|
|
#include "meta-surface-actor.h"
|
2014-03-20 19:29:30 +00:00
|
|
|
|
2015-07-01 13:49:33 +00:00
|
|
|
#define IS_GESTURE_EVENT(e) ((e)->type == CLUTTER_TOUCHPAD_SWIPE || \
|
|
|
|
(e)->type == CLUTTER_TOUCHPAD_PINCH || \
|
|
|
|
(e)->type == CLUTTER_TOUCH_BEGIN || \
|
|
|
|
(e)->type == CLUTTER_TOUCH_UPDATE || \
|
|
|
|
(e)->type == CLUTTER_TOUCH_END || \
|
|
|
|
(e)->type == CLUTTER_TOUCH_CANCEL)
|
|
|
|
|
2014-06-11 20:08:33 +00:00
|
|
|
static MetaWindow *
|
|
|
|
get_window_for_event (MetaDisplay *display,
|
|
|
|
const ClutterEvent *event)
|
2014-03-20 19:29:30 +00:00
|
|
|
{
|
2014-08-15 21:35:40 +00:00
|
|
|
switch (display->event_route)
|
2014-03-20 19:29:30 +00:00
|
|
|
{
|
2014-08-15 21:35:40 +00:00
|
|
|
case META_EVENT_ROUTE_NORMAL:
|
|
|
|
{
|
|
|
|
ClutterActor *source;
|
|
|
|
|
|
|
|
/* Always use the key focused window for key events. */
|
|
|
|
switch (event->type)
|
|
|
|
{
|
|
|
|
case CLUTTER_KEY_PRESS:
|
|
|
|
case CLUTTER_KEY_RELEASE:
|
|
|
|
return display->focus_window;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
source = clutter_event_get_source (event);
|
|
|
|
if (META_IS_SURFACE_ACTOR (source))
|
|
|
|
return meta_surface_actor_get_window (META_SURFACE_ACTOR (source));
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
case META_EVENT_ROUTE_WINDOW_OP:
|
|
|
|
case META_EVENT_ROUTE_COMPOSITOR_GRAB:
|
2015-01-19 19:27:27 +00:00
|
|
|
case META_EVENT_ROUTE_WAYLAND_POPUP:
|
|
|
|
case META_EVENT_ROUTE_FRAME_BUTTON:
|
2014-08-15 21:35:40 +00:00
|
|
|
return display->grab_window;
|
2014-03-20 19:29:30 +00:00
|
|
|
default:
|
2014-08-15 21:35:40 +00:00
|
|
|
g_assert_not_reached ();
|
2014-03-20 19:29:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-31 00:50:03 +00:00
|
|
|
static void
|
|
|
|
handle_idletime_for_event (const ClutterEvent *event)
|
|
|
|
{
|
2014-05-29 16:11:26 +00:00
|
|
|
#ifdef HAVE_NATIVE_BACKEND
|
2014-03-31 00:50:03 +00:00
|
|
|
/* This is handled by XSync under X11. */
|
2014-05-29 16:06:09 +00:00
|
|
|
MetaBackend *backend = meta_get_backend ();
|
2014-03-31 00:50:03 +00:00
|
|
|
|
2014-05-29 16:06:09 +00:00
|
|
|
if (META_IS_BACKEND_NATIVE (backend))
|
|
|
|
{
|
|
|
|
ClutterInputDevice *device, *source_device;
|
|
|
|
MetaIdleMonitor *core_monitor, *device_monitor;
|
|
|
|
int device_id;
|
2014-03-31 00:50:03 +00:00
|
|
|
|
2014-05-29 16:06:09 +00:00
|
|
|
device = clutter_event_get_device (event);
|
|
|
|
if (device == NULL)
|
|
|
|
return;
|
2014-03-31 00:50:03 +00:00
|
|
|
|
2015-04-27 17:01:51 +00:00
|
|
|
if (event->any.flags & CLUTTER_EVENT_FLAG_SYNTHETIC ||
|
|
|
|
event->type == CLUTTER_ENTER ||
|
|
|
|
event->type == CLUTTER_LEAVE ||
|
|
|
|
event->type == CLUTTER_STAGE_STATE ||
|
|
|
|
event->type == CLUTTER_DESTROY_NOTIFY ||
|
|
|
|
event->type == CLUTTER_CLIENT_MESSAGE ||
|
|
|
|
event->type == CLUTTER_DELETE)
|
|
|
|
return;
|
|
|
|
|
2014-03-31 00:50:03 +00:00
|
|
|
device_id = clutter_input_device_get_device_id (device);
|
2014-05-29 16:06:09 +00:00
|
|
|
|
|
|
|
core_monitor = meta_idle_monitor_get_core ();
|
2014-03-31 00:50:03 +00:00
|
|
|
device_monitor = meta_idle_monitor_get_for_device (device_id);
|
2014-05-29 16:06:09 +00:00
|
|
|
|
|
|
|
meta_idle_monitor_native_reset_idletime (core_monitor);
|
2014-03-31 00:52:25 +00:00
|
|
|
meta_idle_monitor_native_reset_idletime (device_monitor);
|
2014-05-29 16:06:09 +00:00
|
|
|
|
|
|
|
source_device = clutter_event_get_source_device (event);
|
|
|
|
if (source_device != device)
|
|
|
|
{
|
|
|
|
device_id = clutter_input_device_get_device_id (device);
|
|
|
|
device_monitor = meta_idle_monitor_get_for_device (device_id);
|
|
|
|
meta_idle_monitor_native_reset_idletime (device_monitor);
|
|
|
|
}
|
2014-03-31 00:50:03 +00:00
|
|
|
}
|
2014-05-29 16:11:26 +00:00
|
|
|
#endif /* HAVE_NATIVE_BACKEND */
|
2014-03-31 00:50:03 +00:00
|
|
|
}
|
|
|
|
|
2014-07-21 23:14:14 +00:00
|
|
|
static gboolean
|
|
|
|
sequence_is_pointer_emulated (MetaDisplay *display,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
ClutterEventSequence *sequence;
|
|
|
|
|
|
|
|
sequence = clutter_event_get_event_sequence (event);
|
|
|
|
|
|
|
|
if (!sequence)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (clutter_event_is_pointer_emulated (event))
|
|
|
|
return TRUE;
|
|
|
|
|
2014-07-24 18:52:04 +00:00
|
|
|
#ifdef HAVE_NATIVE_BACKEND
|
|
|
|
MetaBackend *backend = meta_get_backend ();
|
2014-07-21 23:14:14 +00:00
|
|
|
|
|
|
|
/* When using Clutter's native input backend there is no concept of
|
|
|
|
* pointer emulating sequence, we still must make up our own to be
|
|
|
|
* able to implement single-touch (hence pointer alike) behavior.
|
|
|
|
*
|
|
|
|
* This is implemented similarly to X11, where only the first touch
|
|
|
|
* on screen gets the "pointer emulated" flag, and it won't get assigned
|
|
|
|
* to another sequence until the next first touch on an idle touchscreen.
|
|
|
|
*/
|
|
|
|
if (META_IS_BACKEND_NATIVE (backend))
|
|
|
|
{
|
|
|
|
MetaGestureTracker *tracker;
|
|
|
|
|
|
|
|
tracker = meta_display_get_gesture_tracker (display);
|
|
|
|
|
|
|
|
if (event->type == CLUTTER_TOUCH_BEGIN &&
|
|
|
|
meta_gesture_tracker_get_n_current_touches (tracker) == 0)
|
|
|
|
return TRUE;
|
|
|
|
}
|
2014-07-24 18:52:04 +00:00
|
|
|
#endif /* HAVE_NATIVE_BACKEND */
|
2014-07-21 23:14:14 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-03-20 19:29:30 +00:00
|
|
|
static gboolean
|
|
|
|
meta_display_handle_event (MetaDisplay *display,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
MetaWindow *window;
|
2014-08-14 00:19:35 +00:00
|
|
|
gboolean bypass_clutter = FALSE;
|
|
|
|
G_GNUC_UNUSED gboolean bypass_wayland = FALSE;
|
2014-06-19 21:10:33 +00:00
|
|
|
MetaGestureTracker *tracker;
|
2014-10-13 14:20:28 +00:00
|
|
|
ClutterEventSequence *sequence;
|
2015-02-11 14:03:25 +00:00
|
|
|
ClutterInputDevice *source;
|
2014-03-20 19:29:30 +00:00
|
|
|
|
2014-10-13 14:20:28 +00:00
|
|
|
sequence = clutter_event_get_event_sequence (event);
|
|
|
|
|
|
|
|
/* Set the pointer emulating sequence on touch begin, if eligible */
|
|
|
|
if (event->type == CLUTTER_TOUCH_BEGIN &&
|
|
|
|
!display->pointer_emulating_sequence &&
|
|
|
|
sequence_is_pointer_emulated (display, event))
|
|
|
|
display->pointer_emulating_sequence = sequence;
|
2014-07-21 23:14:14 +00:00
|
|
|
|
2014-08-14 00:19:35 +00:00
|
|
|
#ifdef HAVE_WAYLAND
|
|
|
|
MetaWaylandCompositor *compositor = NULL;
|
2014-03-20 19:29:30 +00:00
|
|
|
if (meta_is_wayland_compositor ())
|
|
|
|
{
|
|
|
|
compositor = meta_wayland_compositor_get_default ();
|
|
|
|
meta_wayland_compositor_update (compositor, event);
|
|
|
|
}
|
2014-08-14 00:19:35 +00:00
|
|
|
#endif
|
2014-03-20 19:29:30 +00:00
|
|
|
|
2015-02-11 14:03:25 +00:00
|
|
|
source = clutter_event_get_source_device (event);
|
|
|
|
|
|
|
|
if (source)
|
|
|
|
{
|
|
|
|
meta_backend_update_last_device (meta_get_backend (),
|
|
|
|
clutter_input_device_get_device_id (source));
|
|
|
|
}
|
|
|
|
|
2014-08-21 20:57:27 +00:00
|
|
|
if (meta_is_wayland_compositor () && event->type == CLUTTER_MOTION)
|
|
|
|
{
|
2015-09-23 23:24:33 +00:00
|
|
|
meta_cursor_tracker_update_position (meta_cursor_tracker_get_for_screen (NULL),
|
|
|
|
event->motion.x, event->motion.y);
|
2015-04-29 14:20:38 +00:00
|
|
|
display->monitor_cache_invalidated = TRUE;
|
2014-08-21 20:57:27 +00:00
|
|
|
}
|
|
|
|
|
2014-03-31 00:50:03 +00:00
|
|
|
handle_idletime_for_event (event);
|
|
|
|
|
2014-03-20 19:29:30 +00:00
|
|
|
window = get_window_for_event (display, event);
|
|
|
|
|
|
|
|
display->current_time = event->any.time;
|
|
|
|
|
|
|
|
if (window && !window->override_redirect &&
|
2014-06-19 20:23:00 +00:00
|
|
|
(event->type == CLUTTER_KEY_PRESS ||
|
|
|
|
event->type == CLUTTER_BUTTON_PRESS ||
|
|
|
|
event->type == CLUTTER_TOUCH_BEGIN))
|
2014-03-20 19:29:30 +00:00
|
|
|
{
|
|
|
|
if (CurrentTime == display->current_time)
|
|
|
|
{
|
|
|
|
/* We can't use missing (i.e. invalid) timestamps to set user time,
|
|
|
|
* nor do we want to use them to sanity check other timestamps.
|
|
|
|
* See bug 313490 for more details.
|
|
|
|
*/
|
|
|
|
meta_warning ("Event has no timestamp! You may be using a broken "
|
|
|
|
"program such as xse. Please ask the authors of that "
|
|
|
|
"program to fix it.\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
meta_window_set_user_time (window, display->current_time);
|
|
|
|
meta_display_sanity_check_timestamps (display, display->current_time);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-19 21:10:33 +00:00
|
|
|
tracker = meta_display_get_gesture_tracker (display);
|
|
|
|
|
|
|
|
if (meta_gesture_tracker_handle_event (tracker, event))
|
|
|
|
{
|
2014-07-21 23:55:02 +00:00
|
|
|
bypass_wayland = bypass_clutter = TRUE;
|
2014-06-19 21:10:33 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2014-08-15 17:12:22 +00:00
|
|
|
if (display->event_route == META_EVENT_ROUTE_WINDOW_OP)
|
2014-04-21 15:21:19 +00:00
|
|
|
{
|
|
|
|
if (meta_window_handle_mouse_grab_op_event (window, event))
|
|
|
|
{
|
|
|
|
bypass_clutter = TRUE;
|
|
|
|
bypass_wayland = TRUE;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-08 18:53:50 +00:00
|
|
|
/* For key events, it's important to enforce single-handling, or
|
|
|
|
* we can get into a confused state. So if a keybinding is
|
|
|
|
* handled (because it's one of our hot-keys, or because we are
|
|
|
|
* in a keyboard-grabbed mode like moving a window, we don't
|
|
|
|
* want to pass the key event to the compositor or Wayland at all.
|
|
|
|
*/
|
|
|
|
if (meta_keybindings_process_event (display, window, event))
|
|
|
|
{
|
|
|
|
bypass_clutter = TRUE;
|
|
|
|
bypass_wayland = TRUE;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2014-05-08 19:12:58 +00:00
|
|
|
if (window)
|
2014-03-20 19:29:30 +00:00
|
|
|
{
|
2015-07-01 13:49:33 +00:00
|
|
|
/* Events that are likely to trigger compositor gestures should
|
|
|
|
* be known to clutter so they can propagate along the hierarchy.
|
|
|
|
* Gesture-wise, there's two groups of events we should be getting
|
|
|
|
* here:
|
|
|
|
* - CLUTTER_TOUCH_* with a touch sequence that's not yet accepted
|
|
|
|
* by the gesture tracker, these might trigger gesture actions
|
|
|
|
* into recognition. Already accepted touch sequences are handled
|
|
|
|
* directly by meta_gesture_tracker_handle_event().
|
|
|
|
* - CLUTTER_TOUCHPAD_* events over windows. These can likewise
|
|
|
|
* trigger ::captured-event handlers along the way.
|
|
|
|
*/
|
|
|
|
bypass_clutter = !IS_GESTURE_EVENT (event);
|
2014-05-08 19:06:52 +00:00
|
|
|
|
2014-08-15 12:29:16 +00:00
|
|
|
meta_window_handle_ungrabbed_event (window, event);
|
|
|
|
|
|
|
|
/* This might start a grab op. If it does, then filter out the
|
|
|
|
* event, and if it doesn't, replay the event to release our
|
|
|
|
* own sync grab. */
|
|
|
|
|
2015-01-19 19:27:27 +00:00
|
|
|
if (display->event_route == META_EVENT_ROUTE_WINDOW_OP ||
|
|
|
|
display->event_route == META_EVENT_ROUTE_FRAME_BUTTON)
|
2014-05-08 19:09:20 +00:00
|
|
|
{
|
2014-08-15 12:29:16 +00:00
|
|
|
bypass_clutter = TRUE;
|
2014-05-08 19:05:25 +00:00
|
|
|
bypass_wayland = TRUE;
|
2014-03-20 19:29:30 +00:00
|
|
|
}
|
2014-08-15 12:29:16 +00:00
|
|
|
else
|
2014-05-08 19:09:20 +00:00
|
|
|
{
|
2014-08-15 12:29:16 +00:00
|
|
|
/* Only replay button press events, since that's where we
|
|
|
|
* have the synchronous grab. */
|
|
|
|
if (event->type == CLUTTER_BUTTON_PRESS)
|
2014-05-08 19:09:20 +00:00
|
|
|
{
|
2014-08-15 12:29:16 +00:00
|
|
|
MetaBackend *backend = meta_get_backend ();
|
|
|
|
if (META_IS_BACKEND_X11 (backend))
|
|
|
|
{
|
|
|
|
Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
|
|
|
|
meta_verbose ("Allowing events time %u\n",
|
|
|
|
(unsigned int)event->button.time);
|
|
|
|
XIAllowEvents (xdisplay, clutter_event_get_device_id (event),
|
|
|
|
XIReplayDevice, event->button.time);
|
|
|
|
}
|
2014-05-08 19:09:20 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-08 19:12:58 +00:00
|
|
|
|
|
|
|
goto out;
|
2014-03-20 19:29:30 +00:00
|
|
|
}
|
|
|
|
|
2014-04-21 15:21:19 +00:00
|
|
|
out:
|
2014-03-20 19:29:30 +00:00
|
|
|
/* If the compositor has a grab, don't pass that through to Wayland */
|
2014-08-15 17:12:22 +00:00
|
|
|
if (display->event_route == META_EVENT_ROUTE_COMPOSITOR_GRAB)
|
2014-03-20 19:29:30 +00:00
|
|
|
bypass_wayland = TRUE;
|
|
|
|
|
|
|
|
/* If a Wayland client has a grab, don't pass that through to Clutter */
|
2014-08-15 17:12:22 +00:00
|
|
|
if (display->event_route == META_EVENT_ROUTE_WAYLAND_POPUP)
|
2014-03-20 19:29:30 +00:00
|
|
|
bypass_clutter = TRUE;
|
|
|
|
|
2014-08-14 00:19:35 +00:00
|
|
|
#ifdef HAVE_WAYLAND
|
2014-03-20 19:29:30 +00:00
|
|
|
if (compositor && !bypass_wayland)
|
|
|
|
{
|
|
|
|
if (meta_wayland_compositor_handle_event (compositor, event))
|
|
|
|
bypass_clutter = TRUE;
|
|
|
|
}
|
2014-08-14 00:19:35 +00:00
|
|
|
#endif
|
2014-03-20 19:29:30 +00:00
|
|
|
|
2014-10-13 14:20:28 +00:00
|
|
|
/* Unset the pointer emulating sequence after its end event is processed */
|
|
|
|
if (event->type == CLUTTER_TOUCH_END &&
|
|
|
|
display->pointer_emulating_sequence == sequence)
|
|
|
|
display->pointer_emulating_sequence = NULL;
|
|
|
|
|
2014-05-09 15:16:34 +00:00
|
|
|
display->current_time = CurrentTime;
|
2014-03-20 19:29:30 +00:00
|
|
|
return bypass_clutter;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
event_callback (const ClutterEvent *event,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
MetaDisplay *display = data;
|
|
|
|
|
|
|
|
return meta_display_handle_event (display, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-08-15 17:47:57 +00:00
|
|
|
meta_display_init_events (MetaDisplay *display)
|
2014-03-20 19:29:30 +00:00
|
|
|
{
|
|
|
|
display->clutter_event_filter = clutter_event_add_filter (NULL,
|
|
|
|
event_callback,
|
|
|
|
NULL,
|
|
|
|
display);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_display_free_events (MetaDisplay *display)
|
|
|
|
{
|
|
|
|
clutter_event_remove_filter (display->clutter_event_filter);
|
|
|
|
display->clutter_event_filter = 0;
|
|
|
|
}
|