[mutter/wip/xinput2: 16/49] Add pointer/keyboard abstract classes
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/wip/xinput2: 16/49] Add pointer/keyboard abstract classes
- Date: Fri, 15 Jul 2011 16:30:26 +0000 (UTC)
commit 7b9a26fbd83a3627a67903bf9d7551f2f15527f1
Author: Carlos Garnacho <carlosg gnome org>
Date: Sat Jun 11 19:04:58 2011 +0200
Add pointer/keyboard abstract classes
src/Makefile.am | 6 ++
src/core/device-keyboard.c | 39 +++++++++
src/core/device-keyboard.h | 59 +++++++++++++
src/core/device-pointer.c | 121 +++++++++++++++++++++++++++
src/core/device-pointer.h | 95 +++++++++++++++++++++
src/core/device.c | 195 ++++++++++++++++++++++++++++++++++++++++++++
src/core/device.h | 89 ++++++++++++++++++++
7 files changed, 604 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 3bcc141..a8e92f6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -75,6 +75,12 @@ libmutter_la_SOURCES = \
core/constraints.h \
core/core.c \
core/delete.c \
+ core/device.c \
+ core/device.h \
+ core/device-keyboard.c \
+ core/device-keyboard.h \
+ core/device-pointer.c \
+ core/device-pointer.h \
core/display.c \
core/display-private.h \
meta/display.h \
diff --git a/src/core/device-keyboard.c b/src/core/device-keyboard.c
new file mode 100644
index 0000000..ce16cbb
--- /dev/null
+++ b/src/core/device-keyboard.c
@@ -0,0 +1,39 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+
+/* Keyboard device abstraction */
+
+/*
+ * 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 "device-keyboard.h"
+
+G_DEFINE_ABSTRACT_TYPE (MetaDeviceKeyboard,
+ meta_device_keyboard,
+ META_TYPE_DEVICE)
+
+static void
+meta_device_keyboard_class_init (MetaDeviceKeyboardClass *klass)
+{
+}
+
+static void
+meta_device_keyboard_init (MetaDeviceKeyboard *keyboard)
+{
+}
diff --git a/src/core/device-keyboard.h b/src/core/device-keyboard.h
new file mode 100644
index 0000000..795e9b1
--- /dev/null
+++ b/src/core/device-keyboard.h
@@ -0,0 +1,59 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+
+/**
+ * \file device-keyboard.h Keyboard device abstraction
+ *
+ * Input devices.
+ * This file contains the internal abstraction of keyboard devices so
+ * XInput2/core events can be handled similarly.
+ */
+
+/*
+ * 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_DEVICE_KEYBOARD_H
+#define META_DEVICE_KEYBOARD_H
+
+#include "display-private.h"
+#include "device.h"
+
+#define META_TYPE_DEVICE_KEYBOARD (meta_device_keyboard_get_type ())
+#define META_DEVICE_KEYBOARD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_DEVICE_KEYBOARD, MetaDeviceKeyboard))
+#define META_DEVICE_KEYBOARD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), META_TYPE_DEVICE_KEYBOARD, MetaDeviceKeyboardClass))
+#define META_IS_DEVICE_KEYBOARD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), META_TYPE_DEVICE_KEYBOARD))
+#define META_IS_DEVICE_KEYBOARD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), META_TYPE_DEVICE_KEYBOARD))
+#define META_DEVICE_KEYBOARD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), META_TYPE_DEVICE_KEYBOARD, MetaDeviceKeyboardClass))
+
+typedef struct _MetaDeviceKeyboard MetaDeviceKeyboard;
+typedef struct _MetaDeviceKeyboardClass MetaDeviceKeyboardClass;
+
+struct _MetaDeviceKeyboard
+{
+ MetaDevice parent_instance;
+};
+
+struct _MetaDeviceKeyboardClass
+{
+ MetaDeviceClass parent_instance;
+};
+
+GType meta_device_keyboard_get_type (void) G_GNUC_CONST;
+
+
+#endif /* META_DEVICE_KEYBOARD_H */
diff --git a/src/core/device-pointer.c b/src/core/device-pointer.c
new file mode 100644
index 0000000..cd78229
--- /dev/null
+++ b/src/core/device-pointer.c
@@ -0,0 +1,121 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+
+/* Pointer device abstraction */
+
+/*
+ * 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 "device-pointer.h"
+
+G_DEFINE_ABSTRACT_TYPE (MetaDevicePointer,
+ meta_device_pointer,
+ META_TYPE_DEVICE)
+
+static void
+meta_device_pointer_class_init (MetaDevicePointerClass *klass)
+{
+}
+
+static void
+meta_device_pointer_init (MetaDevicePointer *pointer)
+{
+}
+
+void
+meta_device_pointer_warp (MetaDevicePointer *pointer,
+ MetaScreen *screen,
+ gint x,
+ gint y)
+{
+ MetaDevicePointerClass *klass;
+
+ g_return_if_fail (META_IS_DEVICE_POINTER (pointer));
+ g_return_if_fail (META_IS_SCREEN (screen));
+
+ klass = META_DEVICE_POINTER_GET_CLASS (pointer);
+
+ if (klass->warp)
+ (klass->warp) (pointer, screen, x, y);
+}
+
+void
+meta_device_pointer_set_window_cursor (MetaDevicePointer *pointer,
+ Window xwindow,
+ MetaCursor cursor)
+{
+ MetaDevicePointerClass *klass;
+
+ g_return_if_fail (META_IS_DEVICE_POINTER (pointer));
+ g_return_if_fail (xwindow != None);
+
+ klass = META_DEVICE_POINTER_GET_CLASS (pointer);
+
+ if (klass->set_window_cursor)
+ (klass->set_window_cursor) (pointer, xwindow, cursor);
+}
+
+void
+meta_device_pointer_query_position (MetaDevicePointer *pointer,
+ Window xwindow,
+ Window *root_ret,
+ Window *child_ret,
+ gint *root_x_ret,
+ gint *root_y_ret,
+ gint *x_ret,
+ gint *y_ret,
+ guint *mask_ret)
+{
+ MetaDevicePointerClass *klass;
+ gint root_x, root_y, x, y;
+ Window root, child;
+ guint mask;
+
+ g_return_if_fail (META_IS_DEVICE_POINTER (pointer));
+ g_return_if_fail (xwindow != None);
+
+ klass = META_DEVICE_POINTER_GET_CLASS (pointer);
+
+ if (!klass->query_position)
+ return;
+
+ (klass->query_position) (pointer, xwindow, &root, &child,
+ &root_x, &root_y, &x, &y, &mask);
+
+ if (root_ret)
+ *root_ret = root;
+
+ if (child_ret)
+ *child_ret = child;
+
+ if (root_x_ret)
+ *root_x_ret = root_x;
+
+ if (root_y_ret)
+ *root_y_ret = root_y;
+
+ if (x_ret)
+ *x_ret = x;
+
+ if (y_ret)
+ *y_ret = y;
+
+ if (mask_ret)
+ *mask_ret = mask;
+}
diff --git a/src/core/device-pointer.h b/src/core/device-pointer.h
new file mode 100644
index 0000000..e0e439f
--- /dev/null
+++ b/src/core/device-pointer.h
@@ -0,0 +1,95 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+
+/**
+ * \file device-pointer.h Pointer device abstraction
+ *
+ * Input devices.
+ * This file contains the internal abstraction of pointer devices so
+ * XInput2/core events can be handled similarly.
+ */
+
+/*
+ * 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_DEVICE_POINTER_H
+#define META_DEVICE_POINTER_H
+
+#include "display-private.h"
+#include <meta/screen.h>
+#include "device.h"
+
+#define META_TYPE_DEVICE_POINTER (meta_device_pointer_get_type ())
+#define META_DEVICE_POINTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_DEVICE_POINTER, MetaDevicePointer))
+#define META_DEVICE_POINTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), META_TYPE_DEVICE_POINTER, MetaDevicePointerClass))
+#define META_IS_DEVICE_POINTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), META_TYPE_DEVICE_POINTER))
+#define META_IS_DEVICE_POINTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), META_TYPE_DEVICE_POINTER))
+#define META_DEVICE_POINTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), META_TYPE_DEVICE_POINTER, MetaDevicePointerClass))
+
+typedef struct _MetaDevicePointer MetaDevicePointer;
+typedef struct _MetaDevicePointerClass MetaDevicePointerClass;
+
+struct _MetaDevicePointer
+{
+ MetaDevice parent_instance;
+};
+
+struct _MetaDevicePointerClass
+{
+ MetaDeviceClass parent_instance;
+
+ void (* warp) (MetaDevicePointer *pointer,
+ MetaScreen *screen,
+ gint x,
+ gint y);
+
+ void (* set_window_cursor) (MetaDevicePointer *pointer,
+ Window xwindow,
+ MetaCursor cursor);
+ void (* query_position) (MetaDevicePointer *pointer,
+ Window xwindow,
+ Window *root,
+ Window *child,
+ gint *root_x,
+ gint *root_y,
+ gint *x,
+ gint *y,
+ guint *mask);
+};
+
+GType meta_device_pointer_get_type (void) G_GNUC_CONST;
+
+void meta_device_pointer_warp (MetaDevicePointer *pointer,
+ MetaScreen *screen,
+ gint x,
+ gint y);
+void meta_device_pointer_set_window_cursor (MetaDevicePointer *pointer,
+ Window xwindow,
+ MetaCursor cursor);
+
+void meta_device_pointer_query_position (MetaDevicePointer *pointer,
+ Window xwindow,
+ Window *root,
+ Window *child,
+ gint *root_x,
+ gint *root_y,
+ gint *x,
+ gint *y,
+ guint *mask);
+
+#endif /* META_DEVICE_POINTER_H */
diff --git a/src/core/device.c b/src/core/device.c
new file mode 100644
index 0000000..7a6dbb0
--- /dev/null
+++ b/src/core/device.c
@@ -0,0 +1,195 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+
+/* Input device abstraction */
+
+/*
+ * 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 "device.h"
+
+G_DEFINE_ABSTRACT_TYPE (MetaDevice, meta_device, G_TYPE_OBJECT)
+
+enum {
+ PROP_0,
+ PROP_DEVICE_ID,
+ PROP_DISPLAY
+};
+
+typedef struct MetaDevicePrivate MetaDevicePrivate;
+
+struct MetaDevicePrivate
+{
+ MetaDisplay *display;
+ gint device_id;
+};
+
+static void
+meta_device_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ switch (param_id)
+ {
+ case PROP_DEVICE_ID:
+ g_value_set_int (value,
+ meta_device_get_id (META_DEVICE (object)));
+ break;
+ case PROP_DISPLAY:
+ g_value_set_object (value,
+ meta_device_get_display (META_DEVICE (object)));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ }
+}
+
+static void
+meta_device_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ MetaDevicePrivate *priv = META_DEVICE (object)->priv;
+
+ switch (param_id)
+ {
+ case PROP_DEVICE_ID:
+ priv->device_id = g_value_get_int (value);
+ break;
+ case PROP_DISPLAY:
+ priv->display = g_value_get_object (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ }
+}
+
+static void
+meta_device_class_init (MetaDeviceClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->get_property = meta_device_get_property;
+ object_class->set_property = meta_device_set_property;
+
+ g_object_class_install_property (object_class,
+ PROP_DEVICE_ID,
+ g_param_spec_int ("device-id",
+ "Device ID",
+ "Device ID",
+ 2, G_MAXINT, 2,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property (object_class,
+ PROP_DISPLAY,
+ g_param_spec_object ("display",
+ "Display",
+ "Display",
+ META_TYPE_DISPLAY,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY));
+
+ g_type_class_add_private (klass, sizeof (MetaDevicePrivate));
+}
+
+static void
+meta_device_init (MetaDevice *device)
+{
+ device->priv = G_TYPE_INSTANCE_GET_PRIVATE (device,
+ META_TYPE_DEVICE,
+ MetaDevicePrivate);
+}
+
+int
+meta_device_get_id (MetaDevice *device)
+{
+ MetaDevicePrivate *priv;
+
+ g_return_val_if_fail (META_IS_DEVICE (device), 0);
+
+ priv = device->priv;
+ return priv->device_id;
+}
+
+MetaDisplay *
+meta_device_get_display (MetaDevice *device)
+{
+ MetaDevicePrivate *priv;
+
+ g_return_val_if_fail (META_IS_DEVICE (device), NULL);
+
+ priv = device->priv;
+ return priv->display;
+}
+
+void
+meta_device_allow_events (MetaDevice *device,
+ int mode,
+ Time time)
+{
+ MetaDeviceClass *klass;
+
+ g_return_if_fail (META_IS_DEVICE (device));
+
+ klass = META_DEVICE_GET_CLASS (device);
+
+ if (klass->allow_events)
+ (klass->allow_events) (device, mode, time);
+}
+
+gboolean
+meta_device_grab (MetaDevice *device,
+ Window xwindow,
+ guint evmask,
+ MetaCursor cursor,
+ gboolean owner_events,
+ gboolean sync,
+ Time time)
+{
+ MetaDeviceClass *klass;
+
+ g_return_val_if_fail (META_IS_DEVICE (device), FALSE);
+ g_return_val_if_fail (xwindow != None, FALSE);
+
+ klass = META_DEVICE_GET_CLASS (device);
+
+ if (!klass->grab)
+ return FALSE;
+
+ return (klass->grab) (device, xwindow, evmask, cursor,
+ owner_events, sync, time);
+}
+
+void
+meta_device_ungrab (MetaDevice *device,
+ Time time)
+{
+ MetaDeviceClass *klass;
+
+ g_return_if_fail (META_IS_DEVICE (device));
+
+ klass = META_DEVICE_GET_CLASS (device);
+
+ if (klass->ungrab)
+ (klass->ungrab) (device, time);
+}
diff --git a/src/core/device.h b/src/core/device.h
new file mode 100644
index 0000000..45f8c67
--- /dev/null
+++ b/src/core/device.h
@@ -0,0 +1,89 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+
+/**
+ * \file device.h Input device abstraction
+ *
+ * Input devices.
+ * This file contains the internal abstraction of input devices so
+ * XInput2/core events can be handled similarly.
+ */
+
+/*
+ * 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_DEVICE_H
+#define META_DEVICE_H
+
+typedef struct _MetaDevice MetaDevice;
+typedef struct _MetaDeviceClass MetaDeviceClass;
+
+#include "display-private.h"
+
+#define META_TYPE_DEVICE (meta_device_get_type ())
+#define META_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_DEVICE, MetaDevice))
+#define META_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), META_TYPE_DEVICE, MetaDeviceClass))
+#define META_IS_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), META_TYPE_DEVICE))
+#define META_IS_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), META_TYPE_DEVICE))
+#define META_DEVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), META_TYPE_DEVICE, MetaDeviceClass))
+
+struct _MetaDevice
+{
+ GObject parent_instance;
+ gpointer priv;
+};
+
+struct _MetaDeviceClass
+{
+ GObjectClass parent_instance;
+
+ void (* allow_events) (MetaDevice *device,
+ int mode,
+ Time time);
+
+ gboolean (* grab) (MetaDevice *device,
+ Window xwindow,
+ guint evmask,
+ MetaCursor cursor,
+ gboolean owner_events,
+ gboolean sync,
+ Time time);
+ void (* ungrab) (MetaDevice *device,
+ Time time);
+};
+
+GType meta_device_get_type (void) G_GNUC_CONST;
+
+int meta_device_get_id (MetaDevice *device);
+MetaDisplay *meta_device_get_display (MetaDevice *device);
+
+void meta_device_allow_events (MetaDevice *device,
+ int mode,
+ Time time);
+
+gboolean meta_device_grab (MetaDevice *device,
+ Window xwindow,
+ guint evmask,
+ MetaCursor cursor,
+ gboolean owner_events,
+ gboolean sync,
+ Time time);
+void meta_device_ungrab (MetaDevice *device,
+ Time time);
+
+#endif /* META_DEVICE_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]