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 void report_focus_event (void *fp);
30 void report_button_press (void *fp);
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);
35 static void _send_to_magnifier (int x, int y, int w, int h);
37 static boolean use_magnifier = FALSE;
38 static boolean use_festival = FALSE;
39 static boolean festival_chatty = FALSE;
41 static struct sockaddr_un mag_server = { AF_UNIX , "/tmp/magnifier_socket" };
42 static struct sockaddr_un client = { AF_UNIX, "/tmp/mag_client"};
45 main(int argc, char **argv)
51 Accessible *application;
52 AccessibleEventListener *focus_listener;
53 AccessibleEventListener *button_listener;
55 if ((argc > 1) && (!strncmp(argv[1],"-h",2)))
57 printf ("Usage: simple-at\n");
58 printf ("\tEnvironment variables used:\n\t\tFESTIVAL\n\t\tMAGNIFIER\n\t\tFESTIVAL_CHATTY\n");
64 focus_listener = createEventListener (report_focus_event);
65 button_listener = createEventListener (report_button_press);
67 registerGlobalEventListener (focus_listener, "focus:");
68 registerGlobalEventListener (button_listener, "Gtk:GtkWidget:button-press-event");
70 n_desktops = getDesktopCount ();
72 for (i=0; i<n_desktops; ++i)
74 desktop = getDesktop (i);
75 fprintf (stderr, "desktop %d name: %s\n", i, Accessible_getName (desktop));
76 n_apps = Accessible_getChildCount (desktop);
77 for (j=0; j<n_apps; ++j)
79 application = Accessible_getChildAtIndex (desktop, j);
80 fprintf (stderr, "app %d name: %s\n", j, Accessible_getName (application));
84 if (getenv ("FESTIVAL"))
87 if (getenv ("FESTIVAL_CHATTY"))
89 festival_chatty = TRUE;
92 if (getenv("MAGNIFIER"))
97 SPI_event_main(FALSE);
101 report_focus_event (void *p)
103 AccessibleEvent *ev = (AccessibleEvent *) p;
104 fprintf (stderr, "%s event from %s\n", ev->type,
105 Accessible_getName (&ev->source));
111 _festival_say (Accessible_getRole (&ev->source), "voice_don_diphone", TRUE);
113 _festival_say (Accessible_getName (&ev->source), "voice_kal_diphone", festival_chatty==FALSE);
116 if (Accessible_isComponent (&ev->source))
118 long x, y, width, height;
119 AccessibleComponent *component = Accessible_getComponent (&ev->source);
120 fprintf (stderr, "Source implements IDL:Accessibility/Component:1.0\n");
121 AccessibleComponent_getExtents (component, &x, &y, &width, &height,
123 fprintf (stderr, "Bounding box: (%ld, %ld) ; (%ld, %ld)\n",
124 x, y, x+width, y+height);
126 _send_to_magnifier (x, y, width, height);
131 report_button_press (void *p)
133 AccessibleEvent *ev = (AccessibleEvent *) p;
134 fprintf (stderr, "%s event from %s\n", ev->type,
135 Accessible_getName (&ev->source));
138 static int _festival_init ()
141 struct sockaddr_in name;
144 name.sin_family = AF_INET;
145 name.sin_port = htons (1314);
146 name.sin_addr.s_addr = htonl(INADDR_ANY);
147 fd = socket (PF_INET, SOCK_STREAM, 0);
149 while (connect(fd, (struct sockaddr *) &name, sizeof (name)) < 0) {
156 _festival_write ("(audio_mode'async)\n", fd);
157 _festival_write ("(Parameter.set 'Duration_Model 'Tree_ZScore)\n", fd);
158 _festival_write ("(Parameter.set 'Duration_Stretch 0.5)\n", fd);
162 static void _festival_say (const char *text, const char *voice, boolean shutup)
168 static gchar voice_spec[32];
172 fd = _festival_init ();
175 fprintf (stderr, "saying text: %s\n", text);
177 quoted = g_malloc(64+strlen(text)*2);
179 sprintf (prefix, "(SayText \"");
181 strncpy(quoted, prefix, 10);
182 p = quoted+strlen(prefix);
184 if ( *text == '\\' || *text == '"' )
193 if (shutup) _festival_write ("(audio_mode'shutup)\n", fd);
194 if (voice && (strncmp (voice, (char *) (voice_spec+1), strlen(voice))))
196 snprintf (voice_spec, 32, "(%s)\n", voice);
197 _festival_write (voice_spec, fd);
198 _festival_write ("(Parameter.set 'Duration_Model 'Tree_ZScore)\n", fd);
199 _festival_write ("(Parameter.set 'Duration_Stretch 0.5)\n", fd);
202 _festival_write (quoted, fd);
207 static void _festival_write (const gchar *command_string, int fd)
209 fprintf(stderr, command_string);
214 write(fd, command_string, strlen(command_string));
218 _send_to_magnifier(int x, int y, int w, int h)
220 int desc, length_msg;
223 sprintf (buff, "~5:%d,%d:", x+w/2, y+h/2);
226 g_print ("sending magnifier: %s\n", buff);
229 if((desc=socket(AF_UNIX,SOCK_STREAM,0)) == -1){
233 unlink("/tmp/mag_client");
235 if (bind(desc, (struct sockaddr*)&client, sizeof(client)) == -1)
241 if (connect(desc,(struct sockaddr*)&mag_server,sizeof(mag_server)) == -1)
247 length_msg = write(desc,buff,strlen(buff));
248 unlink("/tmp/mag_client");