mousetweaks r247 - in trunk: . src



Author: gerdk
Date: Sat Aug 23 17:29:42 2008
New Revision: 247
URL: http://svn.gnome.org/viewvc/mousetweaks?rev=247&view=rev

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

	Improve a workaround for secondary clicks that caused 
	problems with window frames and desktop icons. See bug #532934.

	* src/mt-main.h: Listen for focus changes.
	* src/mt-main.h: Add 'move-release' variable.

	* src/Makefile.am: Add new files.
	* src/mt-accessible.c: New file.
	* src/mt-accessible.h: New file.
	Add AT-SPI utility functions. Most of them aren't
	used yet.



Added:
   trunk/src/mt-accessible.c
   trunk/src/mt-accessible.h
Modified:
   trunk/ChangeLog
   trunk/src/Makefile.am
   trunk/src/mt-main.c
   trunk/src/mt-main.h

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Sat Aug 23 17:29:42 2008
@@ -32,7 +32,9 @@
 	mt-cursor-manager.c \
 	mt-cursor-manager.h \
 	mt-listener.c	    \
-	mt-listener.h
+	mt-listener.h	    \
+	mt-accessible.c	    \
+	mt-accessible.h
 
 mousetweaks_CFLAGS =		\
 	$(AM_CFLAGS)		\

