mousetweaks r243 - in trunk: . po src



Author: gerdk
Date: Fri Aug 22 17:00:29 2008
New Revision: 243
URL: http://svn.gnome.org/viewvc/mousetweaks?rev=243&view=rev

Log:
2008-08-22 Gerd Kohlberger <gerdk svn gnome org>

	* src/mt-listener.c:
	* src/mt-listener.h:
	Create a MtListener object and move all at-spi signal related
	things to a new file.

	* src/mt-main.c: Use new listener object.
	* src/Makefile.am: Add new files.
	* po/POTFILES.skip: Add mt-listener.c



Added:
   trunk/src/mt-listener.c
   trunk/src/mt-listener.h
Modified:
   trunk/ChangeLog
   trunk/po/POTFILES.skip
   trunk/src/Makefile.am
   trunk/src/mt-main.c

Modified: trunk/po/POTFILES.skip
==============================================================================
--- trunk/po/POTFILES.skip	(original)
+++ trunk/po/POTFILES.skip	Fri Aug 22 17:00:29 2008
@@ -1,2 +1,3 @@
 data/DwellClick_Factory.server.in
 data/PointerCapture_Factory.server.in
+src/mt-listener.c

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Fri Aug 22 17:00:29 2008
@@ -30,7 +30,9 @@
 	mt-cursor.c	    \
 	mt-cursor.h	    \
 	mt-cursor-manager.c \
-	mt-cursor-manager.h
+	mt-cursor-manager.h \
+	mt-listener.c	    \
+	mt-listener.h
 
 mousetweaks_CFLAGS =		\
 	$(AM_CFLAGS)		\

