[134] | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- |
---|
| 2 | * |
---|
| 3 | * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu> |
---|
| 4 | * |
---|
| 5 | * This program is free software; you can redistribute it and/or modify |
---|
| 6 | * it under the terms of the GNU General Public License as published by |
---|
| 7 | * the Free Software Foundation; either version 2 of the License, or |
---|
| 8 | * (at your option) any later version. |
---|
| 9 | * |
---|
| 10 | * This program is distributed in the hope that it will be useful, |
---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 13 | * GNU General Public License for more details. |
---|
| 14 | * |
---|
| 15 | * You should have received a copy of the GNU General Public License |
---|
| 16 | * along with this program; if not, write to the Free Software |
---|
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 18 | */ |
---|
| 19 | |
---|
| 20 | #include "config.h" |
---|
| 21 | |
---|
| 22 | #include <stdlib.h> |
---|
| 23 | #include <libintl.h> |
---|
| 24 | #include <locale.h> |
---|
| 25 | #include <string.h> |
---|
| 26 | #include <unistd.h> |
---|
| 27 | #include <signal.h> |
---|
| 28 | #include <errno.h> |
---|
| 29 | |
---|
| 30 | #include <glib/gi18n.h> |
---|
| 31 | #include <gdk/gdkx.h> |
---|
| 32 | #include <gtk/gtk.h> |
---|
| 33 | #include <gconf/gconf-client.h> |
---|
| 34 | |
---|
| 35 | #include "gdm-common.h" |
---|
| 36 | #include "gdm-log.h" |
---|
| 37 | #include "gdm-settings-client.h" |
---|
| 38 | #include "gdm-settings-keys.h" |
---|
| 39 | |
---|
| 40 | #include "gdm-chooser-session.h" |
---|
| 41 | |
---|
| 42 | #define ACCESSIBILITY_KEY "/desktop/gnome/interface/accessibility" |
---|
| 43 | |
---|
| 44 | static Atom AT_SPI_IOR; |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | static gboolean |
---|
| 48 | assistive_registry_launch (void) |
---|
| 49 | { |
---|
| 50 | GPid pid; |
---|
| 51 | GError *error; |
---|
| 52 | const char *command; |
---|
| 53 | char **argv; |
---|
| 54 | gboolean res; |
---|
| 55 | |
---|
| 56 | command = AT_SPI_REGISTRYD_DIR "/at-spi-registryd"; |
---|
| 57 | |
---|
| 58 | argv = NULL; |
---|
| 59 | error = NULL; |
---|
| 60 | res = g_shell_parse_argv (command, NULL, &argv, &error); |
---|
| 61 | if (! res) { |
---|
| 62 | g_warning ("Unable to parse command: %s", error->message); |
---|
| 63 | return FALSE; |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | error = NULL; |
---|
| 67 | res = g_spawn_async (NULL, |
---|
| 68 | argv, |
---|
| 69 | NULL, |
---|
| 70 | G_SPAWN_SEARCH_PATH |
---|
| 71 | | G_SPAWN_STDOUT_TO_DEV_NULL |
---|
| 72 | | G_SPAWN_STDERR_TO_DEV_NULL, |
---|
| 73 | NULL, |
---|
| 74 | NULL, |
---|
| 75 | &pid, |
---|
| 76 | &error); |
---|
| 77 | g_strfreev (argv); |
---|
| 78 | |
---|
| 79 | if (! res) { |
---|
| 80 | g_warning ("Unable to run command %s: %s", command, error->message); |
---|
| 81 | return FALSE; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | if (kill (pid, 0) < 0) { |
---|
| 85 | g_warning ("at-spi-registryd not running"); |
---|
| 86 | return FALSE; |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | return TRUE; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | static GdkFilterReturn |
---|
| 93 | filter_watch (GdkXEvent *xevent, |
---|
| 94 | GdkEvent *event, |
---|
| 95 | gpointer data) |
---|
| 96 | { |
---|
| 97 | XEvent *xev = (XEvent *)xevent; |
---|
| 98 | |
---|
| 99 | if (xev->xany.type == PropertyNotify |
---|
| 100 | && xev->xproperty.atom == AT_SPI_IOR) { |
---|
| 101 | gtk_main_quit (); |
---|
| 102 | |
---|
| 103 | return GDK_FILTER_REMOVE; |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | return GDK_FILTER_CONTINUE; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | static gboolean |
---|
| 110 | filter_timeout (gpointer data) |
---|
| 111 | { |
---|
| 112 | g_warning ("The accessibility registry was not found."); |
---|
| 113 | |
---|
| 114 | gtk_main_quit (); |
---|
| 115 | |
---|
| 116 | return FALSE; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | static void |
---|
| 120 | assistive_registry_start (void) |
---|
| 121 | { |
---|
| 122 | GdkWindow *root; |
---|
| 123 | guint tid; |
---|
| 124 | |
---|
| 125 | root = gdk_get_default_root_window (); |
---|
| 126 | |
---|
| 127 | if ( ! AT_SPI_IOR) { |
---|
| 128 | AT_SPI_IOR = XInternAtom (GDK_DISPLAY (), "AT_SPI_IOR", False); |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | gdk_window_set_events (root, GDK_PROPERTY_CHANGE_MASK); |
---|
| 132 | |
---|
| 133 | if ( ! assistive_registry_launch ()) { |
---|
| 134 | g_warning ("The accessibility registry could not be started."); |
---|
| 135 | return; |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | gdk_window_add_filter (root, filter_watch, NULL); |
---|
| 139 | tid = g_timeout_add_seconds (5, filter_timeout, NULL); |
---|
| 140 | |
---|
| 141 | gtk_main (); |
---|
| 142 | |
---|
| 143 | gdk_window_remove_filter (root, filter_watch, NULL); |
---|
| 144 | g_source_remove (tid); |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | static void |
---|
| 148 | at_set_gtk_modules (void) |
---|
| 149 | { |
---|
| 150 | GSList *modules_list; |
---|
| 151 | GSList *l; |
---|
| 152 | const char *old; |
---|
| 153 | char **modules; |
---|
| 154 | gboolean found_gail; |
---|
| 155 | gboolean found_atk_bridge; |
---|
| 156 | int n; |
---|
| 157 | |
---|
| 158 | n = 0; |
---|
| 159 | modules_list = NULL; |
---|
| 160 | found_gail = FALSE; |
---|
| 161 | found_atk_bridge = FALSE; |
---|
| 162 | |
---|
| 163 | if ((old = g_getenv ("GTK_MODULES")) != NULL) { |
---|
| 164 | modules = g_strsplit (old, ":", -1); |
---|
| 165 | for (n = 0; modules[n]; n++) { |
---|
| 166 | if (!strcmp (modules[n], "gail")) { |
---|
| 167 | found_gail = TRUE; |
---|
| 168 | } else if (!strcmp (modules[n], "atk-bridge")) { |
---|
| 169 | found_atk_bridge = TRUE; |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | modules_list = g_slist_prepend (modules_list, modules[n]); |
---|
| 173 | modules[n] = NULL; |
---|
| 174 | } |
---|
| 175 | g_free (modules); |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | if (!found_gail) { |
---|
| 179 | modules_list = g_slist_prepend (modules_list, "gail"); |
---|
| 180 | ++n; |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | if (!found_atk_bridge) { |
---|
| 184 | modules_list = g_slist_prepend (modules_list, "atk-bridge"); |
---|
| 185 | ++n; |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | modules = g_new (char *, n + 1); |
---|
| 189 | modules[n--] = NULL; |
---|
| 190 | for (l = modules_list; l; l = l->next) { |
---|
| 191 | modules[n--] = g_strdup (l->data); |
---|
| 192 | } |
---|
| 193 | |
---|
| 194 | g_setenv ("GTK_MODULES", g_strjoinv (":", modules), TRUE); |
---|
| 195 | g_strfreev (modules); |
---|
| 196 | g_slist_free (modules_list); |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | static void |
---|
| 200 | load_a11y (void) |
---|
| 201 | { |
---|
| 202 | const char *env_a_t_support; |
---|
| 203 | gboolean a_t_support; |
---|
| 204 | GConfClient *gconf_client; |
---|
| 205 | |
---|
| 206 | gconf_client = gconf_client_get_default (); |
---|
| 207 | |
---|
| 208 | env_a_t_support = g_getenv ("GNOME_ACCESSIBILITY"); |
---|
| 209 | if (env_a_t_support) { |
---|
| 210 | a_t_support = atoi (env_a_t_support); |
---|
| 211 | } else { |
---|
| 212 | a_t_support = gconf_client_get_bool (gconf_client, ACCESSIBILITY_KEY, NULL); |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | if (a_t_support) { |
---|
| 216 | assistive_registry_start (); |
---|
| 217 | at_set_gtk_modules (); |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | g_object_unref (gconf_client); |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | int |
---|
| 224 | main (int argc, char *argv[]) |
---|
| 225 | { |
---|
| 226 | GdmChooserSession *session; |
---|
| 227 | gboolean res; |
---|
| 228 | GError *error; |
---|
| 229 | |
---|
| 230 | bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); |
---|
| 231 | bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); |
---|
| 232 | textdomain (GETTEXT_PACKAGE); |
---|
| 233 | |
---|
| 234 | setlocale (LC_ALL, ""); |
---|
| 235 | |
---|
| 236 | gdm_set_fatal_warnings_if_unstable (); |
---|
| 237 | |
---|
| 238 | g_type_init (); |
---|
| 239 | |
---|
| 240 | gdm_log_init (); |
---|
| 241 | gdm_log_set_debug (TRUE); |
---|
| 242 | |
---|
| 243 | g_debug ("Chooser for display %s xauthority:%s", |
---|
| 244 | g_getenv ("DISPLAY"), |
---|
| 245 | g_getenv ("XAUTHORITY")); |
---|
| 246 | |
---|
| 247 | gdk_init (&argc, &argv); |
---|
| 248 | |
---|
| 249 | load_a11y (); |
---|
| 250 | |
---|
| 251 | gtk_init (&argc, &argv); |
---|
| 252 | |
---|
| 253 | session = gdm_chooser_session_new (); |
---|
| 254 | if (session == NULL) { |
---|
| 255 | g_critical ("Unable to create chooser session"); |
---|
| 256 | exit (1); |
---|
| 257 | } |
---|
| 258 | |
---|
| 259 | error = NULL; |
---|
| 260 | res = gdm_chooser_session_start (session, &error); |
---|
| 261 | if (! res) { |
---|
| 262 | g_warning ("Unable to start chooser session: %s", error->message); |
---|
| 263 | g_error_free (error); |
---|
| 264 | exit (1); |
---|
| 265 | } |
---|
| 266 | |
---|
| 267 | gtk_main (); |
---|
| 268 | |
---|
| 269 | if (session != NULL) { |
---|
| 270 | g_object_unref (session); |
---|
| 271 | } |
---|
| 272 | |
---|
| 273 | return 0; |
---|
| 274 | } |
---|