2007-03-22 18:21:59 +00:00
|
|
|
/* Clutter.
|
|
|
|
* An OpenGL based 'interactive canvas' library.
|
|
|
|
* Authored By Matthew Allum <mallum@openedhand.com>
|
|
|
|
* Copyright (C) 2006-2007 OpenedHand
|
|
|
|
*
|
|
|
|
* 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, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2007-11-15 14:45:27 +00:00
|
|
|
#include "clutter-stage-x11.h"
|
|
|
|
#include "clutter-backend-x11.h"
|
|
|
|
#include "clutter-x11.h"
|
2007-03-22 18:21:59 +00:00
|
|
|
|
|
|
|
#include "../clutter-backend.h"
|
|
|
|
#include "../clutter-event.h"
|
|
|
|
#include "../clutter-private.h"
|
|
|
|
#include "../clutter-debug.h"
|
|
|
|
#include "../clutter-main.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_XFIXES
|
|
|
|
#include <X11/extensions/Xfixes.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <X11/Xatom.h>
|
|
|
|
|
2008-06-23 09:55:42 +00:00
|
|
|
#ifdef USE_XINPUT
|
|
|
|
#include <X11/extensions/XInput.h>
|
|
|
|
#endif
|
|
|
|
|
2007-04-19 15:24:57 +00: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 18:21:59 +00:00
|
|
|
typedef struct _ClutterEventSource ClutterEventSource;
|
|
|
|
|
|
|
|
struct _ClutterEventSource
|
|
|
|
{
|
|
|
|
GSource source;
|
|
|
|
|
|
|
|
ClutterBackend *backend;
|
|
|
|
GPollFD event_poll_fd;
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
event_source->backend = backend;
|
|
|
|
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2007-05-09 23:31:08 +00:00
|
|
|
check_xpending (ClutterBackend *backend)
|
2007-03-22 18:21:59 +00:00
|
|
|
{
|
2007-11-15 14:45:27 +00:00
|
|
|
return XPending (CLUTTER_BACKEND_X11 (backend)->xdpy);
|
2007-03-22 18:21:59 +00:00
|
|
|
}
|
|
|
|
|
2007-04-19 15:24:57 +00:00
|
|
|
static gboolean
|
2007-11-17 18:11:14 +00:00
|
|
|
xembed_send_message (ClutterBackendX11 *backend_x11,
|
|
|
|
Window window,
|
2008-01-31 11:24:11 +00:00
|
|
|
long message,
|
|
|
|
long detail,
|
2008-02-12 12:39:22 +00:00
|
|
|
long data1,
|
2008-01-31 11:24:11 +00:00
|
|
|
long data2)
|
2007-04-19 15:24:57 +00:00
|
|
|
{
|
|
|
|
XEvent ev;
|
|
|
|
|
|
|
|
memset (&ev, 0, sizeof (ev));
|
|
|
|
|
|
|
|
ev.xclient.type = ClientMessage;
|
|
|
|
ev.xclient.window = window;
|
2007-11-17 18:11:14 +00:00
|
|
|
ev.xclient.message_type = backend_x11->atom_XEMBED;
|
2007-04-19 15:24:57 +00: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 14:45:27 +00:00
|
|
|
clutter_x11_trap_x_errors ();
|
2007-04-19 15:24:57 +00:00
|
|
|
|
2007-11-17 18:11:14 +00:00
|
|
|
XSendEvent (backend_x11->xdpy, window, False, NoEventMask, &ev);
|
|
|
|
XSync (backend_x11->xdpy, False);
|
2007-04-19 15:24:57 +00:00
|
|
|
|
2007-11-15 14:45:27 +00:00
|
|
|
if (clutter_x11_untrap_x_errors ())
|
2007-04-19 15:24:57 +00:00
|
|
|
return False;
|
|
|
|
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-11-17 18:11:14 +00:00
|
|
|
xembed_set_info (ClutterBackendX11 *backend_x11,
|
|
|
|
Window window,
|
|
|
|
gint flags)
|
2007-04-19 15:24:57 +00:00
|
|
|
{
|
|
|
|
gint32 list[2];
|
|
|
|
|
|
|
|
list[0] = MAX_SUPPORTED_XEMBED_VERSION;
|
|
|
|
list[1] = XEMBED_MAPPED;
|
|
|
|
|
2007-11-17 18:11:14 +00:00
|
|
|
XChangeProperty (backend_x11->xdpy, window,
|
|
|
|
backend_x11->atom_XEMBED_INFO,
|
|
|
|
backend_x11->atom_XEMBED_INFO, 32,
|
2007-04-19 15:24:57 +00:00
|
|
|
PropModeReplace, (unsigned char *) list, 2);
|
|
|
|
}
|
2007-03-22 18:21:59 +00:00
|
|
|
|
|
|
|
void
|
2007-11-15 14:45:27 +00:00
|
|
|
_clutter_backend_x11_events_init (ClutterBackend *backend)
|
2007-03-22 18:21:59 +00:00
|
|
|
{
|
2007-11-17 18:11:14 +00:00
|
|
|
ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (backend);
|
2007-03-22 18:21:59 +00:00
|
|
|
GSource *source;
|
|
|
|
ClutterEventSource *event_source;
|
|
|
|
int connection_number;
|
2008-02-12 12:39:22 +00:00
|
|
|
|
2008-02-21 15:18:14 +00:00
|
|
|
if (backend_x11->no_xevent_retrieval)
|
|
|
|
return;
|
|
|
|
|
2007-11-15 14:45:27 +00:00
|
|
|
connection_number = ConnectionNumber (backend_x11->xdpy);
|
2007-03-22 18:21:59 +00:00
|
|
|
CLUTTER_NOTE (EVENT, "Connection number: %d", connection_number);
|
|
|
|
|
2007-11-15 14:45:27 +00:00
|
|
|
source = backend_x11->event_source = clutter_event_source_new (backend);
|
2007-03-22 18:21:59 +00: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);
|
2007-04-19 15:24:57 +00:00
|
|
|
|
2007-03-22 18:21:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-11-15 14:45:27 +00:00
|
|
|
_clutter_backend_x11_events_uninit (ClutterBackend *backend)
|
2007-03-22 18:21:59 +00:00
|
|
|
{
|
2007-11-15 14:45:27 +00:00
|
|
|
ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (backend);
|
2007-03-22 18:21:59 +00:00
|
|
|
|
2007-11-15 14:45:27 +00:00
|
|
|
if (backend_x11->event_source)
|
2007-03-22 18:21:59 +00:00
|
|
|
{
|
|
|
|
CLUTTER_NOTE (EVENT, "Destroying the event source");
|
|
|
|
|
|
|
|
event_sources = g_list_remove (event_sources,
|
2007-11-15 14:45:27 +00:00
|
|
|
backend_x11->event_source);
|
2007-03-22 18:21:59 +00:00
|
|
|
|
2007-11-15 14:45:27 +00:00
|
|
|
g_source_destroy (backend_x11->event_source);
|
|
|
|
g_source_unref (backend_x11->event_source);
|
|
|
|
backend_x11->event_source = NULL;
|
2007-03-22 18:21:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-11-17 18:11:14 +00:00
|
|
|
set_user_time (ClutterBackendX11 *backend_x11,
|
|
|
|
Window *xwindow,
|
|
|
|
long timestamp)
|
2007-03-22 18:21:59 +00:00
|
|
|
{
|
2007-04-19 15:26:54 +00:00
|
|
|
if (timestamp != CLUTTER_CURRENT_TIME)
|
2007-03-22 18:21:59 +00:00
|
|
|
{
|
2007-11-17 18:11:14 +00:00
|
|
|
XChangeProperty (backend_x11->xdpy, *xwindow,
|
|
|
|
backend_x11->atom_NET_WM_USER_TIME,
|
2007-03-22 18:21:59 +00:00
|
|
|
XA_CARDINAL, 32, PropModeReplace,
|
|
|
|
(unsigned char *) ×tamp, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-23 12:45:20 +00:00
|
|
|
static void
|
|
|
|
convert_xdevicekey_to_xkey (XDeviceKeyEvent *xkev, XEvent *xevent)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2008-06-23 09:55:42 +00:00
|
|
|
|
2007-03-22 18:21:59 +00:00
|
|
|
static void
|
2008-06-23 12:45:20 +00:00
|
|
|
translate_key_event (ClutterBackend *backend,
|
|
|
|
ClutterEvent *event,
|
|
|
|
XEvent *xevent)
|
2007-03-22 18:21:59 +00:00
|
|
|
{
|
2008-06-10 14:01:43 +00:00
|
|
|
char buffer[256+1];
|
2008-06-10 10:57:50 +00:00
|
|
|
int n;
|
|
|
|
|
2007-03-22 18:21:59 +00:00
|
|
|
CLUTTER_NOTE (EVENT, "Translating key %s event",
|
|
|
|
xevent->xany.type == KeyPress ? "press" : "release");
|
|
|
|
|
|
|
|
event->key.time = xevent->xkey.time;
|
2007-06-11 09:02:40 +00:00
|
|
|
event->key.modifier_state = (ClutterModifierType) xevent->xkey.state;
|
2007-03-22 18:21:59 +00:00
|
|
|
event->key.hardware_keycode = xevent->xkey.keycode;
|
2007-06-13 23:24:59 +00:00
|
|
|
|
2008-06-10 10:57:50 +00:00
|
|
|
/* keyval is the key ignoring all modifiers ('1' vs. '!') */
|
2008-02-12 12:39:22 +00:00
|
|
|
event->key.keyval =
|
|
|
|
XKeycodeToKeysym (xevent->xkey.display,
|
2007-11-26 12:07:25 +00:00
|
|
|
xevent->xkey.keycode,
|
2008-06-10 10:57:50 +00:00
|
|
|
0);
|
|
|
|
|
|
|
|
/* unicode_value is the printable representation */
|
2008-06-10 14:01:43 +00:00
|
|
|
n = XLookupString (&xevent->xkey, buffer, sizeof (buffer) - 1, NULL, NULL);
|
|
|
|
|
|
|
|
if (n != NoSymbol)
|
2008-06-10 10:57:50 +00:00
|
|
|
{
|
|
|
|
event->key.unicode_value = g_utf8_get_char_validated (buffer, n);
|
2008-06-10 14:01:43 +00:00
|
|
|
if ((event->key.unicode_value != -1) &&
|
|
|
|
(event->key.unicode_value != -2))
|
|
|
|
return;
|
2008-06-10 10:57:50 +00:00
|
|
|
}
|
2008-06-10 14:01:43 +00:00
|
|
|
|
|
|
|
event->key.unicode_value = (gunichar)'\0';
|
2007-03-22 18:21:59 +00:00
|
|
|
}
|
|
|
|
|
2007-04-19 15:26:54 +00:00
|
|
|
static gboolean
|
2007-11-15 14:45:27 +00:00
|
|
|
handle_wm_protocols_event (ClutterBackendX11 *backend_x11,
|
2008-03-28 22:50:55 +00:00
|
|
|
Window window,
|
2007-04-19 15:26:54 +00:00
|
|
|
XEvent *xevent)
|
|
|
|
{
|
|
|
|
Atom atom = (Atom) xevent->xclient.data.l[0];
|
|
|
|
|
2007-11-17 18:11:14 +00:00
|
|
|
if (atom == backend_x11->atom_WM_DELETE_WINDOW &&
|
2008-03-28 22:50:55 +00:00
|
|
|
xevent->xany.window == window)
|
2007-04-19 15:26:54 +00: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 12:07:25 +00:00
|
|
|
CLUTTER_NOTE (EVENT, "delete window:\txid: %ld",
|
2007-04-19 15:26:54 +00:00
|
|
|
xevent->xclient.window);
|
|
|
|
|
2007-11-17 18:11:14 +00:00
|
|
|
set_user_time (backend_x11,
|
2008-03-28 22:50:55 +00:00
|
|
|
&window,
|
2007-04-19 15:26:54 +00:00
|
|
|
xevent->xclient.data.l[1]);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2007-11-17 18:11:14 +00:00
|
|
|
else if (atom == backend_x11->atom_NET_WM_PING &&
|
2008-03-28 22:50:55 +00:00
|
|
|
xevent->xany.window == window)
|
2007-04-25 14:22:24 +00:00
|
|
|
{
|
|
|
|
XClientMessageEvent xclient = xevent->xclient;
|
|
|
|
|
2007-11-15 14:45:27 +00:00
|
|
|
xclient.window = backend_x11->xwin_root;
|
|
|
|
XSendEvent (backend_x11->xdpy, xclient.window,
|
2007-04-25 14:22:24 +00:00
|
|
|
False,
|
|
|
|
SubstructureRedirectMask | SubstructureNotifyMask,
|
|
|
|
(XEvent *) &xclient);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2007-04-19 15:26:54 +00:00
|
|
|
|
2007-04-25 14:22:24 +00:00
|
|
|
/* do not send any of the WM_PROTOCOLS events to the queue */
|
2007-04-19 15:26:54 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2007-11-15 14:45:27 +00:00
|
|
|
handle_xembed_event (ClutterBackendX11 *backend_x11,
|
2007-04-19 15:24:57 +00:00
|
|
|
XEvent *xevent)
|
|
|
|
{
|
|
|
|
ClutterActor *stage;
|
|
|
|
|
2008-03-28 22:50:55 +00:00
|
|
|
stage = clutter_stage_get_default ();
|
2007-04-19 15:24:57 +00: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 18:11:14 +00:00
|
|
|
xembed_set_info (backend_x11,
|
2007-11-15 14:45:27 +00:00
|
|
|
clutter_x11_get_stage_window (CLUTTER_STAGE (stage)),
|
2007-04-19 15:24:57 +00: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 18:11:14 +00:00
|
|
|
xembed_send_message (backend_x11, ParentEmbedderWin,
|
2007-04-19 15:24:57 +00:00
|
|
|
XEMBED_FOCUS_NEXT,
|
|
|
|
0, 0, 0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
CLUTTER_NOTE (EVENT, "got unknown XEMBED message");
|
|
|
|
break;
|
|
|
|
}
|
2007-04-19 15:26:54 +00:00
|
|
|
|
|
|
|
/* do not propagate the XEMBED events to the stage */
|
|
|
|
return FALSE;
|
2007-04-19 15:24:57 +00:00
|
|
|
}
|
|
|
|
|
2007-03-22 18:21:59 +00:00
|
|
|
static gboolean
|
2007-05-09 23:31:08 +00:00
|
|
|
event_translate (ClutterBackend *backend,
|
2008-01-31 11:24:11 +00:00
|
|
|
ClutterEvent *event,
|
|
|
|
XEvent *xevent)
|
2007-03-22 18:21:59 +00:00
|
|
|
{
|
2008-04-04 15:02:11 +00:00
|
|
|
ClutterBackendX11 *backend_x11;
|
|
|
|
ClutterStageX11 *stage_x11;
|
|
|
|
ClutterStage *stage;
|
|
|
|
ClutterStageWindow *impl;
|
2008-06-23 09:55:42 +00:00
|
|
|
gboolean res, not_yet_handled = FALSE;
|
2008-04-04 15:02:11 +00:00
|
|
|
Window xwindow, stage_xwindow;
|
2007-03-22 18:21:59 +00:00
|
|
|
|
2007-11-15 14:45:27 +00:00
|
|
|
backend_x11 = CLUTTER_BACKEND_X11 (backend);
|
2007-03-22 18:21:59 +00:00
|
|
|
|
|
|
|
xwindow = xevent->xany.window;
|
|
|
|
|
2007-11-15 14:45:27 +00:00
|
|
|
if (backend_x11->event_filters)
|
2007-05-31 11:13:43 +00:00
|
|
|
{
|
|
|
|
GSList *node;
|
2007-11-15 14:45:27 +00:00
|
|
|
ClutterX11EventFilter *filter;
|
2007-05-31 11:13:43 +00:00
|
|
|
|
2007-11-15 14:45:27 +00:00
|
|
|
node = backend_x11->event_filters;
|
2007-05-31 11:13:43 +00:00
|
|
|
|
|
|
|
while (node)
|
2008-01-31 11:24:11 +00:00
|
|
|
{
|
|
|
|
filter = node->data;
|
|
|
|
|
|
|
|
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 11:13:43 +00:00
|
|
|
}
|
2008-02-12 12:39:22 +00: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-03-28 22:50:55 +00:00
|
|
|
stage = clutter_x11_get_stage_from_window (xwindow);
|
|
|
|
|
|
|
|
if (stage == NULL)
|
2008-06-23 09:55:42 +00:00
|
|
|
return FALSE;
|
2008-02-12 12:39:22 +00:00
|
|
|
|
2008-04-04 15:02:11 +00:00
|
|
|
impl = _clutter_stage_get_window (stage);
|
|
|
|
stage_x11 = CLUTTER_STAGE_X11 (impl);
|
2008-03-28 22:50:55 +00:00
|
|
|
stage_xwindow = xwindow; /* clutter_x11_get_stage_window (stage); */
|
|
|
|
|
|
|
|
event->any.stage = stage;
|
|
|
|
|
2008-06-23 09:55:42 +00:00
|
|
|
|
2007-03-22 18:21:59 +00:00
|
|
|
res = TRUE;
|
|
|
|
|
|
|
|
switch (xevent->type)
|
|
|
|
{
|
2007-08-24 15:12:52 +00:00
|
|
|
case ConfigureNotify:
|
2008-02-21 12:17:01 +00:00
|
|
|
if (!stage_x11->is_foreign_xwin)
|
|
|
|
{
|
2008-04-04 13:46:50 +00:00
|
|
|
/* Set a flag so that the stage will know the actor is being
|
|
|
|
resized in response to the window size changing as
|
|
|
|
opposed to a request from the application. This prevents
|
|
|
|
it from trying to resize the window again */
|
|
|
|
stage_x11->handling_configure = TRUE;
|
2008-02-21 12:17:01 +00:00
|
|
|
|
2008-04-04 13:46:50 +00:00
|
|
|
clutter_actor_set_size (CLUTTER_ACTOR (stage),
|
|
|
|
xevent->xconfigure.width,
|
|
|
|
xevent->xconfigure.height);
|
2008-02-21 12:17:01 +00:00
|
|
|
|
2008-04-04 13:46:50 +00:00
|
|
|
stage_x11->handling_configure = FALSE;
|
2008-02-21 12:17:01 +00:00
|
|
|
}
|
2007-08-24 15:12:52 +00:00
|
|
|
res = FALSE;
|
|
|
|
break;
|
2007-11-26 12:07:25 +00:00
|
|
|
|
2007-08-24 15:12:52 +00:00
|
|
|
case PropertyNotify:
|
2008-02-21 12:45:48 +00:00
|
|
|
if (xevent->xproperty.atom == backend_x11->atom_NET_WM_STATE &&
|
|
|
|
xevent->xproperty.window == stage_xwindow &&
|
|
|
|
!stage_x11->is_foreign_xwin)
|
2007-11-26 12:07:25 +00: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 12:39:22 +00:00
|
|
|
0, G_MAXLONG,
|
2007-11-26 12:07:25 +00: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 11:24:11 +00:00
|
|
|
}
|
2007-11-26 12:07:25 +00:00
|
|
|
|
|
|
|
is_fullscreen =
|
|
|
|
(stage_x11->state & CLUTTER_STAGE_STATE_FULLSCREEN);
|
|
|
|
|
|
|
|
if (fullscreen_set != is_fullscreen)
|
2008-01-31 11:24:11 +00:00
|
|
|
{
|
|
|
|
if (fullscreen_set)
|
2007-11-26 12:07:25 +00:00
|
|
|
stage_x11->state |= CLUTTER_STAGE_STATE_FULLSCREEN;
|
2008-01-31 11:24:11 +00:00
|
|
|
else
|
2007-11-26 12:07:25 +00:00
|
|
|
stage_x11->state &= ~CLUTTER_STAGE_STATE_FULLSCREEN;
|
|
|
|
|
|
|
|
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 12:39:22 +00:00
|
|
|
|
2007-11-26 12:07:25 +00:00
|
|
|
XFree (data);
|
2008-01-31 11:24:11 +00:00
|
|
|
}
|
|
|
|
else
|
2007-11-26 12:07:25 +00:00
|
|
|
res = FALSE;
|
|
|
|
}
|
2008-02-21 12:45:48 +00:00
|
|
|
else
|
|
|
|
res = FALSE;
|
2007-11-26 12:07:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MapNotify:
|
|
|
|
clutter_stage_x11_map (stage_x11);
|
|
|
|
res = FALSE;
|
2007-08-24 15:12:52 +00:00
|
|
|
break;
|
2007-11-26 12:07:25 +00:00
|
|
|
|
|
|
|
case UnmapNotify:
|
|
|
|
clutter_stage_x11_unmap (stage_x11);
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
|
2007-08-24 15:12:52 +00:00
|
|
|
case FocusIn:
|
2007-11-15 14:45:27 +00:00
|
|
|
if (!(stage_x11->state & CLUTTER_STAGE_STATE_ACTIVATED))
|
2008-01-31 11:24:11 +00: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 15:12:52 +00:00
|
|
|
else
|
2008-01-31 11:24:11 +00:00
|
|
|
res = FALSE;
|
2007-08-24 15:12:52 +00:00
|
|
|
break;
|
2007-11-26 12:07:25 +00:00
|
|
|
|
2007-08-24 15:12:52 +00:00
|
|
|
case FocusOut:
|
2007-11-15 14:45:27 +00:00
|
|
|
if (stage_x11->state & CLUTTER_STAGE_STATE_ACTIVATED)
|
2008-01-31 11:24:11 +00:00
|
|
|
{
|
|
|
|
stage_x11->state &= ~CLUTTER_STAGE_STATE_ACTIVATED;
|
2007-08-24 15:12:52 +00:00
|
|
|
|
2008-01-31 11:24:11 +00: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 15:12:52 +00:00
|
|
|
else
|
2008-01-31 11:24:11 +00:00
|
|
|
res = FALSE;
|
2007-08-24 15:12:52 +00:00
|
|
|
break;
|
2007-11-26 12:07:25 +00:00
|
|
|
|
2007-03-22 18:21:59 +00:00
|
|
|
case Expose:
|
|
|
|
{
|
2008-05-13 10:21:25 +00:00
|
|
|
CLUTTER_NOTE (MULTISTAGE, "expose for stage: %p, redrawing", stage);
|
|
|
|
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
|
2007-03-22 18:21:59 +00:00
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DestroyNotify:
|
2007-11-26 12:07:25 +00:00
|
|
|
CLUTTER_NOTE (EVENT, "destroy notify:\txid: %ld",
|
2007-03-23 09:44:21 +00:00
|
|
|
xevent->xdestroywindow.window);
|
2008-01-23 11:08:39 +00: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 18:21:59 +00:00
|
|
|
break;
|
2007-11-26 12:07:25 +00:00
|
|
|
|
2007-04-19 15:24:57 +00:00
|
|
|
case ClientMessage:
|
|
|
|
CLUTTER_NOTE (EVENT, "client message");
|
2008-02-12 12:39:22 +00:00
|
|
|
|
2007-04-19 15:24:57 +00:00
|
|
|
event->type = event->any.type = CLUTTER_CLIENT_MESSAGE;
|
2008-02-12 12:39:22 +00:00
|
|
|
|
2007-11-17 18:11:14 +00:00
|
|
|
if (xevent->xclient.message_type == backend_x11->atom_XEMBED)
|
2007-11-15 14:45:27 +00:00
|
|
|
res = handle_xembed_event (backend_x11, xevent);
|
2007-11-17 18:11:14 +00:00
|
|
|
else if (xevent->xclient.message_type == backend_x11->atom_WM_PROTOCOLS)
|
2007-04-19 15:26:54 +00:00
|
|
|
{
|
2008-03-28 22:50:55 +00:00
|
|
|
res = handle_wm_protocols_event (backend_x11, stage_xwindow, xevent);
|
2007-04-19 15:26:54 +00:00
|
|
|
event->type = event->any.type = CLUTTER_DELETE;
|
|
|
|
}
|
2007-04-19 15:24:57 +00:00
|
|
|
break;
|
2007-11-26 12:07:25 +00:00
|
|
|
|
2007-03-22 18:21:59 +00:00
|
|
|
default:
|
|
|
|
/* ignore every other event */
|
2008-06-23 09:55:42 +00:00
|
|
|
not_yet_handled = TRUE;
|
2007-03-22 18:21:59 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-06-23 09:55:42 +00:00
|
|
|
/* Input device event handling.. */
|
|
|
|
if (not_yet_handled)
|
|
|
|
{
|
|
|
|
if (!clutter_x11_has_xinput ())
|
|
|
|
{
|
|
|
|
/* Regular X event */
|
|
|
|
switch (xevent->type)
|
|
|
|
{
|
|
|
|
case KeyPress:
|
2008-06-23 22:00:37 +00:00
|
|
|
event->key.type = event->type = CLUTTER_KEY_PRESS;
|
2008-06-23 09:55:42 +00:00
|
|
|
translate_key_event (backend, event, xevent);
|
2008-06-23 22:00:37 +00:00
|
|
|
|
2008-06-23 09:55:42 +00:00
|
|
|
set_user_time (backend_x11, &xwindow, xevent->xkey.time);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KeyRelease:
|
2008-06-23 22:00:37 +00:00
|
|
|
event->key.type = event->type = CLUTTER_KEY_RELEASE;
|
2008-06-23 09:55:42 +00:00
|
|
|
translate_key_event (backend, event, xevent);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ButtonPress:
|
|
|
|
switch (xevent->xbutton.button)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
event->button.type = event->type = CLUTTER_BUTTON_PRESS;
|
|
|
|
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;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
set_user_time (backend_x11, &xwindow, event->button.time);
|
|
|
|
break;
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* ignore every other event */
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ /* XInput fun.. Needs clean up. */
|
|
|
|
#ifdef USE_XINPUT
|
|
|
|
int *ev_types = backend_x11->event_types;
|
|
|
|
|
|
|
|
CLUTTER_NOTE (EVENT, "XInput event type: %d", xevent->type);
|
|
|
|
|
|
|
|
if (xevent->type == ev_types [CLUTTER_X11_XINPUT_BUTTON_PRESS_EVENT])
|
|
|
|
{
|
|
|
|
XDeviceButtonEvent *xbev = (XDeviceButtonEvent *)xevent;
|
|
|
|
|
|
|
|
switch (xbev->button)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
= (ClutterInputDevice *)_clutter_x11_get_device_for_xid (xbev->deviceid);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
event->button.type = event->type = CLUTTER_BUTTON_PRESS;
|
|
|
|
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
|
|
|
|
= (ClutterInputDevice *)_clutter_x11_get_device_for_xid (xbev->deviceid);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
set_user_time (backend_x11, &xwindow, xbev->time);
|
|
|
|
|
|
|
|
CLUTTER_NOTE(EVENT, "XINPUT Button press event for %li %d %d",
|
|
|
|
xbev->deviceid, xbev->x, xbev->y);
|
|
|
|
}
|
|
|
|
else if (xevent->type
|
|
|
|
== ev_types[CLUTTER_X11_XINPUT_BUTTON_RELEASE_EVENT])
|
|
|
|
{
|
|
|
|
XDeviceButtonEvent *xbev = (XDeviceButtonEvent *)xevent;
|
|
|
|
|
|
|
|
/* scroll events don't have a corresponding release */
|
|
|
|
if (xbev->button == 4 ||
|
|
|
|
xbev->button == 5 ||
|
|
|
|
xbev->button == 6 ||
|
|
|
|
xbev->button == 7)
|
|
|
|
{
|
|
|
|
res = FALSE;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
= (ClutterInputDevice *)_clutter_x11_get_device_for_xid (xbev->deviceid);
|
|
|
|
CLUTTER_NOTE(EVENT, "XINPUT Button release event for %li %d %d",
|
|
|
|
xbev->deviceid, xbev->x, xbev->y);
|
|
|
|
}
|
|
|
|
else if (xevent->type
|
|
|
|
== ev_types [CLUTTER_X11_XINPUT_MOTION_NOTIFY_EVENT])
|
|
|
|
{
|
|
|
|
XDeviceMotionEvent *xmev = (XDeviceMotionEvent *)xevent;
|
|
|
|
|
|
|
|
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
|
|
|
|
= (ClutterInputDevice *) _clutter_x11_get_device_for_xid (xmev->deviceid);
|
|
|
|
CLUTTER_NOTE(EVENT, "XINPUT Motion event for %li %d %d",
|
|
|
|
xmev->deviceid,
|
|
|
|
xmev->x,
|
|
|
|
xmev->y);
|
|
|
|
}
|
|
|
|
else if (xevent->type
|
|
|
|
== ev_types [CLUTTER_X11_XINPUT_KEY_PRESS_EVENT])
|
|
|
|
{
|
2008-06-23 12:45:20 +00:00
|
|
|
XEvent xevent_converted;
|
2008-06-23 09:55:42 +00:00
|
|
|
XDeviceKeyEvent *xkev = (XDeviceKeyEvent *)xevent;
|
2008-06-23 12:45:20 +00:00
|
|
|
|
|
|
|
convert_xdevicekey_to_xkey (xkev, &xevent_converted);
|
2008-06-23 09:55:42 +00:00
|
|
|
|
2008-06-23 12:45:20 +00:00
|
|
|
event->key.type = event->type = CLUTTER_KEY_PRESS;
|
|
|
|
translate_key_event (backend, event, &xevent_converted);
|
2008-06-23 22:00:37 +00:00
|
|
|
|
2008-06-23 09:55:42 +00:00
|
|
|
set_user_time (backend_x11, &xwindow, xkev->time);
|
|
|
|
}
|
|
|
|
else if (xevent->type
|
|
|
|
== ev_types [CLUTTER_X11_XINPUT_KEY_RELEASE_EVENT])
|
|
|
|
{
|
2008-06-23 12:45:20 +00:00
|
|
|
XEvent xevent_converted;
|
2008-06-23 09:55:42 +00:00
|
|
|
XDeviceKeyEvent *xkev = (XDeviceKeyEvent *)xevent;
|
|
|
|
|
2008-06-23 12:45:20 +00:00
|
|
|
convert_xdevicekey_to_xkey (xkev, &xevent_converted);
|
|
|
|
|
2008-06-23 22:00:37 +00:00
|
|
|
event->key.type = event->type = CLUTTER_KEY_RELEASE;
|
2008-06-23 12:45:20 +00:00
|
|
|
translate_key_event (backend, event, &xevent_converted);
|
2008-06-23 09:55:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
CLUTTER_NOTE (EVENT, "Uknown Event");
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2007-03-22 18:21:59 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2007-05-09 23:31:08 +00:00
|
|
|
static void
|
|
|
|
events_queue (ClutterBackend *backend)
|
2007-03-22 18:21:59 +00:00
|
|
|
{
|
2007-11-15 14:45:27 +00:00
|
|
|
ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (backend);
|
2007-08-23 12:47:25 +00:00
|
|
|
ClutterEvent *event;
|
2007-11-15 14:45:27 +00:00
|
|
|
Display *xdisplay = backend_x11->xdpy;
|
2007-05-09 23:31:08 +00:00
|
|
|
XEvent xevent;
|
|
|
|
ClutterMainContext *clutter_context;
|
2007-03-22 18:21:59 +00:00
|
|
|
|
2007-05-09 23:31:08 +00:00
|
|
|
clutter_context = clutter_context_get_default ();
|
|
|
|
|
|
|
|
while (!clutter_events_pending () && XPending (xdisplay))
|
2007-03-22 18:21:59 +00:00
|
|
|
{
|
|
|
|
XNextEvent (xdisplay, &xevent);
|
|
|
|
|
|
|
|
event = clutter_event_new (CLUTTER_NOTHING);
|
2007-05-09 23:31:08 +00:00
|
|
|
|
|
|
|
if (event_translate (backend, event, &xevent))
|
2007-03-22 18:21:59 +00:00
|
|
|
{
|
2007-08-23 12:47:25 +00:00
|
|
|
/* push directly here to avoid copy of queue_put */
|
|
|
|
g_queue_push_head (clutter_context->events_queue, event);
|
2007-03-22 18:21:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clutter_event_free (event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-21 15:18:14 +00:00
|
|
|
/**
|
2008-06-10 17:11:14 +00:00
|
|
|
* clutter_x11_handle_event:
|
2008-02-21 15:18:14 +00:00
|
|
|
* @xevent: pointer to XEvent structure
|
|
|
|
*
|
|
|
|
* This function processes a single X event; it can be used to hook
|
|
|
|
* into external X event retrieval (for example that done by GDK).
|
|
|
|
*
|
2008-06-10 17:11:14 +00:00
|
|
|
* Return value: #ClutterX11FilterReturn indicating what the caller
|
|
|
|
* should do with the original event.
|
2008-02-21 15:18:14 +00:00
|
|
|
*
|
|
|
|
* Since: 0.8
|
|
|
|
*/
|
|
|
|
ClutterX11FilterReturn
|
|
|
|
clutter_x11_handle_event (XEvent *xevent)
|
|
|
|
{
|
|
|
|
ClutterBackend *backend;
|
|
|
|
ClutterEvent *event;
|
|
|
|
ClutterMainContext *clutter_context;
|
|
|
|
|
|
|
|
clutter_threads_enter ();
|
|
|
|
|
|
|
|
clutter_context = clutter_context_get_default ();
|
|
|
|
backend = clutter_context->backend;
|
|
|
|
|
|
|
|
event = clutter_event_new (CLUTTER_NOTHING);
|
|
|
|
|
|
|
|
if (event_translate (backend, event, xevent))
|
|
|
|
{
|
|
|
|
/* push directly here to avoid copy of queue_put */
|
|
|
|
g_queue_push_head (clutter_context->events_queue, event);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clutter_event_free (event);
|
|
|
|
}
|
|
|
|
|
|
|
|
event = clutter_event_get ();
|
|
|
|
|
|
|
|
if (event)
|
|
|
|
{
|
|
|
|
/* forward the event into clutter for emission etc. */
|
|
|
|
clutter_do_event (event);
|
|
|
|
clutter_event_free (event);
|
|
|
|
}
|
|
|
|
|
|
|
|
clutter_threads_leave ();
|
|
|
|
|
|
|
|
return CLUTTER_X11_FILTER_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_x11_disable_event_retrieval
|
|
|
|
*
|
|
|
|
* Disables retrieval of X events in the main loop. Use to create event-less
|
|
|
|
* canvas or in conjunction with clutter_x11_handle_event.
|
|
|
|
*
|
|
|
|
* This function can only be called before calling clutter_init().
|
|
|
|
*
|
|
|
|
* Since: 0.8
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_x11_disable_event_retrieval (void)
|
|
|
|
{
|
|
|
|
ClutterBackendX11 *backend;
|
|
|
|
ClutterMainContext *clutter_context;
|
|
|
|
|
|
|
|
clutter_context = clutter_context_get_default ();
|
|
|
|
backend = CLUTTER_BACKEND_X11 (clutter_context->backend);
|
|
|
|
|
|
|
|
backend->no_xevent_retrieval = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-22 18:21:59 +00:00
|
|
|
static gboolean
|
|
|
|
clutter_event_prepare (GSource *source,
|
|
|
|
gint *timeout)
|
|
|
|
{
|
|
|
|
ClutterBackend *backend = ((ClutterEventSource *) source)->backend;
|
|
|
|
gboolean retval;
|
|
|
|
|
2007-08-08 10:20:14 +00:00
|
|
|
clutter_threads_enter ();
|
|
|
|
|
2007-03-22 18:21:59 +00:00
|
|
|
*timeout = -1;
|
2007-05-09 23:31:08 +00:00
|
|
|
retval = (clutter_events_pending () || check_xpending (backend));
|
2007-03-22 18:21:59 +00:00
|
|
|
|
2007-08-08 10:20:14 +00:00
|
|
|
clutter_threads_leave ();
|
|
|
|
|
2007-03-22 18:21:59 +00: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 10:20:14 +00:00
|
|
|
clutter_threads_enter ();
|
|
|
|
|
2007-03-22 18:21:59 +00:00
|
|
|
if (event_source->event_poll_fd.revents & G_IO_IN)
|
2007-05-09 23:31:08 +00:00
|
|
|
retval = (clutter_events_pending () || check_xpending (backend));
|
2007-03-22 18:21:59 +00:00
|
|
|
else
|
|
|
|
retval = FALSE;
|
|
|
|
|
2007-08-08 10:20:14 +00:00
|
|
|
clutter_threads_leave ();
|
|
|
|
|
2007-03-22 18:21:59 +00: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 10:20:14 +00:00
|
|
|
clutter_threads_enter ();
|
|
|
|
|
2008-02-12 12:39:22 +00:00
|
|
|
/* Grab the event(s), translate and figure out double click.
|
2007-05-09 23:31:08 +00: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 18:21:59 +00:00
|
|
|
|
|
|
|
if (event)
|
|
|
|
{
|
2007-05-09 23:31:08 +00:00
|
|
|
/* forward the event into clutter for emission etc. */
|
|
|
|
clutter_do_event (event);
|
2007-03-22 18:21:59 +00:00
|
|
|
clutter_event_free (event);
|
|
|
|
}
|
|
|
|
|
2007-08-08 10:20:14 +00:00
|
|
|
clutter_threads_leave ();
|
|
|
|
|
2007-03-22 18:21:59 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|