+
+ /* prepare the keyboard snoopers */
+ key_listener = createKeystrokeListener(report_key_event);
+ /* will listen only to Alt-key combinations */
+ registerKeystrokeListener(key_listener,
+ (KeySet *) ALL_KEYS,
+ KEYMASK_ALT,
+ (unsigned long) ( KeyPress | KeyRelease),
+ KEYLISTENER_CANCONSUME);
+
+ get_environment_vars();
+
+ SPI_event_main(TRUE);
+}
+
+static void
+get_environment_vars()
+{
+ if (getenv ("FESTIVAL"))
+ {
+ use_festival = TRUE;
+ if (getenv ("FESTIVAL_CHATTY"))
+ {
+ festival_chatty = TRUE;
+ }
+ }
+ if (getenv("MAGNIFIER"))
+ {
+ use_magnifier = TRUE;
+ }
+}
+
+void
+report_focussed_accessible (Accessible *obj, boolean shutup_previous_speech)
+{
+ if (use_festival)
+ {
+ if (festival_chatty)
+ {
+ _festival_say (Accessible_getRole (obj), "voice_don_diphone", shutup_previous_speech);
+ }
+ fprintf (stderr, "getting Name\n");
+ _festival_say (Accessible_getName (obj), "voice_kal_diphone",
+ shutup_previous_speech || festival_chatty);
+ }
+
+ if (Accessible_isComponent (obj))
+ {
+ long x, y, width, height;
+ AccessibleComponent *component = Accessible_getComponent (obj);
+ AccessibleComponent_getExtents (component, &x, &y, &width, &height,
+ COORD_TYPE_SCREEN);
+ fprintf (stderr, "Bounding box: (%ld, %ld) ; (%ld, %ld)\n",
+ x, y, x+width, y+height);
+ if (use_magnifier) {
+ magnifier_set_roi ((short) 0, x, y, width, height);
+ }
+ }
+ /* if this is a text object, speak the first sentence. */
+ if (Accessible_isText(obj))
+ {
+ AccessibleText *text_interface;
+ long start_offset, end_offset;
+ char *first_sentence = "empty";
+ text_interface = Accessible_getText (obj);
+ fprintf (stderr, "isText...%p %p\n", text_interface, (void *)*text_interface);
+ first_sentence = AccessibleText_getTextAtOffset (
+ text_interface, (long) 0, TEXT_BOUNDARY_SENTENCE_START, &start_offset, &end_offset);
+ if (first_sentence) _festival_say(first_sentence, "voice_don_diphone", FALSE);
+ fprintf (stderr, "done reporting on focussed object\n");
+ }
+}
+
+void
+report_focus_event (void *p)
+{
+ AccessibleEvent *ev = (AccessibleEvent *) p;
+ fprintf (stderr, "%s event from %s\n", ev->type,
+ Accessible_getName (&ev->source));
+ report_focussed_accessible (&ev->source, TRUE);