2019-03-22 08:53:00 -04:00
|
|
|
/* Copyright (C) 2006, 2007, 2008 OpenedHand Ltd
|
2010-01-15 11:28:00 -05:00
|
|
|
* 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
|
|
|
*/
|
|
|
|
|
2019-03-22 08:53:00 -04:00
|
|
|
#include "config.h"
|
2010-05-19 11:13:07 -04:00
|
|
|
|
2019-03-22 08:53:00 -04:00
|
|
|
#include <glib.h>
|
2007-03-22 14:21:59 -04:00
|
|
|
#include <string.h>
|
|
|
|
|
2019-03-22 08:53:00 -04:00
|
|
|
#include "backends/x11/meta-event-x11.h"
|
|
|
|
#include "clutter/clutter-mutter.h"
|
|
|
|
#include "clutter/x11/clutter-x11.h"
|
2007-03-22 14:21:59 -04:00
|
|
|
|
2019-03-22 08:53:00 -04:00
|
|
|
MetaEventX11 *
|
|
|
|
meta_event_x11_new (void)
|
2010-07-08 10:47:18 -04:00
|
|
|
{
|
2019-03-22 08:53:00 -04:00
|
|
|
return g_slice_new0 (MetaEventX11);
|
2010-07-08 10:47:18 -04:00
|
|
|
}
|
|
|
|
|
2019-03-22 08:53:00 -04:00
|
|
|
MetaEventX11 *
|
|
|
|
meta_event_x11_copy (MetaEventX11 *event_x11)
|
2010-07-08 10:47:18 -04:00
|
|
|
{
|
|
|
|
if (event_x11 != NULL)
|
2019-03-22 08:53:00 -04:00
|
|
|
return g_slice_dup (MetaEventX11, event_x11);
|
2010-07-08 10:47:18 -04:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-03-22 08:53:00 -04:00
|
|
|
meta_event_x11_free (MetaEventX11 *event_x11)
|
2010-07-08 10:47:18 -04:00
|
|
|
{
|
|
|
|
if (event_x11 != NULL)
|
2019-03-22 08:53:00 -04:00
|
|
|
g_slice_free (MetaEventX11, event_x11);
|
2010-07-08 10:47:18 -04:00
|
|
|
}
|
|
|
|
|
2008-02-21 10:18:14 -05:00
|
|
|
/**
|
2019-03-22 08:53:00 -04:00
|
|
|
* meta_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).
|
|
|
|
*
|
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
|
2019-03-22 08:53:00 -04:00
|
|
|
meta_x11_handle_event (XEvent *xevent)
|
2008-02-21 10:18:14 -05:00
|
|
|
{
|
2008-12-22 08:11:59 -05:00
|
|
|
ClutterX11FilterReturn result;
|
event/x11: Rework the way we translate X11 events
This is a lump commit that is fairly difficult to break down without
either breaking bisecting or breaking the test cases.
The new design for handling X11 event translation works this way:
- ClutterBackend::translate_event() has been added as the central
point used by a ClutterBackend implementation to translate a
native event into a ClutterEvent;
- ClutterEventTranslator is a private interface that should be
implemented by backend-specific objects, like stage
implementations and ClutterDeviceManager sub-classes, and
allows dealing with class-specific event translation;
- ClutterStageX11 implements EventTranslator, and deals with the
stage-relative X11 events coming from the X11 event source;
- ClutterStageGLX overrides EventTranslator, in order to
deal with the INTEL_GLX_swap_event extension, and it chains up
to the X11 default implementation;
- ClutterDeviceManagerX11 has been split into two separate classes,
one that deals with core and (optionally) XI1 events, and the
other that deals with XI2 events; the selection is done at run-time,
since the core+XI1 and XI2 mechanisms are mutually exclusive.
All the other backends we officially support still use their own
custom event source and translation function, but the end goal is to
migrate them to the translate_event() virtual function, and have the
event source be a shared part of Clutter core.
2011-01-04 07:32:04 -05:00
|
|
|
ClutterBackend *backend;
|
|
|
|
ClutterEvent *event;
|
|
|
|
gint spin = 1;
|
2011-07-15 11:03:00 -04:00
|
|
|
ClutterBackendX11 *backend_x11;
|
|
|
|
Display *xdisplay;
|
2011-07-14 15:58:25 -04:00
|
|
|
gboolean allocated_event;
|
2008-12-22 08:11:59 -05:00
|
|
|
|
|
|
|
/* The return values here are someone approximate; we return
|
2019-08-31 11:48:43 -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
|
2019-08-31 11:48:43 -04:00
|
|
|
* %CLUTTER_X11_FILTER_REMOVE when more processing is needed.
|
2008-12-22 08:11:59 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
result = CLUTTER_X11_FILTER_CONTINUE;
|
2008-02-21 10:18:14 -05:00
|
|
|
|
event/x11: Rework the way we translate X11 events
This is a lump commit that is fairly difficult to break down without
either breaking bisecting or breaking the test cases.
The new design for handling X11 event translation works this way:
- ClutterBackend::translate_event() has been added as the central
point used by a ClutterBackend implementation to translate a
native event into a ClutterEvent;
- ClutterEventTranslator is a private interface that should be
implemented by backend-specific objects, like stage
implementations and ClutterDeviceManager sub-classes, and
allows dealing with class-specific event translation;
- ClutterStageX11 implements EventTranslator, and deals with the
stage-relative X11 events coming from the X11 event source;
- ClutterStageGLX overrides EventTranslator, in order to
deal with the INTEL_GLX_swap_event extension, and it chains up
to the X11 default implementation;
- ClutterDeviceManagerX11 has been split into two separate classes,
one that deals with core and (optionally) XI1 events, and the
other that deals with XI2 events; the selection is done at run-time,
since the core+XI1 and XI2 mechanisms are mutually exclusive.
All the other backends we officially support still use their own
custom event source and translation function, but the end goal is to
migrate them to the translate_event() virtual function, and have the
event source be a shared part of Clutter core.
2011-01-04 07:32:04 -05:00
|
|
|
backend = clutter_get_default_backend ();
|
2010-04-30 14:50:11 -04:00
|
|
|
|
2008-02-21 10:18:14 -05:00
|
|
|
event = clutter_event_new (CLUTTER_NOTHING);
|
|
|
|
|
2011-07-15 11:03:00 -04:00
|
|
|
backend_x11 = CLUTTER_BACKEND_X11 (backend);
|
|
|
|
xdisplay = backend_x11->xdpy;
|
|
|
|
|
2011-07-14 15:58:25 -04:00
|
|
|
allocated_event = XGetEventData (xdisplay, &xevent->xcookie);
|
|
|
|
|
event/x11: Rework the way we translate X11 events
This is a lump commit that is fairly difficult to break down without
either breaking bisecting or breaking the test cases.
The new design for handling X11 event translation works this way:
- ClutterBackend::translate_event() has been added as the central
point used by a ClutterBackend implementation to translate a
native event into a ClutterEvent;
- ClutterEventTranslator is a private interface that should be
implemented by backend-specific objects, like stage
implementations and ClutterDeviceManager sub-classes, and
allows dealing with class-specific event translation;
- ClutterStageX11 implements EventTranslator, and deals with the
stage-relative X11 events coming from the X11 event source;
- ClutterStageGLX overrides EventTranslator, in order to
deal with the INTEL_GLX_swap_event extension, and it chains up
to the X11 default implementation;
- ClutterDeviceManagerX11 has been split into two separate classes,
one that deals with core and (optionally) XI1 events, and the
other that deals with XI2 events; the selection is done at run-time,
since the core+XI1 and XI2 mechanisms are mutually exclusive.
All the other backends we officially support still use their own
custom event source and translation function, but the end goal is to
migrate them to the translate_event() virtual function, and have the
event source be a shared part of Clutter core.
2011-01-04 07:32:04 -05:00
|
|
|
if (_clutter_backend_translate_event (backend, xevent, event))
|
2008-02-21 10:18:14 -05:00
|
|
|
{
|
event/x11: Rework the way we translate X11 events
This is a lump commit that is fairly difficult to break down without
either breaking bisecting or breaking the test cases.
The new design for handling X11 event translation works this way:
- ClutterBackend::translate_event() has been added as the central
point used by a ClutterBackend implementation to translate a
native event into a ClutterEvent;
- ClutterEventTranslator is a private interface that should be
implemented by backend-specific objects, like stage
implementations and ClutterDeviceManager sub-classes, and
allows dealing with class-specific event translation;
- ClutterStageX11 implements EventTranslator, and deals with the
stage-relative X11 events coming from the X11 event source;
- ClutterStageGLX overrides EventTranslator, in order to
deal with the INTEL_GLX_swap_event extension, and it chains up
to the X11 default implementation;
- ClutterDeviceManagerX11 has been split into two separate classes,
one that deals with core and (optionally) XI1 events, and the
other that deals with XI2 events; the selection is done at run-time,
since the core+XI1 and XI2 mechanisms are mutually exclusive.
All the other backends we officially support still use their own
custom event source and translation function, but the end goal is to
migrate them to the translate_event() virtual function, and have the
event source be a shared part of Clutter core.
2011-01-04 07:32:04 -05:00
|
|
|
_clutter_event_push (event, FALSE);
|
|
|
|
|
2008-12-22 08:11:59 -05:00
|
|
|
result = CLUTTER_X11_FILTER_REMOVE;
|
2008-02-21 10:18:14 -05:00
|
|
|
}
|
|
|
|
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. */
|
2013-11-11 12:16:32 -05:00
|
|
|
_clutter_stage_queue_event (event->any.stage, event, FALSE);
|
2009-01-27 11:37:55 -05:00
|
|
|
--spin;
|
2008-02-21 10:18:14 -05:00
|
|
|
}
|
|
|
|
|
event/x11: Rework the way we translate X11 events
This is a lump commit that is fairly difficult to break down without
either breaking bisecting or breaking the test cases.
The new design for handling X11 event translation works this way:
- ClutterBackend::translate_event() has been added as the central
point used by a ClutterBackend implementation to translate a
native event into a ClutterEvent;
- ClutterEventTranslator is a private interface that should be
implemented by backend-specific objects, like stage
implementations and ClutterDeviceManager sub-classes, and
allows dealing with class-specific event translation;
- ClutterStageX11 implements EventTranslator, and deals with the
stage-relative X11 events coming from the X11 event source;
- ClutterStageGLX overrides EventTranslator, in order to
deal with the INTEL_GLX_swap_event extension, and it chains up
to the X11 default implementation;
- ClutterDeviceManagerX11 has been split into two separate classes,
one that deals with core and (optionally) XI1 events, and the
other that deals with XI2 events; the selection is done at run-time,
since the core+XI1 and XI2 mechanisms are mutually exclusive.
All the other backends we officially support still use their own
custom event source and translation function, but the end goal is to
migrate them to the translate_event() virtual function, and have the
event source be a shared part of Clutter core.
2011-01-04 07:32:04 -05:00
|
|
|
out:
|
2011-07-14 15:58:25 -04:00
|
|
|
if (allocated_event)
|
|
|
|
XFreeEventData (xdisplay, &xevent->xcookie);
|
|
|
|
|
2008-12-22 08:11:59 -05:00
|
|
|
return result;
|
2008-02-21 10:18:14 -05:00
|
|
|
}
|
|
|
|
|
2009-02-18 04:45:26 -05:00
|
|
|
Time
|
2019-03-22 08:53:00 -04:00
|
|
|
meta_x11_get_current_event_time (void)
|
2009-02-18 04:45:26 -05:00
|
|
|
{
|
|
|
|
ClutterBackend *backend = clutter_get_default_backend ();
|
|
|
|
|
|
|
|
return CLUTTER_BACKEND_X11 (backend)->last_event_time;
|
|
|
|
}
|
2010-07-08 10:47:18 -04:00
|
|
|
|
|
|
|
gint
|
2019-03-22 08:53:00 -04:00
|
|
|
meta_x11_event_get_key_group (const ClutterEvent *event)
|
2010-07-08 10:47:18 -04:00
|
|
|
{
|
2019-03-22 08:53:00 -04:00
|
|
|
MetaEventX11 *event_x11;
|
2010-07-08 10:47:18 -04:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2012-09-05 04:38:17 -04:00
|
|
|
|
|
|
|
guint
|
2019-03-22 08:53:00 -04:00
|
|
|
meta_x11_event_sequence_get_touch_detail (const ClutterEventSequence *sequence)
|
2012-09-05 04:38:17 -04:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (sequence != NULL, 0);
|
|
|
|
|
|
|
|
return GPOINTER_TO_UINT (sequence);
|
|
|
|
}
|