[gpointing-device-settings] add functions to handle button map.



commit 33f8135d6a3abf7e08d8cd7b292743b126bc1454
Author: Hiroyuki Ikezoe <poincare ikezoe net>
Date:   Sat Jan 9 09:29:31 2010 +0900

    add functions to handle button map.

 src/gpds-xinput.c  |   66 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/gpds-xinput.h  |    9 ++++++-
 test/test-xinput.c |   30 +++++++++++++++++++++++
 3 files changed, 104 insertions(+), 1 deletions(-)
---
diff --git a/src/gpds-xinput.c b/src/gpds-xinput.c
index 6ad2f92..8e5af89 100644
--- a/src/gpds-xinput.c
+++ b/src/gpds-xinput.c
@@ -652,6 +652,72 @@ gpds_xinput_get_float_properties (GpdsXInput *xinput,
                                                     n_values);
 }
 
+gboolean
+gpds_xinput_get_button_map (GpdsXInput *xinput,
+                            GError **error,
+                            guchar **map,
+                            gshort *n_buttons)
+{
+    XDevice *device;
+    gint x_error_code;
+    Status status;
+    GpdsXInputPriv *priv;
+
+    g_return_val_if_fail(GPDS_IS_XINPUT(xinput), FALSE);
+
+    device = get_device(xinput, error);
+    if (!device)
+        return FALSE;
+
+    priv = GPDS_XINPUT_GET_PRIVATE(xinput);
+    *n_buttons = gpds_xinput_utils_get_device_num_buttons (priv->device_name, error);
+    if (*n_buttons < 0)
+        return FALSE;
+
+    *map = g_new0(guchar, *n_buttons);
+
+    gdk_error_trap_push();
+    status =  XGetDeviceButtonMapping(GDK_DISPLAY(), device, *map, *n_buttons);
+    gdk_flush();
+
+    x_error_code = gdk_error_trap_pop();
+    if (status != Success || x_error_code != 0) {
+        set_x_error(error, x_error_code);
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+gboolean
+gpds_xinput_set_button_map (GpdsXInput *xinput,
+                            GError **error,
+                            guchar *map,
+                            gshort n_buttons)
+{
+    XDevice *device;
+    gint x_error_code;
+    Status status;
+
+    g_return_val_if_fail(GPDS_IS_XINPUT(xinput), FALSE);
+
+    device = get_device(xinput, error);
+    if (!device)
+        return FALSE;
+
+    gdk_error_trap_push();
+    status =  XSetDeviceButtonMapping(GDK_DISPLAY(), device, map, n_buttons);
+    gdk_flush();
+
+    x_error_code = gdk_error_trap_pop();
+    if (status != Success || x_error_code != 0) {
+        set_x_error(error, x_error_code);
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
 void
 gpds_xinput_register_property_entries (GpdsXInput *xinput,
                                        const GpdsXInputPropertyEntry *entries,
diff --git a/src/gpds-xinput.h b/src/gpds-xinput.h
index 2260977..a2a2276 100644
--- a/src/gpds-xinput.h
+++ b/src/gpds-xinput.h
@@ -118,7 +118,14 @@ gboolean     gpds_xinput_get_float_properties_by_name
                                                GError **error,
                                                gdouble **properties,
                                                gulong *n_properties);
-
+gboolean     gpds_xinput_get_button_map       (GpdsXInput *xinput,
+                                               GError **error,
+                                               guchar **map,
+                                               gshort *n_buttons);
+gboolean     gpds_xinput_set_button_map       (GpdsXInput *xinput,
+                                               GError **error,
+                                               guchar *map,
+                                               gshort n_buttons);
 
 G_END_DECLS
 
diff --git a/test/test-xinput.c b/test/test-xinput.c
index 757e9c3..4e523e2 100644
--- a/test/test-xinput.c
+++ b/test/test-xinput.c
@@ -13,11 +13,15 @@ void test_set_int_properties_invalid_n_values (void);
 void test_set_int_properties_invalid_property_enum (void);
 void test_set_float_properties_fail (void);
 void test_get_float_properties_fail (void);
+void test_set_button_map (void);
+void test_get_button_map (void);
 
 static GpdsXInput *xinput;
 static GpdsXInput *tmp_xinput;
 static gint *values;
 static gulong n_values;
+static guchar *actual_map;
+static gshort actual_n_buttons;
 static GError *error;
 static GError *expected_error;
 static gboolean middle_button_emulation;
@@ -92,6 +96,7 @@ setup (void)
     tmp_xinput = NULL;
     values = NULL;
     n_values = 0;
+    actual_map = NULL;
 
     error = NULL;
     expected_error = NULL;
@@ -107,6 +112,7 @@ teardown (void)
     if (tmp_xinput)
         g_object_unref(tmp_xinput);
     g_free(values);
+    g_free(actual_map);
 
     if (expected_error)
         g_clear_error(&expected_error);
@@ -281,6 +287,30 @@ test_set_int_properties_invalid_n_values (void)
     gcut_assert_equal_error(expected_error, error);
 }
 
+void
+test_get_button_map (void)
+{
+    const guchar expected_map[5] = { 1, 2, 3, 4, 5 };
+    cut_trace(test_new());
+
+    gpds_xinput_get_button_map (xinput, &error, &actual_map, &actual_n_buttons);
+    gcut_assert_error(error);
+
+    cut_assert_equal_int(5, actual_n_buttons);
+    cut_assert_equal_memory(expected_map, sizeof(expected_map),
+                            actual_map, actual_n_buttons);
+}
+
+void
+test_set_button_map (void)
+{
+    test_get_button_map();
+
+    gpds_xinput_set_button_map (xinput, &error, actual_map, actual_n_buttons);
+    gcut_assert_error(error);
+
+}
+
 /*
 vi:ts=4:nowrap:ai:expandtab:sw=4
 */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]