[gnome-control-center] mouse: Add mouse test window



commit 7981d4423a35ca6dcebabe8571abd92aa28b317d
Author: Ondrej Holy <oholy redhat com>
Date:   Mon Aug 20 19:24:03 2012 +0200

    mouse: Add mouse test window
    
    https://bugzilla.gnome.org/show_bug.cgi?id=677206

 panels/mouse/Makefile.am             |   10 ++
 panels/mouse/gnome-mouse-test.c      |  171 ++++++++++++++++++++++++++++++++++
 panels/mouse/gnome-mouse-test.h      |   27 ++++++
 panels/mouse/gnome-mouse-test.ui     |   70 ++++++++++++++
 panels/mouse/test-gnome-mouse-test.c |   44 +++++++++
 5 files changed, 322 insertions(+), 0 deletions(-)
---
diff --git a/panels/mouse/Makefile.am b/panels/mouse/Makefile.am
index 6f16aa1..495bd8a 100644
--- a/panels/mouse/Makefile.am
+++ b/panels/mouse/Makefile.am
@@ -26,6 +26,16 @@ libmouse_properties_la_SOURCES =	\
 libmouse_properties_la_LIBADD = $(PANEL_LIBS) $(MOUSE_PANEL_LIBS)
 libmouse_properties_la_LDFLAGS = $(PANEL_LDFLAGS)
 
+test_gnome_mouse_test_SOURCES =			\
+	gnome-mouse-test.c		\
+	gnome-mouse-test.h		\
+	test-gnome-mouse-test.c
+
+noinst_PROGRAMS = test-gnome-mouse-test
+
+test_gnome_mouse_test_CPPFLAGS = $(INCLUDES)
+test_gnome_mouse_test_LDADD = $(PANEL_LIBS) $(MOUSE_PANEL_LIBS)
+
 @INTLTOOL_DESKTOP_RULE@
 
 pixmapdir  = $(pkgdatadir)/pixmaps
