gpointing-device-settings r2 - in trunk: . data po src test



Author: hiikezoe
Date: Tue Feb 24 11:51:35 2009
New Revision: 2
URL: http://svn.gnome.org/viewvc/gpointing-device-settings?rev=2&view=rev

Log:
Initial import.



Added:
   trunk/MAINTAINERS
   trunk/Makefile.am
   trunk/TODO
   trunk/autogen.sh   (contents, props changed)
   trunk/configure.ac
   trunk/data/
   trunk/data/Makefile.am
   trunk/data/gtrackpoint.ui
   trunk/po/
   trunk/po/POTFILES.in
   trunk/src/
   trunk/src/Makefile.am
   trunk/src/gpointing-device-settings.c
   trunk/src/gpointing-device-settings.h
   trunk/src/gtrackpoint-ui.c
   trunk/src/gtrackpoint-ui.h
   trunk/src/gxinput.c
   trunk/src/gxinput.h
   trunk/test/
   trunk/test/Makefile.am
   trunk/test/gpointing-device-settings-test-suite.c
   trunk/test/run-test.sh   (contents, props changed)
   trunk/test/test-xinput.c

Added: trunk/MAINTAINERS
==============================================================================
--- (empty file)
+++ trunk/MAINTAINERS	Tue Feb 24 11:51:35 2009
@@ -0,0 +1,3 @@
+Hiroyuki Ikezoe
+E-mail: poincare ikezoe net
+Userid: hiikezoe

Added: trunk/Makefile.am
==============================================================================
--- (empty file)
+++ trunk/Makefile.am	Tue Feb 24 11:51:35 2009
@@ -0,0 +1,9 @@
+# -*- Mode: Makefile; tab-width: 8; indent-tabs-mode: t; -*-
+
+SUBDIRS = src data test po
+
+ACLOCAL_AMFLAGS = -I m4
+
+EXTRA_DIST = 		\
+	MAINTAINERS	\
+	autogen.sh

Added: trunk/TODO
==============================================================================
--- (empty file)
+++ trunk/TODO	Tue Feb 24 11:51:35 2009
@@ -0,0 +1 @@
+* merge GSynaptics

Added: trunk/autogen.sh
==============================================================================
--- (empty file)
+++ trunk/autogen.sh	Tue Feb 24 11:51:35 2009
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+srcdir=`dirname $0`
+test -z "$srcdir" && srcdir=.
+
+run()
+{
+    $@
+    if test $? -ne 0; then
+	echo "Failed $@"
+	exit 1
+    fi
+}
+
+run ${ACLOCAL:-aclocal} $ACLOCAL_OPTIONS
+run ${LIBTOOLIZE:-libtoolize} --copy --force
+run ${INTLTOOLIZE:-intltoolize} --force --copy
+run ${AUTOHEADER:-autoheader}
+run ${AUTOMAKE:-automake} --add-missing --foreign --copy
+run ${AUTOCONF:-autoconf}

Added: trunk/configure.ac
==============================================================================
--- (empty file)
+++ trunk/configure.ac	Tue Feb 24 11:51:35 2009
@@ -0,0 +1,106 @@
+dnl Process this file with autoconf to produce a configure script.
+AC_PREREQ(2.57)
+
+AC_INIT(gpointing-device-settings, 0.9.0)
+AM_INIT_AUTOMAKE(1.6)
+AM_CONFIG_HEADER(config.h)
+AC_CONFIG_MACRO_DIR([m4])
+
+AM_PROG_LIBTOOL
+
+AC_PATH_PROG([PKG_CONFIG], [pkg-config], [no])
+
+AC_PROG_CC
+AC_PROG_CPP
+AC_PROG_INSTALL
+AC_PROG_MAKE_SET
+AC_PROG_INTLTOOL([0.35.0])
+AM_GLIB_GNU_GETTEXT
+
+GETTEXT_PACKAGE=gpointing-device-settings
+AC_SUBST(GETTEXT_PACKAGE)
+AC_DEFINE_UNQUOTED([GETTEXT_PACKAGE], ["$GETTEXT_PACKAGE"], [Gettext package])
+
+if test "x$GCC" = "xyes"; then
+  case " $CFLAGS " in
+  *[\ \	]-Wall[\ \	]*) ;;
+  *) CFLAGS="$CFLAGS -Wall" ;;
+  esac
+
+  case " $CFLAGS " in
+  *[\ \	]-Wmissing-declarations[\ \	]*) ;;
+  *) CFLAGS="$CFLAGS -Wmissing-declarations" ;;
+  esac
+
+  case " $CFLAGS " in
+  *[\ \	]-Wmissing-prototypes[\ \	]*) ;;
+  *) CFLAGS="$CFLAGS -Wmissing-prototypes" ;;
+  esac
+
+  case " $CFLAGS " in
+  *[\ \	]-Wpointer-arith[\ \	]*) ;;
+  *) CFLAGS="$CFLAGS -Wpointer-arith" ;;
+  esac
+
+  case " $CFLAGS " in
+  *[\ \	]-Wcast-align[\ \	]*) ;;
+  *) CFLAGS="$CFLAGS -Wcast-align" ;;
+  esac
+
+  if test "x$enable_ansi" = "xyes"; then
+    case " $CFLAGS " in
+    *[\ \	]-ansi[\ \	]*) ;;
+    *) CFLAGS="$CFLAGS -ansi" ;;
+    esac
+
+    case " $CFLAGS " in
+    *[\ \	]-pedantic[\ \	]*) ;;
+    *) CFLAGS="$CFLAGS -pedantic" ;;
+    esac
+  fi
+fi
+
+GTK_REQUIRED=2.14.0
+AC_SUBST(GTK_REQUIRED)
+AM_PATH_GTK_2_0($GTK_REQUIRED)
+AC_PATH_PROG(GLIB_GENMARSHAL, glib-genmarshal)
+AC_PATH_PROG(GLIB_MKENUMS, glib-mkenums)
+
+PKG_CHECK_MODULES(XINPUT, inputproto >= 1.4)
+AC_SUBST(XINPUT_CFLAGS)
+AC_SUBST(XINPUT_LIBS)
+
+dnl **************************************************************
+dnl Checks for typedefs, structures, and compiler characteristics.
+dnl **************************************************************
+AC_C_CONST
+
+dnl **************************************************************
+dnl Check for Cutter
+dnl **************************************************************
+m4_ifdef([AC_CHECK_GCUTTER], [
+AC_CHECK_GCUTTER(>= 1.0.6)
+],
+[ac_cv_use_cutter="no"])
+
+AM_CONDITIONAL([WITH_CUTTER], [test "$ac_cv_use_cutter" != "no"])
+if test "$ac_cv_use_cutter" != "no"; then
+  AC_DEFINE(WITH_CUTTER, 1, [Define to 1 if you use Cutter])
+fi
+
+m4_ifdef([AC_CHECK_COVERAGE], [AC_CHECK_COVERAGE])
+GENHTML_OPTIONS="--title 'GPointingDeviceSettings Code Coverage'"
+
+AC_SUBST([AM_CPPFLAGS])
+AC_SUBST([AM_CFLAGS])
+AC_SUBST([AM_LDFLAGS])
+
+AC_CONFIG_FILES([
+Makefile
+src/Makefile
+data/Makefile
+test/Makefile
+po/Makefile.in
+])
+
+AC_OUTPUT