Added: trunk/src/mt-listener.c
==============================================================================
--- (empty file)
+++ trunk/src/mt-listener.c	Fri Aug 22 17:00:29 2008
@@ -0,0 +1,227 @@
+/*
+ * Copyright  2007-2008 Gerd Kohlberger <lowfi chello at>
+ *
+ * This file is part of Mousetweaks.
+ *
+ * Mousetweaks 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Mousetweaks 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib.h>
+#include <cspi/spi.h>
+
+#include "mt-listener.h"
+
+#if GLIB_CHECK_VERSION (2, 10, 0)
+#define I_(s) (g_intern_static_string (s))
+#else
+#define I_(s) (s)
+#endif
+
+#define MT_LISTENER_GET_PRIVATE(o) \
+    (G_TYPE_INSTANCE_GET_PRIVATE ((o), MT_TYPE_LISTENER, MtListenerPrivate))
+
+typedef struct _MtListenerPrivate MtListenerPrivate;
+struct _MtListenerPrivate {
+    AccessibleEventListener *motion;
+    AccessibleEventListener *button;
+    AccessibleEventListener *focus;
+
+    Accessible *current_focus;
+};
+
+enum {
+    MOTION_EVENT,
+    BUTTON_EVENT,
+    FOCUS_CHANGED,
+    LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+static void mt_listener_dispose      (GObject               *object);
+static void mt_listener_motion_event (const AccessibleEvent *event,
+				      gpointer               data);
+static void mt_listener_button_event (const AccessibleEvent *event,
+				      gpointer               data);
+static void mt_listener_focus_event  (const AccessibleEvent *event,
+				      gpointer               data);
+
+G_DEFINE_TYPE (MtListener, mt_listener, G_TYPE_OBJECT)
+
+static void
+mt_listener_class_init (MtListenerClass *klass)
+{
+    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+    gobject_class->dispose = mt_listener_dispose;
+
+    signals[MOTION_EVENT] = 
+	g_signal_new (I_("motion_event"),
+		      G_OBJECT_CLASS_TYPE (klass),
+		      G_SIGNAL_RUN_LAST,
+		      0, NULL, NULL,
+		      g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE,
+		      1, MT_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+
+    signals[BUTTON_EVENT] = 
+	g_signal_new (I_("button_event"),
+		      G_OBJECT_CLASS_TYPE (klass),
+		      G_SIGNAL_RUN_LAST,
+		      0, NULL, NULL,
+		      g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE,
+		      1, MT_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+
+    signals[FOCUS_CHANGED] =
+	g_signal_new (I_("focus_changed"),
+		      G_OBJECT_CLASS_TYPE (klass),
+		      G_SIGNAL_RUN_LAST,
+		      0, NULL, NULL,
+		      g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
+
+    g_type_class_add_private (klass, sizeof (MtListenerPrivate));
+}
+
+static void
+mt_listener_init (MtListener *listener)
+{
+    MtListenerPrivate *priv = MT_LISTENER_GET_PRIVATE (listener);
+
+    priv->current_focus = NULL;
+
+    priv->motion = SPI_createAccessibleEventListener (mt_listener_motion_event,
+						      listener);
+    SPI_registerGlobalEventListener (priv->motion, "mouse:abs");
+
+    priv->button = SPI_createAccessibleEventListener (mt_listener_button_event,
+						      listener);
+    SPI_registerGlobalEventListener (priv->button, "mouse:button:1p");
+    SPI_registerGlobalEventListener (priv->button, "mouse:button:1r");
+
+    priv->focus = SPI_createAccessibleEventListener (mt_listener_focus_event,
+						     listener);
+    SPI_registerGlobalEventListener (priv->focus, "focus:");
+}
+
+static void
+mt_listener_dispose (GObject *object)
+{
+    MtListenerPrivate *priv = MT_LISTENER_GET_PRIVATE (object);
+
+    if (priv->motion) {
+	SPI_deregisterGlobalEventListenerAll (priv->motion);
+	AccessibleEventListener_unref (priv->motion);
+	priv->motion = NULL;
+    }
+    if (priv->button) {
+	SPI_deregisterGlobalEventListenerAll (priv->button);
+	AccessibleEventListener_unref (priv->button);
+	priv->button = NULL;
+    }
+    if (priv->focus) {
+	SPI_deregisterGlobalEventListenerAll (priv->focus);
+	AccessibleEventListener_unref (priv->focus);
+	priv->focus = NULL;
+    }
+    if (priv->current_focus) {
+	Accessible_unref (priv->current_focus);
+	priv->current_focus = NULL;
+    }
+
+    G_OBJECT_CLASS (mt_listener_parent_class)->dispose (object);
+}
+
+GType
+mt_event_get_type (void)
+{
+    static GType event = 0;
+
+    if (G_UNLIKELY (event == 0))
+	event = g_boxed_type_register_static (I_("MtEvent"),
+					      (GBoxedCopyFunc) mt_event_copy,
+					      (GBoxedFreeFunc) mt_event_free);
+    return event;
+}
+
+/* do we need this? */
+MtEvent *
+mt_event_copy (const MtEvent *event)
+{
+    return (MtEvent *) g_memdup (event, sizeof (MtEvent));
+}
+
+void
+mt_event_free (MtEvent *event)
+{
+    g_free (event);
+}
+
+static void
+mt_listener_motion_event (const AccessibleEvent *event, gpointer data)
+{
+    MtEvent ev;
+
+    ev.type = EV_MOTION;
+    ev.x = (gint) event->detail1;
+    ev.y = (gint) event->detail2;
+
+    g_signal_emit (data, signals[MOTION_EVENT], 0, &ev);
+}
+
+static void
+mt_listener_button_event (const AccessibleEvent *event, gpointer data)
+{
+    MtEvent ev;
+
+    ev.type = g_str_equal (event->type, "mouse:button:1p")
+	      ? EV_BUTTON_PRESS : EV_BUTTON_RELEASE;
+    ev.x = (gint) event->detail1;
+    ev.y = (gint) event->detail2;
+
+    g_signal_emit (data, signals[BUTTON_EVENT], 0, &ev);
+}
+
+static void
+mt_listener_focus_event (const AccessibleEvent *event, gpointer data)
+{
+    MtListenerPrivate *priv = MT_LISTENER_GET_PRIVATE (data);
+
+    if (event->source) {
+	if (priv->current_focus)
+	    Accessible_unref (priv->current_focus);
+
+	Accessible_ref (event->source);
+	priv->current_focus = event->source;
+
+	g_signal_emit (data, signals[FOCUS_CHANGED], 0);
+    }
+}
+
+MtListener *
+mt_listener_get_default (void)
+{
+    static MtListener *listener = NULL;
+
+    if (!listener)
+	listener = g_object_new (MT_TYPE_LISTENER, NULL);
+
+    return listener;
+}
+
+Accessible *
+mt_listener_current_focus (MtListener *listener)
+{
+    g_return_val_if_fail (MT_IS_LISTENER (listener), NULL);
+
+    return MT_LISTENER_GET_PRIVATE (listener)->current_focus;
+}