Added: trunk/src/mt-accessible.c
==============================================================================
--- (empty file)
+++ trunk/src/mt-accessible.c	Sat Aug 23 17:29:42 2008
@@ -0,0 +1,248 @@
+/*
+ * 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-accessible.h"
+
+#define MAX_SEARCHES 200
+
+gboolean
+mt_accessible_is_visible (Accessible *accessible)
+{
+    AccessibleStateSet *states;
+    gboolean visible = FALSE;
+
+    if (accessible) {
+	states = Accessible_getStateSet (accessible);
+	visible = AccessibleStateSet_contains (states, SPI_STATE_VISIBLE) &&
+		  AccessibleStateSet_contains (states, SPI_STATE_SHOWING);
+	AccessibleStateSet_unref (states);
+    }
+    return visible;
+}
+
+gboolean
+mt_accessible_is_active (Accessible *accessible)
+{
+    AccessibleStateSet *states;
+    gboolean active = FALSE;
+
+    if (accessible) {
+	states = Accessible_getStateSet (accessible);
+	active = AccessibleStateSet_contains (states, SPI_STATE_ACTIVE);
+	AccessibleStateSet_unref (states);
+    }
+    return active;
+}
+
+gboolean
+mt_accessible_supports_action (Accessible  *accessible,
+			       const gchar *action_name)
+{
+    AccessibleAction *action;
+    gboolean support = FALSE;
+    glong i, n;
+    gchar *name;
+
+    g_return_val_if_fail (action_name != NULL, FALSE);
+
+    if (accessible && Accessible_isAction (accessible)) {
+	action = Accessible_getAction (accessible);
+	n = AccessibleAction_getNActions (action);
+
+	for (i = 0; i < n; ++i) {
+	    name = AccessibleAction_getName (action, i);
+	    support = g_str_equal (name, action_name);
+	    SPI_freeString (name);
+
+	    if (support)
+		break;
+	}
+	AccessibleAction_unref (action);
+    }
+    return support;
+}
+
+gboolean
+mt_accessible_get_extents (Accessible *accessible,
+			   SPIRect    *extents)
+{
+    AccessibleComponent *component;
+
+    g_return_val_if_fail (extents != NULL, FALSE);
+
+    if (accessible && Accessible_isComponent (accessible)) {
+	component = Accessible_getComponent (accessible);
+	AccessibleComponent_getExtents (component,
+					&extents->x,
+					&extents->y,
+					&extents->width,
+					&extents->height,
+					SPI_COORD_TYPE_SCREEN);
+	AccessibleComponent_unref (component);
+	return TRUE;
+    }
+    return FALSE;
+}
+
+gboolean
+mt_accessible_in_extents (Accessible *accessible, gint x, gint y)
+{
+    AccessibleComponent *component;
+    gboolean in = FALSE;
+
+    if (accessible && Accessible_isComponent (accessible)) {
+	component = Accessible_getComponent (accessible);
+	in = AccessibleComponent_contains (component, x, y,
+					   SPI_COORD_TYPE_SCREEN);
+	AccessibleComponent_unref (component);
+    }
+    return in;
+}
+
+gboolean
+mt_accessible_point_in_rect (SPIRect rectangle, glong x, glong y)
+{
+    return x >= rectangle.x &&
+	   y >= rectangle.y &&
+	   x <= (rectangle.x + rectangle.width) &&
+	   y <= (rectangle.y + rectangle.height);
+}
+
+Accessible *
+mt_accessible_search (Accessible  *accessible,
+		      MtSearchType type,
+		      MtSearchFunc eval,
+		      MtSearchFunc push,
+		      gpointer     data)
+{
+    GQueue *queue;
+    Accessible *a;
+    gboolean found;
+    gint n_searches;
+    glong n, i;
+
+    g_return_val_if_fail (accessible != NULL, NULL);
+
+    queue = g_queue_new ();
+    g_queue_push_head (queue, accessible);
+    Accessible_ref (accessible);
+    n_searches = 0;
+
+    if (type == MT_SEARCH_TYPE_BREADTH) {
+	/* (reverse) breadth first search - queue FIFO */
+	while (!g_queue_is_empty (queue)) {
+	    a = g_queue_pop_tail (queue);
+
+	    if ((found = (eval) (a, data)))
+		break;
+	    else if (++n_searches >= MAX_SEARCHES) {
+		Accessible_unref (a);
+		break;
+	    }
+	    if ((push) (a, data)) {
+		n = Accessible_getChildCount (a);
+		for (i = 0; i < n; ++i)
+		    g_queue_push_head (queue,
+				       Accessible_getChildAtIndex (a, i));
+	    }
+	    Accessible_unref (a);
+	}
+    }
+    else if (type == MT_SEARCH_TYPE_DEPTH) {
+	/* depth first search - queue FILO */
+	while (!g_queue_is_empty (queue)) {
+	    a = g_queue_pop_head (queue);
+
+	    if ((found = (eval) (a, data)))
+		break;
+	    else if (++n_searches >= MAX_SEARCHES) {
+		Accessible_unref (a);
+		break;
+	    }
+	    if ((push) (a, data)) {
+		n = Accessible_getChildCount (a);
+		for (i = 0; i < n; ++i)
+		    g_queue_push_head (queue,
+				       Accessible_getChildAtIndex (a, i));
+	    }
+	    Accessible_unref (a);
+	}
+    }
+    else {
+	g_warning ("Unknown search type.");
+	found = FALSE;
+    }
+    g_queue_foreach (queue, (GFunc) Accessible_unref, NULL);
+    g_queue_free (queue);
+
+    return found ? a : NULL; 
+}
+
+Accessible *
+mt_accessible_at_point (gint x, gint y)
+{
+    Accessible *desk, *app, *frame, *a;
+    AccessibleComponent *component;
+    glong n_app, n_child;
+    gint i, j;
+
+    a = NULL;
+    desk = SPI_getDesktop (0);
+    n_app = Accessible_getChildCount (desk);
+
+    for (i = 0; i < n_app; ++i) {
+	app = Accessible_getChildAtIndex (desk, i);
+	if (!app)
+	    continue;
+
+	n_child = Accessible_getChildCount (app);
+	for (j = 0; j < n_child; ++j) {
+	    frame = Accessible_getChildAtIndex (app, j);
+	    if (!frame)
+		continue;
+
+	    if (!Accessible_getRole (frame) == SPI_ROLE_FRAME ||
+		!mt_accessible_is_visible (frame) ||
+		!mt_accessible_is_active (frame) ||
+		!Accessible_isComponent (frame)) {
+		Accessible_unref (frame);
+		continue;
+	    }
+
+	    component = Accessible_getComponent (frame);
+	    a = AccessibleComponent_getAccessibleAtPoint (component, x, y,
+							  SPI_COORD_TYPE_SCREEN);
+	    AccessibleComponent_unref (component);
+	    Accessible_unref (frame);
+
+	    if (a)
+		break;
+	}
+	Accessible_unref (app);
+
+	if (a)
+	    break;
+    }
+    Accessible_unref (desk);
+
+    return a;
+}