Added: trunk/data/Makefile.am
==============================================================================
--- (empty file)
+++ trunk/data/Makefile.am	Tue Feb 24 11:51:35 2009
@@ -0,0 +1,4 @@
+uidir   = $(datadir)/$(PACKAGE)
+ui_DATA = gtrackpoint.ui
+
+EXTRA_DIST = $(ui_DATA)

Added: trunk/data/gtrackpoint.ui
==============================================================================
--- (empty file)
+++ trunk/data/gtrackpoint.ui	Tue Feb 24 11:51:35 2009
@@ -0,0 +1,99 @@
+<?xml version="1.0" standalone="no"?>
+<interface>
+  <object class="GtkLabel" id ="main-widget-label">
+    <property name="visible">True</property>
+    <property name="label" translatable="yes">TrackPoint</property>
+  </object>
+  <object class="GtkVBox" id="main-widget">
+    <property name="visible">True</property>
+    <child>
+      <object class="GtkCheckButton" id="middle_button_emulation">
+        <property name="visible">True</property>
+        <property name="label" translatable="yes">Use middle button emulation</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkHBox" id="middle_button_emulation_box">
+      <property name="visible">True</property>
+      <property name="border-width">5</property>
+      <child>
+        <object class="GtkLabel" id="middle_button_timeout_label">
+          <property name="visible">True</property>
+          <property name="label" translatable="yes">Middle button timeout</property>
+        </object>
+      </child>
+      <child>
+        <object class="GtkAdjustment" id="middle_button_timeout_adjustment">
+          <property name="lower">100</property>
+          <property name="upper">10000</property>
+          <property name="step-increment">50</property>
+        </object>
+        <object class="GtkSpinButton" id="middle_button_timeout">
+          <property name="numeric">True</property>
+          <property name="visible">True</property>
+          <property name="adjustment">middle_button_timeout_adjustment</property>
+        </object>
+      </child>
+      <child>
+        <object class="GtkLabel" id="middle_button_timeout_unit">
+          <property name="visible">True</property>
+          <property name="label" translatable="yes">(ms)</property>
+        </object>
+      </child>
+      </object>
+    </child>
+    <child>
+      <object class="GtkCheckButton" id="wheel_emulation">
+        <property name="visible">True</property>
+        <property name="label" translatable="yes">Use wheel emulation</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkVBox" id="wheel_emulation_box">
+      <property name="visible">True</property>
+      <property name="border-width">5</property>
+      <child>
+        <object class="GtkHBox" id="hbox2">
+        <property name="visible">True</property>
+        <child>
+          <object class="GtkLabel" id="wheel_emulation_timeout_label">
+            <property name="visible">True</property>
+            <property name="label" translatable="yes">Wheel emulation timeout</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkAdjustment" id="wheel_emulation_timeout_adjustment">
+            <property name="lower">100</property>
+            <property name="upper">10000</property>
+            <property name="step-increment">50</property>
+          </object>
+          <object class="GtkSpinButton" id="wheel_emulation_timeout">
+            <property name="numeric">True</property>
+            <property name="visible">True</property>
+            <property name="adjustment">wheel_emulation_timeout_adjustment</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel" id="wheel_emulation_timeout_unit">
+            <property name="visible">True</property>
+            <property name="label" translatable="yes">(ms)</property>
+          </object>
+        </child>
+        </object>
+      </child>
+      <child>
+        <object class="GtkCheckButton" id="wheel_emulation_vertical">
+          <property name="visible">True</property>
+          <property name="label" translatable="yes">Enable vertical scroll</property>
+        </object>
+      </child>
+      <child>
+        <object class="GtkCheckButton" id="wheel_emulation_horizontal">
+          <property name="visible">True</property>
+          <property name="label" translatable="yes">Enable horizontal scroll</property>
+        </object>
+      </child>
+      </object>
+    </child>
+  </object>
+</interface>

Added: trunk/po/POTFILES.in
==============================================================================
--- (empty file)
+++ trunk/po/POTFILES.in	Tue Feb 24 11:51:35 2009
@@ -0,0 +1,2 @@
+src/gxinput.c
+[type: gettext/glade]data/gtrackpoint.ui

Added: trunk/src/Makefile.am
==============================================================================
--- (empty file)
+++ trunk/src/Makefile.am	Tue Feb 24 11:51:35 2009
@@ -0,0 +1,18 @@
+bin_PROGRAMS = gpointing-device-settings
+
+g_pointing-device-settings_CFLAGS =		\
+	-DDATADIR=\""$(datadir)/$(PACKAGE)"\" 	\
+	-DHELPDATADIR=\""$(datadir)"\"	 	\
+	$(XINPUT_CFLAGS)			\
+	$(GTK_CFLAGS)
+
+gpointing-device-settings_SOURCES =	\
+	gpointing-device-settings.c	\
+	gtrackpoint-ui.c		\
+	gtrackpoint-ui.h		\
+	gxinput.c			\
+	gxinput.h
+
+gpointing-device-settings_LDADD =	\
+	$(GTK_LIBS)	\
+	$(XINPUT_LIBS)

