[mutter/wip/xinput2r: 21/68] core: Add core devices implementation
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/wip/xinput2r: 21/68] core: Add core devices implementation
- Date: Wed, 24 Oct 2012 16:11:05 +0000 (UTC)
commit dd7cb017aac025d176b3ec6e344ed1dddf7dc7a6
Author: Carlos Garnacho <carlosg gnome org>
Date: Sat Jun 11 21:25:05 2011 +0200
core: Add core devices implementation
src/Makefile.am | 2 +
src/core/devices-core.c | 224 +++++++++++++++++++++++++++++++++++++++++++++++
src/core/devices-core.h | 90 +++++++++++++++++++
3 files changed, 316 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 2c7e441..7049848 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -81,6 +81,8 @@ libmutter_la_SOURCES = \
core/device-keyboard.h \
core/device-pointer.c \
core/device-pointer.h \
+ core/devices-core.c \
+ core/devices-core.h \
core/display.c \
core/display-private.h \
meta/display.h \
diff --git a/src/core/devices-core.c b/src/core/devices-core.c
new file mode 100644
index 0000000..755d40c
--- /dev/null
+++ b/src/core/devices-core.c
@@ -0,0 +1,224 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+
+/* Core input devices implementation */
+
+/*
+ * Copyright (C) 2011 Carlos Garnacho
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#include <config.h>
+#include "screen-private.h"
+#include "devices-core.h"
+
+/* Common functions */
+static void
+meta_device_core_common_allow_events (MetaDevice *device,
+ int mode,
+ Time time)
+{
+ MetaDisplay *display;
+
+ display = meta_device_get_display (device);
+ XAllowEvents (display->xdisplay, mode, time);
+}
+
+/* Core pointer */
+
+G_DEFINE_TYPE (MetaDevicePointerCore,
+ meta_device_pointer_core,
+ META_TYPE_DEVICE_POINTER)
+
+static gboolean
+meta_device_pointer_core_grab (MetaDevice *device,
+ Window xwindow,
+ guint evmask,
+ MetaCursor cursor,
+ gboolean owner_events,
+ gboolean sync,
+ Time time)
+{
+ MetaDisplay *display;
+ Cursor xcursor;
+ int retval;
+
+ display = meta_device_get_display (device);
+ xcursor = meta_display_create_x_cursor (display, cursor);
+
+ retval = XGrabPointer (display->xdisplay,
+ xwindow, owner_events,
+ evmask,
+ (sync) ? GrabModeSync : GrabModeAsync,
+ (sync) ? GrabModeSync : GrabModeAsync,
+ None, xcursor, time);
+
+ if (xcursor != None)
+ XFreeCursor (display->xdisplay, xcursor);
+
+ return (retval == Success);
+}
+
+static void
+meta_device_pointer_core_ungrab (MetaDevice *device,
+ Time time)
+{
+ MetaDisplay *display;
+
+ display = meta_device_get_display (device);
+ XUngrabPointer (display->xdisplay, time);
+}
+
+static void
+meta_device_pointer_core_warp (MetaDevicePointer *pointer,
+ MetaScreen *screen,
+ gint x,
+ gint y)
+{
+ MetaDisplay *display;
+
+ display = meta_device_get_display (META_DEVICE (pointer));
+ XWarpPointer (display->xdisplay,
+ None, screen->xroot,
+ 0, 0, 0, 0, x, y);
+}
+
+static void
+meta_device_pointer_core_set_window_cursor (MetaDevicePointer *pointer,
+ Window xwindow,
+ MetaCursor cursor)
+{
+ MetaDisplay *display;
+ Cursor xcursor;
+
+ display = meta_device_get_display (META_DEVICE (pointer));
+ xcursor = meta_display_create_x_cursor (display, cursor);
+
+ XDefineCursor (display->xdisplay, xwindow, xcursor);
+
+ if (xcursor != None)
+ XFreeCursor (display->xdisplay, xcursor);
+}
+
+static void
+meta_device_pointer_core_query_position (MetaDevicePointer *pointer,
+ Window xwindow,
+ Window *root,
+ Window *child,
+ gint *root_x,
+ gint *root_y,
+ gint *x,
+ gint *y,
+ guint *mask)
+{
+ MetaDisplay *display;
+
+ display = meta_device_get_display (META_DEVICE (pointer));
+ XQueryPointer (display->xdisplay, xwindow,
+ root, child, root_x, root_y,
+ x, y, mask);
+}
+
+static void
+meta_device_pointer_core_class_init (MetaDevicePointerCoreClass *klass)
+{
+ MetaDevicePointerClass *pointer_class = META_DEVICE_POINTER_CLASS (klass);
+ MetaDeviceClass *device_class = META_DEVICE_CLASS (klass);
+
+ device_class->allow_events = meta_device_core_common_allow_events;
+ device_class->grab = meta_device_pointer_core_grab;
+ device_class->ungrab = meta_device_pointer_core_ungrab;
+
+ pointer_class->warp = meta_device_pointer_core_warp;
+ pointer_class->set_window_cursor = meta_device_pointer_core_set_window_cursor;
+ pointer_class->query_position = meta_device_pointer_core_query_position;
+}
+
+static void
+meta_device_pointer_core_init (MetaDevicePointerCore *pointer)
+{
+}
+
+MetaDevice *
+meta_device_pointer_core_new (MetaDisplay *display)
+{
+ return g_object_new (META_TYPE_DEVICE_POINTER_CORE,
+ "device-id", META_CORE_POINTER_ID,
+ "display", display,
+ NULL);
+}
+
+
+/* Core Keyboard */
+
+G_DEFINE_TYPE (MetaDeviceKeyboardCore,
+ meta_device_keyboard_core,
+ META_TYPE_DEVICE_KEYBOARD)
+
+static gboolean
+meta_device_keyboard_core_grab (MetaDevice *device,
+ Window xwindow,
+ guint evmask,
+ MetaCursor cursor,
+ gboolean owner_events,
+ gboolean sync,
+ Time time)
+{
+ MetaDisplay *display;
+ gint retval;
+
+ display = meta_device_get_display (device);
+ retval = XGrabKeyboard (display->xdisplay, xwindow, owner_events,
+ (sync) ? GrabModeSync : GrabModeAsync,
+ (sync) ? GrabModeSync : GrabModeAsync,
+ time);
+
+ return (retval == Success);
+}
+
+static void
+meta_device_keyboard_core_ungrab (MetaDevice *device,
+ Time time)
+{
+ MetaDisplay *display;
+
+ display = meta_device_get_display (device);
+ XUngrabKeyboard (display->xdisplay, time);
+}
+
+static void
+meta_device_keyboard_core_class_init (MetaDeviceKeyboardCoreClass *klass)
+{
+ MetaDeviceClass *device_class = META_DEVICE_CLASS (klass);
+
+ device_class->allow_events = meta_device_core_common_allow_events;
+ device_class->grab = meta_device_keyboard_core_grab;
+ device_class->ungrab = meta_device_keyboard_core_ungrab;
+}
+
+static void
+meta_device_keyboard_core_init (MetaDeviceKeyboardCore *keyboard)
+{
+}
+
+MetaDevice *
+meta_device_keyboard_core_new (MetaDisplay *display)
+{
+ return g_object_new (META_TYPE_DEVICE_KEYBOARD_CORE,
+ "device-id", META_CORE_KEYBOARD_ID,
+ "display", display,
+ NULL);
+}
diff --git a/src/core/devices-core.h b/src/core/devices-core.h
new file mode 100644
index 0000000..bdb938f
--- /dev/null
+++ b/src/core/devices-core.h
@@ -0,0 +1,90 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+
+/**
+ * \file devices-core.h Core input devices implementation
+ *
+ * Input devices.
+ * This file contains the core X protocol implementation of input devices.
+ */
+
+/*
+ * Copyright (C) 2011 Carlos Garnacho
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#ifndef META_DEVICES_CORE_H
+#define META_DEVICES_CORE_H
+
+#include "device-pointer.h"
+#include "device-keyboard.h"
+
+/* These IDs are the same than those of the
+ * VCP/VCK in XInput2, to keep consistency */
+#define META_CORE_POINTER_ID 2
+#define META_CORE_KEYBOARD_ID 3
+
+/* Pointer */
+#define META_TYPE_DEVICE_POINTER_CORE (meta_device_pointer_core_get_type ())
+#define META_DEVICE_POINTER_CORE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_DEVICE_POINTER_CORE, MetaDevicePointerCore))
+#define META_DEVICE_POINTER_CORE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), META_TYPE_DEVICE_POINTER_CORE, MetaDevicePointerCoreClass))
+#define META_IS_DEVICE_POINTER_CORE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), META_TYPE_DEVICE_POINTER_CORE))
+#define META_IS_DEVICE_POINTER_CORE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), META_TYPE_DEVICE_POINTER_CORE))
+#define META_DEVICE_POINTER_CORE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), META_TYPE_DEVICE_POINTER_CORE, MetaDevicePointerCoreClass))
+
+typedef struct _MetaDevicePointerCore MetaDevicePointerCore;
+typedef struct _MetaDevicePointerCoreClass MetaDevicePointerCoreClass;
+
+struct _MetaDevicePointerCore
+{
+ MetaDevicePointer parent_instance;
+};
+
+struct _MetaDevicePointerCoreClass
+{
+ MetaDevicePointerClass parent_class;
+};
+
+GType meta_device_pointer_core_get_type (void) G_GNUC_CONST;
+
+MetaDevice *meta_device_pointer_core_new (MetaDisplay *display);
+
+/* Keyboard */
+#define META_TYPE_DEVICE_KEYBOARD_CORE (meta_device_keyboard_core_get_type ())
+#define META_DEVICE_KEYBOARD_CORE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_DEVICE_KEYBOARD_CORE, MetaDeviceKeyboardCore))
+#define META_DEVICE_KEYBOARD_CORE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), META_TYPE_DEVICE_KEYBOARD_CORE, MetaDeviceKeyboardCoreClass))
+#define META_IS_DEVICE_KEYBOARD_CORE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), META_TYPE_DEVICE_KEYBOARD_CORE))
+#define META_IS_DEVICE_KEYBOARD_CORE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), META_TYPE_DEVICE_KEYBOARD_CORE))
+#define META_DEVICE_KEYBOARD_CORE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), META_TYPE_DEVICE_KEYBOARD_CORE, MetaDeviceKeyboardCoreClass))
+
+typedef struct _MetaDeviceKeyboardCore MetaDeviceKeyboardCore;
+typedef struct _MetaDeviceKeyboardCoreClass MetaDeviceKeyboardCoreClass;
+
+struct _MetaDeviceKeyboardCore
+{
+ MetaDeviceKeyboard parent_instance;
+};
+
+struct _MetaDeviceKeyboardCoreClass
+{
+ MetaDeviceKeyboardClass parent_class;
+};
+
+GType meta_device_keyboard_core_get_type (void) G_GNUC_CONST;
+
+MetaDevice *meta_device_keyboard_core_new (MetaDisplay *display);
+
+#endif /* META_DEVICES_CORE_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]