diff --git a/panels/mouse/gnome-mouse-test.c b/panels/mouse/gnome-mouse-test.c
new file mode 100644
index 0000000..2e0379f
--- /dev/null
+++ b/panels/mouse/gnome-mouse-test.c
@@ -0,0 +1,171 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2012 Red Hat, Inc.
+ *
+ * Written by: Ondrej Holy <oholy redhat com>,
+ *
+ * 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, 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 <glib/gi18n.h>
+#include <string.h>
+#include <gdk/gdk.h>
+#include <gdk/gdkx.h>
+#include <gnome-settings-daemon/gsd-enums.h>
+#include <math.h>
+
+#include "gnome-mouse-test.h"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#define WID(x) (GtkWidget*) gtk_builder_get_object (dialog, x)
+
+enum
+{
+	DOUBLE_CLICK_TEST_OFF,
+	DOUBLE_CLICK_TEST_MAYBE,
+	DOUBLE_CLICK_TEST_ON
+};
+
+/* State in testing the double-click speed. Global for a great deal of
+ * convenience
+ */
+static gint double_click_state = DOUBLE_CLICK_TEST_OFF;
+static GSettings *mouse_settings = NULL;
+
+/* Double Click handling */
+
+struct test_data_t
+{
+	gint *timeout_id;
+	GtkWidget *image;
+};
+
+/* Timeout for the double click test */
+
+static gboolean
+test_maybe_timeout (struct test_data_t *data)
+{
+	double_click_state = DOUBLE_CLICK_TEST_OFF;
+
+	gtk_image_set_from_icon_name (GTK_IMAGE (data->image), "face-plain", GTK_ICON_SIZE_DIALOG);
+
+	*data->timeout_id = 0;
+
+	return FALSE;
+}
+
+/* Callback issued when the user clicks the double click testing area. */
+
+static gboolean
+event_box_button_press_event (GtkWidget   *widget,
+			      GdkEventButton *event,
+			      GtkBuilder   *dialog)
+{
+	gint                       double_click_time;
+	static struct test_data_t  data;
+	static gint                test_on_timeout_id     = 0;
+	static gint                test_maybe_timeout_id  = 0;
+	static guint32             double_click_timestamp = 0;
+	GtkWidget                 *image;
+
+	if (event->type != GDK_BUTTON_PRESS)
+		return FALSE;
+
+	image = g_object_get_data (G_OBJECT (widget), "image");
+
+	double_click_time = g_settings_get_int (mouse_settings, "double-click");
+
+	if (test_maybe_timeout_id != 0)
+		g_source_remove  (test_maybe_timeout_id);
+	if (test_on_timeout_id != 0)
+		g_source_remove (test_on_timeout_id);
+
+	switch (double_click_state) {
+	case DOUBLE_CLICK_TEST_OFF:
+		double_click_state = DOUBLE_CLICK_TEST_MAYBE;
+		data.image = image;
+		data.timeout_id = &test_maybe_timeout_id;
+		test_maybe_timeout_id = g_timeout_add (double_click_time, (GSourceFunc) test_maybe_timeout, &data);
+		break;
+	case DOUBLE_CLICK_TEST_MAYBE:
+		if (event->time - double_click_timestamp < double_click_time) {
+			double_click_state = DOUBLE_CLICK_TEST_ON;
+			data.image = image;
+			data.timeout_id = &test_on_timeout_id;
+			test_on_timeout_id = g_timeout_add (2500, (GSourceFunc) test_maybe_timeout, &data);
+		}
+		break;
+	case DOUBLE_CLICK_TEST_ON:
+		double_click_state = DOUBLE_CLICK_TEST_OFF;
+		break;
+	}
+
+	double_click_timestamp = event->time;
+
+	switch (double_click_state) {
+	case DOUBLE_CLICK_TEST_ON:
+		gtk_image_set_from_icon_name (GTK_IMAGE (image), "face-laugh", GTK_ICON_SIZE_INVALID);
+		break;
+	case DOUBLE_CLICK_TEST_MAYBE:
+		gtk_image_set_from_icon_name (GTK_IMAGE (image), "face-smile", GTK_ICON_SIZE_INVALID);
+		break;
+	case DOUBLE_CLICK_TEST_OFF:
+		gtk_image_set_from_icon_name (GTK_IMAGE (image), "face-plain", GTK_ICON_SIZE_INVALID);
+		break;
+	}
+
+	return TRUE;
+}
+
+/* Set up the property editors in the dialog. */
+static void
+setup_dialog (GtkBuilder *dialog)
+{
+	GtkImage *image;
+
+	image = GTK_IMAGE (WID ("double_click_image"));
+
+	gtk_image_set_from_icon_name (image, "face-plain", GTK_ICON_SIZE_INVALID);
+	gtk_image_set_pixel_size (image, 256);
+
+	g_object_set_data (G_OBJECT (WID ("double_click_eventbox")), "image", GTK_WIDGET (image));
+	g_signal_connect (WID ("double_click_eventbox"), "button_press_event",
+			  G_CALLBACK (event_box_button_press_event), dialog);
+}
+
+GtkWidget *
+gnome_mouse_test_init (GtkBuilder *dialog)
+{
+	mouse_settings = g_settings_new ("org.gnome.settings-daemon.peripherals.mouse");
+
+	setup_dialog (dialog);
+
+	return WID ("mouse_test_window");
+}
+
+void
+gnome_mouse_test_dispose (GtkWidget *widget)
+{
+	if (mouse_settings != NULL) {
+		g_object_unref (mouse_settings);
+		mouse_settings = NULL;
+	}
+}
+
diff --git a/panels/mouse/gnome-mouse-test.h b/panels/mouse/gnome-mouse-test.h
new file mode 100644
index 0000000..af1a796
--- /dev/null
+++ b/panels/mouse/gnome-mouse-test.h
@@ -0,0 +1,27 @@
+/* -*- mode: c; style: linux -*-
+ * 
+ * Copyright (C) 2012 Red Hat, Inc.
+ *
+ * Written by: Ondrej Holy <oholy redhat com>
+ *
+ * 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, 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 <gtk/gtk.h>
+
+GtkWidget *gnome_mouse_test_init (GtkBuilder *dialog);
+void       gnome_mouse_test_dispose (GtkWidget *widget);
+
diff --git a/panels/mouse/gnome-mouse-test.ui b/panels/mouse/gnome-mouse-test.ui
new file mode 100644
index 0000000..ba87378
--- /dev/null
+++ b/panels/mouse/gnome-mouse-test.ui
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <object class="GtkWindow" id="mouse_test_window">
+    <property name="can_focus">False</property>
+    <child>
+      <object class="GtkGrid" id="test_widget">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="hexpand">True</property>
+        <property name="vexpand">True</property>
+        <property name="border_width">15</property>
+        <property name="column_spacing">10</property>
+        <child>
+          <object class="GtkLabel" id="label33">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+            <property name="halign">center</property>
+            <property name="hexpand">True</property>
+            <property name="xalign">0</property>
+            <property name="label" translatable="yes">To test your settings, try to double-click on the face.</property>
+            <property name="wrap">True</property>
+            <attributes>
+              <attribute name="style" value="italic"/>
+            </attributes>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">1</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkEventBox" id="double_click_eventbox">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+            <property name="halign">center</property>
+            <property name="valign">center</property>
+            <property name="hexpand">True</property>
+            <property name="vexpand">True</property>
+            <property name="visible_window">False</property>
+            <child>
+              <object class="GtkImage" id="double_click_image">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                <property name="stock">gtk-missing-image</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">0</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+  <object class="GtkAdjustment" id="scrolled_window_adjustment">
+    <property name="upper">100</property>
+    <property name="value">100</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
+  </object>
+</interface>
diff --git a/panels/mouse/test-gnome-mouse-test.c b/panels/mouse/test-gnome-mouse-test.c
new file mode 100644
index 0000000..096faca
--- /dev/null
+++ b/panels/mouse/test-gnome-mouse-test.c
@@ -0,0 +1,44 @@
+#include <config.h>
+#include <gtk/gtk.h>
+
+#include "gnome-mouse-test.h"
+
+static gboolean
+delete_event_cb (GtkWidget *widget, GdkEvent *event, gpointer user_data)
+{
+  GtkWidget *window = user_data;
+
+  gnome_mouse_test_dispose (window);
+
+  gtk_main_quit ();
+
+  return FALSE;
+}
+
+int main (int argc, char **argv)
+{
+  GtkBuilder *builder;
+  GtkWidget *window;
+  GError *error = NULL;
+
+  gtk_init (&argc, &argv);
+
+  builder = gtk_builder_new ();
+
+  gtk_builder_add_from_file (builder, "gnome-mouse-test.ui", &error);
+  if (error != NULL)
+    {
+      g_warning ("Error loading UI file: %s", error->message);
+      return 1;
+    }
+
+  window = gnome_mouse_test_init (builder);
+  gtk_widget_show_all (window);
+
+  g_signal_connect (G_OBJECT (window), "delete-event",
+  G_CALLBACK (delete_event_cb), window);
+
+  gtk_main ();
+
+  return 0;
+}



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