summaryrefslogtreecommitdiff
path: root/gdk/broadway/gdkdevicemanager-broadway.c
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2010-11-12 22:50:47 +0100
committerAlexander Larsson <alexl@redhat.com>2010-11-25 22:09:28 +0100
commita54e556ad8c14d34f2bedb7ce9f68f8d539bd34e (patch)
tree4e820f0b8a3f5df0c9f454a219e9a783e5fc68d3 /gdk/broadway/gdkdevicemanager-broadway.c
parent5b480e1b0de0c8184cb2805ac85f7362c42fb2f6 (diff)
downloadgtk+-a54e556ad8c14d34f2bedb7ce9f68f8d539bd34e.tar.gz
Remove event translators
Diffstat (limited to 'gdk/broadway/gdkdevicemanager-broadway.c')
-rw-r--r--gdk/broadway/gdkdevicemanager-broadway.c531
1 files changed, 1 insertions, 530 deletions
diff --git a/gdk/broadway/gdkdevicemanager-broadway.c b/gdk/broadway/gdkdevicemanager-broadway.c
index 7b69bd05f4..bb6a3b6591 100644
--- a/gdk/broadway/gdkdevicemanager-broadway.c
+++ b/gdk/broadway/gdkdevicemanager-broadway.c
@@ -23,7 +23,6 @@
#include "gdktypes.h"
#include "gdkdevicemanager.h"
-#include "gdkeventtranslator.h"
#include "gdkdevice-broadway.h"
#include "gdkkeysyms.h"
#include "gdkprivate-broadway.h"
@@ -44,17 +43,7 @@ static GList * gdk_device_manager_core_list_devices (GdkDeviceManager *device_ma
GdkDeviceType type);
static GdkDevice * gdk_device_manager_core_get_client_pointer (GdkDeviceManager *device_manager);
-static void gdk_device_manager_event_translator_init (GdkEventTranslatorIface *iface);
-
-static gboolean gdk_device_manager_core_translate_event (GdkEventTranslator *translator,
- GdkDisplay *display,
- GdkEvent *event,
- XEvent *xevent);
-
-
-G_DEFINE_TYPE_WITH_CODE (GdkDeviceManagerCore, gdk_device_manager_core, GDK_TYPE_DEVICE_MANAGER,
- G_IMPLEMENT_INTERFACE (GDK_TYPE_EVENT_TRANSLATOR,
- gdk_device_manager_event_translator_init))
+G_DEFINE_TYPE (GdkDeviceManagerCore, gdk_device_manager_core, GDK_TYPE_DEVICE_MANAGER)
static void
gdk_device_manager_core_class_init (GdkDeviceManagerCoreClass *klass)
@@ -68,12 +57,6 @@ gdk_device_manager_core_class_init (GdkDeviceManagerCoreClass *klass)
device_manager_class->get_client_pointer = gdk_device_manager_core_get_client_pointer;
}
-static void
-gdk_device_manager_event_translator_init (GdkEventTranslatorIface *iface)
-{
- iface->translate_event = gdk_device_manager_core_translate_event;
-}
-
static GdkDevice *
create_core_pointer (GdkDeviceManager *device_manager,
GdkDisplay *display)
@@ -373,518 +356,6 @@ is_parent_of (GdkWindow *parent,
return FALSE;
}
-static GdkWindow *
-get_event_window (GdkEventTranslator *translator,
- XEvent *xevent)
-{
- GdkDeviceManager *device_manager;
- GdkDisplay *display;
- GdkWindow *window;
-
- device_manager = GDK_DEVICE_MANAGER (translator);
- display = gdk_device_manager_get_display (device_manager);
- window = gdk_window_lookup_for_display (display, xevent->xany.window);
-
- /* Apply keyboard grabs to non-native windows */
- if (xevent->type == KeyPress || xevent->type == KeyRelease)
- {
- GdkDeviceGrabInfo *info;
- gulong serial;
-
- serial = _gdk_windowing_window_get_next_serial (display);
- info = _gdk_display_has_device_grab (display,
- GDK_DEVICE_MANAGER_CORE (device_manager)->core_keyboard,
- serial);
- if (info &&
- (!is_parent_of (info->window, window) ||
- !info->owner_events))
- {
- /* Report key event against grab window */
- window = info->window;
- }
- }
-
- return window;
-}
-
-static gboolean
-gdk_device_manager_core_translate_event (GdkEventTranslator *translator,
- GdkDisplay *display,
- GdkEvent *event,
- XEvent *xevent)
-{
- GdkDeviceManagerCore *device_manager;
- GdkWindow *window;
- GdkWindowObject *window_private;
- GdkWindowImplX11 *window_impl = NULL;
- gboolean return_val;
- GdkToplevelX11 *toplevel = NULL;
- GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
-
- device_manager = GDK_DEVICE_MANAGER_CORE (translator);
- return_val = FALSE;
-
- window = get_event_window (translator, xevent);
- window_private = (GdkWindowObject *) window;
-
- if (window)
- {
- if (GDK_WINDOW_DESTROYED (window) || !GDK_IS_WINDOW (window))
- return FALSE;
-
- toplevel = _gdk_x11_window_get_toplevel (window);
- window_impl = GDK_WINDOW_IMPL_X11 (window_private->impl);
- g_object_ref (window);
- }
-
- event->any.window = window;
- event->any.send_event = xevent->xany.send_event ? TRUE : FALSE;
-
- if (window_private && GDK_WINDOW_DESTROYED (window))
- {
- if (xevent->type != DestroyNotify)
- {
- return_val = FALSE;
- goto done;
- }
- }
-
- if (window &&
- (xevent->type == MotionNotify ||
- xevent->type == ButtonRelease))
- {
- if (_gdk_moveresize_handle_event (xevent))
- {
- 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:
- if (window_private == NULL)
- {
- return_val = FALSE;
- break;
- }
- translate_key_event (display, device_manager, event, xevent);
- set_user_time (window, event);
- break;
-
- case KeyRelease:
- if (window_private == NULL)
- {
- 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))
- {
- 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)
- {
- return_val = FALSE;
- break;
- }
- }
-
- translate_key_event (display, device_manager, event, xevent);
- break;
-
- case ButtonPress:
- GDK_NOTE (EVENTS,
- 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));
-
- if (window_private == NULL)
- {
- return_val = FALSE;
- break;
- }
-
- /* If we get a ButtonPress event where the button is 4 or 5,
- it's a Scroll event */
- switch (xevent->xbutton.button)
- {
- case 4: /* up */
- case 5: /* down */
- case 6: /* left */
- case 7: /* right */
- event->scroll.type = GDK_SCROLL;
-
- 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;
-
- event->scroll.window = window;
- event->scroll.time = xevent->xbutton.time;
- event->scroll.x = (gdouble) xevent->xbutton.x;
- event->scroll.y = (gdouble) xevent->xbutton.y;
- event->scroll.x_root = (gdouble) xevent->xbutton.x_root;
- event->scroll.y_root = (gdouble) xevent->xbutton.y_root;
- event->scroll.state = (GdkModifierType) xevent->xbutton.state;
- event->scroll.device = device_manager->core_pointer;
-
- if (!set_screen_from_root (display, event, xevent->xbutton.root))
- {
- return_val = FALSE;
- break;
- }
-
- break;
-
- default:
- event->button.type = GDK_BUTTON_PRESS;
- event->button.window = window;
- event->button.time = xevent->xbutton.time;
- event->button.x = (gdouble) xevent->xbutton.x;
- event->button.y = (gdouble) xevent->xbutton.y;
- event->button.x_root = (gdouble) xevent->xbutton.x_root;
- event->button.y_root = (gdouble) xevent->xbutton.y_root;
- event->button.axes = NULL;
- event->button.state = (GdkModifierType) xevent->xbutton.state;
- event->button.button = xevent->xbutton.button;
- event->button.device = device_manager->core_pointer;
-
- if (!set_screen_from_root (display, event, xevent->xbutton.root))
- return_val = FALSE;
-
- break;
- }
-
- set_user_time (window, event);
-
- break;
-
- case ButtonRelease:
- GDK_NOTE (EVENTS,
- g_message ("button release:\twindow: %ld x,y: %d %d button: %d",
- xevent->xbutton.window,
- xevent->xbutton.x, xevent->xbutton.y,
- xevent->xbutton.button));
-
- if (window_private == NULL)
- {
- return_val = FALSE;
- break;
- }
-
- /* 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)
- {
- return_val = FALSE;
- break;
- }
-
- event->button.type = GDK_BUTTON_RELEASE;
- event->button.window = window;
- event->button.time = xevent->xbutton.time;
- event->button.x = (gdouble) xevent->xbutton.x;
- event->button.y = (gdouble) xevent->xbutton.y;
- event->button.x_root = (gdouble) xevent->xbutton.x_root;
- event->button.y_root = (gdouble) xevent->xbutton.y_root;
- event->button.axes = NULL;
- event->button.state = (GdkModifierType) xevent->xbutton.state;
- event->button.button = xevent->xbutton.button;
- event->button.device = device_manager->core_pointer;
-
- if (!set_screen_from_root (display, event, xevent->xbutton.root))
- return_val = FALSE;
-
- break;
-
- case MotionNotify:
- GDK_NOTE (EVENTS,
- 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"));
-
- if (window_private == NULL)
- {
- return_val = FALSE;
- break;
- }
-
- event->motion.type = GDK_MOTION_NOTIFY;
- event->motion.window = window;
- event->motion.time = xevent->xmotion.time;
- event->motion.x = (gdouble) xevent->xmotion.x;
- event->motion.y = (gdouble) xevent->xmotion.y;
- event->motion.x_root = (gdouble) xevent->xmotion.x_root;
- event->motion.y_root = (gdouble) xevent->xmotion.y_root;
- event->motion.axes = NULL;
- event->motion.state = (GdkModifierType) xevent->xmotion.state;
- event->motion.is_hint = xevent->xmotion.is_hint;
- event->motion.device = device_manager->core_pointer;
-
- if (!set_screen_from_root (display, event, xevent->xbutton.root))
- {
- return_val = FALSE;
- break;
- }
-
- break;
-
- case EnterNotify:
- GDK_NOTE (EVENTS,
- g_message ("enter notify:\t\twindow: %ld detail: %d subwin: %ld",
- xevent->xcrossing.window,
- xevent->xcrossing.detail,
- xevent->xcrossing.subwindow));
-
- if (window_private == NULL)
- {
- return_val = FALSE;
- break;
- }
-
- if (!set_screen_from_root (display, event, xevent->xbutton.root))
- {
- return_val = FALSE;
- break;
- }
-
- event->crossing.type = GDK_ENTER_NOTIFY;
- event->crossing.window = window;
- gdk_event_set_device (event, device_manager->core_pointer);
-
- /* If the subwindow field of the XEvent is non-NULL, then
- * lookup the corresponding GdkWindow.
- */
- if (xevent->xcrossing.subwindow != None)
- event->crossing.subwindow = gdk_window_lookup_for_display (display, xevent->xcrossing.subwindow);
- else
- event->crossing.subwindow = NULL;
-
- event->crossing.time = xevent->xcrossing.time;
- event->crossing.x = (gdouble) xevent->xcrossing.x;
- event->crossing.y = (gdouble) xevent->xcrossing.y;
- event->crossing.x_root = (gdouble) xevent->xcrossing.x_root;
- event->crossing.y_root = (gdouble) xevent->xcrossing.y_root;
-
- 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:
- GDK_NOTE (EVENTS,
- g_message ("leave notify:\t\twindow: %ld detail: %d subwin: %ld",
- xevent->xcrossing.window,
- xevent->xcrossing.detail, xevent->xcrossing.subwindow));
-
- if (window_private == NULL)
- {
- return_val = FALSE;
- break;
- }
-
- if (!set_screen_from_root (display, event, xevent->xbutton.root))
- {
- return_val = FALSE;
- break;
- }
-
- event->crossing.type = GDK_LEAVE_NOTIFY;
- event->crossing.window = window;
- gdk_event_set_device (event, device_manager->core_pointer);
-
- /* If the subwindow field of the XEvent is non-NULL, then
- * lookup the corresponding GdkWindow.
- */
- if (xevent->xcrossing.subwindow != None)
- event->crossing.subwindow = gdk_window_lookup_for_display (display, xevent->xcrossing.subwindow);
- else
- event->crossing.subwindow = NULL;
-
- event->crossing.time = xevent->xcrossing.time;
- event->crossing.x = (gdouble) xevent->xcrossing.x;
- event->crossing.y = (gdouble) xevent->xcrossing.y;
- event->crossing.x_root = (gdouble) xevent->xcrossing.x_root;
- event->crossing.y_root = (gdouble) xevent->xcrossing.y_root;
-
- 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;
-
- /* We only care about focus events that indicate that _this_
- * window (not a ancestor or child) got or lost the focus
- */
- case FocusIn:
- GDK_NOTE (EVENTS,
- g_message ("focus in:\t\twindow: %ld, detail: %s, mode: %s",
- xevent->xfocus.window,
- notify_details[xevent->xfocus.detail],
- notify_modes[xevent->xfocus.mode]));
-
- if (toplevel)
- {
- gboolean had_focus = HAS_FOCUS (toplevel);
-
- switch (xevent->xfocus.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 &&
- xevent->xfocus.mode != NotifyGrab &&
- xevent->xfocus.mode != NotifyUngrab)
- toplevel->has_pointer_focus = FALSE;
-
- /* fall through */
- case NotifyNonlinear:
- case NotifyNonlinearVirtual:
- if (xevent->xfocus.mode != NotifyGrab &&
- xevent->xfocus.mode != NotifyUngrab)
- toplevel->has_focus_window = TRUE;
- /* We pretend that the focus moves to the grab
- * window, so we pay attention to NotifyGrab
- * NotifyUngrab, and ignore NotifyWhileGrabbed
- */
- if (xevent->xfocus.mode != NotifyWhileGrabbed)
- toplevel->has_focus = TRUE;
- break;
- case NotifyPointer:
- /* The X server sends NotifyPointer/NotifyGrab,
- * but the pointer focus is ignored while a
- * grab is in effect
- */
- if (xevent->xfocus.mode != NotifyGrab &&
- xevent->xfocus.mode != NotifyUngrab)
- toplevel->has_pointer_focus = TRUE;
- break;
- case NotifyInferior:
- case NotifyPointerRoot:
- case NotifyDetailNone:
- break;
- }
-
- if (HAS_FOCUS (toplevel) != had_focus)
- generate_focus_event (device_manager, window, TRUE);
- }
- break;
- case FocusOut:
- GDK_NOTE (EVENTS,
- g_message ("focus out:\t\twindow: %ld, detail: %s, mode: %s",
- xevent->xfocus.window,
- notify_details[xevent->xfocus.detail],
- notify_modes[xevent->xfocus.mode]));
-
- if (toplevel)
- {
- gboolean had_focus = HAS_FOCUS (toplevel);
-
- switch (xevent->xfocus.detail)
- {
- case NotifyAncestor:
- case NotifyVirtual:
- /* When the focus moves from the window or a descendent
- * of the window to an ancestor of the window, *and* the
- * pointer is inside the window, then we were previously
- * receiving keystroke events in the has_focus_window
- * case and are now receiving them in the
- * has_pointer_focus case.
- */
- if (toplevel->has_pointer &&
- xevent->xfocus.mode != NotifyGrab &&
- xevent->xfocus.mode != NotifyUngrab)
- toplevel->has_pointer_focus = TRUE;
-
- /* fall through */
- case NotifyNonlinear:
- case NotifyNonlinearVirtual:
- if (xevent->xfocus.mode != NotifyGrab &&
- xevent->xfocus.mode != NotifyUngrab)
- toplevel->has_focus_window = FALSE;
- if (xevent->xfocus.mode != NotifyWhileGrabbed)
- toplevel->has_focus = FALSE;
- break;
- case NotifyPointer:
- if (xevent->xfocus.mode != NotifyGrab &&
- xevent->xfocus.mode != NotifyUngrab)
- toplevel->has_pointer_focus = FALSE;
- break;
- case NotifyInferior:
- case NotifyPointerRoot:
- case NotifyDetailNone:
- break;
- }
-
- if (HAS_FOCUS (toplevel) != had_focus)
- generate_focus_event (device_manager, window, FALSE);
- }
- break;
-
- default:
- return_val = FALSE;
- }
-
- done:
- if (return_val)
- {
- if (event->any.window)
- g_object_ref (event->any.window);
-
- if (((event->any.type == GDK_ENTER_NOTIFY) ||
- (event->any.type == GDK_LEAVE_NOTIFY)) &&
- (event->crossing.subwindow != NULL))
- g_object_ref (event->crossing.subwindow);
- }
- else
- {
- /* Mark this event as having no resources to be freed */
- event->any.window = NULL;
- event->any.type = GDK_NOTHING;
- }
-
- if (window)
- g_object_unref (window);
-
- return return_val;
-}
-
static GList *
gdk_device_manager_core_list_devices (GdkDeviceManager *device_manager,
GdkDeviceType type)