Added support for key event strings, and renamespaced some of the at-bridge.
[platform/core/uifw/at-spi2-atk.git] / test / simple-at.c
index 1e66ef1..35ffec3 100644 (file)
 #include <unistd.h>
 #include <sys/socket.h>
 #include <sys/un.h>
-#include <cspi/spi.h>
 #include "../util/mag_client.h"
 #include "../cspi/spi-private.h" /* A hack for now */
 
 static void report_focus_event    (AccessibleEvent *event, void *user_data);
+static void report_generic_event  (AccessibleEvent *event, void *user_data);
 static void report_button_press   (AccessibleEvent *event, void *user_data);
 static void check_property_change (AccessibleEvent *event, void *user_data);
 static SPIBoolean report_command_key_event  (AccessibleKeystroke *stroke, void *user_data);
@@ -46,9 +46,11 @@ static SPIBoolean festival_chatty = FALSE;
 
 static AccessibleEventListener *focus_listener;
 static AccessibleEventListener *property_listener;
+static AccessibleEventListener *generic_listener;
 static AccessibleEventListener *button_listener;
 static AccessibleKeystrokeListener *command_key_listener;
 static AccessibleKeystrokeListener *ordinary_key_listener;
+static AccessibleKeySet *spacebar_key_set;
 
 int
 main (int argc, char **argv)
@@ -56,30 +58,45 @@ main (int argc, char **argv)
   int i, j;
   int n_desktops;
   int n_apps;
+  char *s;
   Accessible *desktop;
   Accessible *application;
-  char *s;
+  const char *modules;
 
   if ((argc > 1) && (!strncmp (argv[1], "-h", 2)))
-  {
-    printf ("Usage: simple-at\n");
-    printf ("\tEnvironment variables used:\n\t\tFESTIVAL\n\t\tMAGNIFIER\n\t\tFESTIVAL_CHATTY\n");
-    exit (0);
-  }
+    {
+      printf ("Usage: simple-at\n");
+      printf ("\tEnvironment variables used:\n\t\tFESTIVAL\n\t\tMAGNIFIER\n\t\tFESTIVAL_CHATTY\n");
+      exit (0);
+    }
+
+  modules = g_getenv ("GTK_MODULES");
+  if (!modules || modules [0] == '\0')
+    {
+      putenv ("GTK_MODULES=gail:at-bridge");
+    }
+  modules = NULL;
 
   SPI_init ();
 
-  focus_listener = createAccessibleEventListener (report_focus_event, NULL);
-  property_listener = createAccessibleEventListener (check_property_change, NULL); 
-  button_listener = createAccessibleEventListener (report_button_press, NULL);
-  registerGlobalEventListener (focus_listener, "focus:");
-  registerGlobalEventListener (property_listener, "object:property-change:accessible-selection"); 
-  registerGlobalEventListener (button_listener, "Gtk:GtkWidget:button-press-event");
-  n_desktops = getDesktopCount ();
+  focus_listener = SPI_createAccessibleEventListener (report_focus_event, NULL);
+  property_listener = SPI_createAccessibleEventListener (check_property_change, NULL); 
+  generic_listener = SPI_createAccessibleEventListener (report_generic_event, NULL); 
+  button_listener = SPI_createAccessibleEventListener (report_button_press, NULL);
+  SPI_registerGlobalEventListener (focus_listener, "focus:");
+  SPI_registerGlobalEventListener (property_listener, "object:property-change:accessible-selection"); 
+  SPI_registerGlobalEventListener (generic_listener, "object:selection-changed"); 
+  SPI_registerGlobalEventListener (generic_listener, "object:children-changed"); 
+  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 (button_listener, "Gtk:GtkWidget:button-press-event");
+  n_desktops = SPI_getDesktopCount ();
 
   for (i=0; i<n_desktops; ++i)
     {
-      desktop = getDesktop (i);
+      desktop = SPI_getDesktop (i);
       s = Accessible_getName (desktop);
       fprintf (stderr, "desktop %d name: %s\n", i, s);
       SPI_freeString (s);
@@ -96,35 +113,45 @@ main (int argc, char **argv)
     }
 
   /* prepare the keyboard snoopers */
-  command_key_listener = createAccessibleKeystrokeListener (report_command_key_event, NULL);
-  ordinary_key_listener = createAccessibleKeystrokeListener (report_ordinary_key_event, NULL);
+  command_key_listener = SPI_createAccessibleKeystrokeListener (report_command_key_event, NULL);
+  ordinary_key_listener = SPI_createAccessibleKeystrokeListener (report_ordinary_key_event, NULL);
   
   /* will listen only to Alt-key combinations, and only to KeyPress events */
