#include <ctype.h>
#include <unistd.h>
#include <sys/socket.h>
+#include <netinet/in.h>
#include <sys/un.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);
-static SPIBoolean report_ordinary_key_event (AccessibleKeystroke *stroke, void *user_data);
+#undef PRINT_TREE
+
+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_text_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 ();
static void _festival_say (const char *text, const char *voice, SPIBoolean shutup);
static void _festival_write (const char *buff, int fd);
+#ifdef PRINT_TREE
+static void print_accessible_tree (Accessible *accessible, char *prefix);
+#endif
+
static SPIBoolean use_magnifier = FALSE;
static SPIBoolean use_festival = FALSE;
static SPIBoolean festival_chatty = FALSE;
static AccessibleEventListener *property_listener;
static AccessibleEventListener *generic_listener;
static AccessibleEventListener *button_listener;
+static AccessibleEventListener *text_listener;
static AccessibleKeystrokeListener *command_key_listener;
static AccessibleKeystrokeListener *ordinary_key_listener;
-static AccessibleKeySet *spacebar_key_set;
+static AccessibleKeySet *command_keyset;
int
main (int argc, char **argv)
modules = g_getenv ("GTK_MODULES");
if (!modules || modules [0] == '\0')
{
- putenv ("GTK_MODULES=gail:at-bridge");
+ putenv ("GTK_MODULES=");
}
modules = NULL;
focus_listener = SPI_createAccessibleEventListener (report_focus_event, NULL);
property_listener = SPI_createAccessibleEventListener (check_property_change, NULL);
generic_listener = SPI_createAccessibleEventListener (report_generic_event, NULL);
+ text_listener = SPI_createAccessibleEventListener (report_text_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: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 (text_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 ();
application = Accessible_getChildAtIndex (desktop, j);
s = Accessible_getName (application);
fprintf (stderr, "app %d name: %s\n", j, s);
+#ifdef PRINT_TREE
+ print_accessible_tree (application, "*");
+#endif
SPI_freeString (s);
Accessible_unref (application);
}
/* prepare the keyboard snoopers */
command_key_listener = SPI_createAccessibleKeystrokeListener (report_command_key_event, NULL);
ordinary_key_listener = SPI_createAccessibleKeystrokeListener (report_ordinary_key_event, NULL);
+
+ command_keyset = SPI_createAccessibleKeySet (11, "qmf23456789", NULL, NULL);
- /* will listen only to Alt-key combinations, and only to KeyPress events */
+ /* will listen only to Control-Alt-q KeyPress events */
SPI_registerAccessibleKeystrokeListener(command_key_listener,
- (AccessibleKeySet *) SPI_KEYSET_ALL_KEYS,
- SPI_KEYMASK_ALT,
+ command_keyset,
+ 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,
- (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 */
+
+ /* will listen only to CAPSLOCK key events, both press and release */
SPI_registerAccessibleKeystrokeListener(ordinary_key_listener,
(AccessibleKeySet *) SPI_KEYSET_ALL_KEYS,
- SPI_KEYMASK_SHIFT,
+ SPI_KEYMASK_SHIFTLOCK,
(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 ();
}
}
+#ifdef PRINT_TREE
+static void
+print_accessible_tree (Accessible *accessible, char *prefix)
+{
+ int n_children;
+ int i;
+ char *name;
+ char *role_name;
+ char *parent_name;
+ char *parent_role;
+ char child_prefix[100];
+ Accessible *child;
+ Accessible *parent;
+
+ strncpy (child_prefix, prefix, 98);
+ strcat (child_prefix, "*");
+ parent = Accessible_getParent (accessible);
+ if (parent)
+ {
+ parent_name = Accessible_getName (parent);
+ parent_role = Accessible_getRoleName (parent);
+ }
+ Accessible_unref (parent);
+ name = Accessible_getName (accessible);
+ role_name = Accessible_getRoleName (accessible);
+ 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);
+ n_children = Accessible_getChildCount (accessible);
+ for (i = 0; i < n_children; ++i)
+ {
+ child = Accessible_getChildAtIndex (accessible, i);
+ print_accessible_tree (child, child_prefix);
+ Accessible_unref (child);
+ }
+}
+#endif
+
void
report_focussed_accessible (Accessible *obj, SPIBoolean shutup_previous_speech)
{
char *s;
int len;
+ long x, y, width, height;
if (use_festival)
{
if (Accessible_isComponent (obj))
{
- long x, y, width, height;
AccessibleComponent *component = Accessible_getComponent (obj);
AccessibleComponent_getExtents (component, &x, &y, &width, &height,
SPI_COORD_TYPE_SCREEN);
fprintf (stderr, "Bounding box: (%ld, %ld) ; (%ld, %ld)\n",
x, y, x+width, y+height);
+ if (Accessible_isText (obj))
+ {
+ long x0, y0, xN, yN, w0, h0, wN, hN, nchars;
+ AccessibleText *text = Accessible_getText (obj);
+ nchars = AccessibleText_getCharacterCount (text);
+ if (nchars > 0)
+ {
+ AccessibleText_getCharacterExtents (text, 0, &x0, &y0, &w0, &h0,
+ SPI_COORD_TYPE_SCREEN);
+ AccessibleText_getCharacterExtents (text, nchars-1, &xN, &yN, &wN, &hN,
+ SPI_COORD_TYPE_SCREEN);
+ x = MIN (x0, xN);
+ width = MAX (x0 + w0, xN + wN) - x;
+ fprintf (stderr, "Text 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);
+ magnifier_set_roi ((short) 0, x, y, width, height);
}
}
text_interface = Accessible_getText (obj);
first_sentence = AccessibleText_getTextAtOffset (
text_interface, (long) 0, SPI_TEXT_BOUNDARY_SENTENCE_START, &start_offset, &end_offset);
- if (first_sentence)
+ if (first_sentence && use_festival)
{
_festival_say(first_sentence, "voice_don_diphone", FALSE);
SPI_freeString (first_sentence);
}
void
-report_focus_event (AccessibleEvent *event, void *user_data)
+report_focus_event (const AccessibleEvent *event, void *user_data)
{
char *s;
}
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_text_event (const AccessibleEvent *event, void *user_data)
{
fprintf (stderr, "%s event received\n", event->type);
+ if (use_magnifier)
+ {
+ AccessibleText *text = Accessible_getText (event->source);
+ long offset = AccessibleText_getCaretOffset (text);
+ long x, y, w, h;
+ fprintf (stderr, "offset %d\n", (int) offset);
+ AccessibleText_getCharacterExtents (text, offset, &x, &y, &w, &h,
+ SPI_COORD_TYPE_SCREEN);
+ 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);
+ }
}
void
-report_button_press (AccessibleEvent *event, void *user_data)
+report_button_press (const AccessibleEvent *event, void *user_data)
{
char *s;
}
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;
SPI_deregisterGlobalEventListenerAll (generic_listener);
AccessibleEventListener_unref (generic_listener);
+ SPI_deregisterGlobalEventListenerAll (text_listener);
+ AccessibleEventListener_unref (text_listener);
+
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);
AccessibleKeystrokeListener_unref (command_key_listener);
+ SPI_freeAccessibleKeySet (command_keyset);
- 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_freeAccessibleKeySet (spacebar_key_set);
-
SPI_event_quit ();
}
static SPIBoolean
-is_command_key (AccessibleKeystroke *key)
+is_command_key (const AccessibleKeystroke *key)
{
switch (key->keyID)
{
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;
}
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); string=%s; time=%lx\n",
(key->modifiers & SPI_KEYMASK_ALT)?"Alt-":"",
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\tstring=\'%s\'\n\ttime %lx\n",
(long) key->keyID,