Added: trunk/src/mt-accessible.h
==============================================================================
--- (empty file)
+++ trunk/src/mt-accessible.h	Sat Aug 23 17:29:42 2008
@@ -0,0 +1,57 @@
+/*
+ * 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_ACCESSIBLE_H__
+#define __MT_ACCESSIBLE_H__
+
+#include <glib.h>
+#include <cspi/spi.h>
+
+G_BEGIN_DECLS
+
+typedef gboolean (*MtSearchFunc) (Accessible *accessible, gpointer data);
+
+typedef enum {
+    MT_SEARCH_TYPE_BREADTH = 0,
+    MT_SEARCH_TYPE_DEPTH
+} MtSearchType;
+
+gboolean     mt_accessible_is_visible      (Accessible  *accessible);
+gboolean     mt_accessible_is_active       (Accessible  *accessible);
+gboolean     mt_accessible_get_extents     (Accessible  *accessible,
+					    SPIRect     *extents);
+gboolean     mt_accessible_in_extents      (Accessible  *accessible,
+					    gint         x,
+					    gint         y);
+gboolean     mt_accessible_supports_action (Accessible  *accessible,
+					    const gchar *action_name);
+Accessible * mt_accessible_search          (Accessible  *accessible,
+					    MtSearchType type,
+					    MtSearchFunc eval,
+					    MtSearchFunc push,
+					    gpointer     data);
+Accessible * mt_accessible_at_point        (gint         x,
+					    gint         y);
+gboolean     mt_accessible_point_in_rect   (SPIRect      rectangle,
+					    glong        x,
+					    glong        y);
+
+G_END_DECLS
+
+#endif /* __MT_ACCESSIBLE_H__ */

Modified: trunk/src/mt-main.c
==============================================================================
--- trunk/src/mt-main.c	(original)
+++ trunk/src/mt-main.c	Sat Aug 23 17:29:42 2008
@@ -33,6 +33,7 @@
 #include "mt-cursor.h"
 #include "mt-main.h"
 #include "mt-listener.h"
+#include "mt-accessible.h"
 
 static void
 mt_cursor_set (GdkCursorType type)
@@ -262,9 +263,19 @@
 
     mt_cursor_manager_restore_all (mt_cursor_manager_get_default ());
 
-    SPI_generateMouseEvent (0, 0, "b1r");
-    SPI_generateMouseEvent (mt->pointer_x, mt->pointer_y, "abs");
-
+    if (mt->move_release) {
+	/* release the click outside of the focused object to
+	 * abort any action started by button-press.
+	 */
+	SPI_generateMouseEvent (0, 0, "b1r");
+	SPI_generateMouseEvent (mt->pointer_x, mt->pointer_y, "abs");
+    }
+    else {
+	SPI_generateMouseEvent (mt->pointer_x, mt->pointer_y, "b1r");
+    }
+    /* wait 100 msec before releasing the button again -
+     * gives apps some time to release active grabs, eg: gnome-panel 'move'
+     */
     g_timeout_add (100, right_click_timeout, data);
 }
 
@@ -326,6 +337,21 @@
     }
 }
 
+static void
+global_focus_event (MtListener *listener, gpointer data)
+{
+    MTClosure *mt = data;
+    Accessible *accessible;
+
+    if (mt->delay_enabled) {
+	accessible = mt_listener_current_focus (listener);
+	/* TODO: check for more objects and conditions.
+	 * Some links don't have jump actions, eg: text-mails in thunderbird.
+	 */
+	mt->move_release = mt_accessible_supports_action (accessible, "jump");
+    }
+}
+
 static gboolean
 cursor_overlay_time (guchar  *image,
 		     gint     width,
@@ -772,6 +798,8 @@
 			  G_CALLBACK (global_motion_event), mt);
 	g_signal_connect (listener, "button_event",
 			  G_CALLBACK (global_button_event), mt);
+	g_signal_connect (listener, "focus_changed",
+			  G_CALLBACK (global_focus_event), mt);
 
 	gtk_main ();
 

Modified: trunk/src/mt-main.h
==============================================================================
--- trunk/src/mt-main.h	(original)
+++ trunk/src/mt-main.h	Sat Aug 23 17:29:42 2008
@@ -39,6 +39,7 @@
     gboolean dwell_drag_started;
     gboolean dwell_gesture_started;
     gboolean override_cursor;
+    gboolean move_release;
 
     gint direction;
     gint pointer_x;



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