2010-05-25 22:38:44 +00:00
|
|
|
/* GDK - The GIMP Drawing Kit
|
|
|
|
* Copyright (C) 2009 Carlos Garnacho <carlosg@gnome.org>
|
|
|
|
*
|
|
|
|
* 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
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2010-05-25 22:38:44 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2010-12-21 04:59:07 +00:00
|
|
|
#include "gdkx11devicemanager-core.h"
|
2010-12-21 16:27:27 +00:00
|
|
|
#include "gdkdevicemanagerprivate-core.h"
|
2010-12-21 04:59:07 +00:00
|
|
|
#include "gdkx11device-core.h"
|
2010-10-15 02:05:51 +00:00
|
|
|
|
2010-12-21 15:37:21 +00:00
|
|
|
#include "gdkdeviceprivate.h"
|
2015-12-19 17:21:10 +00:00
|
|
|
#include "gdkseatdefaultprivate.h"
|
2010-12-13 19:05:59 +00:00
|
|
|
#include "gdkdisplayprivate.h"
|
2010-05-25 22:38:44 +00:00
|
|
|
#include "gdkeventtranslator.h"
|
|
|
|
#include "gdkprivate-x11.h"
|
2018-02-07 05:00:01 +00:00
|
|
|
#include "gdkdisplay-x11.h"
|
2010-12-21 15:37:21 +00:00
|
|
|
#include "gdkkeysyms.h"
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
|
2017-11-25 04:00:40 +00:00
|
|
|
|
2010-05-25 22:38:44 +00:00
|
|
|
#define HAS_FOCUS(toplevel) \
|
|
|
|
((toplevel)->has_focus || (toplevel)->has_pointer_focus)
|
|
|
|
|
2010-12-21 04:59:07 +00:00
|
|
|
static void gdk_x11_device_manager_core_finalize (GObject *object);
|
|
|
|
static void gdk_x11_device_manager_core_constructed (GObject *object);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2010-12-21 04:59:07 +00:00
|
|
|
static void gdk_x11_device_manager_event_translator_init (GdkEventTranslatorIface *iface);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2010-12-21 04:59:07 +00:00
|
|
|
static gboolean gdk_x11_device_manager_core_translate_event (GdkEventTranslator *translator,
|
|
|
|
GdkDisplay *display,
|
|
|
|
GdkEvent *event,
|
2017-12-12 23:39:32 +00:00
|
|
|
const XEvent *xevent);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
|
2017-11-25 04:00:40 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GdkX11DeviceManagerCore, gdk_x11_device_manager_core, G_TYPE_OBJECT,
|
2010-05-25 22:38:44 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GDK_TYPE_EVENT_TRANSLATOR,
|
2010-12-21 04:59:07 +00:00
|
|
|
gdk_x11_device_manager_event_translator_init))
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2017-11-25 04:00:40 +00:00
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
PROP_DISPLAY
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_device_manager_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_DISPLAY:
|
|
|
|
GDK_X11_DEVICE_MANAGER_CORE (object)->display = g_value_get_object (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_device_manager_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_DISPLAY:
|
|
|
|
g_value_set_object (value, GDK_X11_DEVICE_MANAGER_CORE (object)->display);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-25 22:38:44 +00:00
|
|
|
static void
|
2010-12-21 04:59:07 +00:00
|
|
|
gdk_x11_device_manager_core_class_init (GdkX11DeviceManagerCoreClass *klass)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2010-12-21 04:59:07 +00:00
|
|
|
object_class->finalize = gdk_x11_device_manager_core_finalize;
|
|
|
|
object_class->constructed = gdk_x11_device_manager_core_constructed;
|
2017-11-25 04:00:40 +00:00
|
|
|
object_class->set_property = gdk_device_manager_set_property;
|
|
|
|
object_class->get_property = gdk_device_manager_get_property;
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_DISPLAY,
|
|
|
|
g_param_spec_object ("display",
|
|
|
|
"Display",
|
|
|
|
"Display for the device manager",
|
|
|
|
GDK_TYPE_DISPLAY,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-21 04:59:07 +00:00
|
|
|
gdk_x11_device_manager_event_translator_init (GdkEventTranslatorIface *iface)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2010-12-21 04:59:07 +00:00
|
|
|
iface->translate_event = gdk_x11_device_manager_core_translate_event;
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GdkDevice *
|
2017-11-25 04:00:40 +00:00
|
|
|
create_core_pointer (GdkX11DeviceManagerCore *device_manager,
|
|
|
|
GdkDisplay *display)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2010-12-21 04:59:07 +00:00
|
|
|
return g_object_new (GDK_TYPE_X11_DEVICE_CORE,
|
2010-05-25 22:38:44 +00:00
|
|
|
"name", "Core Pointer",
|
|
|
|
"type", GDK_DEVICE_TYPE_MASTER,
|
|
|
|
"input-source", GDK_SOURCE_MOUSE,
|
|
|
|
"input-mode", GDK_MODE_SCREEN,
|
|
|
|
"has-cursor", TRUE,
|
|
|
|
"display", display,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GdkDevice *
|
2017-11-25 04:00:40 +00:00
|
|
|
create_core_keyboard (GdkX11DeviceManagerCore *device_manager,
|
|
|
|
GdkDisplay *display)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2010-12-21 04:59:07 +00:00
|
|
|
return g_object_new (GDK_TYPE_X11_DEVICE_CORE,
|
2010-05-25 22:38:44 +00:00
|
|
|
"name", "Core Keyboard",
|
|
|
|
"type", GDK_DEVICE_TYPE_MASTER,
|
|
|
|
"input-source", GDK_SOURCE_KEYBOARD,
|
|
|
|
"input-mode", GDK_MODE_SCREEN,
|
|
|
|
"has-cursor", FALSE,
|
|
|
|
"display", display,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-21 04:59:07 +00:00
|
|
|
gdk_x11_device_manager_core_init (GdkX11DeviceManagerCore *device_manager)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-21 04:59:07 +00:00
|
|
|
gdk_x11_device_manager_core_finalize (GObject *object)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2010-12-21 04:59:07 +00:00
|
|
|
GdkX11DeviceManagerCore *device_manager_core;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2010-12-21 04:59:07 +00:00
|
|
|
device_manager_core = GDK_X11_DEVICE_MANAGER_CORE (object);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
g_object_unref (device_manager_core->core_pointer);
|
|
|
|
g_object_unref (device_manager_core->core_keyboard);
|
|
|
|
|
2010-12-21 04:59:07 +00:00
|
|
|
G_OBJECT_CLASS (gdk_x11_device_manager_core_parent_class)->finalize (object);
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-21 04:59:07 +00:00
|
|
|
gdk_x11_device_manager_core_constructed (GObject *object)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2010-12-21 04:59:07 +00:00
|
|
|
GdkX11DeviceManagerCore *device_manager;
|
2010-05-25 22:38:44 +00:00
|
|
|
GdkDisplay *display;
|
|
|
|
|
2010-12-21 04:59:07 +00:00
|
|
|
device_manager = GDK_X11_DEVICE_MANAGER_CORE (object);
|
2017-11-25 04:00:40 +00:00
|
|
|
display = device_manager->display;
|
|
|
|
device_manager->core_pointer = create_core_pointer (device_manager, display);
|
|
|
|
device_manager->core_keyboard = create_core_keyboard (device_manager, display);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
_gdk_device_set_associated_device (device_manager->core_pointer, device_manager->core_keyboard);
|
|
|
|
_gdk_device_set_associated_device (device_manager->core_keyboard, device_manager->core_pointer);
|
2015-12-19 17:21:10 +00:00
|
|
|
|
|
|
|
/* We expect subclasses to handle their own seats */
|
|
|
|
if (G_OBJECT_TYPE (object) == GDK_TYPE_X11_DEVICE_MANAGER_CORE)
|
|
|
|
{
|
|
|
|
GdkSeat *seat;
|
|
|
|
|
|
|
|
seat = gdk_seat_default_new_for_master_pair (device_manager->core_pointer,
|
|
|
|
device_manager->core_keyboard);
|
|
|
|
|
|
|
|
gdk_display_add_seat (display, seat);
|
|
|
|
g_object_unref (seat);
|
|
|
|
}
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-21 04:59:07 +00:00
|
|
|
translate_key_event (GdkDisplay *display,
|
|
|
|
GdkX11DeviceManagerCore *device_manager,
|
|
|
|
GdkEvent *event,
|
2017-12-12 23:39:32 +00:00
|
|
|
const XEvent *xevent)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2017-12-15 12:44:58 +00:00
|
|
|
GdkKeymap *keymap = gdk_display_get_keymap (display);
|
2010-05-25 22:38:44 +00:00
|
|
|
GdkModifierType consumed, state;
|
|
|
|
|
2017-10-11 13:35:29 +00:00
|
|
|
event->any.type = xevent->xany.type == KeyPress ? GDK_KEY_PRESS : GDK_KEY_RELEASE;
|
2010-05-25 22:38:44 +00:00
|
|
|
event->key.time = xevent->xkey.time;
|
|
|
|
gdk_event_set_device (event, device_manager->core_keyboard);
|
|
|
|
|
|
|
|
event->key.state = (GdkModifierType) xevent->xkey.state;
|
2012-04-30 19:33:49 +00:00
|
|
|
event->key.group = gdk_x11_keymap_get_group_for_state (keymap, xevent->xkey.state);
|
2010-05-25 22:38:44 +00:00
|
|
|
event->key.hardware_keycode = xevent->xkey.keycode;
|
2016-05-10 19:16:45 +00:00
|
|
|
gdk_event_set_scancode (event, xevent->xkey.keycode);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2010-09-08 17:35:51 +00:00
|
|
|
event->key.keyval = GDK_KEY_VoidSymbol;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
gdk_keymap_translate_keyboard_state (keymap,
|
2010-12-21 04:59:07 +00:00
|
|
|
event->key.hardware_keycode,
|
|
|
|
event->key.state,
|
|
|
|
event->key.group,
|
|
|
|
&event->key.keyval,
|
2010-05-25 22:38:44 +00:00
|
|
|
NULL, NULL, &consumed);
|
|
|
|
|
|
|
|
state = event->key.state & ~consumed;
|
2010-12-16 04:49:31 +00:00
|
|
|
_gdk_x11_keymap_add_virt_mods (keymap, &state);
|
2010-05-25 22:38:44 +00:00
|
|
|
event->key.state |= state;
|
|
|
|
|
2012-04-30 19:33:49 +00:00
|
|
|
event->key.is_modifier = gdk_x11_keymap_key_is_modifier (keymap, event->key.hardware_keycode);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2011-02-05 01:58:41 +00:00
|
|
|
_gdk_x11_event_translate_keyboard_string (&event->key);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
#ifdef G_ENABLE_DEBUG
|
2018-01-12 00:48:27 +00:00
|
|
|
if (GDK_DISPLAY_DEBUG_CHECK (display, EVENTS))
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2010-12-21 04:59:07 +00:00
|
|
|
g_message ("%s:\t\twindow: %ld key: %12s %d",
|
2017-10-11 13:55:19 +00:00
|
|
|
event->any.type == GDK_KEY_PRESS ? "key press " : "key release",
|
2010-12-21 04:59:07 +00:00
|
|
|
xevent->xkey.window,
|
|
|
|
event->key.keyval ? gdk_keyval_name (event->key.keyval) : "(none)",
|
|
|
|
event->key.keyval);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
if (event->key.length > 0)
|
2010-12-21 04:59:07 +00:00
|
|
|
g_message ("\t\tlength: %4d string: \"%s\"",
|
2011-02-05 01:58:41 +00:00
|
|
|
event->key.length, event->key.string);
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
#endif /* G_ENABLE_DEBUG */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
static const char notify_modes[][19] = {
|
|
|
|
"NotifyNormal",
|
|
|
|
"NotifyGrab",
|
|
|
|
"NotifyUngrab",
|
|
|
|
"NotifyWhileGrabbed"
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char notify_details[][23] = {
|
|
|
|
"NotifyAncestor",
|
|
|
|
"NotifyVirtual",
|
|
|
|
"NotifyInferior",
|
|
|
|
"NotifyNonlinear",
|
|
|
|
"NotifyNonlinearVirtual",
|
|
|
|
"NotifyPointer",
|
|
|
|
"NotifyPointerRoot",
|
|
|
|
"NotifyDetailNone"
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void
|
2018-03-20 14:14:10 +00:00
|
|
|
set_user_time (GdkSurface *surface,
|
2010-12-21 04:59:07 +00:00
|
|
|
GdkEvent *event)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (event != NULL);
|
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
surface = gdk_surface_get_toplevel (event->any.surface);
|
|
|
|
g_return_if_fail (GDK_IS_SURFACE (surface));
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
/* If an event doesn't have a valid timestamp, we shouldn't use it
|
|
|
|
* to update the latest user interaction time.
|
|
|
|
*/
|
|
|
|
if (gdk_event_get_time (event) != GDK_CURRENT_TIME)
|
2018-03-20 14:14:10 +00:00
|
|
|
gdk_x11_surface_set_user_time (gdk_surface_get_toplevel (surface),
|
2010-05-25 22:38:44 +00:00
|
|
|
gdk_event_get_time (event));
|
|
|
|
}
|
|
|
|
|
|
|
|
static GdkCrossingMode
|
|
|
|
translate_crossing_mode (int mode)
|
|
|
|
{
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case NotifyNormal:
|
|
|
|
return GDK_CROSSING_NORMAL;
|
|
|
|
case NotifyGrab:
|
|
|
|
return GDK_CROSSING_GRAB;
|
|
|
|
case NotifyUngrab:
|
|
|
|
return GDK_CROSSING_UNGRAB;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
2017-10-24 16:13:45 +00:00
|
|
|
return GDK_CROSSING_NORMAL;
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GdkNotifyType
|
|
|
|
translate_notify_type (int detail)
|
|
|
|
{
|
|
|
|
switch (detail)
|
|
|
|
{
|
|
|
|
case NotifyInferior:
|
|
|
|
return GDK_NOTIFY_INFERIOR;
|
|
|
|
case NotifyAncestor:
|
|
|
|
return GDK_NOTIFY_ANCESTOR;
|
|
|
|
case NotifyVirtual:
|
|
|
|
return GDK_NOTIFY_VIRTUAL;
|
|
|
|
case NotifyNonlinear:
|
|
|
|
return GDK_NOTIFY_NONLINEAR;
|
|
|
|
case NotifyNonlinearVirtual:
|
|
|
|
return GDK_NOTIFY_NONLINEAR_VIRTUAL;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
2017-10-24 16:26:08 +00:00
|
|
|
return GDK_NOTIFY_UNKNOWN;
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2018-03-20 10:40:08 +00:00
|
|
|
is_parent_of (GdkSurface *parent,
|
|
|
|
GdkSurface *child)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2018-03-20 10:40:08 +00:00
|
|
|
GdkSurface *w;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
w = child;
|
|
|
|
while (w != NULL)
|
|
|
|
{
|
|
|
|
if (w == parent)
|
2010-12-21 04:59:07 +00:00
|
|
|
return TRUE;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2018-03-20 10:40:08 +00:00
|
|
|
w = gdk_surface_get_parent (w);
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-03-20 10:40:08 +00:00
|
|
|
static GdkSurface *
|
2018-03-20 11:05:26 +00:00
|
|
|
get_event_surface (GdkEventTranslator *translator,
|
2017-12-12 23:39:32 +00:00
|
|
|
const XEvent *xevent)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
GdkDisplay *display;
|
2018-03-20 14:14:10 +00:00
|
|
|
GdkSurface *surface;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2017-11-25 13:23:25 +00:00
|
|
|
display = GDK_X11_DEVICE_MANAGER_CORE (translator)->display;
|
2018-03-20 14:14:10 +00:00
|
|
|
surface = gdk_x11_surface_lookup_for_display (display, xevent->xany.window);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
/* Apply keyboard grabs to non-native windows */
|
|
|
|
if (xevent->type == KeyPress || xevent->type == KeyRelease)
|
|
|
|
{
|
|
|
|
GdkDeviceGrabInfo *info;
|
|
|
|
gulong serial;
|
|
|
|
|
2010-12-13 19:05:59 +00:00
|
|
|
serial = _gdk_display_get_next_serial (display);
|
2010-05-25 22:38:44 +00:00
|
|
|
info = _gdk_display_has_device_grab (display,
|
2017-11-25 13:23:25 +00:00
|
|
|
GDK_X11_DEVICE_MANAGER_CORE (translator)->core_keyboard,
|
2010-05-25 22:38:44 +00:00
|
|
|
serial);
|
|
|
|
if (info &&
|
2018-03-20 14:14:10 +00:00
|
|
|
(!is_parent_of (info->surface, surface) ||
|
2010-05-25 22:38:44 +00:00
|
|
|
!info->owner_events))
|
|
|
|
{
|
2018-03-20 14:14:10 +00:00
|
|
|
/* Report key event against grab surface */
|
|
|
|
surface = info->surface;
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
return surface;
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2010-12-21 04:59:07 +00:00
|
|
|
gdk_x11_device_manager_core_translate_event (GdkEventTranslator *translator,
|
|
|
|
GdkDisplay *display,
|
|
|
|
GdkEvent *event,
|
2017-12-12 23:39:32 +00:00
|
|
|
const XEvent *xevent)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2018-03-20 10:40:08 +00:00
|
|
|
GdkSurfaceImplX11 *impl;
|
2010-12-21 04:59:07 +00:00
|
|
|
GdkX11DeviceManagerCore *device_manager;
|
2018-03-20 14:14:10 +00:00
|
|
|
GdkSurface *surface;
|
2010-05-25 22:38:44 +00:00
|
|
|
gboolean return_val;
|
2013-06-20 09:40:07 +00:00
|
|
|
int scale;
|
2010-12-20 18:20:10 +00:00
|
|
|
GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2010-12-21 04:59:07 +00:00
|
|
|
device_manager = GDK_X11_DEVICE_MANAGER_CORE (translator);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
surface = get_event_surface (translator, xevent);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2013-06-20 09:40:07 +00:00
|
|
|
scale = 1;
|
2018-03-20 14:14:10 +00:00
|
|
|
if (surface)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2018-03-20 14:14:10 +00:00
|
|
|
if (GDK_SURFACE_DESTROYED (surface) || !GDK_IS_SURFACE (surface))
|
2010-06-04 14:17:41 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
g_object_ref (surface);
|
|
|
|
impl = GDK_SURFACE_IMPL_X11 (surface->impl);
|
2018-03-20 11:05:26 +00:00
|
|
|
scale = impl->surface_scale;
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
event->any.surface = surface;
|
2010-05-25 22:38:44 +00:00
|
|
|
event->any.send_event = xevent->xany.send_event ? TRUE : FALSE;
|
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
if (surface && GDK_SURFACE_DESTROYED (surface))
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
if (xevent->type != DestroyNotify)
|
2010-12-21 04:59:07 +00:00
|
|
|
{
|
|
|
|
return_val = FALSE;
|
|
|
|
goto done;
|
|
|
|
}
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
if (surface &&
|
2010-05-25 22:38:44 +00:00
|
|
|
(xevent->type == MotionNotify ||
|
|
|
|
xevent->type == ButtonRelease))
|
|
|
|
{
|
2010-12-15 22:55:04 +00:00
|
|
|
if (_gdk_x11_moveresize_handle_event (xevent))
|
|
|
|
{
|
2010-05-25 22:38:44 +00:00
|
|
|
return_val = FALSE;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We do a "manual" conversion of the XEvent to a
|
|
|
|
* GdkEvent. The structures are mostly the same so
|
|
|
|
* the conversion is fairly straightforward. We also
|
|
|
|
* optionally print debugging info regarding events
|
|
|
|
* received.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return_val = TRUE;
|
|
|
|
|
|
|
|
switch (xevent->type)
|
|
|
|
{
|
|
|
|
case KeyPress:
|
2018-03-20 14:14:10 +00:00
|
|
|
if (surface == NULL)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
return_val = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
translate_key_event (display, device_manager, event, xevent);
|
2018-03-20 14:14:10 +00:00
|
|
|
set_user_time (surface, event);
|
2010-05-25 22:38:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KeyRelease:
|
2018-03-20 14:14:10 +00:00
|
|
|
if (surface == NULL)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
return_val = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Emulate detectable auto-repeat by checking to see
|
|
|
|
* if the next event is a key press with the same
|
|
|
|
* keycode and timestamp, and if so, ignoring the event.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!display_x11->have_xkb_autorepeat && XPending (xevent->xkey.display))
|
2010-12-21 04:59:07 +00:00
|
|
|
{
|
|
|
|
XEvent next_event;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2010-12-21 04:59:07 +00:00
|
|
|
XPeekEvent (xevent->xkey.display, &next_event);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2010-12-21 04:59:07 +00:00
|
|
|
if (next_event.type == KeyPress &&
|
|
|
|
next_event.xkey.keycode == xevent->xkey.keycode &&
|
|
|
|
next_event.xkey.time == xevent->xkey.time)
|
|
|
|
{
|
|
|
|
return_val = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
translate_key_event (display, device_manager, event, xevent);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ButtonPress:
|
2018-01-12 00:48:27 +00:00
|
|
|
GDK_DISPLAY_NOTE (display, EVENTS,
|
2010-12-21 04:59:07 +00:00
|
|
|
g_message ("button press:\t\twindow: %ld x,y: %d %d button: %d",
|
|
|
|
xevent->xbutton.window,
|
|
|
|
xevent->xbutton.x, xevent->xbutton.y,
|
|
|
|
xevent->xbutton.button));
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
if (surface == NULL)
|
2010-12-21 04:59:07 +00:00
|
|
|
{
|
|
|
|
return_val = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
/* If we get a ButtonPress event where the button is 4 or 5,
|
2010-12-21 04:59:07 +00:00
|
|
|
it's a Scroll event */
|
2010-05-25 22:38:44 +00:00
|
|
|
switch (xevent->xbutton.button)
|
|
|
|
{
|
|
|
|
case 4: /* up */
|
|
|
|
case 5: /* down */
|
|
|
|
case 6: /* left */
|
|
|
|
case 7: /* right */
|
2017-10-11 13:35:29 +00:00
|
|
|
event->any.type = GDK_SCROLL;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
if (xevent->xbutton.button == 4)
|
|
|
|
event->scroll.direction = GDK_SCROLL_UP;
|
|
|
|
else if (xevent->xbutton.button == 5)
|
|
|
|
event->scroll.direction = GDK_SCROLL_DOWN;
|
|
|
|
else if (xevent->xbutton.button == 6)
|
|
|
|
event->scroll.direction = GDK_SCROLL_LEFT;
|
|
|
|
else
|
|
|
|
event->scroll.direction = GDK_SCROLL_RIGHT;
|
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
event->any.surface = surface;
|
2010-12-21 04:59:07 +00:00
|
|
|
event->scroll.time = xevent->xbutton.time;
|
2013-06-20 09:40:07 +00:00
|
|
|
event->scroll.x = (gdouble) xevent->xbutton.x / scale;
|
|
|
|
event->scroll.y = (gdouble) xevent->xbutton.y / scale;
|
|
|
|
event->scroll.x_root = (gdouble) xevent->xbutton.x_root / scale;
|
|
|
|
event->scroll.y_root = (gdouble) xevent->xbutton.y_root / scale;
|
2010-12-21 04:59:07 +00:00
|
|
|
event->scroll.state = (GdkModifierType) xevent->xbutton.state;
|
2017-10-11 06:42:41 +00:00
|
|
|
gdk_event_set_device (event, device_manager->core_pointer);
|
2010-12-21 04:59:07 +00:00
|
|
|
|
2012-01-23 23:46:43 +00:00
|
|
|
event->scroll.delta_x = 0;
|
|
|
|
event->scroll.delta_y = 0;
|
|
|
|
|
2017-10-31 02:15:29 +00:00
|
|
|
gdk_event_set_display (event, display);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2017-10-11 13:35:29 +00:00
|
|
|
event->any.type = GDK_BUTTON_PRESS;
|
2018-03-20 14:14:10 +00:00
|
|
|
event->any.surface = surface;
|
2010-12-21 04:59:07 +00:00
|
|
|
event->button.time = xevent->xbutton.time;
|
2013-06-20 09:40:07 +00:00
|
|
|
event->button.x = (gdouble) xevent->xbutton.x / scale;
|
|
|
|
event->button.y = (gdouble) xevent->xbutton.y / scale;
|
|
|
|
event->button.x_root = (gdouble) xevent->xbutton.x_root / scale;
|
|
|
|
event->button.y_root = (gdouble) xevent->xbutton.y_root / scale;
|
2010-12-21 04:59:07 +00:00
|
|
|
event->button.axes = NULL;
|
|
|
|
event->button.state = (GdkModifierType) xevent->xbutton.state;
|
|
|
|
event->button.button = xevent->xbutton.button;
|
2017-10-11 06:42:41 +00:00
|
|
|
gdk_event_set_device (event, device_manager->core_pointer);
|
2010-12-21 04:59:07 +00:00
|
|
|
|
2017-10-31 02:15:29 +00:00
|
|
|
gdk_event_set_display (event, display);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
break;
|
2010-12-21 04:59:07 +00:00
|
|
|
}
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
set_user_time (surface, event);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ButtonRelease:
|
2018-01-12 00:48:27 +00:00
|
|
|
GDK_DISPLAY_NOTE (display, EVENTS,
|
2010-12-21 04:59:07 +00:00
|
|
|
g_message ("button release:\twindow: %ld x,y: %d %d button: %d",
|
|
|
|
xevent->xbutton.window,
|
|
|
|
xevent->xbutton.x, xevent->xbutton.y,
|
|
|
|
xevent->xbutton.button));
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
if (surface == NULL)
|
2010-12-21 04:59:07 +00:00
|
|
|
{
|
|
|
|
return_val = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
/* We treat button presses as scroll wheel events, so ignore the release */
|
|
|
|
if (xevent->xbutton.button == 4 || xevent->xbutton.button == 5 ||
|
|
|
|
xevent->xbutton.button == 6 || xevent->xbutton.button == 7)
|
2010-12-21 04:59:07 +00:00
|
|
|
{
|
|
|
|
return_val = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2017-10-11 13:35:29 +00:00
|
|
|
event->any.type = GDK_BUTTON_RELEASE;
|
2018-03-20 14:14:10 +00:00
|
|
|
event->any.surface = surface;
|
2010-05-25 22:38:44 +00:00
|
|
|
event->button.time = xevent->xbutton.time;
|
2013-06-20 09:40:07 +00:00
|
|
|
event->button.x = (gdouble) xevent->xbutton.x / scale;
|
|
|
|
event->button.y = (gdouble) xevent->xbutton.y / scale;
|
|
|
|
event->button.x_root = (gdouble) xevent->xbutton.x_root / scale;
|
|
|
|
event->button.y_root = (gdouble) xevent->xbutton.y_root / scale;
|
2010-05-25 22:38:44 +00:00
|
|
|
event->button.axes = NULL;
|
|
|
|
event->button.state = (GdkModifierType) xevent->xbutton.state;
|
|
|
|
event->button.button = xevent->xbutton.button;
|
2017-10-11 06:42:41 +00:00
|
|
|
gdk_event_set_device (event, device_manager->core_pointer);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2017-10-31 02:15:29 +00:00
|
|
|
gdk_event_set_display (event, display);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MotionNotify:
|
2018-01-12 00:48:27 +00:00
|
|
|
GDK_DISPLAY_NOTE (display, EVENTS,
|
2010-12-21 04:59:07 +00:00
|
|
|
g_message ("motion notify:\t\twindow: %ld x,y: %d %d hint: %s",
|
|
|
|
xevent->xmotion.window,
|
|
|
|
xevent->xmotion.x, xevent->xmotion.y,
|
|
|
|
(xevent->xmotion.is_hint) ? "true" : "false"));
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
if (surface == NULL)
|
2010-12-21 04:59:07 +00:00
|
|
|
{
|
|
|
|
return_val = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2017-10-11 13:35:29 +00:00
|
|
|
event->any.type = GDK_MOTION_NOTIFY;
|
2018-03-20 14:14:10 +00:00
|
|
|
event->any.surface = surface;
|
2010-05-25 22:38:44 +00:00
|
|
|
event->motion.time = xevent->xmotion.time;
|
2013-06-20 09:40:07 +00:00
|
|
|
event->motion.x = (gdouble) xevent->xmotion.x / scale;
|
|
|
|
event->motion.y = (gdouble) xevent->xmotion.y / scale;
|
|
|
|
event->motion.x_root = (gdouble) xevent->xmotion.x_root / scale;
|
|
|
|
event->motion.y_root = (gdouble) xevent->xmotion.y_root / scale;
|
2010-05-25 22:38:44 +00:00
|
|
|
event->motion.axes = NULL;
|
|
|
|
event->motion.state = (GdkModifierType) xevent->xmotion.state;
|
2017-10-11 06:42:41 +00:00
|
|
|
gdk_event_set_device (event, device_manager->core_pointer);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2017-10-31 02:15:29 +00:00
|
|
|
gdk_event_set_display (event, display);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EnterNotify:
|
2018-01-12 00:48:27 +00:00
|
|
|
GDK_DISPLAY_NOTE (display, EVENTS,
|
2010-12-21 04:59:07 +00:00
|
|
|
g_message ("enter notify:\t\twindow: %ld detail: %d subwin: %ld",
|
|
|
|
xevent->xcrossing.window,
|
|
|
|
xevent->xcrossing.detail,
|
|
|
|
xevent->xcrossing.subwindow));
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
if (surface == NULL)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
return_val = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-10-31 02:15:29 +00:00
|
|
|
gdk_event_set_display (event, display);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2017-10-11 13:35:29 +00:00
|
|
|
event->any.type = GDK_ENTER_NOTIFY;
|
2018-03-20 14:14:10 +00:00
|
|
|
event->any.surface = surface;
|
2010-05-25 22:38:44 +00:00
|
|
|
gdk_event_set_device (event, device_manager->core_pointer);
|
|
|
|
|
|
|
|
/* If the subwindow field of the XEvent is non-NULL, then
|
2018-03-20 10:40:08 +00:00
|
|
|
* lookup the corresponding GdkSurface.
|
2010-05-25 22:38:44 +00:00
|
|
|
*/
|
|
|
|
if (xevent->xcrossing.subwindow != None)
|
2018-03-20 14:14:10 +00:00
|
|
|
event->crossing.child_surface = gdk_x11_surface_lookup_for_display (display, xevent->xcrossing.subwindow);
|
2010-05-25 22:38:44 +00:00
|
|
|
else
|
2018-03-20 14:14:10 +00:00
|
|
|
event->crossing.child_surface = NULL;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
event->crossing.time = xevent->xcrossing.time;
|
2013-06-20 09:40:07 +00:00
|
|
|
event->crossing.x = (gdouble) xevent->xcrossing.x / scale;
|
|
|
|
event->crossing.y = (gdouble) xevent->xcrossing.y / scale;
|
|
|
|
event->crossing.x_root = (gdouble) xevent->xcrossing.x_root / scale;
|
|
|
|
event->crossing.y_root = (gdouble) xevent->xcrossing.y_root / scale;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
event->crossing.mode = translate_crossing_mode (xevent->xcrossing.mode);
|
|
|
|
event->crossing.detail = translate_notify_type (xevent->xcrossing.detail);
|
|
|
|
|
|
|
|
event->crossing.focus = xevent->xcrossing.focus;
|
|
|
|
event->crossing.state = xevent->xcrossing.state;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LeaveNotify:
|
2018-01-12 00:48:27 +00:00
|
|
|
GDK_DISPLAY_NOTE (display, EVENTS,
|
2010-12-21 04:59:07 +00:00
|
|
|
g_message ("leave notify:\t\twindow: %ld detail: %d subwin: %ld",
|
|
|
|
xevent->xcrossing.window,
|
|
|
|
xevent->xcrossing.detail, xevent->xcrossing.subwindow));
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
if (surface == NULL)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
return_val = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-10-31 02:15:29 +00:00
|
|
|
gdk_event_set_display (event, display);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2017-10-11 13:35:29 +00:00
|
|
|
event->any.type = GDK_LEAVE_NOTIFY;
|
2018-03-20 14:14:10 +00:00
|
|
|
event->any.surface = surface;
|
2010-05-25 22:38:44 +00:00
|
|
|
gdk_event_set_device (event, device_manager->core_pointer);
|
|
|
|
|
|
|
|
/* If the subwindow field of the XEvent is non-NULL, then
|
2018-03-20 10:40:08 +00:00
|
|
|
* lookup the corresponding GdkSurface.
|
2010-05-25 22:38:44 +00:00
|
|
|
*/
|
|
|
|
if (xevent->xcrossing.subwindow != None)
|
2018-03-20 14:14:10 +00:00
|
|
|
event->crossing.child_surface = gdk_x11_surface_lookup_for_display (display, xevent->xcrossing.subwindow);
|
2010-05-25 22:38:44 +00:00
|
|
|
else
|
2018-03-20 14:14:10 +00:00
|
|
|
event->crossing.child_surface = NULL;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
event->crossing.time = xevent->xcrossing.time;
|
2013-06-20 09:40:07 +00:00
|
|
|
event->crossing.x = (gdouble) xevent->xcrossing.x / scale;
|
|
|
|
event->crossing.y = (gdouble) xevent->xcrossing.y / scale;
|
|
|
|
event->crossing.x_root = (gdouble) xevent->xcrossing.x_root / scale;
|
|
|
|
event->crossing.y_root = (gdouble) xevent->xcrossing.y_root / scale;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
event->crossing.mode = translate_crossing_mode (xevent->xcrossing.mode);
|
|
|
|
event->crossing.detail = translate_notify_type (xevent->xcrossing.detail);
|
|
|
|
|
|
|
|
event->crossing.focus = xevent->xcrossing.focus;
|
|
|
|
event->crossing.state = xevent->xcrossing.state;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FocusIn:
|
|
|
|
case FocusOut:
|
2018-03-20 14:14:10 +00:00
|
|
|
if (surface)
|
|
|
|
_gdk_device_manager_core_handle_focus (surface,
|
2011-12-19 11:39:53 +00:00
|
|
|
xevent->xfocus.window,
|
2011-12-22 07:29:47 +00:00
|
|
|
device_manager->core_keyboard,
|
|
|
|
NULL,
|
|
|
|
xevent->type == FocusIn,
|
|
|
|
xevent->xfocus.detail,
|
|
|
|
xevent->xfocus.mode);
|
|
|
|
return_val = FALSE;
|
2010-05-25 22:38:44 +00:00
|
|
|
break;
|
2011-12-19 10:19:35 +00:00
|
|
|
|
2010-05-25 22:38:44 +00:00
|
|
|
default:
|
|
|
|
return_val = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (return_val)
|
|
|
|
{
|
2018-03-20 14:14:10 +00:00
|
|
|
if (event->any.surface)
|
|
|
|
g_object_ref (event->any.surface);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
if (((event->any.type == GDK_ENTER_NOTIFY) ||
|
2010-12-21 04:59:07 +00:00
|
|
|
(event->any.type == GDK_LEAVE_NOTIFY)) &&
|
2018-03-20 14:14:10 +00:00
|
|
|
(event->crossing.child_surface != NULL))
|
|
|
|
g_object_ref (event->crossing.child_surface);
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Mark this event as having no resources to be freed */
|
2018-03-20 14:14:10 +00:00
|
|
|
event->any.surface = NULL;
|
2010-05-25 22:38:44 +00:00
|
|
|
event->any.type = GDK_NOTHING;
|
|
|
|
}
|
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
if (surface)
|
|
|
|
g_object_unref (surface);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
return return_val;
|
|
|
|
}
|
|
|
|
|
2011-02-05 01:58:41 +00:00
|
|
|
void
|
|
|
|
_gdk_x11_event_translate_keyboard_string (GdkEventKey *event)
|
|
|
|
{
|
|
|
|
gunichar c = 0;
|
|
|
|
gchar buf[7];
|
|
|
|
|
|
|
|
/* Fill in event->string crudely, since various programs
|
|
|
|
* depend on it.
|
|
|
|
*/
|
|
|
|
event->string = NULL;
|
|
|
|
|
|
|
|
if (event->keyval != GDK_KEY_VoidSymbol)
|
|
|
|
c = gdk_keyval_to_unicode (event->keyval);
|
|
|
|
|
|
|
|
if (c)
|
|
|
|
{
|
|
|
|
gsize bytes_written;
|
|
|
|
gint len;
|
|
|
|
|
|
|
|
/* Apply the control key - Taken from Xlib
|
|
|
|
*/
|
|
|
|
if (event->state & GDK_CONTROL_MASK)
|
|
|
|
{
|
|
|
|
if ((c >= '@' && c < '\177') || c == ' ') c &= 0x1F;
|
|
|
|
else if (c == '2')
|
|
|
|
{
|
|
|
|
event->string = g_memdup ("\0\0", 2);
|
|
|
|
event->length = 1;
|
|
|
|
buf[0] = '\0';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (c >= '3' && c <= '7') c -= ('3' - '\033');
|
|
|
|
else if (c == '8') c = '\177';
|
|
|
|
else if (c == '/') c = '_' & 0x1F;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = g_unichar_to_utf8 (c, buf);
|
|
|
|
buf[len] = '\0';
|
|
|
|
|
|
|
|
event->string = g_locale_from_utf8 (buf, len,
|
|
|
|
NULL, &bytes_written,
|
|
|
|
NULL);
|
|
|
|
if (event->string)
|
|
|
|
event->length = bytes_written;
|
|
|
|
}
|
|
|
|
else if (event->keyval == GDK_KEY_Escape)
|
|
|
|
{
|
|
|
|
event->length = 1;
|
|
|
|
event->string = g_strdup ("\033");
|
|
|
|
}
|
|
|
|
else if (event->keyval == GDK_KEY_Return ||
|
|
|
|
event->keyval == GDK_KEY_KP_Enter)
|
|
|
|
{
|
|
|
|
event->length = 1;
|
|
|
|
event->string = g_strdup ("\r");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!event->string)
|
|
|
|
{
|
|
|
|
event->length = 0;
|
|
|
|
event->string = g_strdup ("");
|
|
|
|
}
|
|
|
|
}
|
2011-12-19 10:19:35 +00:00
|
|
|
|
|
|
|
/* We only care about focus events that indicate that _this_
|
2018-03-20 14:14:10 +00:00
|
|
|
* surface (not a ancestor or child) got or lost the focus
|
2011-12-19 10:19:35 +00:00
|
|
|
*/
|
|
|
|
void
|
2018-03-20 14:14:10 +00:00
|
|
|
_gdk_device_manager_core_handle_focus (GdkSurface *surface,
|
2011-12-19 11:39:53 +00:00
|
|
|
Window original,
|
2011-12-19 10:19:35 +00:00
|
|
|
GdkDevice *device,
|
|
|
|
GdkDevice *source_device,
|
|
|
|
gboolean focus_in,
|
|
|
|
int detail,
|
|
|
|
int mode)
|
|
|
|
{
|
|
|
|
GdkToplevelX11 *toplevel;
|
2016-02-12 20:59:29 +00:00
|
|
|
GdkX11Screen *x11_screen;
|
2011-12-19 10:19:35 +00:00
|
|
|
gboolean had_focus;
|
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
g_return_if_fail (GDK_IS_SURFACE (surface));
|
2011-12-19 10:19:35 +00:00
|
|
|
g_return_if_fail (GDK_IS_DEVICE (device));
|
|
|
|
g_return_if_fail (source_device == NULL || GDK_IS_DEVICE (source_device));
|
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
GDK_DISPLAY_NOTE (gdk_surface_get_display (surface), EVENTS,
|
2011-12-19 10:19:35 +00:00
|
|
|
g_message ("focus out:\t\twindow: %ld, detail: %s, mode: %s",
|
2018-03-20 14:14:10 +00:00
|
|
|
GDK_SURFACE_XID (surface),
|
2011-12-19 10:19:35 +00:00
|
|
|
notify_details[detail],
|
|
|
|
notify_modes[mode]));
|
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
toplevel = _gdk_x11_surface_get_toplevel (surface);
|
2011-12-19 10:19:35 +00:00
|
|
|
|
|
|
|
if (!toplevel)
|
|
|
|
return;
|
|
|
|
|
2011-12-19 11:39:53 +00:00
|
|
|
if (toplevel->focus_window == original)
|
|
|
|
return;
|
|
|
|
|
2011-12-19 10:19:35 +00:00
|
|
|
had_focus = HAS_FOCUS (toplevel);
|
2018-03-20 14:14:10 +00:00
|
|
|
x11_screen = GDK_X11_SCREEN (GDK_SURFACE_SCREEN (surface));
|
2011-12-19 10:19:35 +00:00
|
|
|
|
|
|
|
switch (detail)
|
|
|
|
{
|
|
|
|
case NotifyAncestor:
|
|
|
|
case NotifyVirtual:
|
|
|
|
/* When the focus moves from an ancestor of the window to
|
|
|
|
* the window or a descendent of the window, *and* the
|
|
|
|
* pointer is inside the window, then we were previously
|
|
|
|
* receiving keystroke events in the has_pointer_focus
|
|
|
|
* case and are now receiving them in the
|
|
|
|
* has_focus_window case.
|
|
|
|
*/
|
|
|
|
if (toplevel->has_pointer &&
|
2016-02-12 20:59:29 +00:00
|
|
|
!x11_screen->wmspec_check_window &&
|
2011-12-19 10:19:35 +00:00
|
|
|
mode != NotifyGrab &&
|
2013-12-04 11:49:02 +00:00
|
|
|
#ifdef XINPUT_2
|
|
|
|
mode != XINotifyPassiveGrab &&
|
|
|
|
mode != XINotifyPassiveUngrab &&
|
|
|
|
#endif /* XINPUT_2 */
|
2011-12-19 10:19:35 +00:00
|
|
|
mode != NotifyUngrab)
|
|
|
|
toplevel->has_pointer_focus = (focus_in) ? FALSE : TRUE;
|
|
|
|
|
|
|
|
/* fall through */
|
|
|
|
case NotifyNonlinear:
|
|
|
|
case NotifyNonlinearVirtual:
|
|
|
|
if (mode != NotifyGrab &&
|
2013-12-04 11:49:02 +00:00
|
|
|
#ifdef XINPUT_2
|
|
|
|
mode != XINotifyPassiveGrab &&
|
|
|
|
mode != XINotifyPassiveUngrab &&
|
|
|
|
#endif /* XINPUT_2 */
|
2011-12-19 10:19:35 +00:00
|
|
|
mode != NotifyUngrab)
|
|
|
|
toplevel->has_focus_window = (focus_in) ? TRUE : FALSE;
|
|
|
|
/* We pretend that the focus moves to the grab
|
|
|
|
* window, so we pay attention to NotifyGrab
|
|
|
|
* NotifyUngrab, and ignore NotifyWhileGrabbed
|
|
|
|
*/
|
|
|
|
if (mode != NotifyWhileGrabbed)
|
|
|
|
toplevel->has_focus = (focus_in) ? TRUE : FALSE;
|
|
|
|
break;
|
|
|
|
case NotifyPointer:
|
|
|
|
/* The X server sends NotifyPointer/NotifyGrab,
|
|
|
|
* but the pointer focus is ignored while a
|
|
|
|
* grab is in effect
|
|
|
|
*/
|
2016-02-12 20:59:29 +00:00
|
|
|
if (!x11_screen->wmspec_check_window &&
|
|
|
|
mode != NotifyGrab &&
|
2013-12-04 11:49:02 +00:00
|
|
|
#ifdef XINPUT_2
|
|
|
|
mode != XINotifyPassiveGrab &&
|
|
|
|
mode != XINotifyPassiveUngrab &&
|
|
|
|
#endif /* XINPUT_2 */
|
2011-12-19 10:19:35 +00:00
|
|
|
mode != NotifyUngrab)
|
|
|
|
toplevel->has_pointer_focus = (focus_in) ? TRUE : FALSE;
|
|
|
|
break;
|
|
|
|
case NotifyInferior:
|
|
|
|
case NotifyPointerRoot:
|
|
|
|
case NotifyDetailNone:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (HAS_FOCUS (toplevel) != had_focus)
|
|
|
|
{
|
|
|
|
GdkEvent *event;
|
|
|
|
|
|
|
|
event = gdk_event_new (GDK_FOCUS_CHANGE);
|
2018-03-20 14:14:10 +00:00
|
|
|
event->any.surface = g_object_ref (surface);
|
2017-10-11 13:35:29 +00:00
|
|
|
event->any.send_event = FALSE;
|
2011-12-19 10:19:35 +00:00
|
|
|
event->focus_change.in = focus_in;
|
|
|
|
gdk_event_set_device (event, device);
|
|
|
|
if (source_device)
|
|
|
|
gdk_event_set_source_device (event, source_device);
|
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
gdk_display_put_event (gdk_surface_get_display (surface), event);
|
2017-10-31 12:35:11 +00:00
|
|
|
g_object_unref (event);
|
2011-12-19 10:19:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|