gpointing-device-settings r89 - in trunk: src test



Author: hiikezoe
Date: Mon Mar  2 04:20:52 2009
New Revision: 89
URL: http://svn.gnome.org/viewvc/gpointing-device-settings?rev=89&view=rev

Log:
Added gpds_xinput_set_int_properties.
gpds_xinput_set_property will be obsoleted.

Modified:
   trunk/src/gpds-xinput.c
   trunk/src/gpds-xinput.h
   trunk/test/test-xinput.c

Modified: trunk/src/gpds-xinput.c
==============================================================================
--- trunk/src/gpds-xinput.c	(original)
+++ trunk/src/gpds-xinput.c	Mon Mar  2 04:20:52 2009
@@ -313,6 +313,65 @@
     return success;
 }
 
+gboolean
+gpds_xinput_set_int_properties (GpdsXInput *xinput,
+                                const gchar *property_name,
+                                gint format_type,
+                                GError **error,
+                                gint *properties,
+                                guint n_properties)
+{
+    XDevice *device;
+    Atom property_atom;
+    gint i;
+    gchar *property_data;
+
+    device = get_device(xinput, error);
+    if (!device)
+        return FALSE;
+
+    property_atom = XInternAtom(GDK_DISPLAY(), property_name, False);
+
+    switch (format_type) {
+    case 8:
+        property_data = (gchar*)g_new(int8_t*, n_properties);
+        break;
+    case 16:
+        property_data = (gchar*)g_new(int16_t*, n_properties);
+        break;
+    case 32:
+    default:
+        property_data = (gchar*)g_new(int32_t*, n_properties);
+        break;
+    }
+
+    for (i = 0; i < n_properties; i++) {
+        switch (format_type) {
+        case 8:
+            *(((int8_t*)property_data) + i) = properties[i];
+            break;
+        case 16:
+            *(((int16_t*)property_data) + i) = properties[i];
+            break;
+        case 32:
+        default:
+            *(((int32_t*)property_data) + i) = properties[i];
+            break;
+        }
+    }
+
+    gdk_error_trap_push();
+    XChangeDeviceProperty(GDK_DISPLAY(),
+                          device, property_atom,
+                          XA_INTEGER, format_type, PropModeReplace,
+                          (unsigned char*)property_data, n_properties);
+    gdk_error_trap_pop();
+
+    g_free(property_data);
+
+    return TRUE;
+}
+
 static Atom
 get_atom (GpdsXInput *xinput, const gchar *property_name, GError **error)
 {

Modified: trunk/src/gpds-xinput.h
==============================================================================
--- trunk/src/gpds-xinput.h	(original)
+++ trunk/src/gpds-xinput.h	Mon Mar  2 04:20:52 2009
@@ -52,25 +52,28 @@
     GObjectClass parent_class;
 };
 
-GQuark       gpds_xinput_error_quark     (void);
-
-GType        gpds_xinput_get_type        (void) G_GNUC_CONST;
-
-gboolean     gpds_xinput_exist_device    (const gchar *device_name);
-
-GpdsXInput  *gpds_xinput_new             (const gchar *device_name);
-
-gboolean     gpds_xinput_set_property    (GpdsXInput *xinput,
-                                          const gchar *property_name,
-                                          gint format_type,
-                                          GError **error,
-                                          gint first_property_value,
-                                          ...) G_GNUC_NULL_TERMINATED;
-gboolean     gpds_xinput_get_property    (GpdsXInput *xinput,
-                                          const gchar *property_name,
-                                          GError **error,
-                                          gint **values,
-                                          gulong *n_values);
+GQuark      gpds_xinput_error_quark        (void);
+GType       gpds_xinput_get_type           (void) G_GNUC_CONST;
+gboolean    gpds_xinput_exist_device       (const gchar *device_name);
+
+GpdsXInput *gpds_xinput_new                (const gchar *device_name);
+gboolean    gpds_xinput_set_property       (GpdsXInput *xinput,
+                                            const gchar *property_name,
+                                            gint format_type,
+                                            GError **error,
+                                            gint first_property_value,
+                                            ...) G_GNUC_NULL_TERMINATED;
+gboolean    gpds_xinput_set_int_properties (GpdsXInput *xinput,
+                                            const gchar *property_name,
+                                            gint format_type,
+                                            GError **error,
+                                            gint *properties,
+                                            guint n_properties);
+gboolean    gpds_xinput_get_property       (GpdsXInput *xinput,
+                                            const gchar *property_name,
+                                            GError **error,
+                                            gint **values,
+                                            gulong *n_values);
 
 G_END_DECLS
 

Modified: trunk/test/test-xinput.c
==============================================================================
--- trunk/test/test-xinput.c	(original)
+++ trunk/test/test-xinput.c	Mon Mar  2 04:20:52 2009
@@ -4,6 +4,7 @@
 
 void test_new (void);
 void test_property (void);
+void test_set_int_properties (void);
 
 static GpdsXInput *xinput;
 static gint *values;
@@ -81,6 +82,27 @@
     cut_assert_equal_int(original_value, values[0]);
 }
 
+void
+test_set_int_properties (void)
+{
+    cut_trace(test_new());
+
+    cut_assert_true(gpds_xinput_get_property(xinput,
+                                             "Evdev Middle Button Emulation",
+                                             &error,
+                                             &values, &n_values));
+    gcut_assert_error(error);
+    cut_assert_equal_int(1, n_values);
+
+    cut_assert_true(gpds_xinput_set_int_properties(xinput,
+                                                   "Evdev Middle Button Emulation",
+                                                   8,
+                                                   &error,
+                                                   (gint*)&values,
+                                                   n_values));
+    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]