Made change to support "string" key name specification in key listener
authorbillh <billh@e2bd861d-eb25-0410-b326-f6ed22b6b98c>
Thu, 9 May 2002 10:55:56 +0000 (10:55 +0000)
committerbillh <billh@e2bd861d-eb25-0410-b326-f6ed22b6b98c>
Thu, 9 May 2002 10:55:56 +0000 (10:55 +0000)
IDL; this breaks binary compatibility but is required by bug
80616.
Added a new test program, "event-listener-test", to connect to
all currently supported events and produce diagnostic output.
Split magnifier IDL, magnifier binary, and magnifier tests
into module gnome-mag.

git-svn-id: http://svn.gnome.org/svn/at-spi/trunk@290 e2bd861d-eb25-0410-b326-f6ed22b6b98c

ChangeLog
Makefile.am
configure.in
cspi/spi_registry.c
idl/Accessibility_Registry.idl
registryd/deviceeventcontroller.c
registryd/registry.c
test/Makefile.am
test/event-listener-test.c [new file with mode: 0644]
test/key-listener-test.c
test/simple-at.c

index 9add290..75c98dd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,68 @@
+2002-05-09  Bill Haneman <bill.haneman@sun.com>
+
+       * test/event-listener-test.c:
+       * test/Makefile.am:
+       Added new test, "event-listener-test"; 
+       this code does two things; it benchmarks traversal time 
+       for the accessible hierarchy for the first running accessible 
+       app, and it connects listeners for all supported event types.  
+       It is thus useful as an example event listener and for 
+       diagnostics/debugging of event generation.
+       
+2002-05-08  Bill Haneman <bill.haneman@sun.com>
+
+       * configure.in: 
+       Removed util/Makefile from targets.
+
+       * Makefile.am:
+       Removed util subdir from SUBDIRS (temporarily, 
+       pending removal of magnifier-only code
+       from UTIL).
+
+       * test/simple-at.c:
+       #ifdef-ed out magnifier dependencies, since
+       magnifier IDL, headers, and binary now live in
+       module gnome-mag and we don't want at-spi to depend 
+       on gnome-mag.  A magnifier demo which can run alongside
+       simple-at is forthcoming in the gnome-mag module.
+       
+       NOTE: Split magnifier binary, IDL, and magnification
+       activation code from at-spi into module gnome-mag.
+
+2002-05-03  Bill Haneman <bill.haneman@sun.com>
+
+       * configure.in:
+       Revved to version 0.13.0
+       
+       * idl/Accessibility_Registry.idl:
+       Changed definition of KeySet from sequence of longs to sequence of
+       KeyDefinitions, and added KeyDefinition struct.
+       Required for fix to bug 80616.
+
+       * cspi/spi_registry.c: SPI_registerAccessibleKeystrokeListener():
+       Changed AccessibleKeySet to Accessibility_KeySet marshalling code
+       to use new definition (see above).  
+
+       * registryd/deviceeventcontroller.c: handle_keygrab(), 
+       spi_keyset_contains_key():
+       Changed to make use of new struct; this allows matching based on
+       string key-name, for instance "Tab".  This also allows matching of
+       composed characters, non-alphanumeric characters in a way that
+       doesn't involve dependencies on X keysym codes directly, etc.
+       
+       * test/key-listener-test.c:
+       Added test for Alt-Tab key using "string" specification of keyset,
+       and modified one of the tests to use a keycode-based keyset.
+       Thus this test both tests and demonstrates the creation and use of
+       keysets of three forms:  specified via keycode array, 
+       keysym array, and string array. (The string case only contains a
+       single string, i.e. a string array of length 1).        
+
+       * test/simple-at.c:
+       Turned on PRINT_TREE option by default.  Also fixed a
+       string-freeing bug in the PRINT_TREE code.  
+       Added a listener to window:minimize events.
+       
 2002-05-08  Padraig O'Briain  <padraig.obriain@sun.com>
 
        * atk-bridge/bridge.c:
