~ubuntu-branches/ubuntu/karmic/xfce4-session/karmic

« back to all changes in this revision

Viewing changes to xfce4-session/xfsm-compat-gnome.c

  • Committer: Bazaar Package Importer
  • Author(s): Yves-Alexis Perez
  • Date: 2005-11-06 22:01:12 UTC
  • mto: (4.1.1 lenny) (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20051106220112-5rusox237ymjghsp
Tags: upstream-4.2.3
ImportĀ upstreamĀ versionĀ 4.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: xfsm-compat-gnome.c 4714 2004-11-02 16:52:58Z benny $ */
 
2
/*-
 
3
 * Copyright (c) 2004 Benedikt Meurer <benny@xfce.org>
 
4
 * All rights reserved.
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2, or (at your option)
 
9
 * any later version.
 
10
 *                                                                              
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *                                                                              
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
19
 * 02111-1307, USA.
 
20
 *
 
21
 * Most parts of this file where taken from gnome-session.
 
22
 */
 
23
 
 
24
#ifdef HAVE_CONFIG_H
 
25
#include <config.h>
 
26
#endif
 
27
 
 
28
#ifdef HAVE_SYS_TYPES_H
 
29
#include <sys/types.h>
 
30
#endif
 
31
#ifdef HAVE_SYS_WAIT_H
 
32
#include <sys/wait.h>
 
33
#endif
 
34
 
 
35
#ifdef HAVE_SIGNAL_H
 
36
#include <signal.h>
 
37
#endif
 
38
#ifdef HAVE_STDLIB_H
 
39
#include <stdlib.h>
 
40
#endif
 
41
#ifdef HAVE_STRING_H
 
42
#include <string.h>
 
43
#endif
 
44
#ifdef HAVE_UNISTD_H
 
45
#include <unistd.h>
 
46
#endif
 
47
 
 
48
#include <X11/Xatom.h>
 
49
#include <X11/Xlib.h>
 
50
 
 
51
#include <gdk/gdkx.h>
 
52
 
 
53
#include <libxfce4util/libxfce4util.h>
 
54
 
 
55
#ifdef HAVE_GCONF
 
56
#include <libgnome/libgnome.h>
 
57
#include <gconf/gconf-client.h>
 
58
#endif
 
59
 
 
60
#include <xfce4-session/xfsm-compat-gnome.h>
 
61
 
 
62
 
 
63
#ifdef HAVE_GCONF
 
64
#define ACCESSIBILITY_KEY "/desktop/gnome/interface/accessibility"
 
65
#define AT_STARTUP_KEY    "/desktop/gnome/accessibility/startup/exec_ats"
 
66
 
 
67
static GConfClient *gnome_conf_client = NULL;
 
68
#endif
 
69
 
 
70
 
 
71
static pid_t gnome_keyring_daemon_pid = 0;
 
72
static Window gnome_smproxy_window = None;
 
73
 
 
74
 
 
75
static void
 
76
gnome_keyring_daemon_startup (void)
 
77
{
 
78
  GError *error = NULL;
 
79
  gchar  *sout;
 
80
  gchar **lines;
 
81
  gint    status;
 
82
  long    pid;
 
83
  gchar  *pid_str;
 
84
  gchar  *end;
 
85
  
 
86
  // FIXME: use async spawn!
 
87
  g_spawn_command_line_sync ("gnome-keyring-daemon",
 
88
                             &sout, NULL, &status, &error);
 
89
 
 
90
  if (error != NULL)
 
91
    {
 
92
      g_printerr ("Failed to run gnome-keyring-daemon: %s\n",
 
93
                  error->message);
 
94
      g_error_free (error);
 
95
    }
 
96
  else
 
97
    {
 
98
      if (WIFEXITED (status) && WEXITSTATUS (status) == 0 && sout != NULL)
 
99
        {
 
100
          lines = g_strsplit (sout, "\n", 3);
 
101
 
 
102
          if (lines[0] != NULL && lines[1] != NULL
 
103
              && g_str_has_prefix (lines[1], "GNOME_KEYRING_PID="))
 
104
          {
 
105
            pid_str = lines[1] + strlen ("GNOME_KEYRING_PID=");
 
106
            pid = strtol (pid_str, &end, 10);
 
107
 
 
108
            if (end != pid_str)
 
109
              {
 
110
                gnome_keyring_daemon_pid = pid;
 
111
                xfce_putenv (lines[0]);
 
112
              }
 
113
          }
 
114
 
 
115
          g_strfreev (lines);
 
116
        }
 
117
      else
 
118
        {
 
119
          /* daemon failed for some reason */
 
120
          g_printerr ("gnome-keyring-daemon failed to start correctly, "
 
121
                      "exit code: %d\n", WEXITSTATUS (status));
 
122
        }
 
123
      
 
124
      g_free (sout);
 
125
    }
 
126
}
 
127
 
 
128
static void
 
129
gnome_keyring_daemon_shutdown (void)
 
130
{
 
131
  if (gnome_keyring_daemon_pid != 0)
 
132
    {
 
133
      kill (gnome_keyring_daemon_pid, SIGTERM);
 
134
      gnome_keyring_daemon_pid = 0;
 
135
    }
 
136
}
 
137
 
 
138
 
 
139
#ifdef HAVE_GCONF
 
140
static void
 
141
gnome_ast_startup (void)
 
142
{
 
143
  GError *error = NULL;
 
144
  GSList *list;
 
145
  GSList *lp;
 
146
  gchar  *path;
 
147
 
 
148
  list = gconf_client_get_list (gnome_conf_client, AT_STARTUP_KEY,
 
149
                                GCONF_VALUE_STRING, &error);
 
150
  
 
151
  if (error != NULL)
 
152
    {
 
153
      g_warning ("Failed to query value of " AT_STARTUP_KEY ": %s",
 
154
                 error->message);
 
155
      g_error_free (error);
 
156
    }
 
157
  else
 
158
    {
 
159
      for (lp = list; lp != NULL; lp = lp->next)
 
160
        {
 
161
          path = g_find_program_in_path ((const gchar *) lp->data);
 
162
          if (path != NULL)
 
163
            {
 
164
              g_spawn_command_line_async (path, &error);
 
165
              if (error != NULL)
 
166
                {
 
167
                  g_warning ("Failed to execute assistive helper %s: %s",
 
168
                             path, error->message);
 
169
                  g_error_free (error);
 
170
                }
 
171
              else
 
172
                {
 
173
                  /* give it some time to fire up */
 
174
                  g_usleep (50 * 1000);
 
175
                }
 
176
              g_free (path);
 
177
            }
 
178
          g_free (lp->data);
 
179
        }
 
180
      g_slist_free (list);
 
181
    }
 
182
}
 
183
#endif
 
184
 
 
185
 
 
186
static void
 
187
xfsm_compat_gnome_smproxy_startup (void)
 
188
{
 
189
  Atom gnome_sm_proxy;
 
190
  Display *dpy;
 
191
  Window root;
 
192
 
 
193
  gdk_error_trap_push ();
 
194
 
 
195
  /* Set GNOME_SM_PROXY property, since some apps (like OOo) seem to require
 
196
   * it to behave properly. Thanks to Jasper/Francois for reporting this.
 
197
   * This has another advantage, since it prevents people from running
 
198
   * gnome-smproxy in xfce4, which would cause trouble otherwise.
 
199
   */
 
200
  dpy = gdk_display;
 
201
  root = RootWindow (dpy, 0);
 
202
  
 
203
  if (gnome_smproxy_window != None)
 
204
    XDestroyWindow (dpy, gnome_smproxy_window);
 
205
  
 
206
  gnome_sm_proxy = XInternAtom (dpy, "GNOME_SM_PROXY", False);
 
207
  gnome_smproxy_window = XCreateSimpleWindow (dpy, root, 1, 1, 1, 1, 0, 0, 0);
 
208
  
 
209
  XChangeProperty (dpy, gnome_smproxy_window, gnome_sm_proxy,
 
210
                   XA_CARDINAL, 32, PropModeReplace,
 
211
                   (unsigned char *) (void *) &gnome_smproxy_window, 1);
 
212
  XChangeProperty (dpy, root, gnome_sm_proxy,
 
213
                   XA_CARDINAL, 32, PropModeReplace,
 
214
                   (unsigned char *) (void *) &gnome_smproxy_window, 1);
 
215
 
 
216
  XSync (dpy, False);
 
217
 
 
218
  gdk_error_trap_pop ();
 
219
}
 
220
 
 
221
 
 
222
static void
 
223
xfsm_compat_gnome_smproxy_shutdown (void)
 
224
{
 
225
  gdk_error_trap_push ();
 
226
 
 
227
  if (gnome_smproxy_window != None)
 
228
    {
 
229
      XDestroyWindow (gdk_display, gnome_smproxy_window);
 
230
      XSync (gdk_display, False);
 
231
      gnome_smproxy_window = None;
 
232
    }
 
233
 
 
234
  gdk_error_trap_pop ();
 
235
}
 
236
 
 
237
 
 
238
void
 
239
xfsm_compat_gnome_startup (XfsmSplashScreen *splash)
 
240
{
 
241
  xfsm_compat_gnome_smproxy_startup ();
 
242
 
 
243
  /* fire up the keyring daemon */
 
244
  if (G_LIKELY (splash != NULL))
 
245
    xfsm_splash_screen_next (splash, _("Starting The Gnome Keyring Daemon"));
 
246
  gnome_keyring_daemon_startup ();
 
247
 
 
248
#ifdef HAVE_GCONF
 
249
  /* connect to the GConf daemon */
 
250
  gnome_conf_client = gconf_client_get_default ();
 
251
  if (gnome_conf_client != NULL)
 
252
    {
 
253
      if (gconf_client_get_bool (gnome_conf_client, ACCESSIBILITY_KEY, NULL))
 
254
        {
 
255
          if (G_LIKELY (splash != NULL))
 
256
            {
 
257
              xfsm_splash_screen_next (splash, _("Starting Gnome Assistive Technologies"));
 
258
            }
 
259
 
 
260
          gnome_ast_startup ();
 
261
        }
 
262
    }
 
263
#endif
 
264
}
 
265
 
 
266
 
 
267
void
 
268
xfsm_compat_gnome_shutdown (void)
 
269
{
 
270
  GError *error = NULL;
 
271
  gint    status;
 
272
 
 
273
  /* shutdown the keyring daemon */
 
274
  gnome_keyring_daemon_shutdown ();
 
275
 
 
276
#ifdef HAVE_GCONF
 
277
  if (gnome_conf_client != NULL)
 
278
    {
 
279
      g_object_unref (G_OBJECT (gnome_conf_client));
 
280
      gnome_conf_client = NULL;
 
281
    }
 
282
#endif
 
283
 
 
284
  /* shutdown the GConf daemon */
 
285
  if (!g_spawn_command_line_sync ("gconftool-2 --shutdown", NULL,
 
286
                                  NULL, &status, &error))
 
287
    {
 
288
      g_warning ("Failed to shutdown the GConf daemon on logout: %s",
 
289
                 error->message);
 
290
      g_error_free (error);
 
291
    }
 
292
  else if (status != 0)
 
293
    {
 
294
      g_warning ("Failed to shutdown the GConf daemon on logout: "
 
295
                 "gconftool-2 returned status %d", status);
 
296
    }
 
297
 
 
298
  xfsm_compat_gnome_smproxy_shutdown ();
 
299
}
 
300