int main (int argc, char **argv) { GtkWidget *window; GtkWidget *collection; GError *err; clock_t start, end; GtkWidget *notebook; int i; bindtextdomain (GETTEXT_PACKAGE, MARCO_LOCALEDIR); textdomain(GETTEXT_PACKAGE); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); run_position_expression_tests (); #if 0 run_position_expression_timings (); #endif gtk_init (&argc, &argv); if (g_getenv ("MARCO_DEBUG") != NULL) { meta_set_debugging (TRUE); meta_set_verbose (TRUE); } start = clock (); err = NULL; if (argc == 1) global_theme = meta_theme_load ("ClearlooksRe", &err); else if (argc == 2) global_theme = meta_theme_load (argv[1], &err); else { g_printerr (_("Usage: marco-theme-viewer [THEMENAME]\n")); exit (1); } end = clock (); if (global_theme == NULL) { g_printerr (_("Error loading theme: %s\n"), err->message); g_error_free (err); exit (1); } g_print (_("Loaded theme \"%s\" in %g seconds\n"), global_theme->name, (end - start) / (double) CLOCKS_PER_SEC); run_theme_benchmark (); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size (GTK_WINDOW (window), 350, 350); if (strcmp (global_theme->name, global_theme->readable_name)==0) gtk_window_set_title (GTK_WINDOW (window), global_theme->readable_name); else { /* The theme directory name is different from the name the theme * gives itself within its file. Display both, directory name first. */ gchar *title = g_strconcat (global_theme->name, " - ", global_theme->readable_name, NULL); gtk_window_set_title (GTK_WINDOW (window), title); g_free (title); } g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL); gtk_widget_realize (window); g_assert (window->style); g_assert (window->style->font_desc); notebook = gtk_notebook_new (); gtk_container_add (GTK_CONTAINER (window), notebook); collection = preview_collection (FONT_SIZE_NORMAL, window->style->font_desc); gtk_notebook_append_page (GTK_NOTEBOOK (notebook), collection, gtk_label_new (_("Normal Title Font"))); collection = preview_collection (FONT_SIZE_SMALL, window->style->font_desc); gtk_notebook_append_page (GTK_NOTEBOOK (notebook), collection, gtk_label_new (_("Small Title Font"))); collection = preview_collection (FONT_SIZE_LARGE, window->style->font_desc); gtk_notebook_append_page (GTK_NOTEBOOK (notebook), collection, gtk_label_new (_("Large Title Font"))); collection = previews_of_button_layouts (); gtk_notebook_append_page (GTK_NOTEBOOK (notebook), collection, gtk_label_new (_("Button Layouts"))); collection = benchmark_summary (); gtk_notebook_append_page (GTK_NOTEBOOK (notebook), collection, gtk_label_new (_("Benchmark"))); i = 0; while (i < (int) G_N_ELEMENTS (previews)) { /* preview widget likes to be realized before its size request. * it's lame that way. */ gtk_widget_realize (previews[i]); ++i; } gtk_widget_show_all (window); gtk_main (); return 0; }
/** * meta_init: (skip) * * Initialize muffin. Call this after meta_get_option_context() and * meta_plugin_manager_set_plugin_type(), and before meta_run(). */ void meta_init (void) { struct sigaction act; sigset_t empty_mask; GIOChannel *channel; sigemptyset (&empty_mask); act.sa_handler = SIG_IGN; act.sa_mask = empty_mask; act.sa_flags = 0; if (sigaction (SIGPIPE, &act, NULL) < 0) g_printerr ("Failed to register SIGPIPE handler: %s\n", g_strerror (errno)); #ifdef SIGXFSZ if (sigaction (SIGXFSZ, &act, NULL) < 0) g_printerr ("Failed to register SIGXFSZ handler: %s\n", g_strerror (errno)); #endif if (pipe (sigterm_pipe_fds) != 0) g_printerr ("Failed to create SIGTERM pipe: %s\n", g_strerror (errno)); channel = g_io_channel_unix_new (sigterm_pipe_fds[0]); g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL); g_io_add_watch (channel, G_IO_IN, (GIOFunc) on_sigterm, NULL); g_io_channel_set_close_on_unref (channel, TRUE); g_io_channel_unref (channel); act.sa_handler = &sigterm_handler; if (sigaction (SIGTERM, &act, NULL) < 0) g_printerr ("Failed to register SIGTERM handler: %s\n", g_strerror (errno)); if (g_getenv ("MUFFIN_VERBOSE")) meta_set_verbose (TRUE); if (g_getenv ("MUFFIN_DEBUG")) meta_set_debugging (TRUE); if (g_get_home_dir ()) if (chdir (g_get_home_dir ()) < 0) meta_warning ("Could not change to home directory %s.\n", g_get_home_dir ()); meta_print_self_identity (); #ifdef HAVE_INTROSPECTION g_irepository_prepend_search_path (MUFFIN_PKGLIBDIR); #endif meta_set_syncing (opt_sync || (g_getenv ("MUFFIN_SYNC") != NULL)); meta_select_display (opt_display_name); if (opt_replace_wm) meta_set_replace_current_wm (TRUE); if (opt_save_file && opt_client_id) meta_fatal ("Can't specify both SM save file and SM client id\n"); meta_main_loop = g_main_loop_new (NULL, FALSE); meta_ui_init (); /* * Clutter can only be initialized after the UI. */ meta_clutter_init (); const char *renderer = (const char *) glGetString (GL_RENDERER); if (strstr (renderer, "llvmpipe") || strstr (renderer, "Rasterizer") || strstr (renderer, "softpipe")) { /* Clutter envs not set, since they won't work after Clutter init */ g_setenv ("CINNAMON_SOFTWARE_RENDERING", "1", FALSE); g_setenv ("CINNAMON_SLOWDOWN_FACTOR", "0.0001", FALSE); g_setenv ("MUFFIN_NO_SHADOWS", "1", FALSE); meta_warning ("Software rendering detected: %s\n", renderer); } }
/** * meta_init: (skip) * * Initialize mutter. Call this after meta_get_option_context() and * meta_plugin_manager_set_plugin_type(), and before meta_run(). */ void meta_init (void) { struct sigaction act; sigset_t empty_mask; sigemptyset (&empty_mask); act.sa_handler = SIG_IGN; act.sa_mask = empty_mask; act.sa_flags = 0; if (sigaction (SIGPIPE, &act, NULL) < 0) g_printerr ("Failed to register SIGPIPE handler: %s\n", g_strerror (errno)); #ifdef SIGXFSZ if (sigaction (SIGXFSZ, &act, NULL) < 0) g_printerr ("Failed to register SIGXFSZ handler: %s\n", g_strerror (errno)); #endif g_unix_signal_add (SIGTERM, on_sigterm, NULL); if (g_getenv ("MUTTER_VERBOSE")) meta_set_verbose (TRUE); if (g_getenv ("MUTTER_DEBUG")) meta_set_debugging (TRUE); #if defined(CLUTTER_WINDOWING_EGL) && defined(HAVE_NATIVE_BACKEND) if (opt_display_server) clutter_set_windowing_backend (CLUTTER_WINDOWING_EGL); else #endif clutter_set_windowing_backend (CLUTTER_WINDOWING_X11); #ifdef HAVE_WAYLAND meta_set_is_wayland_compositor (opt_wayland); #endif if (g_get_home_dir ()) if (chdir (g_get_home_dir ()) < 0) meta_warning ("Could not change to home directory %s.\n", g_get_home_dir ()); meta_print_self_identity (); #ifdef HAVE_INTROSPECTION g_irepository_prepend_search_path (MUTTER_PKGLIBDIR); #endif #ifdef HAVE_WAYLAND if (meta_is_wayland_compositor ()) meta_wayland_pre_clutter_init (); #endif /* NB: When running as a hybrid wayland compositor we run our own headless X * server so the user can't control the X display to connect too. */ if (!meta_is_wayland_compositor ()) meta_select_display (opt_display_name); meta_clutter_init (); #ifdef HAVE_WAYLAND /* Bring up Wayland. This also launches Xwayland and sets DISPLAY as well... */ if (meta_is_wayland_compositor ()) meta_wayland_init (); #endif meta_set_syncing (opt_sync || (g_getenv ("MUTTER_SYNC") != NULL)); if (opt_replace_wm) meta_set_replace_current_wm (TRUE); if (opt_save_file && opt_client_id) meta_fatal ("Can't specify both SM save file and SM client id\n"); meta_main_loop = g_main_loop_new (NULL, FALSE); meta_ui_init (); meta_restart_init (); }
/** * meta_init: (skip) * * Initialize muffin. Call this after meta_get_option_context() and * meta_plugin_type_register(), and before meta_run(). */ void meta_init (void) { struct sigaction act; sigset_t empty_mask; GIOChannel *channel; g_type_init (); sigemptyset (&empty_mask); act.sa_handler = SIG_IGN; act.sa_mask = empty_mask; act.sa_flags = 0; if (sigaction (SIGPIPE, &act, NULL) < 0) g_printerr ("Failed to register SIGPIPE handler: %s\n", g_strerror (errno)); #ifdef SIGXFSZ if (sigaction (SIGXFSZ, &act, NULL) < 0) g_printerr ("Failed to register SIGXFSZ handler: %s\n", g_strerror (errno)); #endif if (pipe (sigterm_pipe_fds) != 0) g_printerr ("Failed to create SIGTERM pipe: %s\n", g_strerror (errno)); channel = g_io_channel_unix_new (sigterm_pipe_fds[0]); g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL); g_io_add_watch (channel, G_IO_IN, (GIOFunc) on_sigterm, NULL); g_io_channel_set_close_on_unref (channel, TRUE); g_io_channel_unref (channel); act.sa_handler = &sigterm_handler; if (sigaction (SIGTERM, &act, NULL) < 0) g_printerr ("Failed to register SIGTERM handler: %s\n", g_strerror (errno)); if (g_getenv ("MUFFIN_VERBOSE")) meta_set_verbose (TRUE); if (g_getenv ("MUFFIN_DEBUG")) meta_set_debugging (TRUE); if (g_get_home_dir ()) if (chdir (g_get_home_dir ()) < 0) meta_warning ("Could not change to home directory %s.\n", g_get_home_dir ()); meta_print_self_identity (); #ifdef HAVE_INTROSPECTION g_irepository_prepend_search_path (MUFFIN_PKGLIBDIR); #endif meta_set_syncing (opt_sync || (g_getenv ("MUFFIN_SYNC") != NULL)); meta_select_display (opt_display_name); if (opt_replace_wm) meta_set_replace_current_wm (TRUE); if (opt_save_file && opt_client_id) meta_fatal ("Can't specify both SM save file and SM client id\n"); meta_main_loop = g_main_loop_new (NULL, FALSE); meta_ui_init (); /* * Clutter can only be initialized after the UI. */ meta_clutter_init (); }
/** * This is where the story begins. It parses commandline options and * environment variables, sets up the screen, hands control off to * GTK, and cleans up afterwards. * * \param argc Number of arguments (as usual) * \param argv Array of arguments (as usual) * * \bug It's a bit long. It would be good to split it out into separate * functions. */ int main (int argc, char **argv) { struct sigaction act; sigset_t empty_mask; MetaArguments meta_args; const gchar *log_domains[] = { NULL, G_LOG_DOMAIN, "Gtk", "Gdk", "GLib", "Pango", "GLib-GObject", "GThread" }; guint i; GIOChannel *channel; if (setlocale (LC_ALL, "") == NULL) meta_warning ("Locale not understood by C library, internationalization will not work\n"); sigemptyset (&empty_mask); act.sa_handler = SIG_IGN; act.sa_mask = empty_mask; act.sa_flags = 0; if (sigaction (SIGPIPE, &act, NULL) < 0) g_printerr ("Failed to register SIGPIPE handler: %s\n", g_strerror (errno)); #ifdef SIGXFSZ if (sigaction (SIGXFSZ, &act, NULL) < 0) g_printerr ("Failed to register SIGXFSZ handler: %s\n", g_strerror (errno)); #endif if (pipe (sigterm_pipe_fds) != 0) g_printerr ("Failed to create SIGTERM pipe: %s\n", g_strerror (errno)); channel = g_io_channel_unix_new (sigterm_pipe_fds[0]); g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL); g_io_add_watch (channel, G_IO_IN, (GIOFunc) on_sigterm, NULL); g_io_channel_set_close_on_unref (channel, TRUE); g_io_channel_unref (channel); act.sa_handler = &sigterm_handler; if (sigaction (SIGTERM, &act, NULL) < 0) g_printerr ("Failed to register SIGTERM handler: %s\n", g_strerror (errno)); if (g_getenv ("METACITY_VERBOSE")) meta_set_verbose (TRUE); if (g_getenv ("METACITY_DEBUG")) meta_set_debugging (TRUE); if (g_get_home_dir ()) if (chdir (g_get_home_dir ()) < 0) meta_warning ("Could not change to home directory %s.\n", g_get_home_dir ()); meta_print_self_identity (); bindtextdomain (GETTEXT_PACKAGE, METACITY_LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); /* Parse command line arguments.*/ meta_parse_options (&argc, &argv, &meta_args); meta_set_syncing (meta_args.sync || (g_getenv ("METACITY_SYNC") != NULL)); if (meta_args.print_version) version (); meta_select_display (meta_args.display_name); if (meta_args.replace_wm) meta_set_replace_current_wm (TRUE); if (meta_args.save_file && meta_args.client_id) meta_fatal ("Can't specify both SM save file and SM client id\n"); meta_main_loop = g_main_loop_new (NULL, FALSE); meta_ui_init (&argc, &argv); /* must be after UI init so we can override GDK handlers */ meta_errors_init (); /* Load prefs */ meta_prefs_init (); meta_prefs_add_listener (prefs_changed_callback, NULL); #if 1 for (i=0; i<G_N_ELEMENTS(log_domains); i++) g_log_set_handler (log_domains[i], G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, log_handler, NULL); #endif if (g_getenv ("METACITY_G_FATAL_WARNINGS") != NULL) g_log_set_always_fatal (G_LOG_LEVEL_MASK); meta_ui_set_current_theme (meta_prefs_get_theme (), FALSE); /* Try to find some theme that'll work if the theme preference * doesn't exist. First try Simple (the default theme) then just * try anything in the themes directory. */ if (!meta_ui_have_a_theme ()) meta_ui_set_current_theme ("Simple", FALSE); if (!meta_ui_have_a_theme ()) { const char *dir_entry = NULL; GError *err = NULL; GDir *themes_dir = NULL; if (!(themes_dir = g_dir_open (METACITY_DATADIR"/themes", 0, &err))) { meta_fatal (_("Failed to scan themes directory: %s\n"), err->message); g_error_free (err); } else { while (((dir_entry = g_dir_read_name (themes_dir)) != NULL) && (!meta_ui_have_a_theme ())) { meta_ui_set_current_theme (dir_entry, FALSE); } g_dir_close (themes_dir); } } if (!meta_ui_have_a_theme ()) meta_fatal (_("Could not find a theme! Be sure %s exists and contains the usual themes.\n"), METACITY_DATADIR"/themes"); /* Connect to SM as late as possible - but before managing display, * or we might try to manage a window before we have the session * info */ if (!meta_args.disable_sm) { if (meta_args.client_id == NULL) { const gchar *desktop_autostart_id; desktop_autostart_id = g_getenv ("DESKTOP_AUTOSTART_ID"); if (desktop_autostart_id != NULL) meta_args.client_id = g_strdup (desktop_autostart_id); } /* Unset DESKTOP_AUTOSTART_ID in order to avoid child processes to * use the same client id. */ g_unsetenv ("DESKTOP_AUTOSTART_ID"); meta_session_init (meta_args.client_id, meta_args.save_file); } /* Free memory possibly allocated by the argument parsing which are * no longer needed. */ g_free (meta_args.save_file); g_free (meta_args.display_name); g_free (meta_args.client_id); if (meta_args.composite || meta_args.no_composite) meta_prefs_set_compositing_manager (meta_args.composite); if (meta_args.no_force_fullscreen) meta_prefs_set_force_fullscreen (FALSE); if (!meta_display_open ()) meta_exit (META_EXIT_ERROR); g_main_loop_run (meta_main_loop); meta_finalize (); if (meta_restart_after_quit) { GError *err; err = NULL; if (!g_spawn_async (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &err)) { meta_fatal (_("Failed to restart: %s\n"), err->message); g_error_free (err); /* not reached anyhow */ meta_exit_code = META_EXIT_ERROR; } } return meta_exit_code; }
/** * meta_init: (skip) * * Initialize mutter. Call this after meta_get_option_context() and * meta_plugin_manager_set_plugin_type(), and before meta_run(). */ void meta_init (void) { struct sigaction act; sigset_t empty_mask; ClutterSettings *clutter_settings; sigemptyset (&empty_mask); act.sa_handler = SIG_IGN; act.sa_mask = empty_mask; act.sa_flags = 0; if (sigaction (SIGPIPE, &act, NULL) < 0) g_printerr ("Failed to register SIGPIPE handler: %s\n", g_strerror (errno)); #ifdef SIGXFSZ if (sigaction (SIGXFSZ, &act, NULL) < 0) g_printerr ("Failed to register SIGXFSZ handler: %s\n", g_strerror (errno)); #endif g_unix_signal_add (SIGTERM, on_sigterm, NULL); if (g_getenv ("MUTTER_VERBOSE")) meta_set_verbose (TRUE); if (g_getenv ("MUTTER_DEBUG")) meta_set_debugging (TRUE); #if defined(CLUTTER_WINDOWING_EGL) && defined(HAVE_NATIVE_BACKEND) if (opt_display_server) clutter_set_windowing_backend (CLUTTER_WINDOWING_EGL); #endif meta_set_is_wayland_compositor (opt_wayland); if (g_get_home_dir ()) if (chdir (g_get_home_dir ()) < 0) meta_warning ("Could not change to home directory %s.\n", g_get_home_dir ()); meta_print_self_identity (); #ifdef HAVE_INTROSPECTION g_irepository_prepend_search_path (MUTTER_PKGLIBDIR); #endif if (meta_is_wayland_compositor ()) { /* NB: When running as a hybrid wayland compositor we run our own headless X * server so the user can't control the X display to connect too. */ meta_wayland_init (); } else meta_select_display (opt_display_name); meta_set_syncing (opt_sync || (g_getenv ("MUTTER_SYNC") != NULL)); if (opt_replace_wm) meta_set_replace_current_wm (TRUE); if (opt_save_file && opt_client_id) meta_fatal ("Can't specify both SM save file and SM client id\n"); meta_main_loop = g_main_loop_new (NULL, FALSE); meta_ui_init (); /* If we are running with wayland then we don't wait until we have * an X connection before initializing clutter we instead initialize * it earlier since we need to initialize the GL driver so the driver * can register any needed wayland extensions. */ if (!meta_is_wayland_compositor ()) { /* * Clutter can only be initialized after the UI. */ meta_clutter_init (); } meta_restart_init (); /* * XXX: We cannot handle high dpi scaling yet, so fix the scale to 1 * for now. */ clutter_settings = clutter_settings_get_default (); g_object_set (clutter_settings, "window-scaling-factor", 1, NULL); }