-  registerAccessibleKeystrokeListener(command_key_listener,
-                                     (AccessibleKeySet *) SPI_KEYSET_ALL_KEYS,
-                                     SPI_KEYMASK_ALT,
-                                     (unsigned long) ( KeyPress ),
-                                     SPI_KEYLISTENER_ALL_WINDOWS);
+  SPI_registerAccessibleKeystrokeListener(command_key_listener,
+                                         (AccessibleKeySet *) SPI_KEYSET_ALL_KEYS,
+                                         SPI_KEYMASK_ALT,
+                                         (unsigned long) ( SPI_KEY_PRESSED ),
+                                         SPI_KEYLISTENER_ALL_WINDOWS);
   
   /* will listen only to unshifted key events, both press and release */
-  registerAccessibleKeystrokeListener(ordinary_key_listener,
-                                     (AccessibleKeySet *) SPI_KEYSET_ALL_KEYS,
-                                     SPI_KEYMASK_UNMODIFIED,
-                                     (unsigned long) ( KeyPress | KeyRelease),
-                                     SPI_KEYLISTENER_NOSYNC);
+  SPI_registerAccessibleKeystrokeListener(ordinary_key_listener,
+                                         (AccessibleKeySet *) SPI_KEYSET_ALL_KEYS,
+                                         SPI_KEYMASK_UNMODIFIED,
+                                         (unsigned long) ( SPI_KEY_PRESSED | SPI_KEY_RELEASED ),
+                                         SPI_KEYLISTENER_NOSYNC);
                                      
   /* will listen only to shifted key events, both press and release */
-  registerAccessibleKeystrokeListener(ordinary_key_listener,
-                                     (AccessibleKeySet *) SPI_KEYSET_ALL_KEYS,
-                                     SPI_KEYMASK_SHIFT,
-                                     (unsigned long) ( KeyPress | KeyRelease),
-                                     SPI_KEYLISTENER_NOSYNC);
+  SPI_registerAccessibleKeystrokeListener(ordinary_key_listener,
+                                         (AccessibleKeySet *) SPI_KEYSET_ALL_KEYS,
+                                         SPI_KEYMASK_SHIFT,
+                                         (unsigned long) ( SPI_KEY_PRESSED | SPI_KEY_RELEASED ),
+                                         SPI_KEYLISTENER_NOSYNC);
 
+  spacebar_key_set = SPI_createAccessibleKeySet (1, " ", NULL, NULL);
+  
+  /* will listen only to shift-spacebar events, on release, globally */
+  SPI_registerAccessibleKeystrokeListener(command_key_listener,
+                                         spacebar_key_set,
+                                         SPI_KEYMASK_SHIFT,
+                                         (unsigned long) ( SPI_KEY_RELEASED ),
+                                         SPI_KEYLISTENER_ALL_WINDOWS);
+
+  
   get_environment_vars ();
 
   SPI_event_main ();
 
-  setenv ("AT_BRIDGE_SHUTDOWN", "1", TRUE);
+  putenv ("AT_BRIDGE_SHUTDOWN=1");
 
   return SPI_exit ();
 }
@@ -146,6 +173,15 @@ get_environment_vars (void)
       fprintf (stderr, "Using magnifier\n");
       use_magnifier = TRUE;
     }  
+  else
+    {
+      fprintf (stderr, "Not using magnifier\n");
+    }
+
+  if (!use_festival)
+    {
+      fprintf (stderr, "No speech output\n");
+    }
 }
 
 void
@@ -154,14 +190,14 @@ report_focussed_accessible (Accessible *obj, SPIBoolean shutup_previous_speech)
   char *s;
   int len;
 
-  g_warning ("Report focused !");
-
   if (use_festival)
     {
-    if (festival_chatty)           
-      {
-        _festival_say (Accessible_getRole (obj), "voice_don_diphone", shutup_previous_speech);
-      }
+      if (festival_chatty)         
+        {
+         s = Accessible_getRoleName (obj);     
+          _festival_say (s, "voice_don_diphone", shutup_previous_speech);
+         SPI_freeString (s);
+        }
       fprintf (stderr, "getting Name\n");
       s = Accessible_getName (obj);
       _festival_say (s, "voice_kal_diphone",
@@ -181,6 +217,15 @@ report_focussed_accessible (Accessible *obj, SPIBoolean shutup_previous_speech)
              magnifier_set_roi ((short) 0, x, y, width, height);
       }
     }
+
+  if (Accessible_isValue (obj))
+    {
+      AccessibleValue *value = Accessible_getValue (obj);
+      fprintf (stderr, "Current value = %f, min = %f; max = %f\n",
+               AccessibleValue_getCurrentValue (value),
+               AccessibleValue_getMinimumValue (value),
+              AccessibleValue_getMaximumValue (value));
+    }
   /* if this is a text object, speak the first sentence. */
 
   if (Accessible_isText(obj))