Added: trunk/src/gpointing-device-settings.c
==============================================================================
--- (empty file)
+++ trunk/src/gpointing-device-settings.c	Tue Feb 24 11:51:35 2009
@@ -0,0 +1,77 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ *  Copyright (C) 2009 Hiroyuki Ikezoe  <poincare ikezoe net>
+ *
+ *  This library is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This library 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 Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+#include "gpointin-device-settings.h"
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include "gtrackpoint-ui.h"
+#include "gxinput.h"
+
+static void
+cb_response (GtkDialog *dialog, gint response_id, gpointer user_data)
+{
+    gtk_main_quit();
+}
+
+int
+main (int argc, char *argv[])
+{
+    GTrackPointUI *ui;
+    GtkWidget *dialog, *notebook, *content_area;
+    GtkWidget *widget;
+
+    gtk_init(&argc, &argv);
+
+    dialog = gtk_dialog_new_with_buttons(_("TrackPoint Settings"),
+                                         NULL,
+                                         0, 
+                                         GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
+                                         NULL);
+    g_signal_connect(dialog, "response",
+                     G_CALLBACK(cb_response), NULL);
+
+    notebook = gtk_notebook_new();
+    content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
+    gtk_container_add(GTK_CONTAINER(content_area),
+                      notebook);
+
+    ui = g_track_point_ui_new();
+    widget = g_track_point_ui_get_widget(ui);
+    if (!widget)
+        widget = gtk_label_new(_("No device availlable"));
+
+    gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
+                             widget, NULL);
+
+    gtk_widget_show_all(dialog);
+    gtk_main();
+
+    g_object_unref(ui);
+
+    return 0;
+}
+
+/*
+vi:ts=4:nowrap:ai:expandtab:sw=4
+*/

Added: trunk/src/gpointing-device-settings.h
==============================================================================
--- (empty file)
+++ trunk/src/gpointing-device-settings.h	Tue Feb 24 11:51:35 2009
@@ -0,0 +1,33 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ *  Copyright (C) 2009 Hiroyuki Ikezoe  <poincare ikezoe net>
+ *
+ *  This library is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This library 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 Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef __GTRACKPOINT_H__
+#define __GTRACKPOINT_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+
+G_END_DECLS
+
+#endif /* __GTRACKPOINT_H__ */
+/*
+vi:ts=4:nowrap:ai:expandtab:sw=4
+*/

