marco 1.29.1
Window manager
Loading...
Searching...
No Matches
main.c File Reference
View source

Program startup. More...

#include <config.h>
#include <glib/gi18n-lib.h>
#include "main.h"
#include "util.h"
#include "display-private.h"
#include "errors.h"
#include "keybindings.h"
#include "ui.h"
#include "session.h"
#include "prefs.h"
#include "core.h"
#include <glib-object.h>
#include <glib/gprintf.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <locale.h>
#include <time.h>
Include dependency graph for main.c:

Data Structures

struct  MetaArguments
 The set of possible options that can be set on Marco's command line. More...
 

Macros

#define _GNU_SOURCE
 
#define _XOPEN_SOURCE   /* for putenv() and some signal-related functions */
 
#define COMPOSITE_OPTS_FLAGS   G_OPTION_FLAG_HIDDEN
 

Functions

static void prefs_changed_callback (MetaPreference pref, gpointer data)
 Called on pref changes.
 
static void log_handler (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data)
 Prints log messages.
 
static void meta_print_compilation_info (void)
 Prints a list of which configure script options were used to build this copy of Marco.
 
static void meta_print_self_identity (void)
 Prints the version number, the current timestamp (not the build date), the locale, the character encoding, and a list of configure script options that were used to build this copy of Marco.
 
static void meta_parse_options (int *argc, char ***argv, MetaArguments *meta_args)
 Parses argc and argv and returns the arguments that Marco understands in meta_args.
 
static void meta_select_display (gchar *display_name)
 Selects which display Marco should use.
 
static void meta_finalize (void)
 
static void sigterm_handler (int signum)
 
static gboolean on_sigterm (GIOChannel *source, GIOCondition condition, gpointer user_data)
 
int main (int argc, char **argv)
 This is where the story begins.
 
void meta_quit (MetaExitCode code)
 Stops Marco.
 
void meta_restart (void)
 Restarts Marco.
 

Variables

static MetaExitCode meta_exit_code = META_EXIT_SUCCESS
 The exit code we'll return to our parent process when we eventually die.
 
static GMainLoop * meta_main_loop = NULL
 Handle on the main loop, so that we have an easy way of shutting Marco down.
 
static gboolean meta_restart_after_quit = FALSE
 If set, Marco will spawn an identical copy of itself immediately before quitting.
 
static int sigterm_pipe_fds [2] = { -1, -1 }
 

Detailed Description

Program startup.

Functions which parse the command-line arguments, create the display, kick everything off and then close down Marco when it's time to go.

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE

◆ _XOPEN_SOURCE

#define _XOPEN_SOURCE   /* for putenv() and some signal-related functions */

◆ COMPOSITE_OPTS_FLAGS

#define COMPOSITE_OPTS_FLAGS   G_OPTION_FLAG_HIDDEN

Function Documentation

◆ log_handler()

static void log_handler ( const gchar *  log_domain,
GLogLevelFlags  log_level,
const gchar *  message,
gpointer  user_data 
)
static

Prints log messages.

If Marco was compiled with backtrace support, also prints a backtrace (see meta_print_backtrace()).

Parameters
log_domainthe domain the error occurred in (we ignore this)
log_levelthe log level so that we can filter out less important messages
messagethe message to log
user_dataarbitrary data (we ignore this)

References meta_print_backtrace(), and meta_warning().

Referenced by main().

Here is the call graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

◆ meta_finalize()

static void meta_finalize ( void  )
static

References meta_display_close(), meta_get_display(), and meta_session_shutdown().

Referenced by main().

Here is the call graph for this function:

◆ meta_parse_options()

static void meta_parse_options ( int *  argc,
char ***  argv,
MetaArguments *  meta_args 
)
static

Parses argc and argv and returns the arguments that Marco understands in meta_args.

The strange call signature has to be written like it is so that g_option_context_parse() gets a chance to modify argc and argv.

Parameters
argcPointer to the number of arguments Marco was given
argvPointer to the array of arguments Marco was given
meta_argsThe result of parsing the arguments.

