[gnome-shell] main: Add a --list-modes command line option



commit ecff2fa2b7baba8e608c0554f5662c3b3242cef2
Author: Florian MÃllner <fmuellner gnome org>
Date:   Fri May 18 03:52:57 2012 +0200

    main: Add a --list-modes command line option
    
    Add a command line option to list available modes, i.e. possible
    arguments for the --mode switch.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=676156

 js/ui/sessionMode.js |    6 ++++
 src/Makefile.am      |    3 +-
 src/main.c           |   68 ++++++++++++++++++++++++++++++++++++++++++++++---
 3 files changed, 71 insertions(+), 6 deletions(-)
---
diff --git a/js/ui/sessionMode.js b/js/ui/sessionMode.js
index dd36873..ab9c61b 100644
--- a/js/ui/sessionMode.js
+++ b/js/ui/sessionMode.js
@@ -80,6 +80,12 @@ function modeExists(mode) {
     return modes.indexOf(mode) != -1;
 }
 
+function listModes() {
+    let modes = Object.getOwnPropertyNames(_modes);
+    for (let i = 0; i < modes.length; i++)
+        print(modes[i]);
+}
+
 const SessionMode = new Lang.Class({
     Name: 'SessionMode',
 
diff --git a/src/Makefile.am b/src/Makefile.am
index dc5137e..8023794 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -93,7 +93,8 @@ gnome_shell_cflags =				\
 	-DGNOME_SHELL_LIBEXECDIR=\"$(libexecdir)\"	\
 	-DGNOME_SHELL_DATADIR=\"$(pkgdatadir)\"	\
 	-DGNOME_SHELL_PKGLIBDIR=\"$(pkglibdir)\" \
-	-DJSDIR=\"$(pkgdatadir)/js\"
+	-DJSDIR=\"$(pkgdatadir)/js\"		\
+	-DMUTTER_TYPELIB_DIR=\"$(MUTTER_TYPELIB_DIR)\"
 
 privlibdir = $(pkglibdir)
 privlib_LTLIBRARIES = libgnome-shell.la libgnome-shell-js.la
diff --git a/src/main.c b/src/main.c
index 97ad90a..1f20039 100644
--- a/src/main.c
+++ b/src/main.c
@@ -28,6 +28,8 @@
 #include "shell-perf-log.h"
 #include "st.h"
 
+#include <jsapi.h>
+
 extern GType gnome_shell_plugin_get_type (void);
 
 #define SHELL_DBUS_SERVICE "org.gnome.Shell"
@@ -176,6 +178,18 @@ shell_prefs_init (void)
 }
 
 static void
+shell_introspection_init (void)
+{
+
+  g_irepository_prepend_search_path (MUTTER_TYPELIB_DIR);
+  g_irepository_prepend_search_path (GNOME_SHELL_PKGLIBDIR);
+#if HAVE_BLUETOOTH
+  g_irepository_prepend_search_path (BLUETOOTH_DIR);
+#endif
+
+}
+
+static void
 malloc_statistics_callback (ShellPerfLog *perf_log,
                             gpointer      data)
 {
@@ -240,6 +254,48 @@ default_log_handler (const char     *log_domain,
     g_log_default_handler (log_domain, log_level, message, data);
 }
 
+static void
+shut_up (const char     *domain,
+         GLogLevelFlags  level,
+         const char     *message,
+         gpointer        user_data)
+{
+}
+
+static gboolean
+list_modes (const char  *option_name,
+            const char  *value,
+            gpointer     data,
+            GError     **error)
+{
+  ShellGlobal *global;
+  GjsContext *context;
+  const char *script;
+  int status;
+
+  /* Many of our imports require global to be set, so rather than
+   * tayloring our imports carefully here to avoid that dependency,
+   * we just set it.
+   * ShellGlobal has some GTK+ dependencies, so initialize GTK+; we
+   * don't really care if it fails though (e.g. when running from a tty),
+   * so we mute all warnings */
+  g_log_set_default_handler (shut_up, NULL);
+  gtk_init_check (NULL, NULL);
+
+  _shell_global_init (NULL);
+  global = shell_global_get ();
+  context = _shell_global_get_gjs_context (global);
+
+  shell_introspection_init ();
+
+  script = "imports.ui.environment.init();"
+           "imports.ui.sessionMode.listModes();";
+  if (!gjs_context_eval (context, script, -1, "<main>", &status, NULL))
+      g_message ("Retrieving list of available modes failed.");
+
+  exit (status);
+}
+
 static gboolean
 print_version (const gchar    *option_name,
                const gchar    *value,
@@ -269,6 +325,12 @@ GOptionEntry gnome_shell_options[] = {
     N_("Use a specific mode, e.g. \"gdm\" for login screen"),
     "MODE"
   },
+  {
+    "list-modes", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
+    list_modes,
+    N_("List possible modes"),
+    NULL
+  },
   { NULL }
 };
 
@@ -315,11 +377,7 @@ main (int argc, char **argv)
   shell_a11y_init ();
   shell_perf_log_init ();
   shell_prefs_init ();
-
-  g_irepository_prepend_search_path (GNOME_SHELL_PKGLIBDIR);
-#if HAVE_BLUETOOTH
-  g_irepository_prepend_search_path (BLUETOOTH_DIR);
-#endif
+  shell_introspection_init ();
 
   /* Turn on telepathy-glib debugging but filter it out in
    * default_log_handler. This handler also exposes all the logs over D-Bus



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]