@@ -208,12 +253,10 @@ report_focus_event (AccessibleEvent *event, void *user_data)
 {
   char *s;
 
-  g_warning ("report focus event");
-
   g_return_if_fail (event->source != NULL);
 
   s = Accessible_getName (event->source);
-  if (cspi_warn_ev (cspi_ev (), "Foobar"))
+  if (s)
     {
       fprintf (stderr, "%s event from %s\n", event->type, s);
       SPI_freeString (s);
@@ -223,6 +266,12 @@ report_focus_event (AccessibleEvent *event, void *user_data)
 }
 
 void
+report_generic_event (AccessibleEvent *event, void *user_data)
+{
+  fprintf (stderr, "%s event received\n", event->type);
+}
+
+void
 report_button_press (AccessibleEvent *event, void *user_data)
 {
   char *s;
@@ -268,20 +317,26 @@ check_property_change (AccessibleEvent *event, void *user_data)
 static void
 simple_at_exit ()
 {
-  deregisterGlobalEventListenerAll (focus_listener);
-  AccessibleEventListener_unref    (focus_listener);
+  SPI_deregisterGlobalEventListenerAll (focus_listener);
+  AccessibleEventListener_unref        (focus_listener);
+
+  SPI_deregisterGlobalEventListenerAll (property_listener);
+  AccessibleEventListener_unref        (property_listener);
+
+  SPI_deregisterGlobalEventListenerAll (generic_listener);
+  AccessibleEventListener_unref        (generic_listener);
+
+  SPI_deregisterGlobalEventListenerAll (button_listener);
+  AccessibleEventListener_unref        (button_listener);
 
-  deregisterGlobalEventListenerAll (property_listener);
-  AccessibleEventListener_unref    (property_listener);
+  SPI_deregisterAccessibleKeystrokeListener (command_key_listener, SPI_KEYMASK_ALT);
+  AccessibleKeystrokeListener_unref         (command_key_listener);
 
-  deregisterGlobalEventListenerAll (button_listener);
-  AccessibleEventListener_unref    (button_listener);
+  SPI_deregisterAccessibleKeystrokeListener (ordinary_key_listener, SPI_KEYMASK_UNMODIFIED);
+  SPI_deregisterAccessibleKeystrokeListener (ordinary_key_listener, SPI_KEYMASK_SHIFT);
+  AccessibleKeystrokeListener_unref         (ordinary_key_listener);
 
-  deregisterAccessibleKeystrokeListener (command_key_listener, SPI_KEYMASK_ALT);
-  deregisterAccessibleKeystrokeListener (ordinary_key_listener, SPI_KEYMASK_UNMODIFIED);
-  deregisterAccessibleKeystrokeListener (ordinary_key_listener, SPI_KEYMASK_SHIFT);
-  AccessibleKeystrokeListener_unref (command_key_listener);
-  AccessibleKeystrokeListener_unref (ordinary_key_listener);
+  SPI_freeAccessibleKeySet (spacebar_key_set);
   
   SPI_event_quit ();
 }
@@ -311,11 +366,13 @@ is_command_key (AccessibleKeystroke *key)
 static SPIBoolean
 report_command_key_event (AccessibleKeystroke *key, void *user_data)
 {
-  fprintf (stderr, "Command KeyEvent %s%c (keycode %d)\n",
+  fprintf (stderr, "Command KeyEvent %s%c (keycode %d); string=%s; time=%lx\n",
          (key->modifiers & SPI_KEYMASK_ALT)?"Alt-":"",
          ((key->modifiers & SPI_KEYMASK_SHIFT)^(key->modifiers & SPI_KEYMASK_SHIFTLOCK))?
          (char) toupper((int) key->keyID) : (char) tolower((int) key->keyID),
-         (int) key->keycode);
+         (int) key->keycode,
+         key->keystring,
+         (long int) key->timestamp);
   return is_command_key (key);
 }
 
@@ -323,10 +380,11 @@ report_command_key_event (AccessibleKeystroke *key, void *user_data)
 static SPIBoolean
 report_ordinary_key_event (AccessibleKeystroke *key, void *user_data)
 {
-  fprintf (stderr, "Received key event:\tsym %ld\n\tmods %x\n\tcode %d\n\ttime %ld\n",
+  fprintf (stderr, "Received key event:\tsym %ld\n\tmods %x\n\tcode %d\n\tstring=\'%s\'\n\ttime %lx\n",
           (long) key->keyID,
           (unsigned int) key->modifiers,
           (int) key->keycode,
+          key->keystring,
           (long int) key->timestamp);
   return FALSE;
 }