~ubuntu-branches/debian/jessie/gnome-shell/jessie

« back to all changes in this revision

Viewing changes to src/shell-global.c

  • Committer: Bazaar Package Importer
  • Author(s): Emilio Pozuelo Monfort
  • Date: 2011-03-16 21:47:27 UTC
  • mto: (18.4.1 precise-proposed) (1.4.3)
  • mto: This revision was merged to the branch mainline in revision 19.
  • Revision ID: james.westby@ubuntu.com-20110316214727-fgahz9dd4ss0bxya
Tags: upstream-2.91.91
ImportĀ upstreamĀ versionĀ 2.91.91

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
#include "config.h"
4
4
 
5
 
#include "shell-global-private.h"
6
 
#include "shell-enum-types.h"
7
 
#include "shell-perf-log.h"
8
 
#include "shell-window-tracker.h"
9
 
#include "shell-marshal.h"
10
 
#include "shell-wm.h"
11
 
#include "st.h"
12
 
 
13
 
#include "display.h"
14
 
#include "util.h"
15
 
#include <clutter/glx/clutter-glx.h>
16
 
#include <clutter/x11/clutter-x11.h>
17
 
#include <gdk/gdkx.h>
18
5
#include <dirent.h>
19
6
#include <errno.h>
20
7
#include <fcntl.h>
 
8
#include <math.h>
21
9
#include <stdlib.h>
22
10
#include <string.h>
23
11
#include <unistd.h>
 
12
#ifdef HAVE_SYS_RESOURCE_H
 
13
#include <sys/resource.h>
 
14
#endif
 
15
 
 
16
#include <X11/extensions/Xfixes.h>
 
17
#include <canberra.h>
 
18
#include <clutter/glx/clutter-glx.h>
 
19
#include <clutter/x11/clutter-x11.h>
24
20
#include <dbus/dbus-glib.h>
 
21
#include <gdk/gdkx.h>
25
22
#include <gio/gio.h>
26
 
#include <math.h>
27
 
#include <X11/extensions/Xfixes.h>
28
23
#include <gjs/gjs-module.h>
29
 
#include <canberra.h>
30
 
#include <libxml/xmlmemory.h>
31
24
#include <libxml/parser.h>
32
25
#include <libxml/tree.h>
33
 
#ifdef HAVE_SYS_RESOURCE_H
34
 
#include <sys/resource.h>
35
 
#endif
 
26
#include <libxml/xmlmemory.h>
 
27
#include <meta/display.h>
 
28
#include <meta/util.h>
 
29
 
 
30
#include "shell-enum-types.h"
 
31
#include "shell-global-private.h"
36
32
#include "shell-jsapi-compat-private.h"
37
 
 
38
 
#define SHELL_DBUS_SERVICE "org.gnome.Shell"
39
 
#define MAGNIFIER_DBUS_SERVICE "org.gnome.Magnifier"
 
33
#include "shell-marshal.h"
 
34
#include "shell-perf-log.h"
 
35
#include "shell-window-tracker.h"
 
36
#include "shell-wm.h"
 
37
#include "st.h"
40
38
 
41
39
static void grab_notify (GtkWidget *widget, gboolean is_grab, gpointer user_data);
42
40
 
206
204
shell_global_init (ShellGlobal *global)
207
205
{
208
206
  const char *datadir = g_getenv ("GNOME_SHELL_DATADIR");
209
 
  char *imagedir;
 
207
  const char *shell_js = g_getenv("GNOME_SHELL_JS");
 
208
  char *imagedir, **search_path;
210
209
 
211
210
  if (!datadir)
212
211
    datadir = GNOME_SHELL_DATADIR;
245
244
  ca_context_create (&global->sound_context);
246
245
  ca_context_change_props (global->sound_context, CA_PROP_APPLICATION_NAME, PACKAGE_NAME, CA_PROP_APPLICATION_ID, "org.gnome.Shell", NULL);
247
246
  ca_context_open (global->sound_context);
 
247
 
 
248
  if (!shell_js)
 
249
    shell_js = JSDIR;
 
250
  search_path = g_strsplit (shell_js, ":", -1);
 
251
  global->js_context = g_object_new (GJS_TYPE_CONTEXT,
 
252
                                     "search-path", search_path,
 
253
                                     "js-version", "1.8",
 
254
                                     NULL);
 
255
  g_strfreev (search_path);
248
256
}
249
257
 
250
258
static void
794
802
  global->focus_manager = st_focus_manager_get_for_stage (CLUTTER_STAGE (stage));
795
803
}
796
804
 
797
 
void
798
 
_shell_global_set_gjs_context (ShellGlobal *global,
799
 
                               GjsContext  *context)
 
805
GjsContext *
 
806
_shell_global_get_gjs_context (ShellGlobal *global)
800
807
{
801
 
  global->js_context = context;
 
808
  return global->js_context;
802
809
}
803
810
 