Added: trunk/src/gtrackpoint-ui.c
==============================================================================
--- (empty file)
+++ trunk/src/gtrackpoint-ui.c	Tue Feb 24 11:51:35 2009
@@ -0,0 +1,410 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ *  Copyright (C) 2009 Hiroyuki Ikezoe  <poincare ikezoe net>
+ *
+ *  This library is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This library 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 Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+#include "gtrackpoint-ui.h"
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include "gxinput.h"
+
+#define DEVICE_NAME "TPPS/2 IBM TrackPoint"
+#define MIDDLE_BUTTON_EMULATION "Middle Button Emulation"
+#define MIDDLE_BUTTON_TIMEOUT "Middle Button Timeout"
+#define WHEEL_EMULATION "Wheel Emulation"
+#define WHEEL_EMULATION_INERTIA "Wheel Emulation Inertia"
+#define WHEEL_EMULATION_X_AXIS "Wheel Emulation X Axis"
+#define WHEEL_EMULATION_Y_AXIS "Wheel Emulation Y Axis"
+#define WHEEL_EMULATION_TIMEOUT "Wheel Emulation Timeout"
+#define WHEEL_EMULATION_BUTTON "Wheel Emulation Button"
+#define DRAG_LOCK_BUTTONS "Drag Lock Buttons"
+
+typedef struct _GTrackPointUIPriv GTrackPointUIPriv;
+struct _GTrackPointUIPriv
+{
+    GtkBuilder *builder;
+    GError *error;
+    GXInput *xinput;
+};
+
+
+#define G_TRACK_POINT_UI_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), G_TYPE_TRACK_POINT_UI, GTrackPointUIPriv))
+
+G_DEFINE_TYPE (GTrackPointUI, g_track_point_ui, G_TYPE_OBJECT)
+
+static void dispose      (GObject      *object);
+
+static void
+g_track_point_ui_class_init (GTrackPointUIClass *klass)
+{
+    GObjectClass   *gobject_class = G_OBJECT_CLASS(klass);
+
+    gobject_class->dispose = dispose;
+
+    g_type_class_add_private(gobject_class, sizeof(GTrackPointUIPriv));
+}
+
+static void
+g_track_point_ui_init (GTrackPointUI *ui)
+{
+    GTrackPointUIPriv *priv = G_TRACK_POINT_UI_GET_PRIVATE(ui);
+
+    priv->xinput = NULL;
+    priv->error = NULL;
+
+    priv->builder = gtk_builder_new();
+    gtk_builder_add_from_file(priv->builder, 
+                              DATADIR "/gtrackpoint.ui", &priv->error);
+    if (priv->error) {
+        g_print("%s\n", priv->error->message);
+    }
+}
+
+static void
+dispose (GObject *object)
+{
+    GTrackPointUIPriv *priv = G_TRACK_POINT_UI_GET_PRIVATE(object);
+
+    if (priv->builder) {
+        g_object_unref(priv->builder);
+        priv->builder = NULL;
+    }
+
+    if (priv->xinput) {
+        g_object_unref(priv->xinput);
+        priv->xinput = NULL;
+    }
+
+    if (priv->error) {
+        g_error_free(priv->error);
+        priv->error = NULL;
+    }
+
+    if (G_OBJECT_CLASS(g_track_point_ui_parent_class)->dispose)
+        G_OBJECT_CLASS(g_track_point_ui_parent_class)->dispose(object);
+}
+
+static void
+show_error (GError *error)
+{
+    if (!error)
+        return;
+
+    g_print("%s\n", error->message);
+}
+
+static void
+set_toggle_property (GXInput *xinput, GtkToggleButton *button, const gchar *property_name)
+{
+    GError *error = NULL;
+    gboolean active;
+
+    active = gtk_toggle_button_get_active(button);
+    g_xinput_set_property(xinput,
+                          property_name,
+                          &error,
+                          active ? 1 : 0,
+                          NULL);
+    if (error) {
+        show_error(error);
+        g_error_free(error);
+    }
+}
+
+static void
+set_spin_property (GXInput *xinput, GtkSpinButton *button, const gchar *property_name)
+{
+    GError *error = NULL;
+    gdouble value;
+
+    value = gtk_spin_button_get_value(button);
+    g_xinput_set_property(xinput,
+                          property_name,
+                          &error,
+                          (gint)value,
+                          NULL);
+    if (error) {
+        show_error(error);
+        g_error_free(error);
+    }
+}
+
+static void
+set_widget_sensitivity (GtkBuilder *builder,
+                        const gchar *widget_id, 
+                        GtkToggleButton *button)
+{
+    GObject *object;
+
+    object = gtk_builder_get_object(builder, widget_id);
+    gtk_widget_set_sensitive(GTK_WIDGET(object),
+                             gtk_toggle_button_get_active(button));
+}
+
+static void
+cb_middle_button_emulation_toggled (GtkToggleButton *button, gpointer user_data)
+{
+    GTrackPointUIPriv *priv = G_TRACK_POINT_UI_GET_PRIVATE(user_data);
+
+    set_toggle_property(priv->xinput, button, MIDDLE_BUTTON_EMULATION);
+    set_widget_sensitivity(priv->builder, "middle_button_emulation_box", button);
+}
+
+static void
+cb_wheel_emulation_toggled (GtkToggleButton *button, gpointer user_data)
+{
+    GTrackPointUIPriv *priv = G_TRACK_POINT_UI_GET_PRIVATE(user_data);
+
+    set_toggle_property(priv->xinput, button, WHEEL_EMULATION);
+    set_widget_sensitivity(priv->builder, "wheel_emulation_box", button);
+}
+
+static void
+set_toggle_scroll_property (GXInput *xinput, GtkToggleButton *button,
+                            const gchar *property_name,
+                            gint first_value, gint second_value)
+{
+    GError *error = NULL;
+    gboolean active;
+
+    active = gtk_toggle_button_get_active(button);
+    if (active) {
+        g_xinput_set_property(xinput,
+                              property_name,
+                              &error,
+                              first_value, second_value,
+                              NULL);
+    } else {
+        /* This call causes crash. why? */ 
+        /*
+        g_xinput_set_property(xinput,
+                              property_name,
+                              &error,
+                              0,
+                              NULL);
+        */
+    }
+
+    if (error) {
+        show_error(error);
+        g_error_free(error);
+    }
+}
+
+static void
+cb_wheel_emulation_vertical_toggled (GtkToggleButton *button, gpointer user_data)
+{
+    GTrackPointUIPriv *priv = G_TRACK_POINT_UI_GET_PRIVATE(user_data);
+
+    set_toggle_scroll_property(priv->xinput, button, WHEEL_EMULATION_X_AXIS, 6, 7);
+}
+
+static void
+cb_wheel_emulation_horizontal_toggled (GtkToggleButton *button, gpointer user_data)
+{
+    GTrackPointUIPriv *priv = G_TRACK_POINT_UI_GET_PRIVATE(user_data);
+
+    set_toggle_scroll_property(priv->xinput, button, WHEEL_EMULATION_Y_AXIS, 4, 5);
+}
+
+static void
+cb_wheel_emulation_timeout_value_changed (GtkSpinButton *button, gpointer user_data)
+{
+    GTrackPointUIPriv *priv = G_TRACK_POINT_UI_GET_PRIVATE(user_data);
+
+    set_spin_property(priv->xinput, button, WHEEL_EMULATION_TIMEOUT);
+}
+
+static void
+cb_middle_button_timeout_value_changed (GtkSpinButton *button, gpointer user_data)
+{
+    GTrackPointUIPriv *priv = G_TRACK_POINT_UI_GET_PRIVATE(user_data);
+
+    set_spin_property(priv->xinput, button, MIDDLE_BUTTON_TIMEOUT);
+}
+
+static void
+setup_signals (GTrackPointUI *ui)
+{
+    GTrackPointUIPriv *priv = G_TRACK_POINT_UI_GET_PRIVATE(ui);
+    GObject *object;
+
+#define CONNECT(object_name, signal_name)                               \
+    object = gtk_builder_get_object(priv->builder, #object_name);       \
+    g_signal_connect(object, #signal_name,                              \
+                     G_CALLBACK(cb_ ## object_name ## _ ## signal_name),\
+                     ui)
+
+    CONNECT(middle_button_emulation, toggled);
+    CONNECT(middle_button_timeout, value_changed);
+    CONNECT(wheel_emulation, toggled);
+    CONNECT(wheel_emulation_timeout, value_changed);
+    CONNECT(wheel_emulation_vertical, toggled);
+    CONNECT(wheel_emulation_horizontal, toggled);
+
+#undef CONNECT
+}
+
+static gboolean
+get_integer_property (GXInput *xinput, const gchar *property_name,
+                      gint **values, gulong *n_values)
+{
+    GError *error = NULL;
+
+    g_xinput_get_property(xinput,
+                          property_name,
+                          &error,
+                          values, n_values);
+    if (error) {
+        show_error(error);
+        g_error_free(error);
+        return FALSE;
+    }
+
+    return TRUE;
+
+}
+
+static void
+set_integer_property (GXInput *xinput, const gchar *property_name,
+                      GtkBuilder *builder, const gchar *object_name)
+{
+    GObject *object;
+    gint *values;
+    gulong n_values;
+
+    if (!get_integer_property(xinput, property_name,
+                              &values, &n_values)) {
+        return;
+    }
+
+    object = gtk_builder_get_object(builder, object_name);
+    gtk_spin_button_set_value(GTK_SPIN_BUTTON(object),
+                              values[0]);
+    g_free(values);
+}
+
+static void
+set_boolean_property (GXInput *xinput, const gchar *property_name,
+                      GtkBuilder *builder, const gchar *object_name)
+{
+    GObject *object;
+    gint *values;
+    gulong n_values;
+
+    if (!get_integer_property(xinput, property_name,
+                              &values, &n_values)) {
+        return;
+    }
+
+    object = gtk_builder_get_object(builder, object_name);
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(object),
+                                 values[0] == 1 ? TRUE : FALSE);
+    g_free(values);
+}
+
+static void
+set_scroll_property (GXInput *xinput, const gchar *property_name,
+                     GtkBuilder *builder, const gchar *object_name)
+{
+    GObject *object;
+    gint *values;
+    gulong n_values;
+
+    if (!get_integer_property(xinput, property_name,
+                              &values, &n_values)) {
+        return;
+    }
+
+    object = gtk_builder_get_object(builder, object_name);
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(object),
+                                 n_values == 2 ? TRUE : FALSE);
+    g_free(values);
+}
+
+static void
+setup_current_values (GTrackPointUI *ui)
+{
+    GTrackPointUIPriv *priv = G_TRACK_POINT_UI_GET_PRIVATE(ui);
+
+    set_boolean_property(priv->xinput, MIDDLE_BUTTON_EMULATION,
+                         priv->builder, "middle_button_emulation");
+    set_boolean_property(priv->xinput, WHEEL_EMULATION,
+                         priv->builder, "wheel_emulation");
+
+    set_integer_property(priv->xinput, MIDDLE_BUTTON_TIMEOUT,
+                         priv->builder, "middle_button_timeout");
+    set_integer_property(priv->xinput, WHEEL_EMULATION_TIMEOUT,
+                         priv->builder, "wheel_emulation_timeout");
+
+    set_scroll_property(priv->xinput, WHEEL_EMULATION_X_AXIS,
+                        priv->builder, "wheel_emulation_vertical");
+    set_scroll_property(priv->xinput, WHEEL_EMULATION_Y_AXIS,
+                        priv->builder, "wheel_emulation_horizontal");
+}
+
+static void
+setup (GTrackPointUI *ui)
+{
+    setup_current_values(ui);
+    setup_signals(ui);
+}
+
+GTrackPointUI *
+g_track_point_ui_new (void)
+{
+    return g_object_new(G_TYPE_TRACK_POINT_UI, NULL);
+}
+
+GtkWidget *
+g_track_point_ui_get_widget (GTrackPointUI *ui)
+{
+    GTrackPointUIPriv *priv = G_TRACK_POINT_UI_GET_PRIVATE(ui);
+
+    if (!priv->builder)
+        return NULL;
+
+    if (!g_xinput_exist_device(DEVICE_NAME)) {
+        g_print("No %s found\n", DEVICE_NAME);
+        return NULL;
+    }
+
+    priv->xinput = g_xinput_new(DEVICE_NAME);
+    setup(ui);
+
+    return GTK_WIDGET(gtk_builder_get_object(priv->builder, "main-widget"));
+}
+
+GtkWidget *
+g_track_point_ui_get_label_widget (GTrackPointUI *ui)
+{
+    GTrackPointUIPriv *priv = G_TRACK_POINT_UI_GET_PRIVATE(ui);
+
+    if (!priv->builder)
+        return NULL;
+
+    return GTK_WIDGET(gtk_builder_get_object(priv->builder, "main-widget-label"));
+}
+
+/*
+vi:ts=4:nowrap:ai:expandtab:sw=4
+*/

