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); }
int main(int argc, char **argv) { GOptionContext *context; GError *error = NULL; ShellGlobal *global; GjsContext *js_context; char *script; const char *filename; char *title; gsize len; int code; gtk_init (&argc, &argv); clutter_x11_set_display (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ())); clutter_x11_disable_event_retrieval (); if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return 1; gdk_window_add_filter (NULL, event_filter, NULL); context = g_option_context_new (NULL); /* pass unknown through to the JS script */ g_option_context_set_ignore_unknown_options (context, TRUE); g_option_context_add_main_entries (context, entries, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) g_error ("option parsing failed: %s", error->message); setlocale (LC_ALL, ""); g_type_init (); _shell_global_init (NULL); global = shell_global_get (); js_context = _shell_global_get_gjs_context (global); /* prepare command line arguments */ if (!gjs_context_define_string_array (js_context, "ARGV", argc - 2, (const char**)argv + 2, &error)) { g_printerr ("Failed to defined ARGV: %s", error->message); exit (1); } if (command != NULL) { script = command; len = strlen (script); filename = "<command line>"; } else if (argc <= 1) { script = g_strdup ("const Console = imports.console; Console.interact();"); len = strlen (script); filename = "<stdin>"; } else /*if (argc >= 2)*/ { error = NULL; if (!g_file_get_contents (argv[1], &script, &len, &error)) { g_printerr ("%s\n", error->message); exit (1); } filename = argv[1]; } title = g_filename_display_basename (filename); g_set_prgname (title); g_free (title); #if HAVE_BLUETOOTH /* The module imports are all so intertwined that if the test * imports anything in js/ui, it will probably eventually end up * pulling in ui/status/bluetooth.js. So we need this. */ g_irepository_prepend_search_path (BLUETOOTH_DIR); #endif /* evaluate the script */ error = NULL; if (!gjs_context_eval (js_context, script, len, filename, &code, &error)) { g_free (script); g_printerr ("%s\n", error->message); exit (1); } g_free (script); exit (code); }