Added: trunk/src/mt-listener.h
==============================================================================
--- (empty file)
+++ trunk/src/mt-listener.h	Fri Aug 22 17:00:29 2008
@@ -0,0 +1,70 @@
+/*
+ * Copyright  2007-2008 Gerd Kohlberger <lowfi chello at>
+ *
+ * This file is part of Mousetweaks.
+ *
+ * Mousetweaks 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Mousetweaks 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __MT_LISTENER_H__
+#define __MT_LISTENER_H__
+
+#include <glib-object.h>
+#include <cspi/spi.h>
+
+G_BEGIN_DECLS
+
+#define MT_TYPE_EVENT            (mt_event_get_type ())
+#define MT_TYPE_LISTENER         (mt_listener_get_type ())
+#define MT_LISTENER(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), MT_TYPE_LISTENER, MtListener))
+#define MT_LISTENER_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST ((k), MT_TYPE_LISTENER, MtListenerClass))
+#define MT_IS_LISTENER(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), MT_TYPE_LISTENER))
+#define MT_IS_LISTENER_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), MT_TYPE_LISTENER))
+#define MT_LISTENER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MT_TYPE_LISTENER, MtListenerClass))
+
+typedef struct _MtListener MtListener;
+typedef struct _MtListenerClass MtListenerClass;
+
+struct _MtListener {
+    GObject parent;
+};
+
+struct _MtListenerClass {
+    GObjectClass parent;
+};
+
+GType        mt_listener_get_type       (void) G_GNUC_CONST;
+MtListener * mt_listener_get_default    (void);
+Accessible * mt_listener_current_focus  (MtListener *listener);
+
+enum {
+    EV_MOTION = 0,
+    EV_BUTTON_PRESS,
+    EV_BUTTON_RELEASE
+};
+
+typedef struct _MtEvent MtEvent;
+struct _MtEvent {
+    gint type;
+    gint x;
+    gint y;
+};
+
+GType     mt_event_get_type (void) G_GNUC_CONST;
+MtEvent * mt_event_copy     (const MtEvent *event);
+void      mt_event_free     (MtEvent       *event);
+
+G_END_DECLS
+
+#endif /* __MT_LISTENER_H__ */

Modified: trunk/src/mt-main.c
==============================================================================
--- trunk/src/mt-main.c	(original)
+++ trunk/src/mt-main.c	Fri Aug 22 17:00:29 2008
@@ -18,13 +18,9 @@
  */
 
 #include <signal.h>
-#include <errno.h>
-#include <string.h>
-#include <math.h>
 #include <unistd.h>
 
 #include <gtk/gtk.h>
-#include <gdk/gdkx.h>
 #include <cspi/spi.h>
 #include <dbus/dbus-glib.h>
 
@@ -36,6 +32,7 @@
 #include "mt-cursor-manager.h"
 #include "mt-cursor.h"
 #include "mt-main.h"
+#include "mt-listener.h"
 
 static void
 mt_cursor_set (GdkCursorType type)
@@ -271,32 +268,34 @@
     g_timeout_add (100, right_click_timeout, data);
 }
 
-/* at-spi callbacks */
+/* at-spi listener callbacks */
 static void