index 1c51db0..668253d 100644 (file)
@@ -1,4 +1,4 @@
-SUBDIRS = docs idl libspi registryd atk-bridge cspi util test
+SUBDIRS = docs idl libspi registryd atk-bridge cspi test
 
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = libspi-1.0.pc cspi-1.0.pc
index 6d1a631..2f6a356 100644 (file)
@@ -1,8 +1,8 @@
 AC_INIT(idl/Accessibility.idl)
 
 AT_SPI_MAJOR_VERSION=0
-AT_SPI_MINOR_VERSION=12
-AT_SPI_MICRO_VERSION=1
+AT_SPI_MINOR_VERSION=13
+AT_SPI_MICRO_VERSION=0
 AT_SPI_INTERFACE_AGE=0
 AT_SPI_BINARY_AGE=0
 AT_SPI_VERSION="$AT_SPI_MAJOR_VERSION.$AT_SPI_MINOR_VERSION.$AT_SPI_MICRO_VERSION"
@@ -116,14 +116,6 @@ PKG_CHECK_MODULES(TESTS, \
 AC_SUBST(TESTS_LIBS)
 AC_SUBST(TESTS_CFLAGS)
 
-PKG_CHECK_MODULES(UTILS, \
-       libbonobo-2.0 >= 1.107.0 \
-       gtk+-2.0 >= 2.0.0 \
-       gdk-pixbuf-2.0 >= 2.0.0
-       gdk-pixbuf-xlib-2.0 >= 2.0.0)
-AC_SUBST(UTILS_LIBS)
-AC_SUBST(UTILS_CFLAGS)
-
 PKG_CHECK_MODULES(ATK_BRIDGE, \
        libbonobo-2.0 >= 1.107.0 \
        atk >= 0.10)
@@ -198,8 +190,6 @@ atk-bridge/Makefile
 test/Makefile
 cspi/Makefile
 cspi/bonobo/Makefile
-util/Makefile
-util/Accessibility_Util.server
 ])
 
 echo "AT-SPI setup:
index 904c857..bb7e3c3 100644 (file)
@@ -80,8 +80,8 @@
  *            window:reparent
  *            window:desktop-create
  *            window:desktop-destroy
- *            window:focus-in
- *            window:focus-out
+ *            window:activate
+ *            window:deactivate
  *            window:raise
  *            window:lower
  *            window:move
@@ -346,10 +346,10 @@ SPI_registerAccessibleKeystrokeListener (AccessibleKeystrokeListener  *listener,
       key_set._buffer = Accessibility_KeySet_allocbuf (keys->len);
       for (i = 0; i < key_set._length; ++i)
         {
-          /* we overload the keyset long w/keycodes, the - bit acts as a flag */
-          key_set._buffer[i] = (keys->keysyms[i]) ? keys->keysyms[i] :
-                                                 - keys->keycodes[i];
-         /* fprintf (stderr, "key-set %d = %d\n", i, (int) key_set->_buffer[i]); */
+          key_set._buffer[i].keycode = keys->keycodes[i];
+         key_set._buffer[i].keysym = keys->keysyms[i];
+         key_set._buffer[i].keystring = (keys->keystrings[i] != NULL) ?
+                 keys->keystrings[i] : CORBA_string_dup("");
         }
     }
   else
index 3d9d212..6e8e554 100644 (file)
@@ -200,7 +200,14 @@ module Accessibility {
     boolean is_text;
   };
 
