2007-03-22 14:21:59 -04:00
|
|
|
/* Clutter.
|
|
|
|
* An OpenGL based 'interactive canvas' library.
|
2010-01-15 11:28:00 -05:00
|
|
|
*
|
|
|
|
* Copyright (C) 2006, 2007, 2008 OpenedHand Ltd
|
|
|
|
* Copyright (C) 2009, 2010 Intel Corp.
|
2007-03-22 14:21:59 -04:00
|
|
|
*
|
|
|
|
* 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
|
2010-03-01 07:56:10 -05:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*
|
2010-01-15 11:28:00 -05:00
|
|
|
*
|
|
|
|
* Authored by:
|
|
|
|
* Matthew Allum <mallum@openedhand.com>
|
|
|
|
* Emmanuele Bassi <ebassi@linux.intel.com>
|
2007-03-22 14:21:59 -04:00
|
|
|
*/
|
|
|
|
|
2008-06-30 12:01:56 -04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2007-03-22 14:21:59 -04:00
|
|
|
#include "config.h"
|
2008-06-30 12:01:56 -04:00
|
|
|
#endif
|
2007-03-22 14:21:59 -04:00
|
|
|
|
2007-11-15 09:45:27 -05:00
|
|
|
#include "clutter-stage-x11.h"
|
|
|
|
#include "clutter-backend-x11.h"
|
2010-07-12 12:11:30 -04:00
|
|
|
#include "clutter-keymap-x11.h"
|
2007-11-15 09:45:27 -05:00
|
|
|
#include "clutter-x11.h"
|
2007-03-22 14:21:59 -04:00
|
|
|
|
|
|
|
#include "../clutter-backend.h"
|
|
|
|
#include "../clutter-event.h"
|
|
|
|
#include "../clutter-private.h"
|
|
|
|
#include "../clutter-debug.h"
|
|
|
|
#include "../clutter-main.h"
|
|
|
|
|
2010-05-19 11:13:07 -04:00
|
|
|
#include "cogl/cogl-internal.h"
|
|
|
|
|
2007-03-22 14:21:59 -04:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_XFIXES
|
|
|
|
#include <X11/extensions/Xfixes.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <X11/Xatom.h>
|
|
|
|
|
2009-06-04 08:41:32 -04:00
|
|
|
#ifdef HAVE_XINPUT
|
2008-06-23 05:55:42 -04:00
|
|
|
#include <X11/extensions/XInput.h>
|
|
|
|
#endif
|
|
|
|
|
2010-07-08 10:47:18 -04:00
|
|
|
#ifdef HAVE_XKB
|
|
|
|
#include <X11/XKBlib.h>
|
|
|
|
#endif
|
|
|
|
|
2007-04-19 11:24:57 -04:00
|
|
|
/* XEMBED protocol support for toolkit embedding */
|
|
|
|
#define XEMBED_MAPPED (1 << 0)
|
|
|
|
#define MAX_SUPPORTED_XEMBED_VERSION 1
|
|
|
|
|
|
|
|
#define XEMBED_EMBEDDED_NOTIFY 0
|
|
|
|
#define XEMBED_WINDOW_ACTIVATE 1
|
|
|
|
#define XEMBED_WINDOW_DEACTIVATE 2
|
|
|
|
#define XEMBED_REQUEST_FOCUS 3
|
|
|
|
#define XEMBED_FOCUS_IN 4
|
|
|
|
#define XEMBED_FOCUS_OUT 5
|
|
|
|
#define XEMBED_FOCUS_NEXT 6
|
|
|
|
#define XEMBED_FOCUS_PREV 7
|
|
|
|
/* 8-9 were used for XEMBED_GRAB_KEY/XEMBED_UNGRAB_KEY */
|
|
|
|
#define XEMBED_MODALITY_ON 10
|
|
|
|
#define XEMBED_MODALITY_OFF 11
|
|
|
|
#define XEMBED_REGISTER_ACCELERATOR 12
|
|
|
|
#define XEMBED_UNREGISTER_ACCELERATOR 13
|
|
|
|
#define XEMBED_ACTIVATE_ACCELERATOR 14
|
|
|
|
|
|
|
|
static Window ParentEmbedderWin = None;
|
|
|
|
|
2007-03-22 14:21:59 -04:00
|
|
|
typedef struct _ClutterEventSource ClutterEventSource;
|
|
|
|
|
|
|
|
struct _ClutterEventSource
|
|
|
|
{
|
|
|
|
GSource source;
|
|
|
|
|
|
|
|
ClutterBackend *backend;
|
|
|
|
GPollFD event_poll_fd;
|
|
|
|
};
|
|
|
|
|
2010-07-08 10:47:18 -04:00
|
|
|
struct _ClutterEventX11
|
|
|
|
{
|
|
|
|
/* additional fields for Key events */
|
|
|
|
gint key_group;
|
2010-07-13 04:15:21 -04:00
|
|
|
|
2010-07-13 06:54:44 -04:00
|
|
|
guint key_is_modifier : 1;
|
|
|
|
guint num_lock_set : 1;
|
|
|
|
guint caps_lock_set : 1;
|
2010-07-08 10:47:18 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
ClutterEventX11 *
|
|
|
|
_clutter_event_x11_new (void)
|
|
|
|
{
|
|
|
|
return g_slice_new0 (ClutterEventX11);
|
|
|
|
}
|
|
|
|
|
|
|
|
ClutterEventX11 *
|
|
|
|
_clutter_event_x11_copy (ClutterEventX11 *event_x11)
|
|
|
|
{
|
|
|
|
if (event_x11 != NULL)
|
|
|
|
return g_slice_dup (ClutterEventX11, event_x11);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_clutter_event_x11_free (ClutterEventX11 *event_x11)
|
|
|
|
{
|
|
|
|
if (event_x11 != NULL)
|
|
|
|
g_slice_free (ClutterEventX11, event_x11);
|
|
|
|
}
|
|
|
|
|
2007-03-22 14:21:59 -04:00
|
|
|
static gboolean clutter_event_prepare (GSource *source,
|
|
|
|
gint *timeout);
|
|
|
|
static gboolean clutter_event_check (GSource *source);
|
|
|
|
static gboolean clutter_event_dispatch (GSource *source,
|
|
|
|
GSourceFunc callback,
|
|
|
|
gpointer user_data);
|
|
|
|
|
|
|
|
static GList *event_sources = NULL;
|
|
|
|
|
|
|
|
static GSourceFuncs event_funcs = {
|
|
|
|
clutter_event_prepare,
|
|
|
|
clutter_event_check,
|
|
|
|
clutter_event_dispatch,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static GSource *
|
|
|
|
clutter_event_source_new (ClutterBackend *backend)
|
|
|
|
{
|
|
|
|
GSource *source = g_source_new (&event_funcs, sizeof (ClutterEventSource));
|
|
|
|
ClutterEventSource *event_source = (ClutterEventSource *) source;
|
|
|
|
|
2010-06-03 23:34:09 -04:00
|
|
|
#if GLIB_CHECK_VERSION (2, 25, 8)
|
|
|
|
g_source_set_name (source, "Clutter X11 Event");
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 14:21:59 -04:00
|
|
|
event_source->backend = backend;
|
|
|
|
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2007-05-09 19:31:08 -04:00
|
|
|
check_xpending (ClutterBackend *backend)
|
2007-03-22 14:21:59 -04:00
|
|
|
{
|
2007-11-15 09:45:27 -05:00
|
|
|
return XPending (CLUTTER_BACKEND_X11 (backend)->xdpy);
|
2007-03-22 14:21:59 -04:00
|
|
|
}
|
|
|
|
|
2007-04-19 11:24:57 -04:00
|
|
|
static gboolean
|
2007-11-17 13:11:14 -05:00
|
|
|
xembed_send_message (ClutterBackendX11 *backend_x11,
|
|
|
|
Window window,
|
2008-01-31 06:24:11 -05:00
|
|
|
long message,
|
|
|
|
long detail,
|
2008-02-12 07:39:22 -05:00
|
|
|
long data1,
|
2008-01-31 06:24:11 -05:00
|
|
|
long data2)
|
2007-04-19 11:24:57 -04:00
|
|
|
{
|
|
|
|
XEvent ev;
|
|
|
|
|
|
|
|
memset (&ev, 0, sizeof (ev));
|
|
|
|
|
|
|
|
ev.xclient.type = ClientMessage;
|
|
|
|
ev.xclient.window = window;
|
2007-11-17 13:11:14 -05:00
|
|
|
ev.xclient.message_type = backend_x11->atom_XEMBED;
|
2007-04-19 11:24:57 -04:00
|
|
|
ev.xclient.format = 32;
|
|
|
|
ev.xclient.data.l[0] = CurrentTime;
|
|
|
|
ev.xclient.data.l[1] = message;
|
|
|
|
ev.xclient.data.l[2] = detail;
|
|
|
|
ev.xclient.data.l[3] = data1;
|
|
|
|
ev.xclient.data.l[4] = data2;
|
|
|
|
|
2007-11-15 09:45:27 -05:00
|
|
|
clutter_x11_trap_x_errors ();
|
2007-04-19 11:24:57 -04:00
|
|
|
|
2007-11-17 13:11:14 -05:00
|
|
|
XSendEvent (backend_x11->xdpy, window, False, NoEventMask, &ev);
|
|
|
|
XSync (backend_x11->xdpy, False);
|
2007-04-19 11:24:57 -04:00
|
|
|
|
2007-11-15 09:45:27 -05:00
|
|
|
if (clutter_x11_untrap_x_errors ())
|
2007-04-19 11:24:57 -04:00
|
|
|
return False;
|
|
|
|
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-11-17 13:11:14 -05:00
|
|
|
xembed_set_info (ClutterBackendX11 *backend_x11,
|
|
|
|
Window window,
|
|
|
|
gint flags)
|
2007-04-19 11:24:57 -04:00
|
|
|
{
|
|
|
|
gint32 list[2];
|
|
|
|
|
|
|
|
list[0] = MAX_SUPPORTED_XEMBED_VERSION;
|
|
|
|
list[1] = XEMBED_MAPPED;
|
|
|
|
|
2007-11-17 13:11:14 -05:00
|
|
|
XChangeProperty (backend_x11->xdpy, window,
|
|
|
|
backend_x11->atom_XEMBED_INFO,
|
|
|
|
backend_x11->atom_XEMBED_INFO, 32,
|
2007-04-19 11:24:57 -04:00
|
|
|
PropModeReplace, (unsigned char *) list, 2);
|
|
|
|
}
|
2007-03-22 14:21:59 -04:00
|
|
|
|
|
|
|
void
|
2007-11-15 09:45:27 -05:00
|
|
|
_clutter_backend_x11_events_init (ClutterBackend *backend)
|
2007-03-22 14:21:59 -04:00
|
|
|
{
|
2007-11-17 13:11:14 -05:00
|
|
|
ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (backend);
|
2007-03-22 14:21:59 -04:00
|
|
|
GSource *source;
|
|
|
|
ClutterEventSource *event_source;
|
|
|
|
int connection_number;
|
2008-02-12 07:39:22 -05:00
|
|
|
|
2007-11-15 09:45:27 -05:00
|
|
|
connection_number = ConnectionNumber (backend_x11->xdpy);
|
2007-03-22 14:21:59 -04:00
|
|
|
CLUTTER_NOTE (EVENT, "Connection number: %d", connection_number);
|
|
|
|
|
2007-11-15 09:45:27 -05:00
|
|
|
source = backend_x11->event_source = clutter_event_source_new (backend);
|
2007-03-22 14:21:59 -04:00
|
|
|
event_source = (ClutterEventSource *) source;
|
|
|
|
g_source_set_priority (source, CLUTTER_PRIORITY_EVENTS);
|
|
|
|
|
|
|
|
event_source->event_poll_fd.fd = connection_number;
|
|
|
|
event_source->event_poll_fd.events = G_IO_IN;
|
|
|
|
|
|
|
|
event_sources = g_list_prepend (event_sources, event_source);
|
|
|
|
|
|
|
|
g_source_add_poll (source, &event_source->event_poll_fd);
|
|
|
|
g_source_set_can_recurse (source, TRUE);
|
|
|
|
g_source_attach (source, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-11-15 09:45:27 -05:00
|
|
|
_clutter_backend_x11_events_uninit (ClutterBackend *backend)
|
2007-03-22 14:21:59 -04:00
|
|
|
{
|
2007-11-15 09:45:27 -05:00
|
|
|
ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (backend);
|
2007-03-22 14:21:59 -04:00
|
|
|
|
2007-11-15 09:45:27 -05:00
|
|
|
if (backend_x11->event_source)
|
2007-03-22 14:21:59 -04:00
|
|
|
{
|
|
|
|
CLUTTER_NOTE (EVENT, "Destroying the event source");
|
|
|
|
|
|
|
|
event_sources = g_list_remove (event_sources,
|
2007-11-15 09:45:27 -05:00
|
|
|
backend_x11->event_source);
|
2007-03-22 14:21:59 -04:00
|
|
|
|
2007-11-15 09:45:27 -05:00
|
|
|
g_source_destroy (backend_x11->event_source);
|
|
|
|
g_source_unref (backend_x11->event_source);
|
|
|
|
backend_x11->event_source = NULL;
|
2007-03-22 14:21:59 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-18 04:45:26 -05:00
|
|
|
static void
|
|
|
|
update_last_event_time (ClutterBackendX11 *backend_x11,
|
|
|
|
XEvent *xevent)
|
|
|
|
{
|
|
|
|
Time current_time = CurrentTime;
|
|
|
|
Time last_time = backend_x11->last_event_time;
|
|
|
|
|
|
|
|
switch (xevent->type)
|
|
|
|
{
|
|
|
|
case KeyPress:
|
|
|
|
case KeyRelease:
|
|
|
|
current_time = xevent->xkey.time;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ButtonPress:
|
|
|
|
case ButtonRelease:
|
|
|
|
current_time = xevent->xbutton.time;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MotionNotify:
|
|
|
|
current_time = xevent->xmotion.time;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EnterNotify:
|
|
|
|
case LeaveNotify:
|
|
|
|
current_time = xevent->xcrossing.time;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PropertyNotify:
|
|
|
|
current_time = xevent->xproperty.time;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* only change the current event time if it's after the previous event
|
|
|
|
* time, or if it is at least 30 seconds earlier - in case the system
|
|
|
|
* clock was changed
|
|
|
|
*/
|
2009-02-18 11:54:18 -05:00
|
|
|
if ((current_time != CurrentTime) &&
|
|
|
|
(current_time > last_time || (last_time - current_time > (30 * 1000))))
|
2009-02-18 04:45:26 -05:00
|
|
|
backend_x11->last_event_time = current_time;
|
|
|
|
}
|
|
|
|
|
2007-03-22 14:21:59 -04:00
|
|
|
static void
|
2007-11-17 13:11:14 -05:00
|
|
|
set_user_time (ClutterBackendX11 *backend_x11,
|
|
|
|
Window *xwindow,
|
|
|
|
long timestamp)
|
2007-03-22 14:21:59 -04:00
|
|
|
{
|
2007-04-19 11:26:54 -04:00
|
|
|
if (timestamp != CLUTTER_CURRENT_TIME)
|
2007-03-22 14:21:59 -04:00
|
|
|
{
|
2007-11-17 13:11:14 -05:00
|
|
|
XChangeProperty (backend_x11->xdpy, *xwindow,
|
|
|
|
backend_x11->atom_NET_WM_USER_TIME,
|
2007-03-22 14:21:59 -04:00
|
|
|
XA_CARDINAL, 32, PropModeReplace,
|
|
|
|
(unsigned char *) ×tamp, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-20 14:40:58 -05:00
|
|
|
#ifdef HAVE_XINPUT
|
2008-06-23 08:45:20 -04:00
|
|
|
static void
|
2010-01-20 14:40:58 -05:00
|
|
|
convert_xdevicekey_to_xkey (XDeviceKeyEvent *xkev,
|
|
|
|
XEvent *xevent)
|
2008-06-23 08:45:20 -04:00
|
|
|
{
|
|
|
|
xevent->xany.type = xevent->xkey.type = xkev->type;
|
|
|
|
xevent->xkey.serial = xkev->serial;
|
|
|
|
xevent->xkey.display = xkev->display;
|
|
|
|
xevent->xkey.window = xkev->window;
|
|
|
|
xevent->xkey.root = xkev->root;
|
|
|
|
xevent->xkey.subwindow = xkev->subwindow;
|
|
|
|
xevent->xkey.time = xkev->time;
|
|
|
|
xevent->xkey.x = xkev->x;
|
|
|
|
xevent->xkey.y = xkev->y;
|
|
|
|
xevent->xkey.x_root = xkev->x_root;
|
|
|
|
xevent->xkey.y_root = xkev->y_root;
|
|
|
|
xevent->xkey.state = xkev->state;
|
|
|
|
xevent->xkey.keycode = xkev->keycode;
|
|
|
|
xevent->xkey.same_screen = xkev->same_screen;
|
|
|
|
}
|
2009-06-04 08:41:32 -04:00
|
|
|
#endif /* HAVE_XINPUT */
|
2008-06-23 05:55:42 -04:00
|
|
|
|
2010-07-13 04:15:21 -04:00
|
|
|
static inline void
|
2010-07-12 13:04:03 -04:00
|
|
|
translate_key_event (ClutterBackendX11 *backend_x11,
|
|
|
|
ClutterEvent *event,
|
|
|
|
XEvent *xevent)
|
2007-03-22 14:21:59 -04:00
|
|
|
{
|
2010-07-08 10:47:18 -04:00
|
|
|
ClutterEventX11 *event_x11;
|
|
|
|
char buffer[256 + 1];
|
2008-06-10 06:57:50 -04:00
|
|
|
int n;
|
2007-03-22 14:21:59 -04:00
|
|
|
|
2010-07-08 10:47:18 -04:00
|
|
|
/* KeyEvents have platform specific data associated to them */
|
|
|
|
event_x11 = _clutter_event_x11_new ();
|
|
|
|
_clutter_event_set_platform_data (event, event_x11);
|
|
|
|
|
2007-03-22 14:21:59 -04:00
|
|
|
event->key.time = xevent->xkey.time;
|
2007-06-11 05:02:40 -04:00
|
|
|
event->key.modifier_state = (ClutterModifierType) xevent->xkey.state;
|
2007-03-22 14:21:59 -04:00
|
|
|
event->key.hardware_keycode = xevent->xkey.keycode;
|
2007-06-13 19:24:59 -04:00
|
|
|
|
2008-06-10 06:57:50 -04:00
|
|
|
/* keyval is the key ignoring all modifiers ('1' vs. '!') */
|
2008-02-12 07:39:22 -05:00
|
|
|
event->key.keyval =
|
2010-07-13 06:54:44 -04:00
|
|
|
_clutter_keymap_x11_translate_key_state (backend_x11->keymap,
|
|
|
|
event->key.hardware_keycode,
|
|
|
|
event->key.modifier_state,
|
|
|
|
NULL);
|
2008-06-10 06:57:50 -04:00
|
|
|
|
2010-07-12 12:11:30 -04:00
|
|
|
event_x11->key_group =
|
2010-07-12 13:04:03 -04:00
|
|
|
_clutter_keymap_x11_get_key_group (backend_x11->keymap,
|
|
|
|
event->key.modifier_state);
|
2010-07-13 06:54:44 -04:00
|
|
|
event_x11->key_is_modifier =
|
|
|
|
_clutter_keymap_x11_get_is_modifier (backend_x11->keymap,
|
|
|
|
event->key.hardware_keycode);
|
2010-07-13 04:15:21 -04:00
|
|
|
event_x11->num_lock_set =
|
|
|
|
_clutter_keymap_x11_get_num_lock_state (backend_x11->keymap);
|
|
|
|
event_x11->caps_lock_set =
|
|
|
|
_clutter_keymap_x11_get_caps_lock_state (backend_x11->keymap);
|
2010-07-12 12:11:30 -04:00
|
|
|
|
2008-06-10 06:57:50 -04:00
|
|
|
/* unicode_value is the printable representation */
|
2008-06-10 10:01:43 -04:00
|
|
|
n = XLookupString (&xevent->xkey, buffer, sizeof (buffer) - 1, NULL, NULL);
|
|
|
|
|
|
|
|
if (n != NoSymbol)
|
2008-06-10 06:57:50 -04:00
|
|
|
{
|
|
|
|
event->key.unicode_value = g_utf8_get_char_validated (buffer, n);
|
2008-06-10 10:01:43 -04:00
|
|
|
if ((event->key.unicode_value != -1) &&
|
|
|
|
(event->key.unicode_value != -2))
|
2010-07-13 04:15:21 -04:00
|
|
|
goto out;
|
2008-06-10 06:57:50 -04:00
|
|
|
}
|
2010-07-08 10:47:18 -04:00
|
|
|
else
|
|
|
|
event->key.unicode_value = (gunichar)'\0';
|
2010-07-13 04:15:21 -04:00
|
|
|
|
|
|
|
out:
|
|
|
|
return;
|
2007-03-22 14:21:59 -04:00
|
|
|
}
|
|
|
|
|
2007-04-19 11:26:54 -04:00
|
|
|
static gboolean
|
2007-11-15 09:45:27 -05:00
|
|
|
handle_wm_protocols_event (ClutterBackendX11 *backend_x11,
|
2008-03-28 18:50:55 -04:00
|
|
|
Window window,
|
2007-04-19 11:26:54 -04:00
|
|
|
XEvent *xevent)
|
|
|
|
{
|
|
|
|
Atom atom = (Atom) xevent->xclient.data.l[0];
|
|
|
|
|
2007-11-17 13:11:14 -05:00
|
|
|
if (atom == backend_x11->atom_WM_DELETE_WINDOW &&
|
2008-03-28 18:50:55 -04:00
|
|
|
xevent->xany.window == window)
|
2007-04-19 11:26:54 -04:00
|
|
|
{
|
|
|
|
/* the WM_DELETE_WINDOW is a request: we do not destroy
|
|
|
|
* the window right away, as it might contain vital data;
|
|
|
|
* we relay the event to the application and we let it
|
|
|
|
* handle the request
|
|
|
|
*/
|
2007-11-26 07:07:25 -05:00
|
|
|
CLUTTER_NOTE (EVENT, "delete window:\txid: %ld",
|
2007-04-19 11:26:54 -04:00
|
|
|
xevent->xclient.window);
|
|
|
|
|
2007-11-17 13:11:14 -05:00
|
|
|
set_user_time (backend_x11,
|
2008-03-28 18:50:55 -04:00
|
|
|
&window,
|
2007-04-19 11:26:54 -04:00
|
|
|
xevent->xclient.data.l[1]);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2007-11-17 13:11:14 -05:00
|
|
|
else if (atom == backend_x11->atom_NET_WM_PING &&
|
2008-03-28 18:50:55 -04:00
|
|
|
xevent->xany.window == window)
|
2007-04-25 10:22:24 -04:00
|
|
|
{
|
|
|
|
XClientMessageEvent xclient = xevent->xclient;
|
|
|
|
|
2007-11-15 09:45:27 -05:00
|
|
|
xclient.window = backend_x11->xwin_root;
|
|
|
|
XSendEvent (backend_x11->xdpy, xclient.window,
|
2007-04-25 10:22:24 -04:00
|
|
|
False,
|
|
|
|
SubstructureRedirectMask | SubstructureNotifyMask,
|
|
|
|
(XEvent *) &xclient);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2007-04-19 11:26:54 -04:00
|
|
|
|
2007-04-25 10:22:24 -04:00
|
|
|
/* do not send any of the WM_PROTOCOLS events to the queue */
|
2007-04-19 11:26:54 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2007-11-15 09:45:27 -05:00
|
|
|
handle_xembed_event (ClutterBackendX11 *backend_x11,
|
2007-04-19 11:24:57 -04:00
|
|
|
XEvent *xevent)
|
|
|
|
{
|
|
|
|
ClutterActor *stage;
|
|
|
|
|
2008-03-28 18:50:55 -04:00
|
|
|
stage = clutter_stage_get_default ();
|
2007-04-19 11:24:57 -04:00
|
|
|
|
|
|
|
switch (xevent->xclient.data.l[1])
|
|
|
|
{
|
|
|
|
case XEMBED_EMBEDDED_NOTIFY:
|
|
|
|
CLUTTER_NOTE (EVENT, "got XEMBED_EMBEDDED_NOTIFY from %lx",
|
|
|
|
xevent->xclient.data.l[3]);
|
|
|
|
|
|
|
|
ParentEmbedderWin = xevent->xclient.data.l[3];
|
|
|
|
|
|
|
|
clutter_actor_realize (stage);
|
|
|
|
clutter_actor_show (stage);
|
|
|
|
|
2007-11-17 13:11:14 -05:00
|
|
|
xembed_set_info (backend_x11,
|
2007-11-15 09:45:27 -05:00
|
|
|
clutter_x11_get_stage_window (CLUTTER_STAGE (stage)),
|
2007-04-19 11:24:57 -04:00
|
|
|
XEMBED_MAPPED);
|
|
|
|
break;
|
|
|
|
case XEMBED_WINDOW_ACTIVATE:
|
|
|
|
CLUTTER_NOTE (EVENT, "got XEMBED_WINDOW_ACTIVATE");
|
|
|
|
break;
|
|
|
|
case XEMBED_WINDOW_DEACTIVATE:
|
|
|
|
CLUTTER_NOTE (EVENT, "got XEMBED_WINDOW_DEACTIVATE");
|
|
|
|
break;
|
|
|
|
case XEMBED_FOCUS_IN:
|
|
|
|
CLUTTER_NOTE (EVENT, "got XEMBED_FOCUS_IN");
|
|
|
|
if (ParentEmbedderWin)
|
2007-11-17 13:11:14 -05:00
|
|
|
xembed_send_message (backend_x11, ParentEmbedderWin,
|
2007-04-19 11:24:57 -04:00
|
|
|
XEMBED_FOCUS_NEXT,
|
|
|
|
0, 0, 0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
CLUTTER_NOTE (EVENT, "got unknown XEMBED message");
|
|
|
|
break;
|
|
|
|
}
|
2007-04-19 11:26:54 -04:00
|
|
|
|
|
|
|
/* do not propagate the XEMBED events to the stage */
|
|
|
|
return FALSE;
|
2007-04-19 11:24:57 -04:00
|
|
|
}
|
|
|
|
|
2010-09-07 20:15:00 -04:00
|
|
|
static gboolean
|
|
|
|
clipped_redraws_cool_off_cb (void *data)
|
|
|
|
{
|
|
|
|
ClutterStageX11 *stage_x11 = data;
|
|
|
|
|
|
|
|
stage_x11->clipped_redraws_cool_off = 0;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-03-22 14:21:59 -04:00
|
|
|
static gboolean
|
2007-05-09 19:31:08 -04:00
|
|
|
event_translate (ClutterBackend *backend,
|
2008-01-31 06:24:11 -05:00
|
|
|
ClutterEvent *event,
|
|
|
|
XEvent *xevent)
|
2007-03-22 14:21:59 -04:00
|
|
|
{
|
2009-11-20 11:24:16 -05:00
|
|
|
ClutterBackendX11 *backend_x11;
|
|
|
|
ClutterStageX11 *stage_x11;
|
|
|
|
ClutterStage *stage;
|
2008-04-04 11:02:11 -04:00
|
|
|
ClutterStageWindow *impl;
|
2010-02-17 12:06:25 -05:00
|
|
|
ClutterDeviceManager *manager;
|
2009-11-20 11:24:16 -05:00
|
|
|
gboolean res, not_yet_handled = FALSE;
|
|
|
|
Window xwindow, stage_xwindow;
|
2009-12-08 19:03:13 -05:00
|
|
|
ClutterInputDevice *device;
|
2007-03-22 14:21:59 -04:00
|
|
|
|
2009-11-20 11:24:16 -05:00
|
|
|
backend_x11 = CLUTTER_BACKEND_X11 (backend);
|
2007-03-22 14:21:59 -04:00
|
|
|
|
|
|
|
xwindow = xevent->xany.window;
|
|
|
|
|
2007-11-15 09:45:27 -05:00
|
|
|
if (backend_x11->event_filters)
|
2007-05-31 07:13:43 -04:00
|
|
|
{
|
2009-12-08 13:33:01 -05:00
|
|
|
GSList *node;
|
2007-05-31 07:13:43 -04:00
|
|
|
|
2007-11-15 09:45:27 -05:00
|
|
|
node = backend_x11->event_filters;
|
2007-05-31 07:13:43 -04:00
|
|
|
|
|
|
|
while (node)
|
2008-01-31 06:24:11 -05:00
|
|
|
{
|
2009-12-08 13:33:01 -05:00
|
|
|
ClutterX11EventFilter *filter = node->data;
|
2008-01-31 06:24:11 -05:00
|
|
|
|
|
|
|
switch (filter->func (xevent, event, filter->data))
|
|
|
|
{
|
|
|
|
case CLUTTER_X11_FILTER_CONTINUE:
|
|
|
|
break;
|
|
|
|
case CLUTTER_X11_FILTER_TRANSLATE:
|
|
|
|
return TRUE;
|
|
|
|
case CLUTTER_X11_FILTER_REMOVE:
|
|
|
|
return FALSE;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
node = node->next;
|
|
|
|
}
|
2007-05-31 07:13:43 -04:00
|
|
|
}
|
2008-02-12 07:39:22 -05:00
|
|
|
|
2010-05-19 11:13:07 -04:00
|
|
|
/* Pass the event through Cogl */
|
|
|
|
if (_cogl_xlib_handle_event (xevent) == COGL_XLIB_FILTER_REMOVE)
|
|
|
|
return FALSE;
|
|
|
|
|
2009-12-08 13:33:01 -05:00
|
|
|
/* Do further processing only on events for the stage window (the x11
|
|
|
|
* filters might be getting events for other windows, so do not mess
|
|
|
|
* them about.
|
2008-02-12 07:39:22 -05:00
|
|
|
*/
|
2008-03-28 18:50:55 -04:00
|
|
|
stage = clutter_x11_get_stage_from_window (xwindow);
|
|
|
|
if (stage == NULL)
|
2009-12-08 13:33:01 -05:00
|
|
|
return FALSE;
|
2008-02-12 07:39:22 -05:00
|
|
|
|
2009-11-20 11:24:16 -05:00
|
|
|
impl = _clutter_stage_get_window (stage);
|
|
|
|
stage_x11 = CLUTTER_STAGE_X11 (impl);
|
|
|
|
stage_xwindow = xwindow; /* clutter_x11_get_stage_window (stage); */
|
2008-03-28 18:50:55 -04:00
|
|
|
|
|
|
|
event->any.stage = stage;
|
|
|
|
|
2007-03-22 14:21:59 -04:00
|
|
|
res = TRUE;
|
|
|
|
|
2009-02-18 04:45:26 -05:00
|
|
|
update_last_event_time (backend_x11, xevent);
|
|
|
|
|
2010-02-17 12:06:25 -05:00
|
|
|
manager = clutter_device_manager_get_default ();
|
|
|
|
|
2007-03-22 14:21:59 -04:00
|
|
|
switch (xevent->type)
|
|
|
|
{
|
2007-08-24 11:12:52 -04:00
|
|
|
case ConfigureNotify:
|
2008-02-21 07:17:01 -05:00
|
|
|
if (!stage_x11->is_foreign_xwin)
|
|
|
|
{
|
2009-01-12 06:15:41 -05:00
|
|
|
CLUTTER_NOTE (BACKEND, "%s: ConfigureNotify[%x] (%d, %d)",
|
|
|
|
G_STRLOC,
|
|
|
|
(unsigned int) stage_x11->xwin,
|
|
|
|
xevent->xconfigure.width,
|
|
|
|
xevent->xconfigure.height);
|
|
|
|
|
2010-02-17 11:56:30 -05:00
|
|
|
/* Queue a relayout - we want glViewport to be called
|
|
|
|
* with the correct values, and this is done in ClutterStage
|
|
|
|
* via _cogl_onscreen_clutter_backend_set_size ().
|
|
|
|
*
|
|
|
|
* We queue a relayout, because if this ConfigureNotify is
|
|
|
|
* in response to a size we set in the application, the
|
|
|
|
* set_size above is essentially a null-op.
|
|
|
|
*
|
|
|
|
* Make sure we do this only when the size has changed,
|
|
|
|
* otherwise we end up relayouting on window moves.
|
|
|
|
*/
|
|
|
|
if ((stage_x11->state & CLUTTER_STAGE_STATE_FULLSCREEN) ||
|
|
|
|
(stage_x11->xwin_width != xevent->xconfigure.width) ||
|
|
|
|
(stage_x11->xwin_height != xevent->xconfigure.height))
|
2010-07-08 10:47:18 -04:00
|
|
|
{
|
|
|
|
clutter_actor_queue_relayout (CLUTTER_ACTOR (stage));
|
|
|
|
}
|
2010-02-17 11:56:30 -05:00
|
|
|
|
2010-02-16 09:50:14 -05:00
|
|
|
/* If we're fullscreened, we want these variables to
|
|
|
|
* represent the size of the window before it was set
|
|
|
|
* to fullscreen.
|
|
|
|
*/
|
|
|
|
if (!(stage_x11->state & CLUTTER_STAGE_STATE_FULLSCREEN))
|
|
|
|
{
|
|
|
|
stage_x11->xwin_width = xevent->xconfigure.width;
|
|
|
|
stage_x11->xwin_height = xevent->xconfigure.height;
|
|
|
|
}
|
2010-02-15 13:53:58 -05:00
|
|
|
|
2009-10-05 07:24:19 -04:00
|
|
|
clutter_actor_set_size (CLUTTER_ACTOR (stage),
|
|
|
|
xevent->xconfigure.width,
|
|
|
|
xevent->xconfigure.height);
|
2008-02-21 07:17:01 -05:00
|
|
|
|
2010-09-07 20:15:00 -04:00
|
|
|
/* XXX: This is a workaround for a race condition when
|
|
|
|
* resizing windows while there are in-flight
|
|
|
|
* glXCopySubBuffer blits happening.
|
|
|
|
*
|
|
|
|
* The problem stems from the fact that rectangles for the
|
|
|
|
* blits are described relative to the bottom left of the
|
|
|
|
* window and because we can't guarantee control over the X
|
|
|
|
* window gravity used when resizing so the gravity is
|
|
|
|
* typically NorthWest not SouthWest.
|
|
|
|
*
|
|
|
|
* This means if you grow a window vertically the server
|
|
|
|
* will make sure to place the old contents of the window
|
|
|
|
* at the top-left/north-west of your new larger window, but
|
|
|
|
* that may happen asynchronous to GLX preparing to do a
|
|
|
|
* blit specified relative to the bottom-left/south-west of
|
|
|
|
* the window (based on the old smaller window geometry).
|
|
|
|
*
|
|
|
|
* When the GLX issued blit finally happens relative to the
|
|
|
|
* new bottom of your window, the destination will have
|
|
|
|
* shifted relative to the top-left where all the pixels you
|
|
|
|
* care about are so it will result in a nasty artefact
|
|
|
|
* making resizing look very ugly!
|
|
|
|
*
|
|
|
|
* We can't currently fix this completely, in-part because
|
|
|
|
* the window manager tends to trample any gravity we might
|
|
|
|
* set. This workaround instead simply disables blits for a
|
|
|
|
* while if we are notified of any resizes happening so if
|
|
|
|
* the user is resizing a window via the window manager then
|
|
|
|
* they may see an artefact for one frame but then we will
|
|
|
|
* fallback to redrawing the full stage until the cooling
|
|
|
|
* off period is over.
|
|
|
|
*/
|
|
|
|
if (stage_x11->clipped_redraws_cool_off)
|
|
|
|
g_source_remove (stage_x11->clipped_redraws_cool_off);
|
|
|
|
stage_x11->clipped_redraws_cool_off =
|
|
|
|
g_timeout_add_seconds (1, clipped_redraws_cool_off_cb, stage_x11);
|
|
|
|
|
2009-06-25 09:41:25 -04:00
|
|
|
CLUTTER_UNSET_PRIVATE_FLAGS (stage_x11->wrapper,
|
2010-07-21 11:10:46 -04:00
|
|
|
CLUTTER_IN_RESIZE);
|
2009-06-25 09:41:25 -04:00
|
|
|
|
2009-01-12 06:15:41 -05:00
|
|
|
/* the resize process is complete, so we can ask the stage
|
|
|
|
* to set up the GL viewport with the new size
|
2009-01-09 07:06:46 -05:00
|
|
|
*/
|
2009-06-25 09:41:25 -04:00
|
|
|
clutter_stage_ensure_viewport (stage);
|
2008-02-21 07:17:01 -05:00
|
|
|
}
|
2007-08-24 11:12:52 -04:00
|
|
|
res = FALSE;
|
|
|
|
break;
|
2007-11-26 07:07:25 -05:00
|
|
|
|
2007-08-24 11:12:52 -04:00
|
|
|
case PropertyNotify:
|
2008-02-21 07:45:48 -05:00
|
|
|
if (xevent->xproperty.atom == backend_x11->atom_NET_WM_STATE &&
|
|
|
|
xevent->xproperty.window == stage_xwindow &&
|
|
|
|
!stage_x11->is_foreign_xwin)
|
2007-11-26 07:07:25 -05:00
|
|
|
{
|
|
|
|
Atom type;
|
|
|
|
gint format;
|
|
|
|
gulong n_items, bytes_after;
|
|
|
|
guchar *data = NULL;
|
|
|
|
gboolean fullscreen_set = FALSE;
|
|
|
|
|
|
|
|
clutter_x11_trap_x_errors ();
|
|
|
|
XGetWindowProperty (backend_x11->xdpy, stage_xwindow,
|
|
|
|
backend_x11->atom_NET_WM_STATE,
|
2008-02-12 07:39:22 -05:00
|
|
|
0, G_MAXLONG,
|
2007-11-26 07:07:25 -05:00
|
|
|
False, XA_ATOM,
|
|
|
|
&type, &format, &n_items,
|
|
|
|
&bytes_after, &data);
|
|
|
|
clutter_x11_untrap_x_errors ();
|
|
|
|
|
|
|
|
if (type != None && data != NULL)
|
|
|
|
{
|
|
|
|
Atom *atoms = (Atom *) data;
|
|
|
|
gulong i;
|
|
|
|
gboolean is_fullscreen = FALSE;
|
|
|
|
|
|
|
|
for (i = 0; i < n_items; i++)
|
|
|
|
{
|
|
|
|
if (atoms[i] == backend_x11->atom_NET_WM_STATE_FULLSCREEN)
|
|
|
|
fullscreen_set = TRUE;
|
2008-01-31 06:24:11 -05:00
|
|
|
}
|
2007-11-26 07:07:25 -05:00
|
|
|
|
|
|
|
is_fullscreen =
|
|
|
|
(stage_x11->state & CLUTTER_STAGE_STATE_FULLSCREEN);
|
|
|
|
|
|
|
|
if (fullscreen_set != is_fullscreen)
|
2008-01-31 06:24:11 -05:00
|
|
|
{
|
|
|
|
if (fullscreen_set)
|
2007-11-26 07:07:25 -05:00
|
|
|
stage_x11->state |= CLUTTER_STAGE_STATE_FULLSCREEN;
|
2008-01-31 06:24:11 -05:00
|
|
|
else
|
2007-11-26 07:07:25 -05:00
|
|
|
stage_x11->state &= ~CLUTTER_STAGE_STATE_FULLSCREEN;
|
|
|
|
|
2010-02-16 09:50:14 -05:00
|
|
|
stage_x11->fullscreening = fullscreen_set;
|
|
|
|
|
2007-11-26 07:07:25 -05:00
|
|
|
event->type = CLUTTER_STAGE_STATE;
|
|
|
|
event->stage_state.changed_mask =
|
|
|
|
CLUTTER_STAGE_STATE_FULLSCREEN;
|
|
|
|
event->stage_state.new_state = stage_x11->state;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
res = FALSE;
|
2008-02-12 07:39:22 -05:00
|
|
|
|
2007-11-26 07:07:25 -05:00
|
|
|
XFree (data);
|
2008-01-31 06:24:11 -05:00
|
|
|
}
|
|
|
|
else
|
2007-11-26 07:07:25 -05:00
|
|
|
res = FALSE;
|
|
|
|
}
|
2008-02-21 07:45:48 -05:00
|
|
|
else
|
|
|
|
res = FALSE;
|
2007-11-26 07:07:25 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MapNotify:
|
|
|
|
res = FALSE;
|
2007-08-24 11:12:52 -04:00
|
|
|
break;
|
2007-11-26 07:07:25 -05:00
|
|
|
|
|
|
|
case UnmapNotify:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
|
2007-08-24 11:12:52 -04:00
|
|
|
case FocusIn:
|
2007-11-15 09:45:27 -05:00
|
|
|
if (!(stage_x11->state & CLUTTER_STAGE_STATE_ACTIVATED))
|
2008-01-31 06:24:11 -05:00
|
|
|
{
|
|
|
|
/* TODO: check xevent->xfocus.detail ? */
|
|
|
|
stage_x11->state |= CLUTTER_STAGE_STATE_ACTIVATED;
|
|
|
|
|
|
|
|
event->type = CLUTTER_STAGE_STATE;
|
|
|
|
event->stage_state.changed_mask = CLUTTER_STAGE_STATE_ACTIVATED;
|
|
|
|
event->stage_state.new_state = stage_x11->state;
|
|
|
|
}
|
2007-08-24 11:12:52 -04:00
|
|
|
else
|
2008-01-31 06:24:11 -05:00
|
|
|
res = FALSE;
|
2007-08-24 11:12:52 -04:00
|
|
|
break;
|
2007-11-26 07:07:25 -05:00
|
|
|
|
2007-08-24 11:12:52 -04:00
|
|
|
case FocusOut:
|
2007-11-15 09:45:27 -05:00
|
|
|
if (stage_x11->state & CLUTTER_STAGE_STATE_ACTIVATED)
|
2008-01-31 06:24:11 -05:00
|
|
|
{
|
|
|
|
stage_x11->state &= ~CLUTTER_STAGE_STATE_ACTIVATED;
|
2007-08-24 11:12:52 -04:00
|
|
|
|
2008-01-31 06:24:11 -05:00
|
|
|
event->type = CLUTTER_STAGE_STATE;
|
|
|
|
event->stage_state.changed_mask = CLUTTER_STAGE_STATE_ACTIVATED;
|
|
|
|
event->stage_state.new_state = stage_x11->state;
|
|
|
|
}
|
2007-08-24 11:12:52 -04:00
|
|
|
else
|
2008-01-31 06:24:11 -05:00
|
|
|
res = FALSE;
|
2007-08-24 11:12:52 -04:00
|
|
|
break;
|
2007-11-26 07:07:25 -05:00
|
|
|
|
2007-03-22 14:21:59 -04:00
|
|
|
case Expose:
|
|
|
|
{
|
2008-05-13 06:21:25 -04:00
|
|
|
CLUTTER_NOTE (MULTISTAGE, "expose for stage: %p, redrawing", stage);
|
|
|
|
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
|
2010-09-07 20:03:15 -04:00
|
|
|
XExposeEvent *expose = (XExposeEvent *)xevent;
|
|
|
|
ClutterPaintVolume clip;
|
|
|
|
ClutterVertex origin;
|
|
|
|
|
|
|
|
CLUTTER_NOTE (MULTISTAGE,
|
|
|
|
"expose for stage: %p, "
|
|
|
|
"redrawing (x=%d, y=%d, width=%d, height=%d)",
|
|
|
|
stage,
|
|
|
|
expose->x,
|
|
|
|
expose->y,
|
|
|
|
expose->width,
|
|
|
|
expose->height);
|
|
|
|
|
|
|
|
origin.x = expose->x;
|
|
|
|
origin.y = expose->y;
|
|
|
|
origin.z = 0;
|
|
|
|
|
|
|
|
_clutter_paint_volume_init_static (CLUTTER_ACTOR (stage), &clip);
|
|
|
|
|
|
|
|
clutter_paint_volume_set_origin (&clip, &origin);
|
|
|
|
clutter_paint_volume_set_width (&clip, expose->width);
|
|
|
|
clutter_paint_volume_set_height (&clip, expose->height);
|
|
|
|
|
|
|
|
_clutter_actor_queue_redraw_with_clip (CLUTTER_ACTOR (stage), 0, &clip);
|
|
|
|
|
|
|
|
clutter_paint_volume_free (&clip);
|
|
|
|
|
2007-03-22 14:21:59 -04:00
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DestroyNotify:
|
2007-11-26 07:07:25 -05:00
|
|
|
CLUTTER_NOTE (EVENT, "destroy notify:\txid: %ld",
|
2007-03-23 05:44:21 -04:00
|
|
|
xevent->xdestroywindow.window);
|
2008-01-23 06:08:39 -05:00
|
|
|
if (xevent->xdestroywindow.window == stage_xwindow &&
|
|
|
|
!stage_x11->is_foreign_xwin)
|
|
|
|
event->type = event->any.type = CLUTTER_DESTROY_NOTIFY;
|
|
|
|
else
|
|
|
|
res = FALSE;
|
2007-03-22 14:21:59 -04:00
|
|
|
break;
|
2007-11-26 07:07:25 -05:00
|
|
|
|
2007-04-19 11:24:57 -04:00
|
|
|
case ClientMessage:
|
|
|
|
CLUTTER_NOTE (EVENT, "client message");
|
2008-02-12 07:39:22 -05:00
|
|
|
|
2007-04-19 11:24:57 -04:00
|
|
|
event->type = event->any.type = CLUTTER_CLIENT_MESSAGE;
|
2008-02-12 07:39:22 -05:00
|
|
|
|
2007-11-17 13:11:14 -05:00
|
|
|
if (xevent->xclient.message_type == backend_x11->atom_XEMBED)
|
2007-11-15 09:45:27 -05:00
|
|
|
res = handle_xembed_event (backend_x11, xevent);
|
2007-11-17 13:11:14 -05:00
|
|
|
else if (xevent->xclient.message_type == backend_x11->atom_WM_PROTOCOLS)
|
2007-04-19 11:26:54 -04:00
|
|
|
{
|
2008-03-28 18:50:55 -04:00
|
|
|
res = handle_wm_protocols_event (backend_x11, stage_xwindow, xevent);
|
2007-04-19 11:26:54 -04:00
|
|
|
event->type = event->any.type = CLUTTER_DELETE;
|
|
|
|
}
|
2007-04-19 11:24:57 -04:00
|
|
|
break;
|
2007-11-26 07:07:25 -05:00
|
|
|
|
2008-06-30 10:01:03 -04:00
|
|
|
case KeyPress:
|
|
|
|
event->key.type = event->type = CLUTTER_KEY_PRESS;
|
2010-02-17 12:06:25 -05:00
|
|
|
event->key.device =
|
|
|
|
clutter_device_manager_get_core_device (manager,
|
2010-06-29 10:30:25 -04:00
|
|
|
CLUTTER_KEYBOARD_DEVICE);
|
2010-01-08 12:51:00 -05:00
|
|
|
|
2010-07-12 13:04:03 -04:00
|
|
|
translate_key_event (backend_x11, event, xevent);
|
2008-06-30 10:01:03 -04:00
|
|
|
|
|
|
|
set_user_time (backend_x11, &xwindow, xevent->xkey.time);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KeyRelease:
|
2009-12-09 13:46:25 -05:00
|
|
|
/* old-style X11 terminals require that even modern X11 send
|
|
|
|
* KeyPress/KeyRelease pairs when auto-repeating. for this
|
|
|
|
* reason modern(-ish) API like XKB has a way to detect
|
|
|
|
* auto-repeat and do a single KeyRelease at the end of a
|
|
|
|
* KeyPress sequence.
|
|
|
|
*
|
|
|
|
* this check emulates XKB's detectable auto-repeat; we peek
|
|
|
|
* the next event and check if it's a KeyPress for the same key
|
|
|
|
* and timestamp - and then ignore it if it matches the
|
|
|
|
* KeyRelease
|
2010-07-12 13:04:03 -04:00
|
|
|
*
|
|
|
|
* if we have XKB, and autorepeat is enabled, then this becomes
|
|
|
|
* a no-op
|
2009-12-09 13:46:25 -05:00
|
|
|
*/
|
2010-07-12 13:04:03 -04:00
|
|
|
if (!backend_x11->have_xkb_autorepeat && XPending (xevent->xkey.display))
|
2009-12-09 13:46:25 -05:00
|
|
|
{
|
|
|
|
XEvent next_event;
|
|
|
|
|
|
|
|
XPeekEvent (xevent->xkey.display, &next_event);
|
|
|
|
|
|
|
|
if (next_event.type == KeyPress &&
|
|
|
|
next_event.xkey.keycode == xevent->xkey.keycode &&
|
|
|
|
next_event.xkey.time == xevent->xkey.time)
|
|
|
|
{
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-30 10:01:03 -04:00
|
|
|
event->key.type = event->type = CLUTTER_KEY_RELEASE;
|
2010-02-17 12:06:25 -05:00
|
|
|
event->key.device =
|
|
|
|
clutter_device_manager_get_core_device (manager,
|
|
|
|
CLUTTER_KEYBOARD_DEVICE);
|
2010-01-08 12:51:00 -05:00
|
|
|
|
2010-07-12 13:04:03 -04:00
|
|
|
translate_key_event (backend_x11, event, xevent);
|
2008-06-30 10:01:03 -04:00
|
|
|
break;
|
|
|
|
|
2007-03-22 14:21:59 -04:00
|
|
|
default:
|
|
|
|
/* ignore every other event */
|
2008-06-23 05:55:42 -04:00
|
|
|
not_yet_handled = TRUE;
|
2007-03-22 14:21:59 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-06-23 05:55:42 -04:00
|
|
|
/* Input device event handling.. */
|
|
|
|
if (not_yet_handled)
|
|
|
|
{
|
2010-02-17 12:06:25 -05:00
|
|
|
device = clutter_device_manager_get_core_device (manager,
|
|
|
|
CLUTTER_POINTER_DEVICE);
|
2009-12-08 19:03:13 -05:00
|
|
|
|
2010-01-15 11:28:00 -05:00
|
|
|
/* Regular X event */
|
|
|
|
switch (xevent->type)
|
|
|
|
{
|
|
|
|
case ButtonPress:
|
|
|
|
switch (xevent->xbutton.button)
|
2008-06-23 05:55:42 -04:00
|
|
|
{
|
2010-01-15 11:28:00 -05:00
|
|
|
case 4: /* up */
|
|
|
|
case 5: /* down */
|
|
|
|
case 6: /* left */
|
|
|
|
case 7: /* right */
|
|
|
|
event->scroll.type = event->type = CLUTTER_SCROLL;
|
|
|
|
|
|
|
|
if (xevent->xbutton.button == 4)
|
|
|
|
event->scroll.direction = CLUTTER_SCROLL_UP;
|
|
|
|
else if (xevent->xbutton.button == 5)
|
|
|
|
event->scroll.direction = CLUTTER_SCROLL_DOWN;
|
|
|
|
else if (xevent->xbutton.button == 6)
|
|
|
|
event->scroll.direction = CLUTTER_SCROLL_LEFT;
|
|
|
|
else
|
|
|
|
event->scroll.direction = CLUTTER_SCROLL_RIGHT;
|
2009-11-20 10:36:43 -05:00
|
|
|
|
2010-01-15 11:28:00 -05:00
|
|
|
event->scroll.time = xevent->xbutton.time;
|
|
|
|
event->scroll.x = xevent->xbutton.x;
|
|
|
|
event->scroll.y = xevent->xbutton.y;
|
|
|
|
event->scroll.modifier_state = xevent->xbutton.state;
|
|
|
|
event->scroll.device = device;
|
2008-06-23 05:55:42 -04:00
|
|
|
break;
|
2010-01-15 11:28:00 -05:00
|
|
|
|
|
|
|
default:
|
|
|
|
event->button.type = event->type = CLUTTER_BUTTON_PRESS;
|
2008-06-23 05:55:42 -04:00
|
|
|
event->button.time = xevent->xbutton.time;
|
|
|
|
event->button.x = xevent->xbutton.x;
|
|
|
|
event->button.y = xevent->xbutton.y;
|
|
|
|
event->button.modifier_state = xevent->xbutton.state;
|
|
|
|
event->button.button = xevent->xbutton.button;
|
2009-12-08 19:03:13 -05:00
|
|
|
event->button.device = device;
|
2008-06-23 05:55:42 -04:00
|
|
|
break;
|
2010-01-15 11:28:00 -05:00
|
|
|
}
|
2009-02-12 12:21:18 -05:00
|
|
|
|
2010-01-15 11:28:00 -05:00
|
|
|
set_user_time (backend_x11, &xwindow, event->button.time);
|
2009-12-08 19:03:13 -05:00
|
|
|
|
2010-01-15 11:28:00 -05:00
|
|
|
res = TRUE;
|
|
|
|
break;
|
2009-02-12 12:21:18 -05:00
|
|
|
|
2010-01-15 11:28:00 -05:00
|
|
|
case ButtonRelease:
|
|
|
|
/* scroll events don't have a corresponding release */
|
|
|
|
if (xevent->xbutton.button == 4 ||
|
|
|
|
xevent->xbutton.button == 5 ||
|
|
|
|
xevent->xbutton.button == 6 ||
|
|
|
|
xevent->xbutton.button == 7)
|
|
|
|
{
|
2008-06-23 05:55:42 -04:00
|
|
|
res = FALSE;
|
2010-01-15 11:28:00 -05:00
|
|
|
goto out;
|
2008-06-23 05:55:42 -04:00
|
|
|
}
|
|
|
|
|
2010-01-15 11:28:00 -05:00
|
|
|
event->button.type = event->type = CLUTTER_BUTTON_RELEASE;
|
|
|
|
event->button.time = xevent->xbutton.time;
|
|
|
|
event->button.x = xevent->xbutton.x;
|
|
|
|
event->button.y = xevent->xbutton.y;
|
|
|
|
event->button.modifier_state = xevent->xbutton.state;
|
|
|
|
event->button.button = xevent->xbutton.button;
|
|
|
|
event->button.device = device;
|
|
|
|
|
|
|
|
res = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MotionNotify:
|
|
|
|
event->motion.type = event->type = CLUTTER_MOTION;
|
|
|
|
event->motion.time = xevent->xmotion.time;
|
|
|
|
event->motion.x = xevent->xmotion.x;
|
|
|
|
event->motion.y = xevent->xmotion.y;
|
|
|
|
event->motion.modifier_state = xevent->xmotion.state;
|
|
|
|
event->motion.device = device;
|
|
|
|
|
|
|
|
res = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EnterNotify:
|
|
|
|
/* we know that we are entering the stage here */
|
|
|
|
_clutter_input_device_set_stage (device, stage);
|
|
|
|
CLUTTER_NOTE (EVENT, "Entering the stage");
|
|
|
|
|
|
|
|
/* Convert enter notifies to motion events because X
|
|
|
|
doesn't emit the corresponding motion notify */
|
|
|
|
event->motion.type = event->type = CLUTTER_MOTION;
|
|
|
|
event->motion.time = xevent->xcrossing.time;
|
|
|
|
event->motion.x = xevent->xcrossing.x;
|
|
|
|
event->motion.y = xevent->xcrossing.y;
|
|
|
|
event->motion.modifier_state = xevent->xcrossing.state;
|
|
|
|
event->motion.source = CLUTTER_ACTOR (stage);
|
|
|
|
event->motion.device = device;
|
|
|
|
|
|
|
|
res = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LeaveNotify:
|
|
|
|
if (device->stage == NULL)
|
2010-01-15 07:22:29 -05:00
|
|
|
{
|
2010-01-15 11:28:00 -05:00
|
|
|
CLUTTER_NOTE (EVENT,
|
|
|
|
"Discarding LeaveNotify for ButtonRelease "
|
|
|
|
"event off-stage");
|
|
|
|
res = FALSE;
|
|
|
|
goto out;
|
2010-01-15 07:22:29 -05:00
|
|
|
}
|
|
|
|
|
2010-01-15 11:28:00 -05:00
|
|
|
/* we know that we are leaving the stage here */
|
|
|
|
_clutter_input_device_set_stage (device, NULL);
|
|
|
|
CLUTTER_NOTE (EVENT, "Leaving the stage (time:%u)",
|
|
|
|
event->crossing.time);
|
|
|
|
|
|
|
|
event->crossing.type = event->type = CLUTTER_LEAVE;
|
|
|
|
event->crossing.time = xevent->xcrossing.time;
|
|
|
|
event->crossing.x = xevent->xcrossing.x;
|
|
|
|
event->crossing.y = xevent->xcrossing.y;
|
|
|
|
event->crossing.source = CLUTTER_ACTOR (stage);
|
|
|
|
event->crossing.device = device;
|
|
|
|
res = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-01-15 07:22:29 -05:00
|
|
|
|
2010-01-15 11:28:00 -05:00
|
|
|
/* XInput fun...*/
|
|
|
|
if (!res && clutter_x11_has_xinput ())
|
|
|
|
{
|
|
|
|
#ifdef HAVE_XINPUT
|
|
|
|
int *ev_types = backend_x11->event_types;
|
|
|
|
int button_press, button_release;
|
2010-01-20 14:40:58 -05:00
|
|
|
int key_press, key_release;
|
2010-01-15 11:28:00 -05:00
|
|
|
int motion_notify;
|
2009-06-19 08:07:20 -04:00
|
|
|
|
2010-01-15 11:28:00 -05:00
|
|
|
button_press = ev_types[CLUTTER_X11_XINPUT_BUTTON_PRESS_EVENT];
|
|
|
|
button_release = ev_types[CLUTTER_X11_XINPUT_BUTTON_RELEASE_EVENT];
|
|
|
|
motion_notify = ev_types[CLUTTER_X11_XINPUT_MOTION_NOTIFY_EVENT];
|
2010-01-20 14:40:58 -05:00
|
|
|
key_press = ev_types[CLUTTER_X11_XINPUT_KEY_PRESS_EVENT];
|
|
|
|
key_release = ev_types[CLUTTER_X11_XINPUT_KEY_RELEASE_EVENT];
|
2009-12-08 19:03:13 -05:00
|
|
|
|
2010-01-15 11:28:00 -05:00
|
|
|
CLUTTER_NOTE (EVENT, "XInput event type: %d", xevent->type);
|
2008-06-23 05:55:42 -04:00
|
|
|
|
2010-01-15 11:28:00 -05:00
|
|
|
if (xevent->type == button_press)
|
|
|
|
{
|
|
|
|
XDeviceButtonEvent *xbev = (XDeviceButtonEvent *) xevent;
|
|
|
|
|
|
|
|
device = _clutter_x11_get_device_for_xid (xbev->deviceid);
|
|
|
|
_clutter_input_device_set_stage (device, stage);
|
|
|
|
|
|
|
|
CLUTTER_NOTE (EVENT,
|
|
|
|
"XI ButtonPress for %li ('%s') at %d, %d",
|
|
|
|
xbev->deviceid,
|
|
|
|
device->device_name,
|
|
|
|
xbev->x,
|
|
|
|
xbev->y);
|
2008-06-23 05:55:42 -04:00
|
|
|
|
2010-01-15 11:28:00 -05:00
|
|
|
switch (xbev->button)
|
2008-06-23 05:55:42 -04:00
|
|
|
{
|
2010-01-15 11:28:00 -05:00
|
|
|
case 4:
|
|
|
|
case 5:
|
|
|
|
case 6:
|
|
|
|
case 7:
|
|
|
|
event->scroll.type = event->type = CLUTTER_SCROLL;
|
|
|
|
|
|
|
|
if (xbev->button == 4)
|
|
|
|
event->scroll.direction = CLUTTER_SCROLL_UP;
|
|
|
|
else if (xbev->button == 5)
|
|
|
|
event->scroll.direction = CLUTTER_SCROLL_DOWN;
|
|
|
|
else if (xbev->button == 6)
|
|
|
|
event->scroll.direction = CLUTTER_SCROLL_LEFT;
|
|
|
|
else
|
|
|
|
event->scroll.direction = CLUTTER_SCROLL_RIGHT;
|
|
|
|
|
|
|
|
event->scroll.time = xbev->time;
|
|
|
|
event->scroll.x = xbev->x;
|
|
|
|
event->scroll.y = xbev->y;
|
|
|
|
event->scroll.modifier_state = xbev->state;
|
|
|
|
event->scroll.device = device;
|
|
|
|
break;
|
2008-06-23 05:55:42 -04:00
|
|
|
|
2010-01-15 11:28:00 -05:00
|
|
|
default:
|
|
|
|
event->button.type = event->type = CLUTTER_BUTTON_PRESS;
|
2008-06-23 05:55:42 -04:00
|
|
|
event->button.time = xbev->time;
|
|
|
|
event->button.x = xbev->x;
|
|
|
|
event->button.y = xbev->y;
|
|
|
|
event->button.modifier_state = xbev->state;
|
|
|
|
event->button.button = xbev->button;
|
2009-12-08 19:03:13 -05:00
|
|
|
event->button.device = device;
|
2010-01-15 11:28:00 -05:00
|
|
|
break;
|
|
|
|
}
|
2008-06-23 05:55:42 -04:00
|
|
|
|
2010-01-15 11:28:00 -05:00
|
|
|
set_user_time (backend_x11, &xwindow, xbev->time);
|
2008-06-23 18:00:37 -04:00
|
|
|
|
2010-01-15 11:28:00 -05:00
|
|
|
res = TRUE;
|
|
|
|
}
|
|
|
|
else if (xevent->type == button_release)
|
|
|
|
{
|
|
|
|
XDeviceButtonEvent *xbev = (XDeviceButtonEvent *)xevent;
|
|
|
|
|
|
|
|
device = _clutter_x11_get_device_for_xid (xbev->deviceid);
|
|
|
|
_clutter_input_device_set_stage (device, stage);
|
|
|
|
|
|
|
|
CLUTTER_NOTE (EVENT, "XI ButtonRelease for %li ('%s') at %d, %d",
|
|
|
|
xbev->deviceid,
|
|
|
|
device->device_name,
|
|
|
|
xbev->x,
|
|
|
|
xbev->y);
|
|
|
|
|
|
|
|
/* scroll events don't have a corresponding release */
|
|
|
|
if (xbev->button == 4 ||
|
|
|
|
xbev->button == 5 ||
|
|
|
|
xbev->button == 6 ||
|
|
|
|
xbev->button == 7)
|
2008-06-23 05:55:42 -04:00
|
|
|
{
|
|
|
|
res = FALSE;
|
2010-01-15 11:28:00 -05:00
|
|
|
goto out;
|
2008-06-23 05:55:42 -04:00
|
|
|
}
|
2010-01-15 11:28:00 -05:00
|
|
|
|
|
|
|
event->button.type = event->type = CLUTTER_BUTTON_RELEASE;
|
|
|
|
event->button.time = xbev->time;
|
|
|
|
event->button.x = xbev->x;
|
|
|
|
event->button.y = xbev->y;
|
|
|
|
event->button.modifier_state = xbev->state;
|
|
|
|
event->button.button = xbev->button;
|
|
|
|
event->button.device = device;
|
|
|
|
|
|
|
|
res = TRUE;
|
|
|
|
}
|
|
|
|
else if (xevent->type == motion_notify)
|
|
|
|
{
|
|
|
|
XDeviceMotionEvent *xmev = (XDeviceMotionEvent *)xevent;
|
|
|
|
|
|
|
|
device = _clutter_x11_get_device_for_xid (xmev->deviceid);
|
|
|
|
_clutter_input_device_set_stage (device, stage);
|
|
|
|
|
|
|
|
CLUTTER_NOTE (EVENT, "XI Motion for %li ('%s') at %d, %d",
|
|
|
|
xmev->deviceid,
|
|
|
|
device->device_name,
|
|
|
|
xmev->x,
|
|
|
|
xmev->y);
|
|
|
|
|
|
|
|
event->motion.type = event->type = CLUTTER_MOTION;
|
|
|
|
event->motion.time = xmev->time;
|
|
|
|
event->motion.x = xmev->x;
|
|
|
|
event->motion.y = xmev->y;
|
|
|
|
event->motion.modifier_state = xmev->state;
|
|
|
|
event->motion.device = device;
|
|
|
|
|
|
|
|
res = TRUE;
|
|
|
|
}
|
2010-01-20 14:40:58 -05:00
|
|
|
else if (xevent->type == key_press || xevent->type == key_release)
|
|
|
|
{
|
|
|
|
/* the XInput 1.x handling of key presses/releases is broken:
|
|
|
|
* it makes key repeat, key presses and releases outside the
|
|
|
|
* window not generate events even when the window has focus
|
|
|
|
*/
|
|
|
|
XDeviceKeyEvent *xkev = (XDeviceKeyEvent *) xevent;
|
|
|
|
XEvent xevent_converted;
|
|
|
|
|
|
|
|
convert_xdevicekey_to_xkey (xkev, &xevent_converted);
|
|
|
|
|
|
|
|
event->key.type = event->type = (xevent->type == key_press)
|
|
|
|
? CLUTTER_KEY_PRESS
|
|
|
|
: CLUTTER_KEY_RELEASE;
|
|
|
|
|
2010-07-12 13:04:03 -04:00
|
|
|
translate_key_event (backend_x11, event, &xevent_converted);
|
2010-01-20 14:40:58 -05:00
|
|
|
|
|
|
|
if (xevent->type == key_press)
|
|
|
|
set_user_time (backend_x11, &xwindow, xkev->time);
|
|
|
|
}
|
2010-01-15 11:28:00 -05:00
|
|
|
else
|
|
|
|
#endif /* HAVE_XINPUT */
|
|
|
|
{
|
|
|
|
CLUTTER_NOTE (EVENT, "Uknown Event");
|
|
|
|
res = FALSE;
|
2008-06-23 05:55:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-15 11:28:00 -05:00
|
|
|
out:
|
2007-03-22 14:21:59 -04:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2007-05-09 19:31:08 -04:00
|
|
|
static void
|
|
|
|
events_queue (ClutterBackend *backend)
|
2007-03-22 14:21:59 -04:00
|
|
|
{
|
2007-11-15 09:45:27 -05:00
|
|
|
ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (backend);
|
2009-11-12 15:37:01 -05:00
|
|
|
ClutterBackendX11Class *backend_x11_class =
|
|
|
|
CLUTTER_BACKEND_X11_GET_CLASS (backend_x11);
|
2007-08-23 08:47:25 -04:00
|
|
|
ClutterEvent *event;
|
2007-11-15 09:45:27 -05:00
|
|
|
Display *xdisplay = backend_x11->xdpy;
|
2007-05-09 19:31:08 -04:00
|
|
|
XEvent xevent;
|
|
|
|
ClutterMainContext *clutter_context;
|
2007-03-22 14:21:59 -04:00
|
|
|
|
2009-06-17 12:59:54 -04:00
|
|
|
clutter_context = _clutter_context_get_default ();
|
2007-05-09 19:31:08 -04:00
|
|
|
|
|
|
|
while (!clutter_events_pending () && XPending (xdisplay))
|
2007-03-22 14:21:59 -04:00
|
|
|
{
|
|
|
|
XNextEvent (xdisplay, &xevent);
|
|
|
|
|
2009-11-12 15:37:01 -05:00
|
|
|
if (backend_x11_class->handle_event (backend_x11, &xevent))
|
|
|
|
continue;
|
|
|
|
|
2007-03-22 14:21:59 -04:00
|
|
|
event = clutter_event_new (CLUTTER_NOTHING);
|
2007-05-09 19:31:08 -04:00
|
|
|
|
|
|
|
if (event_translate (backend, event, &xevent))
|
2007-03-22 14:21:59 -04:00
|
|
|
{
|
2007-08-23 08:47:25 -04:00
|
|
|
/* push directly here to avoid copy of queue_put */
|
|
|
|
g_queue_push_head (clutter_context->events_queue, event);
|
2007-03-22 14:21:59 -04:00
|
|
|
}
|
|
|
|
else
|
2010-07-08 10:47:18 -04:00
|
|
|
clutter_event_free (event);
|
2007-03-22 14:21:59 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-21 10:18:14 -05:00
|
|
|
/**
|
2008-06-10 13:11:14 -04:00
|
|
|
* clutter_x11_handle_event:
|
2008-02-21 10:18:14 -05:00
|
|
|
* @xevent: pointer to XEvent structure
|
|
|
|
*
|
|
|
|
* This function processes a single X event; it can be used to hook
|
2010-07-22 05:48:21 -04:00
|
|
|
* into external X11 event processing (for example, a GDK filter
|
|
|
|
* function).
|
|
|
|
*
|
|
|
|
* If clutter_x11_disable_event_retrieval() has been called, you must
|
|
|
|
* let this function process events to update Clutter's internal state.
|
2008-02-21 10:18:14 -05:00
|
|
|
*
|
2008-12-22 08:11:59 -05:00
|
|
|
* Return value: #ClutterX11FilterReturn. %CLUTTER_X11_FILTER_REMOVE
|
|
|
|
* indicates that Clutter has internally handled the event and the
|
|
|
|
* caller should do no further processing. %CLUTTER_X11_FILTER_CONTINUE
|
|
|
|
* indicates that Clutter is either not interested in the event,
|
|
|
|
* or has used the event to update internal state without taking
|
|
|
|
* any exclusive action. %CLUTTER_X11_FILTER_TRANSLATE will not
|
|
|
|
* occur.
|
2008-02-21 10:18:14 -05:00
|
|
|
*
|
2010-07-22 05:48:21 -04:00
|
|
|
* Since: 0.8
|
2008-02-21 10:18:14 -05:00
|
|
|
*/
|
|
|
|
ClutterX11FilterReturn
|
|
|
|
clutter_x11_handle_event (XEvent *xevent)
|
|
|
|
{
|
|
|
|
ClutterBackend *backend;
|
2010-04-30 14:50:11 -04:00
|
|
|
ClutterBackendX11Class *backend_x11_class;
|
2008-02-21 10:18:14 -05:00
|
|
|
ClutterEvent *event;
|
|
|
|
ClutterMainContext *clutter_context;
|
2008-12-22 08:11:59 -05:00
|
|
|
ClutterX11FilterReturn result;
|
2009-01-27 11:37:55 -05:00
|
|
|
gint spin = 1;
|
2008-12-22 08:11:59 -05:00
|
|
|
|
|
|
|
/* The return values here are someone approximate; we return
|
2010-04-30 14:50:11 -04:00
|
|
|
* CLUTTER_X11_FILTER_REMOVE if a clutter event is
|
2008-12-22 08:11:59 -05:00
|
|
|
* generated for the event. This mostly, but not entirely,
|
|
|
|
* corresponds to whether other event processing should be
|
|
|
|
* excluded. As long as the stage window is not shared with another
|
|
|
|
* toolkit it should be safe, and never return
|
|
|
|
* %CLUTTER_X11_FILTER_REMOVE when more processing is needed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
result = CLUTTER_X11_FILTER_CONTINUE;
|
2008-02-21 10:18:14 -05:00
|
|
|
|
|
|
|
clutter_threads_enter ();
|
|
|
|
|
2009-06-17 12:59:54 -04:00
|
|
|
clutter_context = _clutter_context_get_default ();
|
2008-02-21 10:18:14 -05:00
|
|
|
backend = clutter_context->backend;
|
2010-04-30 14:50:11 -04:00
|
|
|
backend_x11_class = CLUTTER_BACKEND_X11_GET_CLASS (backend);
|
|
|
|
|
|
|
|
/* If the backend just observed the event and didn't want it
|
|
|
|
* removed it could return FALSE, so assume that a TRUE return
|
|
|
|
* means that our caller should also do no further processing. */
|
|
|
|
if (backend_x11_class->handle_event (CLUTTER_BACKEND_X11(backend), xevent))
|
|
|
|
return CLUTTER_X11_FILTER_REMOVE;
|
2008-02-21 10:18:14 -05:00
|
|
|
|
|
|
|
event = clutter_event_new (CLUTTER_NOTHING);
|
|
|
|
|
|
|
|
if (event_translate (backend, event, xevent))
|
|
|
|
{
|
|
|
|
/* push directly here to avoid copy of queue_put */
|
2008-12-22 08:11:59 -05:00
|
|
|
result = CLUTTER_X11_FILTER_REMOVE;
|
2008-02-21 10:18:14 -05:00
|
|
|
g_queue_push_head (clutter_context->events_queue, event);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clutter_event_free (event);
|
2008-12-22 08:11:59 -05:00
|
|
|
goto out;
|
2008-02-21 10:18:14 -05:00
|
|
|
}
|
|
|
|
|
2009-01-27 11:37:55 -05:00
|
|
|
/*
|
|
|
|
* Motion events can generate synthetic enter and leave events, so if we
|
|
|
|
* are processing a motion event, we need to spin the event loop at least
|
|
|
|
* two extra times to pump the enter/leave events through (otherwise they
|
|
|
|
* just get pushed down the queue and never processed).
|
|
|
|
*/
|
|
|
|
if (event->type == CLUTTER_MOTION)
|
|
|
|
spin += 2;
|
2008-02-21 10:18:14 -05:00
|
|
|
|
2009-01-27 11:37:55 -05:00
|
|
|
while (spin > 0 && (event = clutter_event_get ()))
|
2008-02-21 10:18:14 -05:00
|
|
|
{
|
|
|
|
/* forward the event into clutter for emission etc. */
|
|
|
|
clutter_do_event (event);
|
|
|
|
clutter_event_free (event);
|
2009-01-27 11:37:55 -05:00
|
|
|
--spin;
|
2008-02-21 10:18:14 -05:00
|
|
|
}
|
|
|
|
|
2008-12-22 08:11:59 -05:00
|
|
|
out:
|
2008-02-21 10:18:14 -05:00
|
|
|
clutter_threads_leave ();
|
|
|
|
|
2008-12-22 08:11:59 -05:00
|
|
|
return result;
|
2008-02-21 10:18:14 -05:00
|
|
|
}
|
|
|
|
|
2007-03-22 14:21:59 -04:00
|
|
|
static gboolean
|
|
|
|
clutter_event_prepare (GSource *source,
|
|
|
|
gint *timeout)
|
|
|
|
{
|
|
|
|
ClutterBackend *backend = ((ClutterEventSource *) source)->backend;
|
|
|
|
gboolean retval;
|
|
|
|
|
2007-08-08 06:20:14 -04:00
|
|
|
clutter_threads_enter ();
|
|
|
|
|
2007-03-22 14:21:59 -04:00
|
|
|
*timeout = -1;
|
2007-05-09 19:31:08 -04:00
|
|
|
retval = (clutter_events_pending () || check_xpending (backend));
|
2007-03-22 14:21:59 -04:00
|
|
|
|
2007-08-08 06:20:14 -04:00
|
|
|
clutter_threads_leave ();
|
|
|
|
|
2007-03-22 14:21:59 -04:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
clutter_event_check (GSource *source)
|
|
|
|
{
|
|
|
|
ClutterEventSource *event_source = (ClutterEventSource *) source;
|
|
|
|
ClutterBackend *backend = event_source->backend;
|
|
|
|
gboolean retval;
|
|
|
|
|
2007-08-08 06:20:14 -04:00
|
|
|
clutter_threads_enter ();
|
|
|
|
|
2007-03-22 14:21:59 -04:00
|
|
|
if (event_source->event_poll_fd.revents & G_IO_IN)
|
2007-05-09 19:31:08 -04:00
|
|
|
retval = (clutter_events_pending () || check_xpending (backend));
|
2007-03-22 14:21:59 -04:00
|
|
|
else
|
|
|
|
retval = FALSE;
|
|
|
|
|
2007-08-08 06:20:14 -04:00
|
|
|
clutter_threads_leave ();
|
|
|
|
|
2007-03-22 14:21:59 -04:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
clutter_event_dispatch (GSource *source,
|
|
|
|
GSourceFunc callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
ClutterBackend *backend = ((ClutterEventSource *) source)->backend;
|
|
|
|
ClutterEvent *event;
|
|
|
|
|
2007-08-08 06:20:14 -04:00
|
|
|
clutter_threads_enter ();
|
|
|
|
|
2008-02-12 07:39:22 -05:00
|
|
|
/* Grab the event(s), translate and figure out double click.
|
2007-05-09 19:31:08 -04:00
|
|
|
* The push onto queue (stack) if valid.
|
|
|
|
*/
|
|
|
|
events_queue (backend);
|
|
|
|
|
|
|
|
/* Pop an event off the queue if any */
|
|
|
|
event = clutter_event_get ();
|
2007-03-22 14:21:59 -04:00
|
|
|
|
|
|
|
if (event)
|
|
|
|
{
|
2007-05-09 19:31:08 -04:00
|
|
|
/* forward the event into clutter for emission etc. */
|
|
|
|
clutter_do_event (event);
|
2007-03-22 14:21:59 -04:00
|
|
|
clutter_event_free (event);
|
|
|
|
}
|
|
|
|
|
2007-08-08 06:20:14 -04:00
|
|
|
clutter_threads_leave ();
|
|
|
|
|
2007-03-22 14:21:59 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2009-02-18 04:45:26 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_x11_get_current_event_time:
|
|
|
|
*
|
|
|
|
* Retrieves the timestamp of the last X11 event processed by
|
|
|
|
* Clutter. This might be different from the timestamp returned
|
|
|
|
* by clutter_get_current_event_time(), as Clutter may synthesize
|
|
|
|
* or throttle events.
|
|
|
|
*
|
|
|
|
* Return value: a timestamp, in milliseconds
|
|
|
|
*
|
|
|
|
* Since: 1.0
|
|
|
|
*/
|
|
|
|
Time
|
|
|
|
clutter_x11_get_current_event_time (void)
|
|
|
|
{
|
|
|
|
ClutterBackend *backend = clutter_get_default_backend ();
|
|
|
|
|
|
|
|
return CLUTTER_BACKEND_X11 (backend)->last_event_time;
|
|
|
|
}
|
2010-07-08 10:47:18 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_x11_event_get_key_group:
|
|
|
|
* @event: a #ClutterEvent of type %CLUTTER_KEY_PRESS or %CLUTTER_KEY_RELEASE
|
|
|
|
*
|
|
|
|
* Retrieves the group for the modifiers set in @event
|
|
|
|
*
|
|
|
|
* Return value: the group id
|
|
|
|
*
|
|
|
|
* Since: 1.4
|
|
|
|
*/
|
|
|
|
gint
|
|
|
|
clutter_x11_event_get_key_group (const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
ClutterEventX11 *event_x11;
|
|
|
|
|
|
|
|
g_return_val_if_fail (event != NULL, 0);
|
|
|
|
g_return_val_if_fail (event->type == CLUTTER_KEY_PRESS ||
|
|
|
|
event->type == CLUTTER_KEY_RELEASE, 0);
|
|
|
|
|
|
|
|
event_x11 = _clutter_event_get_platform_data (event);
|
|
|
|
if (event_x11 == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return event_x11->key_group;
|
|
|
|
}
|