-spi_motion_event (const AccessibleEvent *event, void *data)
+global_motion_event (MtListener *listener,
+		     MtEvent    *event,
+		     gpointer    data)
 {
     MTClosure *mt = data;
 
     if (mt->dwell_enabled) {
-	if (!below_threshold (mt, event->detail1, event->detail2) &&
+	if (!below_threshold (mt, event->x, event->y) &&
 	    !mt->dwell_gesture_started) {
-	    mt->pointer_x = (gint) event->detail1;
-	    mt->pointer_y = (gint) event->detail2;
+	    mt->pointer_x = event->x;
+	    mt->pointer_y = event->y;
 	    mt_timer_start (mt->dwell_timer);
 	}
+
 	if (mt->dwell_gesture_started) {
 	    if (mt->x_old > -1 && mt->y_old > -1)
 		draw_line (mt->pointer_x, mt->pointer_y, mt->x_old, mt->y_old);
 
-	    draw_line (mt->pointer_x, mt->pointer_y,
-		       event->detail1, event->detail2);
-
-	    mt->x_old = (gint) event->detail1;
-	    mt->y_old = (gint) event->detail2;
+	    draw_line (mt->pointer_x, mt->pointer_y, event->x, event->y);
+	    mt->x_old = event->x;
+	    mt->y_old = event->y;
 	}
     }
+
     if (mt_timer_is_running (mt->delay_timer)) {
-	if (!below_threshold (mt, event->detail1, event->detail2)) {
+	if (!below_threshold (mt, event->x, event->y)) {
 	    mt_timer_stop (mt->delay_timer);
 	    mt_cursor_manager_restore_all (mt_cursor_manager_get_default ());
 	}
@@ -304,20 +303,22 @@
 }
 
 static void
-spi_button_event (const AccessibleEvent *event, void *data)
+global_button_event (MtListener *listener,
+		     MtEvent    *event,
+		     gpointer    data)
 {
     MTClosure *mt = data;
 
-    if (g_str_equal (event->type, "mouse:button:1p")) {
+    if (event->type == EV_BUTTON_PRESS) {
 	if (mt->delay_enabled) {
-	    mt->pointer_x = (gint) event->detail1;
-	    mt->pointer_y = (gint) event->detail2;
+	    mt->pointer_x = event->x;
+	    mt->pointer_y = event->y;
 	    mt_timer_start (mt->delay_timer);
 	}
 	if (mt->dwell_gesture_started)
 	    dwell_stop_gesture (mt);
     }
-    else if (g_str_equal (event->type, "mouse:button:1r")) {
+    else {
 	if (mt->delay_enabled) {
 	    mt_timer_stop (mt->delay_timer);
 	    mt_cursor_manager_restore_all (mt_cursor_manager_get_default ());
@@ -432,7 +433,7 @@
 static void
 signal_handler (int sig)
 {
-    SPI_event_quit ();
+    gtk_main_quit ();
 }
 
 static void
@@ -690,7 +691,7 @@
     g_print ("Starting daemon.\n");
 
     if ((pid = fork ()) < 0) {
-	g_print ("Fork failed.\n");
+	g_error ("fork() failed.");
 	return 1;
     }
     else if (pid) {
@@ -701,7 +702,7 @@
 	/* Child process */
 	MTClosure *mt;
 	MtCursorManager *manager;
-	AccessibleEventListener *bl, *ml;
+	MtListener *listener;
 	gint spi_status;
 	gint spi_leaks = 0;
 
@@ -726,13 +727,6 @@
 	    goto FINISH;
 	}
 
-	/* add at-spi listeners */
-	ml = SPI_createAccessibleEventListener (spi_motion_event, (void *) mt);
-	SPI_registerGlobalEventListener (ml, "mouse:abs");
-	bl = SPI_createAccessibleEventListener (spi_button_event, (void *) mt);
-	SPI_registerGlobalEventListener (bl, "mouse:button:1p");
-	SPI_registerGlobalEventListener (bl, "mouse:button:1r");
-
 	/* command-line options */
 	if (dwell_click)
 	    gconf_client_set_bool (mt->client, OPT_DWELL, TRUE, NULL);
@@ -763,6 +757,7 @@
 	if (!mt_ctw_init (mt, pos_x, pos_y))
 	    goto CLEANUP;
 
+	/* init cursor animation */
 	manager = mt_cursor_manager_get_default ();
 	g_signal_connect (manager, "cursor_changed",
 			  G_CALLBACK (cursor_changed), mt);
@@ -771,23 +766,28 @@
 
 	mt->cursor = mt_cursor_manager_current_cursor (manager);
 
-	SPI_event_main ();
+	/* init at-spi signals */
+	listener = mt_listener_get_default ();
+	g_signal_connect (listener, "motion_event",
+			  G_CALLBACK (global_motion_event), mt);
+	g_signal_connect (listener, "button_event",
+			  G_CALLBACK (global_button_event), mt);
+
+	gtk_main ();
 
 	mt_cursor_manager_restore_all (manager);
 	g_object_unref (manager);
+	g_object_unref (listener);
 
 	CLEANUP:
-	    SPI_deregisterGlobalEventListenerAll (bl);
-	    AccessibleEventListener_unref (bl);
-	    SPI_deregisterGlobalEventListenerAll (ml);
-	    AccessibleEventListener_unref (ml);
 	    spi_leaks = SPI_exit ();
 	    mt_closure_free (mt);
 	FINISH:
 	    mt_pidfile_remove ();
 
 	if (spi_leaks)
-	    g_warning ("AT-SPI reported %i leaks", spi_leaks);
+	    g_warning ("AT-SPI reported %i leak%s.",
+		       spi_leaks, spi_leaks != 1 ? "s" : "");
     }
     return 0;
 }



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