-  typedef sequence< long > KeySet;
+  struct KeyDefinition {
+    long keycode;
+    long keysym;
+    string keystring;
+    long unused;
+  };   
+
+  typedef sequence< KeyDefinition > KeySet;
   typedef sequence< KeyEventType > KeyEventTypeSeq;
 
   interface DeviceEventListener : Bonobo::Unknown {
index 3054e6a..e1c2a25 100644 (file)
@@ -24,7 +24,8 @@
 
 #include <config.h>
 
-#define  SPI_DEBUG
+#undef  SPI_DEBUG
+#define  SPI_KEYEVENT_DEBUG
 
 #include <string.h>
 #include <ctype.h>
@@ -246,12 +247,21 @@ handle_keygrab (SpiDEController         *controller,
 
       for (i = 0; i < key_listener->keys->_length; ++i)
         {
-         long int key_val = key_listener->keys->_buffer[i];
+         Accessibility_KeyDefinition keydef = key_listener->keys->_buffer[i];  
+         long int key_val = keydef.keysym;
          /* X Grabs require keycodes, not keysyms */
-         if (key_val >= 0)
+         if (keydef.keystring)
+           {
+             key_val = XStringToKeysym(keydef.keystring);                  
+           }
+         if (key_val > 0)
            {
              key_val = XKeysymToKeycode (spi_get_display (), (KeySym) key_val);
            }
+         else
+           {
+             key_val = keydef.keycode;
+           }
          grab_mask.key_val = key_val;
 
          process_cb (controller, &grab_mask);
@@ -371,14 +381,19 @@ spi_key_set_contains_key (Accessibility_KeySet            *key_set,
     {
 #ifdef SPI_KEYEVENT_DEBUG          
       g_print ("key_set[%d] = %d; key_event %d, code %d\n",
-               i, (int) key_set->_buffer[i],
+               i, (int) key_set->_buffer[i].keycode,
               (int) key_event->id, (int) key_event->hw_code); 
 #endif
-      if (key_set->_buffer[i] == (CORBA_long) key_event->id)
+      if (key_set->_buffer[i].keysym == (CORBA_long) key_event->id)
         {
           return TRUE;
        }
-      if (key_set->_buffer[i] == (CORBA_long) -key_event->hw_code)
+      if (key_set->_buffer[i].keycode == (CORBA_long) key_event->hw_code)
+        {
+          return TRUE;
+       }
+      if (key_event->event_string && key_event->event_string[0] && !strcmp
+         (key_set->_buffer[i].keystring, key_event->event_string))
         {
           return TRUE;
        }
@@ -474,7 +489,7 @@ spi_notify_keylisteners (GList                          **key_listeners,
 #ifdef SPI_KEYEVENT_DEBUG
   if (!notify)
     {
-      g_print ("no match for listener %d\n", i);
+      g_print ("no match for event\n");
     }
 #endif
 
@@ -534,6 +549,9 @@ spi_keystroke_from_x_key_event (XKeyEvent *x_key_event)
         key_event.event_string = CORBA_string_dup ("space");
         break;
       case XK_Tab:
+#ifdef SPI_KEYEVENT_DEBUG
+       fprintf(stderr, "Tab\n");
+#endif
         key_event.event_string = CORBA_string_dup ("Tab");
        break;
       case XK_BackSpace:
index 466489b..a0ff39a 100644 (file)
@@ -558,8 +558,8 @@ notify_listeners_cb (GList * const *list, gpointer user_data)
   ls = (*list)->data;
 
 #ifdef SPI_LISTENER_DEBUG
-  fprintf (stderr, "event quarks: %lx %lx %lx\n", ls->event_type_quark, etype.major, etype.minor);
-  fprintf (stderr, "event name: %s\n", etype.event_name);
+  fprintf (stderr, "event quarks: %lx %lx %lx\n", ls->event_type_quark, ctx->etype.major, ctx->etype.minor);
+  fprintf (stderr, "event name: %s\n", ctx->etype.event_name);
 #endif
 
   if ((ls->event_type_quark == ctx->etype.major) ||
index f07563c..f03064d 100644 (file)
@@ -1,9 +1,11 @@
 NULL=
 
-noinst_PROGRAMS = test-simple at app simple-at keysynth-demo accessx-gui key-listener-test
+noinst_PROGRAMS = test-simple at app simple-at keysynth-demo accessx-gui key-listener-test event-listener-test
 
 key_listener_test_SOURCES = key-listener-test.c
 
+event_listener_test_SOURCES = event-listener-test.c
+
 at_SOURCES = at.c 
 
 app_SOURCES = app.c
diff --git a/test/event-listener-test.c b/test/event-listener-test.c
new file mode 100644 (file)
index 0000000..3853cef
--- /dev/null
@@ -0,0 +1,197 @@
+/*
+ * AT-SPI - Assistive Technology Service Provider Interface
+ * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
+ *
+ * Copyright 2001 Sun Microsystems Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <stdlib.h>
+#include "../cspi/spi-private.h" /* A hack for now */
+
+static void traverse_accessible_tree (Accessible *accessible);
+
+static void report_event  (const AccessibleEvent *event, void *user_data);
+static void report_detail_event  (const AccessibleEvent *event, void *user_data);
+
+static AccessibleEventListener *generic_listener;
+static AccessibleEventListener *specific_listener;
+static gint n_elements_traversed = 0;
+
+int
+main (int argc, char **argv)
+{
+  int i, j;
+  int n_desktops;
+  int n_apps;
+  char *s;
+  GTimer *timer;
+  gdouble elapsed_time;
+  Accessible *desktop;
+  Accessible *application;
+  const char *modules;
+
+  SPI_init ();
+
+  generic_listener = SPI_createAccessibleEventListener (
+         report_event, NULL); 
+  specific_listener = SPI_createAccessibleEventListener (
+         report_detail_event, NULL); 
+
+  SPI_registerGlobalEventListener (generic_listener,
+                                  "focus:");
+  SPI_registerGlobalEventListener (generic_listener,
+                                  "object:property-change");
+  SPI_registerGlobalEventListener (specific_listener,
+                                  "object:property-change:accessible-name");
+  SPI_registerGlobalEventListener (generic_listener,
+                                  "object:state-changed"); 
+  SPI_registerGlobalEventListener (generic_listener,
+                                  "object:selection-changed"); 
+  SPI_registerGlobalEventListener (generic_listener,
+                                  "object:children-changed"); 
+  SPI_registerGlobalEventListener (specific_listener,
+                                  "object:children-changed:add"); 
+  SPI_registerGlobalEventListener (generic_listener,
+                                  "object:visible-data-changed"); 
+  SPI_registerGlobalEventListener (generic_listener,
+                                  "object:text-selection-changed"); 
+  SPI_registerGlobalEventListener (generic_listener,
+                                  "object:text-caret-moved"); 
+  SPI_registerGlobalEventListener (generic_listener,
+                                  "object:text-changed"); 
+  SPI_registerGlobalEventListener (generic_listener,
+                                  "object:column-inserted"); 
+  SPI_registerGlobalEventListener (generic_listener,
+                                  "object:row-inserted"); 
+  SPI_registerGlobalEventListener (generic_listener,
+                                  "object:column-reordered"); 
+  SPI_registerGlobalEventListener (generic_listener,
+                                  "object:row-reordered"); 
+  SPI_registerGlobalEventListener (generic_listener,
+                                  "object:column-deleted"); 
+  SPI_registerGlobalEventListener (generic_listener,
+                                  "object:row-deleted"); 
+  SPI_registerGlobalEventListener (generic_listener,
+                                  "object:model-changed"); 
+  SPI_registerGlobalEventListener (generic_listener,
+                                  "window:minimize");
+  SPI_registerGlobalEventListener (generic_listener,
+                                  "window:maximize");
+  SPI_registerGlobalEventListener (generic_listener,
+                                  "window:restore");
+  SPI_registerGlobalEventListener (generic_listener,
+                                  "window:activate");
+  SPI_registerGlobalEventListener (generic_listener,
+                                  "window:deactivate");
+  SPI_registerGlobalEventListener (generic_listener,
+                                  "window:close");
+#ifdef NOT_YET_IMPLEMENTED
+  SPI_registerGlobalEventListener (generic_listener,
+                                  "window:lower");
+  SPI_registerGlobalEventListener (generic_listener,
+                                  "window:raise");
+  SPI_registerGlobalEventListener (generic_listener,
+                                  "window:resize");
+  SPI_registerGlobalEventListener (generic_listener,
+                                  "window:shade");
+  SPI_registerGlobalEventListener (generic_listener,
+                                  "window:unshade");
+  /* event below possibly should just be property change? */
+  SPI_registerGlobalEventListener (generic_listener,
+                                  "window:restyle"); 
+  SPI_registerGlobalEventListener (generic_listener,
+                                  "window:desktop-create");
+  SPI_registerGlobalEventListener (generic_listener,
+                                  "window:desktop-destroy");
+#endif
+  
+  timer = g_timer_new ();
+  traverse_accessible_tree (SPI_getDesktop (0));
+  g_print ("Time for first traversal of %d elements: %lf\n", 
+           n_elements_traversed,
+          g_timer_elapsed (timer, NULL));
+  g_timer_start (timer);
+  traverse_accessible_tree (SPI_getDesktop (0));
+  g_timer_stop (timer);
+  g_print ("Time for subsequent traversal %f\n", g_timer_elapsed (timer, NULL));
+  g_print ("[%f elements/sec, %f SPI calls/sec]\n", 
+       n_elements_traversed/g_timer_elapsed(timer, NULL),
+       (n_elements_traversed*8+1)/g_timer_elapsed(timer, NULL));
+  
+  SPI_event_main ();
+
+  putenv ("AT_BRIDGE_SHUTDOWN=1");
+
+  /*
+   * TODO: Add a key event listener that calls test_exit, to
+   * deregister and cleanup appropriately.
+   */
+
+  return SPI_exit ();
+}
+
+static void
+traverse_accessible_tree (Accessible *accessible)
+{
+       int n_children;
+       int i;
+       char *name;
+       char *role_name;
+       Accessible *child;
+       
+        n_elements_traversed++;
+       name = Accessible_getName (accessible);
+       role_name = Accessible_getRoleName (accessible);
+#ifdef VERBOSE
+       fprintf (stdout, "[%s] \"%s\"\n",
+                role_name, name);
+#endif
+       SPI_freeString (name);
+       SPI_freeString (role_name);
+       n_children = Accessible_getChildCount (accessible);
+       if (!Accessible_isTable (accessible)) 
+       {
+               for (i = 0; i < n_children; ++i)
+               {
+                       child = Accessible_getChildAtIndex (accessible, i);
+                       traverse_accessible_tree (child);
+                       Accessible_unref (child);
+               }
+       }
+}
+
+void
+report_event (const AccessibleEvent *event, void *user_data)
+{
+  fprintf (stderr, "%s\n", event->type);
+}
+
+void
+report_detail_event (const AccessibleEvent *event, void *user_data)
+{
+  fprintf (stderr, "%s\n", event->type);
+}
+
+void
+test_exit ()
+{
+  SPI_deregisterGlobalEventListenerAll (generic_listener);
+  AccessibleEventListener_unref (generic_listener);
+  SPI_deregisterGlobalEventListenerAll (specific_listener);
+  AccessibleEventListener_unref (specific_listener);
+}
index 9fdeb62..c1bba64 100644 (file)
 static SPIBoolean report_command_key_event  (const AccessibleKeystroke *stroke, void *user_data);
 static SPIBoolean report_ordinary_key_event (const AccessibleKeystroke *stroke, void *user_data);
 static SPIBoolean report_synchronous_key_event (const AccessibleKeystroke *stroke, void *user_data);
+static SPIBoolean report_tab_key_event (const AccessibleKeystroke *stroke, void *user_data);
+static SPIBoolean report_all_key_event (const AccessibleKeystroke *stroke, void *user_data);
 
 static AccessibleKeystrokeListener *command_key_listener;
 static AccessibleKeystrokeListener *ordinary_key_listener;
 static AccessibleKeystrokeListener *synchronous_key_listener;
+static AccessibleKeystrokeListener *tab_key_listener;
+static AccessibleKeystrokeListener *all_key_listener;
 static AccessibleKeySet            *command_keyset;
 static AccessibleKeySet            *async_keyset;
 static AccessibleKeySet            *sync_keyset;
+static AccessibleKeySet            *tab_keyset;
 
 int
 main (int argc, char **argv)
 {
-
+  char *tab_strings[1];
+  short keycodes[] = {65, 64, 23};
+       
   SPI_init ();
 
   /* prepare the keyboard snoopers */
   command_key_listener = SPI_createAccessibleKeystrokeListener (report_command_key_event, NULL);
   ordinary_key_listener = SPI_createAccessibleKeystrokeListener (report_ordinary_key_event, NULL);
   synchronous_key_listener = SPI_createAccessibleKeystrokeListener (report_synchronous_key_event, NULL);
-
-  command_keyset = SPI_createAccessibleKeySet (11, "q", NULL, NULL);
-  async_keyset = SPI_createAccessibleKeySet (11, "abc", NULL, NULL);
-  sync_keyset = SPI_createAccessibleKeySet (11, "def", NULL, NULL);
+  tab_key_listener = SPI_createAccessibleKeystrokeListener (report_tab_key_event, NULL);
+  all_key_listener = SPI_createAccessibleKeystrokeListener (report_all_key_event, NULL);
   
+  command_keyset = SPI_createAccessibleKeySet (1, "q", NULL, NULL);
+  async_keyset = SPI_createAccessibleKeySet (3, NULL, keycodes, NULL);
+  sync_keyset = SPI_createAccessibleKeySet (3, "def", NULL, NULL);
+  tab_strings[0] = "Tab";
+  tab_keyset = SPI_createAccessibleKeySet (1,  NULL, NULL, tab_strings);
   SPI_registerAccessibleKeystrokeListener(command_key_listener,
                                          command_keyset,
                                          SPI_KEYMASK_ALT | SPI_KEYMASK_CONTROL,
@@ -73,6 +83,18 @@ main (int argc, char **argv)
                                          (unsigned long) ( SPI_KEY_PRESSED | SPI_KEY_RELEASED ),
                                          SPI_KEYLISTENER_CANCONSUME);
 
+  SPI_registerAccessibleKeystrokeListener(tab_key_listener,
+                                         tab_keyset,
+                                         SPI_KEYMASK_ALT,
+                                         (unsigned long) ( SPI_KEY_PRESSED | SPI_KEY_RELEASED ),
+                                         SPI_KEYLISTENER_ALL_WINDOWS);
+
+  SPI_registerAccessibleKeystrokeListener(all_key_listener,
+                                         SPI_KEYSET_ALL_KEYS,
+                                         SPI_KEYMASK_UNMODIFIED,
+                                         (unsigned long) ( SPI_KEY_PRESSED | SPI_KEY_RELEASED ),
+                                         SPI_KEYLISTENER_CANCONSUME);
+
   SPI_event_main ();
 
   putenv ("AT_BRIDGE_SHUTDOWN=1");
@@ -87,14 +109,19 @@ simple_at_exit ()
   AccessibleKeystrokeListener_unref         (command_key_listener);
   SPI_freeAccessibleKeySet                  (command_keyset);
   
-  SPI_deregisterAccessibleKeystrokeListener (ordinary_key_listener, SPI_KEYMASK_ALT | SPI_KEYMASK_CONTROL);
+/*
+  SPI_deregisterAccessibleKeystrokeListener (ordinary_key_listener, SPI_KEYMASK_ALT | SPI_KEYMASK_CONTROL); */
   AccessibleKeystrokeListener_unref         (ordinary_key_listener);
   SPI_freeAccessibleKeySet                  (async_keyset);
   
-  SPI_deregisterAccessibleKeystrokeListener (synchronous_key_listener, SPI_KEYMASK_ALT | SPI_KEYMASK_CONTROL);
+/*  SPI_deregisterAccessibleKeystrokeListener (synchronous_key_listener, SPI_KEYMASK_ALT | SPI_KEYMASK_CONTROL); */
   AccessibleKeystrokeListener_unref         (synchronous_key_listener);
   SPI_freeAccessibleKeySet                  (sync_keyset);
 
+  SPI_deregisterAccessibleKeystrokeListener (tab_key_listener, SPI_KEYMASK_ALT | SPI_KEYMASK_CONTROL);
+  AccessibleKeystrokeListener_unref         (tab_key_listener);
+  SPI_freeAccessibleKeySet                  (tab_keyset);
+
   SPI_event_quit ();
 }
 
@@ -147,3 +174,17 @@ report_synchronous_key_event (const AccessibleKeystroke *key, void *user_data)
   return ( key->keyID == 'd' ) ? TRUE : FALSE;
 }
 
+static SPIBoolean
+report_tab_key_event (const AccessibleKeystroke *key, void *user_data)
+{
+  print_key_event (key, "[TAB]");      
+  return FALSE;
+}
+
+static SPIBoolean
+report_all_key_event (const AccessibleKeystroke *key, void *user_data)
+{
+  g_print("(%d)", key->keyID);
+  return FALSE;
+}
+
index 63bec0a..5e7a1c7 100644 (file)
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <sys/un.h>
-#include "../util/mag_client.h"
+#undef MAGNIFIER_ENABLED
 #include "../cspi/spi-private.h" /* A hack for now */
 
-#undef PRINT_TREE
+#define PRINT_TREE
 
 static void report_focus_event    (const AccessibleEvent *event, void *user_data);
 static void report_generic_event  (const AccessibleEvent *event, void *user_data);
@@ -49,7 +49,10 @@ static void _festival_write (const char *buff, int fd);
 static void print_accessible_tree (Accessible *accessible, char *prefix);
 #endif
 
+#ifdef MAGNIFIER_ENABLED
 static SPIBoolean use_magnifier = FALSE;
+#endif
+
 static SPIBoolean use_festival = FALSE;
 static SPIBoolean festival_chatty = FALSE;
 static SPIBoolean name_changed = FALSE;
@@ -106,9 +109,9 @@ main (int argc, char **argv)
   SPI_registerGlobalEventListener (generic_listener, "object:visible-data-changed"); 
   SPI_registerGlobalEventListener (generic_listener, "object:text-selection-changed"); 
   SPI_registerGlobalEventListener (text_listener, "object:text-caret-moved"); 
-  SPI_registerGlobalEventListener (generic_listener, "object:text-changed"); 
+  SPI_registerGlobalEventListener (text_listener, "object:text-changed"); 
   SPI_registerGlobalEventListener (button_listener, "Gtk:GtkWidget:button-press-event");
-  SPI_registerGlobalEventListener (window_listener, "Gtk:GtkWidget:window-state-event");
+  SPI_registerGlobalEventListener (window_listener, "window:minimize");
   n_desktops = SPI_getDesktopCount ();
 
   for (i=0; i<n_desktops; ++i)
@@ -173,6 +176,7 @@ get_environment_vars (void)
           festival_chatty = TRUE;
        }
     }
+#ifdef MAGNIFIER_ENABLED
   if (g_getenv ("MAGNIFIER"))
     {
       fprintf (stderr, "Using magnifier\n");
@@ -182,6 +186,7 @@ get_environment_vars (void)
     {
       fprintf (stderr, "Not using magnifier\n");
     }
+#endif
 
   if (!use_festival)
     {
@@ -197,8 +202,8 @@ print_accessible_tree (Accessible *accessible, char *prefix)
        int i;
        char *name;
        char *role_name;
-       char *parent_name;
-       char *parent_role;
+       char *parent_name = NULL;
+       char *parent_role = NULL;
        char child_prefix[100];
        Accessible *child;
        Accessible *parent;
@@ -210,15 +215,16 @@ print_accessible_tree (Accessible *accessible, char *prefix)
          {
                parent_name = Accessible_getName (parent);
                parent_role = Accessible_getRoleName (parent);
+               Accessible_unref (parent);
          }
-       Accessible_unref (parent);
        name = Accessible_getName (accessible);
        role_name = Accessible_getRoleName (accessible);
-       fprintf (stdout, "%sAccessible [%s] \"%s\"; parent [%s] %s\n",
+       fprintf (stdout, "%sAccessible [%s] \"%s\"; parent [%s] %s.\n",
                 prefix, role_name, name, parent_role, parent_name);
        SPI_freeString (name);
        SPI_freeString (role_name);
        SPI_freeString (parent_name);
+       SPI_freeString (parent_role);
        n_children = Accessible_getChildCount (accessible);
        for (i = 0; i < n_children; ++i)
                {
@@ -277,11 +283,14 @@ report_focussed_accessible (Accessible *obj, SPIBoolean shutup_previous_speech)
                       x, y, x+width, y+height);
            }
        }
+#ifdef MAGNIFIER_ENABLED
       if (use_magnifier) {
        magnifier_set_roi ((short) 0, x, y, width, height);
       }
+#endif
     }
 
+
   if (Accessible_isValue (obj))
     {
       AccessibleValue *value = Accessible_getValue (obj);
@@ -346,6 +355,7 @@ report_text_event (const AccessibleEvent *event, void *user_data)
 {
   AccessibleText *text = Accessible_getText (event->source);
   fprintf (stderr, "%s event received\n", event->type);
+#ifdef MAGNIFIER_ENABLED
   if (use_magnifier && strcmp (event->type, "object:text-changed"))
     {
       long offset = AccessibleText_getCaretOffset (text);
@@ -356,13 +366,27 @@ report_text_event (const AccessibleEvent *event, void *user_data)
       fprintf (stderr, "new roi %d %d %d %d\n", (int) x, (int) y, (int) w, (int) h);
       magnifier_set_roi ((short) 0, x, y, w, h);
     }
+#endif
   if (!strcmp (event->type, "object:text-changed"))
     {
       long start, end;
-      char *new_text = AccessibleText_getTextAtOffset (text, (long) 0, SPI_TEXT_BOUNDARY_SENTENCE_START, &start, &end);
+      char *new_text = AccessibleText_getTextAtOffset (text, (long) event->detail1, SPI_TEXT_BOUNDARY_WORD_START, &start, &end);
       _festival_say (new_text, "voice_kal_diphone", FALSE);
+      fprintf (stderr, "text changed: %s", new_text ? new_text : "");
       SPI_freeString (new_text);
     }
+  else
+    {
+      long start, end;
+      char *word_text = AccessibleText_getTextAtOffset (text, (long) event->detail1, SPI_TEXT_BOUNDARY_WORD_START, &start, &end);
+      char *sentence_text = AccessibleText_getTextAtOffset (text, (long) event->detail1, SPI_TEXT_BOUNDARY_SENTENCE_START, &start, &end);
+      fprintf (stderr, "text changed: word %s; sentence %s at %d",
+              (word_text ? word_text : ""),
+              (sentence_text ? sentence_text : ""),
+              event->detail1);
+      if (word_text) SPI_freeString (word_text);
+      if (sentence_text) SPI_freeString (sentence_text);
+    }
 }
 
 void
@@ -455,11 +479,13 @@ is_command_key (const AccessibleKeystroke *key)
     case 'q':
            simple_at_exit(); 
            return TRUE; /* not reached */
+#ifdef MAGNIFIER_ENABLED
     case 'M':
     case 'm':
            use_magnifier = ! use_magnifier;
             fprintf (stderr, "%ssing magnifier\n", use_magnifier ? "U" : "Not u");
            return TRUE;
+#endif
     case 'F':
     case 'f':
            use_festival = ! use_festival;