2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001 Sun Microsystems Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
24 #include <sys/socket.h>
28 static void report_focus_event (void *fp);
29 static void report_button_press (void *fp);
30 static void get_environment_vars (void);
32 static int _festival_init ();
33 static void _festival_say (const char *text, const char *voice, boolean shutup);
34 static void _festival_write (const char *buff, int fd);
36 static boolean use_magnifier = FALSE;
37 static boolean use_festival = FALSE;
38 static boolean festival_chatty = FALSE;
41 main(int argc, char **argv)
47 Accessible *application;
48 AccessibleEventListener *focus_listener;
49 AccessibleEventListener *button_listener;
51 if ((argc > 1) && (!strncmp(argv[1],"-h",2)))
53 printf ("Usage: simple-at\n");
54 printf ("\tEnvironment variables used:\n\t\tFESTIVAL\n\t\tMAGNIFIER\n\t\tFESTIVAL_CHATTY\n");
60 focus_listener = createEventListener (report_focus_event);
61 button_listener = createEventListener (report_button_press);
63 registerGlobalEventListener (focus_listener, "focus:");
64 registerGlobalEventListener (button_listener, "Gtk:GtkWidget:button-press-event");
66 n_desktops = getDesktopCount ();
68 for (i=0; i<n_desktops; ++i)
70 desktop = getDesktop (i);
71 fprintf (stderr, "desktop %d name: %s\n", i, Accessible_getName (desktop));
72 n_apps = Accessible_getChildCount (desktop);
73 for (j=0; j<n_apps; ++j)
75 application = Accessible_getChildAtIndex (desktop, j);
76 fprintf (stderr, "app %d name: %s\n", j, Accessible_getName (application));
80 get_environment_vars();
82 SPI_event_main(FALSE);
86 get_environment_vars()
88 if (getenv ("FESTIVAL"))
91 if (getenv ("FESTIVAL_CHATTY"))
93 festival_chatty = TRUE;
96 if (getenv("MAGNIFIER"))
103 report_focus_event (void *p)
105 AccessibleEvent *ev = (AccessibleEvent *) p;
106 fprintf (stderr, "%s event from %s\n", ev->type,
107 Accessible_getName (&ev->source));
113 _festival_say (Accessible_getRole (&ev->source), "voice_don_diphone", TRUE);
115 _festival_say (Accessible_getName (&ev->source), "voice_kal_diphone", festival_chatty==FALSE);
118 if (Accessible_isComponent (&ev->source))
120 long x, y, width, height;
121 AccessibleComponent *component = Accessible_getComponent (&ev->source);
122 AccessibleComponent_getExtents (component, &x, &y, &width, &height,
124 fprintf (stderr, "Bounding box: (%ld, %ld) ; (%ld, %ld)\n",
125 x, y, x+width, y+height);
127 magnifier_set_roi (x, y, width, height);
133 report_button_press (void *p)
135 AccessibleEvent *ev = (AccessibleEvent *) p;
136 fprintf (stderr, "%s event from %s\n", ev->type,
137 Accessible_getName (&ev->source));
140 static int _festival_init ()
143 struct sockaddr_in name;
146 name.sin_family = AF_INET;
147 name.sin_port = htons (1314);
148 name.sin_addr.s_addr = htonl(INADDR_ANY);
149 fd = socket (PF_INET, SOCK_STREAM, 0);
151 while (connect(fd, (struct sockaddr *) &name, sizeof (name)) < 0) {
158 _festival_write ("(audio_mode'async)\n", fd);
159 _festival_write ("(Parameter.set 'Duration_Model 'Tree_ZScore)\n", fd);
160 _festival_write ("(Parameter.set 'Duration_Stretch 0.5)\n", fd);
164 static void _festival_say (const char *text, const char *voice, boolean shutup)
170 static gchar voice_spec[32];
174 fd = _festival_init ();
177 fprintf (stderr, "saying text: %s\n", text);
179 quoted = g_malloc(64+strlen(text)*2);
181 sprintf (prefix, "(SayText \"");
183 strncpy(quoted, prefix, 10);
184 p = quoted+strlen(prefix);
186 if ( *text == '\\' || *text == '"' )
195 if (shutup) _festival_write ("(audio_mode'shutup)\n", fd);
196 if (voice && (strncmp (voice, (char *) (voice_spec+1), strlen(voice))))
198 snprintf (voice_spec, 32, "(%s)\n", voice);
199 _festival_write (voice_spec, fd);
200 _festival_write ("(Parameter.set 'Duration_Model 'Tree_ZScore)\n", fd);
201 _festival_write ("(Parameter.set 'Duration_Stretch 0.5)\n", fd);
204 _festival_write (quoted, fd);
209 static void _festival_write (const gchar *command_string, int fd)
211 fprintf(stderr, command_string);
216 write(fd, command_string, strlen(command_string));