Added: trunk/src/gtrackpoint-ui.h
==============================================================================
--- (empty file)
+++ trunk/src/gtrackpoint-ui.h	Tue Feb 24 11:51:35 2009
@@ -0,0 +1,61 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ *  Copyright (C) 2009 Hiroyuki Ikezoe  <poincare ikezoe net>
+ *
+ *  This library is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This library 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 Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef __GTRACKPOINT_UI_H__
+#define __GTRACKPOINT_UI_H__
+
+#include <glib-object.h>
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define G_TYPE_TRACK_POINT_UI            (g_track_point_ui_get_type ())
+#define G_TRACK_POINT_UI(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), G_TYPE_TRACK_POINT_UI, GTrackPointUI))
+#define G_TRACK_POINT_UI_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), G_TYPE_TRACK_POINT_UI, GTrackPointUIClass))
+#define G_IS_TRACK_POINT_UI(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), G_TYPE_TRACK_POINT_UI))
+#define G_IS_TRACK_POINT_UI_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), G_TYPE_TRACK_POINT_UI))
+#define G_TRACK_POINT_UI_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_TRACK_POINT_UI, GTrackPointUIClass))
+
+typedef struct _GTrackPointUI GTrackPointUI;
+typedef struct _GTrackPointUIClass GTrackPointUIClass;
+
+struct _GTrackPointUI
+{
+    GObject parent;
+};
+
+struct _GTrackPointUIClass
+{
+    GObjectClass parent_class;
+};
+
+void g_track_point_create_window (void);
+
+GType          g_track_point_ui_get_type   (void) G_GNUC_CONST;
+GTrackPointUI *g_track_point_ui_new        (void);
+GtkWidget     *g_track_point_ui_get_widget (GTrackPointUI *ui);
+GtkWidget     *g_track_point_ui_get_label_widget
+                                           (GTrackPointUI *ui);
+
+G_END_DECLS
+
+#endif /* __GTRACKPOINT_UI_H__ */
+/*
+vi:ts=4:nowrap:ai:expandtab:sw=4
+*/

