2002-01-11 Michael Meeks <michael@ximian.com>
[platform/core/uifw/at-spi2-atk.git] / test / simple-at.c
index 1901e68..996a900 100644 (file)
 #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);
-static SPIBoolean report_ordinary_key_event (AccessibleKeystroke *stroke, void *user_data);
+static void report_focus_event    (const AccessibleEvent *event, void *user_data);
+static void report_generic_event  (const AccessibleEvent *event, void *user_data);
+static void report_button_press   (const AccessibleEvent *event, void *user_data);
+static void check_property_change (const AccessibleEvent *event, void *user_data);
+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 void get_environment_vars (void);
 
 static int _festival_init ();
@@ -72,7 +72,7 @@ main (int argc, char **argv)
   modules = g_getenv ("GTK_MODULES");
   if (!modules || modules [0] == '\0')
     {
-      putenv ("GTK_MODULES=gail:at-bridge");
+      putenv ("GTK_MODULES=gail:atk-bridge");
     }
   modules = NULL;
 
@@ -115,27 +115,27 @@ main (int argc, char **argv)
   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 */
+  /* will listen only to Control-Alt-key combinations, and only to KeyPress events */
   SPI_registerAccessibleKeystrokeListener(command_key_listener,
                                          (AccessibleKeySet *) SPI_KEYSET_ALL_KEYS,
-                                         SPI_KEYMASK_ALT,
-                                         (unsigned long) ( KeyPress ),
+                                         SPI_KEYMASK_ALT | SPI_KEYMASK_CONTROL,
+                                         (unsigned long) ( SPI_KEY_PRESSED ),
                                          SPI_KEYLISTENER_ALL_WINDOWS);
-  
-  /* will listen only to unshifted key events, both press and release */
-  SPI_registerAccessibleKeystrokeListener(ordinary_key_listener,
+
+  /* will listen only to CAPSLOCK-Alt-key combinations, and only to KeyPress events */
+  SPI_registerAccessibleKeystrokeListener(command_key_listener,
                                          (AccessibleKeySet *) SPI_KEYSET_ALL_KEYS,
-                                         SPI_KEYMASK_UNMODIFIED,
-                                         (unsigned long) ( KeyPress | KeyRelease),
-                                         SPI_KEYLISTENER_NOSYNC);
-                                     
-  /* will listen only to shifted key events, both press and release */
+                                         SPI_KEYMASK_ALT | SPI_KEYMASK_SHIFTLOCK,
+                                         (unsigned long) ( SPI_KEY_PRESSED ),
+                                         SPI_KEYLISTENER_ALL_WINDOWS);
+  
+  /* will listen only to CAPSLOCK key events, both press and release */
   SPI_registerAccessibleKeystrokeListener(ordinary_key_listener,
                                          (AccessibleKeySet *) SPI_KEYSET_ALL_KEYS,
-                                         SPI_KEYMASK_SHIFT,
-                                         (unsigned long) ( KeyPress | KeyRelease),
+                                         SPI_KEYMASK_SHIFTLOCK,
+                                         (unsigned long) ( SPI_KEY_PRESSED | SPI_KEY_RELEASED ),
                                          SPI_KEYLISTENER_NOSYNC);
-  
+
   get_environment_vars ();
 
   SPI_event_main ();
@@ -238,7 +238,7 @@ report_focussed_accessible (Accessible *obj, SPIBoolean shutup_previous_speech)
 }
 
 void
-report_focus_event (AccessibleEvent *event, void *user_data)
+report_focus_event (const AccessibleEvent *event, void *user_data)
 {
   char *s;
 
@@ -255,13 +255,13 @@ report_focus_event (AccessibleEvent *event, void *user_data)
 }
 
 void
-report_generic_event (AccessibleEvent *event, void *user_data)
+report_generic_event (const AccessibleEvent *event, void *user_data)
 {
   fprintf (stderr, "%s event received\n", event->type);
 }
 
 void
-report_button_press (AccessibleEvent *event, void *user_data)
+report_button_press (const AccessibleEvent *event, void *user_data)
 {
   char *s;
 
@@ -277,7 +277,7 @@ report_button_press (AccessibleEvent *event, void *user_data)
 }
 
 void
-check_property_change (AccessibleEvent *event, void *user_data)
+check_property_change (const AccessibleEvent *event, void *user_data)
 {
   AccessibleSelection *selection = Accessible_getSelection (event->source);
   int n_selections;
@@ -318,18 +318,19 @@ simple_at_exit ()
   SPI_deregisterGlobalEventListenerAll (button_listener);
   AccessibleEventListener_unref        (button_listener);
 
-  SPI_deregisterAccessibleKeystrokeListener (command_key_listener, SPI_KEYMASK_ALT);
+  SPI_deregisterAccessibleKeystrokeListener (command_key_listener, SPI_KEYMASK_ALT | SPI_KEYMASK_CONTROL);
+  SPI_deregisterAccessibleKeystrokeListener (command_key_listener, SPI_KEYMASK_ALT | SPI_KEYMASK_SHIFTLOCK);
   AccessibleKeystrokeListener_unref         (command_key_listener);
 
   SPI_deregisterAccessibleKeystrokeListener (ordinary_key_listener, SPI_KEYMASK_UNMODIFIED);
-  SPI_deregisterAccessibleKeystrokeListener (ordinary_key_listener, SPI_KEYMASK_SHIFT);
+  SPI_deregisterAccessibleKeystrokeListener (ordinary_key_listener, SPI_KEYMASK_SHIFTLOCK);
   AccessibleKeystrokeListener_unref         (ordinary_key_listener);
-  
+
   SPI_event_quit ();
 }
 
 static SPIBoolean
-is_command_key (AccessibleKeystroke *key)
+is_command_key (const AccessibleKeystroke *key)
 {
   switch (key->keyID)
     {
@@ -340,10 +341,12 @@ is_command_key (AccessibleKeystroke *key)
     case 'M':
     case 'm':
            use_magnifier = ! use_magnifier;
+            fprintf (stderr, "%ssing magnifier\n", use_magnifier ? "U" : "Not u");
            return TRUE;
     case 'F':
     case 'f':
            use_festival = ! use_festival;
+            fprintf (stderr, "%speech output\n", use_festival ? "S" : "No s");
            return TRUE;
     default:
            return FALSE;
@@ -351,24 +354,27 @@ is_command_key (AccessibleKeystroke *key)
 }
 
 static SPIBoolean
-report_command_key_event (AccessibleKeystroke *key, void *user_data)
+report_command_key_event (const 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);
 }
 
 
 static SPIBoolean
-report_ordinary_key_event (AccessibleKeystroke *key, void *user_data)
+report_ordinary_key_event (const 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;
 }