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
This commit is contained in:
Florian Müllner 2012-05-18 03:52:57 +02:00
parent e49b94658c
commit ecff2fa2b7
3 changed files with 71 additions and 6 deletions

View File

@ -80,6 +80,12 @@ function modeExists(mode) {
return modes.indexOf(mode) != -1; 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({ const SessionMode = new Lang.Class({
Name: 'SessionMode', Name: 'SessionMode',

View File

@ -93,7 +93,8 @@ gnome_shell_cflags = \
-DGNOME_SHELL_LIBEXECDIR=\"$(libexecdir)\" \ -DGNOME_SHELL_LIBEXECDIR=\"$(libexecdir)\" \
-DGNOME_SHELL_DATADIR=\"$(pkgdatadir)\" \ -DGNOME_SHELL_DATADIR=\"$(pkgdatadir)\" \
-DGNOME_SHELL_PKGLIBDIR=\"$(pkglibdir)\" \ -DGNOME_SHELL_PKGLIBDIR=\"$(pkglibdir)\" \
-DJSDIR=\"$(pkgdatadir)/js\" -DJSDIR=\"$(pkgdatadir)/js\" \
-DMUTTER_TYPELIB_DIR=\"$(MUTTER_TYPELIB_DIR)\"
privlibdir = $(pkglibdir) privlibdir = $(pkglibdir)
privlib_LTLIBRARIES = libgnome-shell.la libgnome-shell-js.la privlib_LTLIBRARIES = libgnome-shell.la libgnome-shell-js.la

View File

@ -28,6 +28,8 @@
#include "shell-perf-log.h" #include "shell-perf-log.h"
#include "st.h" #include "st.h"
#include <jsapi.h>
extern GType gnome_shell_plugin_get_type (void); extern GType gnome_shell_plugin_get_type (void);
#define SHELL_DBUS_SERVICE "org.gnome.Shell" #define SHELL_DBUS_SERVICE "org.gnome.Shell"
@ -175,6 +177,18 @@ shell_prefs_init (void)
OVERRIDES_SCHEMA); OVERRIDES_SCHEMA);
} }
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 static void
malloc_statistics_callback (ShellPerfLog *perf_log, malloc_statistics_callback (ShellPerfLog *perf_log,
gpointer data) gpointer data)
@ -240,6 +254,48 @@ default_log_handler (const char *log_domain,
g_log_default_handler (log_domain, log_level, message, data); 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 static gboolean
print_version (const gchar *option_name, print_version (const gchar *option_name,
const gchar *value, const gchar *value,
@ -269,6 +325,12 @@ GOptionEntry gnome_shell_options[] = {
N_("Use a specific mode, e.g. \"gdm\" for login screen"), N_("Use a specific mode, e.g. \"gdm\" for login screen"),
"MODE" "MODE"
}, },
{
"list-modes", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
list_modes,
N_("List possible modes"),
NULL
},
{ NULL } { NULL }
}; };
@ -315,11 +377,7 @@ main (int argc, char **argv)
shell_a11y_init (); shell_a11y_init ();
shell_perf_log_init (); shell_perf_log_init ();
shell_prefs_init (); shell_prefs_init ();
shell_introspection_init ();
g_irepository_prepend_search_path (GNOME_SHELL_PKGLIBDIR);
#if HAVE_BLUETOOTH
g_irepository_prepend_search_path (BLUETOOTH_DIR);
#endif
/* Turn on telepathy-glib debugging but filter it out in /* Turn on telepathy-glib debugging but filter it out in
* default_log_handler. This handler also exposes all the logs over D-Bus * default_log_handler. This handler also exposes all the logs over D-Bus