Added: trunk/src/gxinput.c
==============================================================================
--- (empty file)
+++ trunk/src/gxinput.c	Tue Feb 24 11:51:35 2009
@@ -0,0 +1,419 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ *  Copyright (C) 2009 Hiroyuki Ikezoe  <poincare ikezoe net>
+ *
+ *  This library is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This library 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 Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+#include "gxinput.h"
+
+#include <gtk/gtk.h>
+#include <gdk/gdkx.h>
+#include <glib/gi18n.h>
+#include <X11/extensions/XInput.h>
+#include <X11/Xatom.h>
+#include <string.h>
+
+typedef struct _GXInputPriv GXInputPriv;
+struct _GXInputPriv
+{
+    gchar *device_name;
+    XDeviceInfo *device_info_list;
+    XDevice *device;
+};
+
+enum
+{
+    PROP_0,
+    PROP_DEVICE_NAME
+};
+
+#define G_XINPUT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), G_TYPE_XINPUT, GXInputPriv))
+
+G_DEFINE_TYPE (GXInput, g_xinput, G_TYPE_OBJECT)
+
+static void dispose      (GObject      *object);
+static void set_property (GObject      *object,
+                          guint         prop_id,
+                          const GValue *value,
+                          GParamSpec   *pspec);
+static void get_property (GObject      *object,
+                          guint         prop_id,
+                          GValue       *value,
+                          GParamSpec   *pspec);
+
+static void
+g_xinput_class_init (GXInputClass *klass)
+{
+    GObjectClass   *gobject_class = G_OBJECT_CLASS(klass);
+
+    gobject_class->dispose = dispose;
+    gobject_class->set_property = set_property;
+    gobject_class->get_property = get_property;
+
+    g_object_class_install_property
+        (gobject_class,
+         PROP_DEVICE_NAME,
+         g_param_spec_string("device-name",
+             "Device Name",
+             "The device name",
+             NULL,
+             G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+    g_type_class_add_private(gobject_class, sizeof(GXInputPriv));
+}
+
+static void
+g_xinput_init (GXInput *xinput)
+{
+    GXInputPriv *priv = G_XINPUT_GET_PRIVATE(xinput);
+
+    priv->device_name = NULL;
+    priv->device_info_list = NULL;
+    priv->device = NULL;
+}
+
+static void
+dispose (GObject *object)
+{
+    GXInputPriv *priv = G_XINPUT_GET_PRIVATE(object);
+
+    g_free(priv->device_name);
+
+    if (priv->device_info_list) {
+        XFreeDeviceList(priv->device_info_list);
+        priv->device_info_list = NULL;
+    }
+    
+    if (priv->device) {
+        XCloseDevice(GDK_DISPLAY(), priv->device);
+        priv->device = NULL;
+    }
+
+    if (G_OBJECT_CLASS(g_xinput_parent_class)->dispose)
+        G_OBJECT_CLASS(g_xinput_parent_class)->dispose(object);
+}
+
+static void
+set_property (GObject      *object,
+              guint         prop_id,
+              const GValue *value,
+              GParamSpec   *pspec)
+{
+    GXInputPriv *priv = G_XINPUT_GET_PRIVATE(object);
+
+    switch (prop_id) {
+    case PROP_DEVICE_NAME:
+        g_free(priv->device_name);
+        priv->device_name = g_value_dup_string(value);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+        break;
+    }
+}
+
+static void
+get_property (GObject    *object,
+              guint       prop_id,
+              GValue     *value,
+              GParamSpec *pspec)
+{
+    GXInputPriv *priv = G_XINPUT_GET_PRIVATE(object);
+
+    switch (prop_id) {
+    case PROP_DEVICE_NAME:
+        g_value_set_string(value, priv->device_name);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+        break;
+    }
+}
+
+GQuark
+g_xinput_error_quark (void)
+{
+    return g_quark_from_static_string("g-track-point-xinput-error-quark");
+}
+
+GXInput *
+g_xinput_new (const gchar *device_name)
+{
+    return g_object_new(G_TYPE_XINPUT,
+                        "device-name", device_name,
+                        NULL);
+}
+
+static XDeviceInfo *
+get_device_info (const gchar *device_name)
+{
+    XDeviceInfo *device_infos;
+    gint i, n_device_infos;
+
+    device_infos = XListInputDevices(GDK_DISPLAY(), &n_device_infos);
+
+    for (i = 0; i < n_device_infos; i++) {
+        if (!strcmp(device_infos[i].name, device_name))
+            return &device_infos[i];
+    }
+
+    XFreeDeviceList(device_infos);
+
+    return NULL;
+}
+
+static XDevice *
+open_device (const gchar *device_name, GError **error)
+{
+    XDeviceInfo *device_info;
+    XDevice *device;
+
+    device_info = get_device_info(device_name);
+    if (!device_info) {
+        g_set_error(error,
+                    G_XINPUT_ERROR,
+                    G_XINPUT_ERROR_NO_DEVICE,
+                    _("No  device found."));
+        return NULL;
+    }
+
+    device = XOpenDevice(GDK_DISPLAY(), device_info->id);
+    if (!device) {
+        g_set_error(error,
+                    G_XINPUT_ERROR,
+                    G_XINPUT_ERROR_NO_DEVICE,
+                    _("Could not open %s device."), device_name);
+        return NULL;
+    }
+
+    return device;
+}
+
+static XDevice *
+get_device (GXInput *xinput, GError **error)
+{
+    GXInputPriv *priv = G_XINPUT_GET_PRIVATE(xinput);
+
+    if (priv->device)
+        return priv->device;
+
+    priv->device = open_device(priv->device_name, error);
+    return priv->device;
+}
+
+static gboolean
+set_property_va_list (GXInput *xinput,
+                      const gchar *property_name,
+                      GError **error,
+                      gint first_value, va_list var_args)
+{
+    XDevice *device;
+    Atom property_atom;
+    gint i, n_values = 1;
+    gint *values;
+    gint max_value;
+    gchar *property_data;
+    va_list copy_var_args;
+    int format;
+
+    device = get_device(xinput, error);
+    if (!device)
+        return FALSE;
+
+    property_atom = XInternAtom(GDK_DISPLAY(), property_name, False);
+
+    G_VA_COPY(copy_var_args, var_args);
+    while (va_arg(var_args, gint))
+        n_values++;
+
+    values = g_new(gint, n_values);
+    values[0] = first_value;
+    max_value = values[0];
+    for (i = 1; i < n_values; i++) {
+        values[i] = va_arg(copy_var_args, gint);
+        max_value = MAX(max_value, values[i]);
+    }
+
+    if (max_value <= G_MAXINT8) {
+        property_data = (gchar*)g_new(int8_t*, n_values);
+        format = 8;
+    } else if (max_value <= G_MAXINT16) {
+        property_data = (gchar*)g_new(int16_t*, n_values);
+        format = 16;
+    } else {
+        property_data = (gchar*)g_new(int32_t*, n_values);
+        format = 32;
+    }
+
+    for (i = 0; i < n_values; i++) {
+        switch (format) {
+        case 8:
+            *(((int8_t*)property_data) + i) = values[i];
+            break;
+        case 16:
+            *(((int16_t*)property_data) + i) = values[i];
+            break;
+        case 32:
+        default:
+            *(((int32_t*)property_data) + i) = values[i];
+            break;
+        }
+    }
+
+    va_end(copy_var_args);
+    g_free(values);
+
+    XChangeDeviceProperty(GDK_DISPLAY(),
+                          device, property_atom,
+                          XA_INTEGER, format, PropModeReplace,
+                          (unsigned char*)property_data, n_values);
+
+    g_free(property_data);
+
+    return TRUE;
+}
+
+gboolean
+g_xinput_set_property (GXInput *xinput,
+                       const gchar *property_name,
+                       GError **error,
+                       gint first_value, ...)
+{
+    gboolean success;
+    va_list var_args;
+
+    va_start(var_args, first_value);
+    success = set_property_va_list(xinput, property_name, error, first_value, var_args);
+    va_end(var_args);
+
+    return success;
+}
+
+static Atom
+get_atom (GXInput *xinput, const gchar *property_name, GError **error)
+{
+    gint i, n_properties;
+    XDevice *device;
+    Atom *properties;
+    Atom found_atom = -1; 
+
+    device = get_device(xinput, error);
+    if (!device)
+        return -1;
+
+    properties = XListDeviceProperties(GDK_DISPLAY(), device, &n_properties);
+    for (i = 0; i < n_properties; i++) {
+        gchar *name;
+
+        name = XGetAtomName(GDK_DISPLAY(), properties[i]);
+        if (!strcmp(name, property_name)) {
+            found_atom = properties[i];
+            break;
+        }
+    }
+    XFree(properties);
+
+    return found_atom;
+}
+
+static gboolean
+get_int_property (GXInput *xinput,
+                  const gchar *property_name,
+                  GError **error,
+                  gint **values, gulong *n_values)
+{
+    XDevice *device;
+    Atom atom;
+    Atom actual_type;
+    int actual_format;
+    unsigned long bytes_after;
+    unsigned char *data, *data_position;
+    gulong i;
+    gint *int_values;
+
+    device = get_device(xinput, error);
+    if (!device)
+        return FALSE;
+
+    atom = get_atom(xinput, property_name, error);
+    if (atom < 0)
+        return FALSE;
+
+
+    if (XGetDeviceProperty(GDK_DISPLAY(), device, atom, 0, 1000, False,
+                           XA_INTEGER, &actual_type, &actual_format,
+                           n_values, &bytes_after, &data) != Success) {
+        return FALSE;
+    }
+
+    if (actual_type != XA_INTEGER) {
+        XFree(data);
+        return FALSE;
+    }
+
+    data_position = data;
+    int_values = g_new(gint, *n_values);
+
+    for (i = 0; i < *n_values; i++) {
+        switch (actual_format) {
+        case 8:
+            int_values[i] = *((int8_t*)data_position);
+            break;
+        case 16:
+            int_values[i] = *((int16_t*)data_position);
+            break;
+        case 32:
+            int_values[i] = *((int32_t*)data_position);
+            break;
+        }
+        data_position += actual_format / 8;
+    }
+
+    *values = int_values;
+    XFree(data);
+
+    return TRUE;
+}
+
+gboolean
+g_xinput_get_property (GXInput *xinput,
+                       const gchar *property_name,
+                       GError **error,
+                       gint **values,
+                       gulong *n_values)
+{
+    XDevice *device;
+
+    device = get_device(xinput, error);
+    if (!device)
+        return FALSE;
+
+    return get_int_property(xinput, property_name, error, values, n_values);
+}
+
+gboolean
+g_xinput_exist_device (const gchar *device_name)
+{
+    return get_device_info(device_name) ? TRUE : FALSE;
+}
+
+/*
+vi:ts=4:nowrap:ai:expandtab:sw=4
+*/

Added: trunk/src/gxinput.h
==============================================================================
--- (empty file)
+++ trunk/src/gxinput.h	Tue Feb 24 11:51:35 2009
@@ -0,0 +1,81 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ *  Copyright (C) 2009 Hiroyuki Ikezoe  <poincare ikezoe net>
+ *
+ *  This library is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This library 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 Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef __G_XINPUT_H__
+#define __G_XINPUT_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define G_XINPUT_ERROR           (g_xinput_error_quark())
+
+#define G_TYPE_XINPUT            (g_xinput_get_type ())
+#define G_XINPUT(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), G_TYPE_XINPUT, GXInput))
+#define G_XINPUT_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), G_TYPE_XINPUT, GXInputClass))
+#define G_IS_XINPUT(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), G_TYPE_XINPUT))
+#define G_IS_XINPUT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), G_TYPE_XINPUT))
+#define G_XINPUT_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_XINPUT, GXInputClass))
+
+typedef enum
+{
+    G_XINPUT_ERROR_NO_DEVICE,
+    G_XINPUT_ERROR_UNABLE_TO_OPEN_DEVICE
+} GXInputError;
+
+typedef struct _GXInput GXInput;
+typedef struct _GXInputClass GXInputClass;
+
+struct _GXInput
+{
+    GObject parent;
+};
+
+struct _GXInputClass
+{
+    GObjectClass parent_class;
+};
+
+GQuark       g_xinput_error_quark     (void);
+
+GType        g_xinput_get_type        (void) G_GNUC_CONST;
+
+gboolean     g_xinput_exist_device    (const gchar *device_name);
+
+GXInput     *g_xinput_new             (const gchar *device_name);
+
+gboolean     g_xinput_set_property    (GXInput *xinput,
+                                       const gchar *property_name,
+                                       GError **error,
+                                       gint first_property_value,
+                                       ...) G_GNUC_NULL_TERMINATED;
+gboolean     g_xinput_get_property    (GXInput *xinput,
+                                       const gchar *property_name,
+                                       GError **error,
+                                       gint **values,
+                                       gulong *n_values);
+
+G_END_DECLS
+
+#endif /* __G_XINPUT_H__ */
+
+/*
+vi:ts=4:nowrap:ai:expandtab:sw=4
+*/
+

Added: trunk/test/Makefile.am
==============================================================================
--- (empty file)
+++ trunk/test/Makefile.am	Tue Feb 24 11:51:35 2009
@@ -0,0 +1,38 @@
+if WITH_CUTTER
+TESTS = run-test.sh
+TESTS_ENVIRONMENT = NO_MAKE=yes CUTTER="$(CUTTER)"
+
+noinst_LTLIBRARIES =			\
+	suite_gpointing-device-settings_test.la	\
+	test_xinput.la	
+endif
+
+EXTRA_DIST =		\
+	run-test.sh
+
+INCLUDES =			\
+	-I$(srcdir)		\
+	-I$(top_srcdir)		\
+	-I$(top_srcdir)/src
+
+AM_CFLAGS = 			\
+	$(GCUTTER_CFLAGS)	\
+	$(GTK_CFLAGS)
+
+AM_LDFLAGS =			\
+	-module			\
+	-rpath "`pwd`/.libs"	\
+	-avoid-version		\
+	-no-undefined
+
+LIBS =				\
+	$(GTK_LIBS)		\
+	$(GCUTTER_LIBS)
+
+suite_gpointing-device-settings_test_la_SOURCES = gpointing-device-settings-test-suite.c
+
+test_xinput_la_SOURCES = test-xinput.c
+test_xinput_la_LIBADD = $(top_builddir)/src/gpointing-device-settings-gxinput.o
+
+echo-cutter:
+	@echo $(CUTTER)

Added: trunk/test/gpointing-device-settings-test-suite.c
==============================================================================
--- (empty file)
+++ trunk/test/gpointing-device-settings-test-suite.c	Tue Feb 24 11:51:35 2009
@@ -0,0 +1,14 @@
+#include <gcutter.h>
+#include <gtk/gtk.h>
+
+void gtrackpoint_test_warmup (void);
+
+void
+gtrackpoint_test_warmup (void)
+{
+    gtk_init(0, NULL);
+}
+
+/*
+vi:ts=4:nowrap:ai:expandtab:sw=4
+*/

Added: trunk/test/run-test.sh
==============================================================================
--- (empty file)
+++ trunk/test/run-test.sh	Tue Feb 24 11:51:35 2009
@@ -0,0 +1,62 @@
+#!/bin/sh
+#
+# Copyright (C) 2008  Kouhei Sutou <kou cozmixng org>
+#
+# This library is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This library 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 Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this library.  If not, see <http://www.gnu.org/licenses/>.
+
+unset LANG
+
+export BASE_DIR="`dirname $0`"
+top_dir="$BASE_DIR/.."
+top_dir="`cd $top_dir; pwd`"
+export KZ_EMBED_MODULE_DIR="$top_dir/module/embed/gecko/.libs"
+
+if test x"$NO_MAKE" != x"yes"; then
+    if which gmake > /dev/null; then
+	MAKE=${MAKE:-"gmake"}
+    else
+	MAKE=${MAKE:-"make"}
+    fi
+    $MAKE -C $top_dir/ > /dev/null || exit 1
+fi
+
+if test -z "$CUTTER"; then
+    CUTTER="`make -s -C $BASE_DIR echo-cutter`"
+fi
+
+CUTTER_ARGS=
+CUTTER_WRAPPER=
+if test x"$CUTTER_DEBUG" = x"yes"; then
+    CUTTER_WRAPPER="$top_dir/libtool --mode=execute gdb --args"
+    CUTTER_ARGS="--keep-opening-modules"
+elif test x"$CUTTER_CHECK_LEAK" = x"yes"; then
+    CUTTER_WRAPPER="$top_dir/libtool --mode=execute valgrind "
+    CUTTER_WRAPPER="$CUTTER_WRAPPER --leak-check=full --show-reachable=yes -v"
+    CUTTER_ARGS="--keep-opening-modules"
+fi
+
+export CUTTER
+
+CUTTER_ARGS="$CUTTER_ARGS -s $BASE_DIR --exclude-directory fixtures"
+if echo "$@" | grep -- --mode=analyze > /dev/null; then
+    :
+fi
+if test x"$USE_GTK" = x"yes"; then
+    CUTTER_ARGS="-u gtk $CUTTER_ARGS"
+fi
+
+ruby_dir=$top_dir/ext/ruby
+export RUBYLIB=$RUBYLIB:$ruby_dir/lib
+
+$CUTTER_WRAPPER $CUTTER $CUTTER_ARGS "$@" $BASE_DIR

Added: trunk/test/test-xinput.c
==============================================================================
--- (empty file)
+++ trunk/test/test-xinput.c	Tue Feb 24 11:51:35 2009
@@ -0,0 +1,84 @@
+#include "gxinput.h"
+
+#include <gcutter.h>
+
+void test_new (void);
+void test_property (void);
+
+static GXInput *xinput;
+static gint *values;
+static gulong n_values;
+static GError *error;
+
+void
+setup (void)
+{
+    xinput = NULL;
+    values = NULL;
+    n_values = 0;
+
+    error = NULL;
+}
+
+void
+teardown (void)
+{
+    if (xinput)
+        g_object_unref(xinput);
+    g_free(values);
+}
+
+void
+test_new (void)
+{
+    xinput = g_xinput_new("TPPS/2 IBM TrackPoint");
+    cut_assert(xinput);
+}
+
+void
+test_property (void)
+{
+    gint original_value;
+    cut_trace(test_new());
+
+    cut_assert_true(g_xinput_get_property(xinput,
+                                          "Middle Button Emulation",
+                                          &error,
+                                          &values, &n_values));
+    gcut_assert_error(error);
+    cut_assert_equal_int(1, n_values);
+    original_value = values[0];
+
+    cut_assert_true(g_xinput_set_property(xinput,
+                                          "Middle Button Emulation",
+                                          &error,
+                                          1, NULL));
+    gcut_assert_error(error);
+    g_free(values);
+    cut_assert_true(g_xinput_get_property(xinput,
+                                          "Middle Button Emulation",
+                                          &error,
+                                          &values, &n_values));
+    gcut_assert_error(error);
+    cut_assert_equal_int(1, n_values);
+    cut_assert_equal_int(1, values[0]);
+
+    cut_assert_true(g_xinput_set_property(xinput,
+                                          "Middle Button Emulation",
+                                          &error,
+                                          original_value, NULL));
+    gcut_assert_error(error);
+
+    g_free(values);
+    cut_assert_true(g_xinput_get_property(xinput,
+                                          "Middle Button Emulation",
+                                          &error,
+                                          &values, &n_values));
+    gcut_assert_error(error);
+    cut_assert_equal_int(1, n_values);
+    cut_assert_equal_int(original_value, values[0]);
+}
+
+/*
+vi:ts=4:nowrap:ai:expandtab:sw=4
+*/



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