804
811
/**
1231
1238
  gjs_context_maybe_gc (global->js_context);
1232
1239
}
1233
1240
 
1234
 
void
1235
 
shell_global_grab_dbus_service (ShellGlobal *global)
1236
 
{
1237
 
  GError *error = NULL;
1238
 
  DBusGConnection *session;
1239
 
  DBusGProxy *bus;
1240
 
  guint32 request_name_result;
1241
 
  
1242
 
  session = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
1243
 
  
1244
 
  bus = dbus_g_proxy_new_for_name (session,
1245
 
                                   DBUS_SERVICE_DBUS,
1246
 
                                   DBUS_PATH_DBUS,
1247
 
                                   DBUS_INTERFACE_DBUS);
1248
 
  
1249
 
  if (!dbus_g_proxy_call (bus, "RequestName", &error,
1250
 
                          G_TYPE_STRING, SHELL_DBUS_SERVICE,
1251
 
                          G_TYPE_UINT, 0,
1252
 
                          G_TYPE_INVALID,
1253
 
                          G_TYPE_UINT, &request_name_result,
1254
 
                          G_TYPE_INVALID)) 
1255
 
    {
1256
 
      g_print ("failed to acquire org.gnome.Shell: %s\n", error->message);
1257
 
      /* If we somehow got started again, it's not an error to be running
1258
 
       * already.  So just exit 0.
1259
 
       */
1260
 
      exit (0);  
1261
 
    }
1262
 
 
1263
 
  /* Also grab org.gnome.Panel to replace any existing panel process,
1264
 
   * unless a special environment variable is passed.  The environment
1265
 
   * variable is used by the gnome-shell (no --replace) launcher in
1266
 
   * Xephyr */
1267
 
  if (!g_getenv ("GNOME_SHELL_NO_REPLACE"))
1268
 
    {
1269
 
      if (!dbus_g_proxy_call (bus, "RequestName", &error, G_TYPE_STRING,
1270
 
                              "org.gnome.Panel", G_TYPE_UINT,
1271
 
                              DBUS_NAME_FLAG_REPLACE_EXISTING | DBUS_NAME_FLAG_DO_NOT_QUEUE,
1272
 
                              G_TYPE_INVALID, G_TYPE_UINT,
1273
 
                              &request_name_result, G_TYPE_INVALID))
1274
 
        {
1275
 
          g_print ("failed to acquire org.gnome.Panel: %s\n", error->message);
1276
 
          exit (1);
1277
 
        }
1278
 
    }
1279
 
 
1280
 
  /* ...and the org.gnome.Magnifier service.
1281
 
   */
1282
 
  if (!dbus_g_proxy_call (bus, "RequestName", &error,
1283
 
                          G_TYPE_STRING, MAGNIFIER_DBUS_SERVICE,
1284
 
                          G_TYPE_UINT, 0,
1285
 
                          G_TYPE_INVALID,
1286
 
                          G_TYPE_UINT, &request_name_result,
1287
 
                          G_TYPE_INVALID))
1288
 
    {
1289
 
      g_print ("failed to acquire %s: %s\n", MAGNIFIER_DBUS_SERVICE, error->message);
1290
 
      /* Failing to acquire the magnifer service is not fatal.  Log the error,
1291
 
       * but keep going. */
1292
 
    }
1293
 
  g_object_unref (bus);
1294
 
}
1295
 
 
1296
1241
static void
1297
1242
grab_notify (GtkWidget *widget, gboolean was_grabbed, gpointer user_data)
1298
1243
{
2049
1994
                                       shell_global_get_tp_contacts_cb,
2050
1995
                                       callback, NULL, NULL);
2051
1996
}
 
1997
 
 
1998
/**
 
1999
 * shell_global_launch_calendar_server:
 
2000
 * @global: The #ShellGlobal.
 
2001
 *
 
2002
 * Launch the gnome-shell-calendar-server helper.
 
2003
 */
 
2004
void
 
2005
shell_global_launch_calendar_server (ShellGlobal *global)
 
2006
{
 
2007
  const gchar *bin_dir;
 
2008
  gchar *calendar_server_exe;
 
2009
  GError *error;
 
2010
  gchar *argv[2];
 
2011
  gint child_standard_input;
 
2012
 
 
2013
  /* launch calendar-server */
 
2014
  bin_dir = g_getenv ("GNOME_SHELL_BINDIR");
 
2015
  if (bin_dir != NULL)
 
2016
    calendar_server_exe = g_strdup_printf ("%s/gnome-shell-calendar-server", bin_dir);
 
2017
  else
 
2018
    calendar_server_exe = g_strdup_printf (GNOME_SHELL_LIBEXECDIR "/gnome-shell-calendar-server");
 
2019
 
 
2020
  argv[0] = calendar_server_exe;
 
2021
  argv[1] = NULL;
 
2022
  error = NULL;
 
2023
  if (!g_spawn_async_with_pipes (NULL, /* working_directory */
 
2024
                                 argv,
 
2025
                                 NULL, /* envp */
 
2026
                                 0, /* GSpawnFlags */
 
2027
                                 NULL, /* child_setup */
 
2028
                                 NULL, /* user_data */
 
2029
                                 NULL, /* GPid *child_pid */
 
2030
                                 &child_standard_input,
 
2031
                                 NULL, /* gint *stdout */
 
2032
                                 NULL, /* gint *stderr */
 
2033
                                 &error))
 
2034
    {
 
2035
      g_warning ("Error launching `%s': %s (%s %d)",
 
2036
                 calendar_server_exe,
 
2037
                 error->message,
 
2038
                 g_quark_to_string (error->domain),
 
2039
                 error->code);
 
2040
      g_error_free (error);
 
2041
    }
 
2042
  /* Note that gnome-shell-calendar-server exits whenever its stdin
 
2043
   * file descriptor is HUP'ed. This means that whenever the the shell
 
2044
   * process exits or is being replaced, the calendar server is also
 
2045
   * exits...and if the shell is being replaced, a new copy of the
 
2046
   * calendar server is launched...
 
2047
   */
 
2048
 
 
2049
  g_free (calendar_server_exe);
 
2050
}