References MetaArguments::client_id, MetaArguments::composite, COMPOSITE_OPTS_FLAGS, MetaArguments::disable_sm, MetaArguments::display_name, FALSE, MetaArguments::no_composite, MetaArguments::no_force_fullscreen, MetaArguments::no_keybindings, NULL, MetaArguments::print_version, MetaArguments::replace_wm, MetaArguments::save_file, and MetaArguments::sync.

Referenced by main().

◆ meta_print_compilation_info()

static void meta_print_compilation_info ( void  )
static

Prints a list of which configure script options were used to build this copy of Marco.

This is actually always called on startup, but it's all no-op unless we're in verbose mode (see meta_set_verbose).

References META_DEBUG_XINERAMA.

Referenced by meta_print_self_identity().

◆ meta_print_self_identity()

static void meta_print_self_identity ( void  )
static

Prints the version number, the current timestamp (not the build date), the locale, the character encoding, and a list of configure script options that were used to build this copy of Marco.

This is actually always called on startup, but it's all no-op unless we're in verbose mode (see meta_set_verbose).

References meta_print_compilation_info(), and NULL.

Referenced by main().

Here is the call graph for this function:

◆ meta_quit()

void meta_quit ( MetaExitCode  code)

Stops Marco.

This tells the event loop to stop processing; it is rather dangerous to use this rather than meta_restart() because this will leave the user with no window manager. We generally do this only if, for example, the session manager asks us to; we assume the session manager knows what it's talking about.

Parameters
codeThe success or failure code to return to the calling process.

References meta_exit_code, and meta_main_loop.

Referenced by meta_display_close(), meta_restart(), and on_sigterm().

◆ meta_restart()

void meta_restart ( void  )

Restarts Marco.

In practice, this tells the event loop to stop processing, having first set the meta_restart_after_quit flag which tells Marco to spawn an identical copy of itself before quitting. This happens on receipt of a _MARCO_RESTART_MESSAGE client event.

References META_EXIT_SUCCESS, meta_quit(), meta_restart_after_quit, and TRUE.

Referenced by event_callback().

Here is the call graph for this function:

◆ meta_select_display()

static void meta_select_display ( gchar *  display_name)
static

Selects which display Marco should use.

It first tries to use display_name as the display. If display_name is NULL then try to use the environment variable MARCO_DISPLAY. If that also is NULL, use the default - :0.0

References NULL.

Referenced by main().

◆ on_sigterm()

static gboolean on_sigterm ( GIOChannel *  source,
GIOCondition  condition,
gpointer  user_data 
)
static

References FALSE, META_EXIT_SUCCESS, and meta_quit().

Referenced by main().

Here is the call graph for this function:

◆ prefs_changed_callback()

static void prefs_changed_callback ( MetaPreference  pref,
gpointer  data 
)
static

Called on pref changes.

(One of several functions of its kind and purpose.)

Bug:
Why are these particular prefs handled in main.c and not others? Should they be?
Parameters
prefWhich preference has changed
dataArbitrary data (which we ignore)

References FALSE, meta_display_retheme_all(), meta_display_set_cursor_theme(), meta_invalidate_all_icons(), META_PREF_CURSOR_SIZE, META_PREF_CURSOR_THEME, META_PREF_ICON_SIZE, META_PREF_THEME, meta_prefs_get_cursor_size(), meta_prefs_get_cursor_theme(), meta_prefs_get_theme(), and meta_ui_set_current_theme().

Referenced by main().

Here is the call graph for this function:

◆ sigterm_handler()

static void sigterm_handler ( int  signum)
static

References sigterm_pipe_fds.

Referenced by main().

Variable Documentation

◆ meta_exit_code

MetaExitCode meta_exit_code = META_EXIT_SUCCESS
static

The exit code we'll return to our parent process when we eventually die.

Referenced by main(), and meta_quit().

◆ meta_main_loop

GMainLoop* meta_main_loop = NULL
static

Handle on the main loop, so that we have an easy way of shutting Marco down.

Referenced by main(), and meta_quit().

◆ meta_restart_after_quit

gboolean meta_restart_after_quit = FALSE
static

If set, Marco will spawn an identical copy of itself immediately before quitting.

Referenced by main(), and meta_restart().

◆ sigterm_pipe_fds

int sigterm_pipe_fds[2] = { -1, -1 }
static

Referenced by main(), and sigterm_handler().