i3
main.c File Reference
#include "all.h"
#include "shmlog.h"
#include <libev/ev.h>
#include <fcntl.h>
#include <getopt.h>
#include <libgen.h>
#include <locale.h>
#include <signal.h>
#include <sys/mman.h>
#include <sys/resource.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/un.h>
#include <unistd.h>
#include <xcb/xcb_atom.h>
#include <xcb/xinerama.h>
#include <xcb/bigreq.h>
#include "sd-daemon.h"
#include "i3-atoms_NET_SUPPORTED.xmacro.h"
#include "i3-atoms_rest.xmacro.h"
Include dependency graph for main.c:

Go to the source code of this file.

Macros

#define xmacro(atom)
 
#define xmacro(atom)
 
#define xmacro(name)
 
#define PCF_REPLY_ERROR(_value)
 

Functions

I3_NET_SUPPORTED_ATOMS_XMACRO static I3_REST_ATOMS_XMACRO void xcb_got_event (EV_P_ struct ev_io *w, int revents)
 
static void xcb_prepare_cb (EV_P_ ev_prepare *w, int revents)
 
void main_set_x11_cb (bool enable)
 Enable or disable the main X11 event handling function.
 
static void i3_exit (void)
 
static void handle_core_signal (int sig, siginfo_t *info, void *data)
 
static void handle_term_signal (struct ev_loop *loop, ev_signal *signal, int revents)
 
static void setup_term_handlers (void)
 
static int parse_restart_fd (void)
 
int main (int argc, char *argv[])
 

Variables

struct rlimit original_rlimit_core
 The original value of RLIMIT_CORE when i3 was started.
 
int listen_fds
 The number of file descriptors passed via socket activation.
 
static struct ev_prepare * xcb_prepare
 
char ** start_argv
 
xcb_connection_t * conn
 XCB connection and root screen.
 
int conn_screen
 
SnDisplay * sndisplay
 
xcb_timestamp_t last_timestamp = XCB_CURRENT_TIME
 The last timestamp we got from X11 (timestamps are included in some events and are used for some things, like determining a unique ID in startup notification).
 
xcb_screen_t * root_screen
 
xcb_window_t root
 
xcb_window_t wm_sn_selection_owner
 
xcb_atom_t wm_sn
 
uint8_t root_depth
 
xcb_visualtype_t * visual_type
 
xcb_colormap_t colormap
 
struct ev_loop * main_loop
 
xcb_key_symbols_t * keysyms
 
const int default_shmlog_size = 25 * 1024 * 1024
 
struct bindings_head * bindings
 
const char * current_binding_mode = NULL
 
struct autostarts_head autostarts = TAILQ_HEAD_INITIALIZER(autostarts)
 
struct autostarts_always_head autostarts_always = TAILQ_HEAD_INITIALIZER(autostarts_always)
 
struct assignments_head assignments = TAILQ_HEAD_INITIALIZER(assignments)
 
struct ws_assignments_head ws_assignments = TAILQ_HEAD_INITIALIZER(ws_assignments)
 
bool xkb_supported = true
 
bool shape_supported = true
 
bool force_xinerama = false
 

Macro Definition Documentation

◆ PCF_REPLY_ERROR

#define PCF_REPLY_ERROR ( _value)
Value:
do { \
if (pcf_reply == NULL || !(pcf_reply->value & (_value))) { \
ELOG("Could not set " #_value "\n"); \
} \
} while (0)

Referenced by main().

◆ xmacro [1/3]

#define xmacro ( atom)
Value:
xcb_atom_t A_##atom;

Definition at line 110 of file main.c.

◆ xmacro [2/3]

#define xmacro ( atom)
Value:
xcb_intern_atom_cookie_t atom##_cookie = xcb_intern_atom(conn, 0, strlen(#atom), #atom);
xcb_connection_t * conn
XCB connection and root screen.
Definition main.c:54

Definition at line 110 of file main.c.

◆ xmacro [3/3]

#define xmacro ( name)
Value:
do { \
xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(conn, name##_cookie, NULL); \
if (!reply) { \
ELOG("Could not get atom " #name "\n"); \
exit(-1); \
} \
A_##name = reply->atom; \
free(reply); \
} while (0);

Definition at line 110 of file main.c.

Function Documentation

◆ handle_core_signal()

static void handle_core_signal ( int sig,
siginfo_t * info,
void * data )
static

Definition at line 217 of file main.c.

References shmlogname.

Referenced by main().

◆ handle_term_signal()

static void handle_term_signal ( struct ev_loop * loop,
ev_signal * signal,
int revents )
static

Definition at line 230 of file main.c.

Referenced by setup_term_handlers().

◆ i3_exit()

static void i3_exit ( void )
static

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 279 of file main.c.

References __attribute__(), xoutput::active, aio_get_mod_mask_for(), autostarts, autostarts_always, barconfigs, C_LOAD, C_VALIDATE, xoutput::changed, colormap, Autostart::command, xoutput::con, con_activate(), con_descend_focused(), config, conn, conn_screen, create_socket(), croot, current_log_stream_socket_path, current_socketpath, default_shmlog_size, die, Config::disable_randr15, display_running_version(), DLOG, ELOG, ewmh_setup_hints(), ewmh_update_desktop_properties(), ewmh_update_workarea(), Config::fake_outputs, fake_outputs_init(), Config::force_xinerama, force_xinerama, FREE, get_first_output(), get_output_containing(), get_process_filename(), get_visualtype(), grab_all_keys(), handle_core_signal(), handle_event(), i3_exit(), I3_NET_SUPPORTED_ATOMS_XMACRO, I3_REST_ATOMS_XMACRO, i3_version, Barconfig::i3bar_command, Barconfig::id, init_dpi(), init_logging(), ipc_confirm_restart(), ipc_new_client(), ipc_new_client_on_fd(), ipc_recv_message(), ipc_send_message(), Config::ipc_socket_path, is_background_set(), is_debug_build(), keysyms, last_timestamp, listen_fds, load_configuration(), load_keymap(), LOG, log_new_client(), logical_px(), main_loop, manage_existing_windows(), Con::name, Autostart::no_startup_id, only_check_config, original_rlimit_core, output_get_content(), output_init_con(), output_primary_name(), outputs, parse_restart_fd(), PCF_REPLY_ERROR, property_handlers_init(), randr_base, randr_disable_output(), randr_init(), restore_connect(), root, root_atom_contents(), root_depth, ROOT_EVENT_MASK, root_screen, sasprintf(), scalloc(), scratchpad_fix_resolution(), sd_listen_fds(), SD_LISTEN_FDS_START, sd_notify(), set_debug_logging(), set_screenshot_as_wallpaper(), set_verbosity(), setup_signal_handler(), setup_term_handlers(), shape_base, shape_supported, shmlog_size, smalloc(), sndisplay, srealloc(), sstrdup(), start_application(), start_argv, TAILQ_EMPTY, TAILQ_FIRST, TAILQ_FOREACH, TAILQ_REMOVE, xoutput::to_be_disabled, translate_keysyms(), tree_init(), tree_render(), tree_restore(), Barconfig::verbose, visual_type, wm_sn, wm_sn_selection_owner, x_set_i3_atoms(), xcb_got_event(), XCB_NUM_LOCK, xcb_numlock_mask, xcb_prepare, xcb_prepare_cb(), XCURSOR_CURSOR_POINTER, xcursor_load_cursors(), xcursor_set_root_cursor(), xinerama_init(), xkb_base, and xkb_supported.

◆ main_set_x11_cb()

void main_set_x11_cb ( bool enable)

Enable or disable the main X11 event handling function.

This is used by drag_pointer() which has its own, modal event handler, which takes precedence over the normal event handler.

Definition at line 166 of file main.c.

References DLOG, main_loop, and xcb_prepare.

Referenced by drag_pointer().

◆ parse_restart_fd()

static int parse_restart_fd ( void )
static

Definition at line 265 of file main.c.

References ELOG, and parse_long().

Referenced by main().

Here is the call graph for this function:

◆ setup_term_handlers()

static void setup_term_handlers ( void )
static

Definition at line 240 of file main.c.

References handle_term_signal(), and main_loop.

Referenced by main().

Here is the call graph for this function:

◆ xcb_got_event()

I3_NET_SUPPORTED_ATOMS_XMACRO static I3_REST_ATOMS_XMACRO void xcb_got_event ( EV_P_ struct ev_io * w,
int revents )
static

Definition at line 120 of file main.c.

Referenced by main().

◆ xcb_prepare_cb()

static void xcb_prepare_cb ( EV_P_ ev_prepare * w,
int revents )
static

Definition at line 130 of file main.c.

References conn, DLOG, event_is_ignored(), and handle_event().

Referenced by main().

Here is the call graph for this function:

Variable Documentation

◆ assignments

struct assignments_head assignments = TAILQ_HEAD_INITIALIZER(assignments)

Definition at line 97 of file main.c.

Referenced by assignment_for(), CFGFUN(), CFGFUN(), CFGFUN(), CFGFUN(), free_configuration(), and run_assignments().

◆ autostarts

struct autostarts_head autostarts = TAILQ_HEAD_INITIALIZER(autostarts)

Definition at line 91 of file main.c.

Referenced by CFGFUN(), and main().

◆ autostarts_always

struct autostarts_always_head autostarts_always = TAILQ_HEAD_INITIALIZER(autostarts_always)

Definition at line 94 of file main.c.

Referenced by CFGFUN(), and main().

◆ bindings

◆ colormap

xcb_colormap_t colormap

Definition at line 77 of file main.c.

Referenced by main(), and x_con_init().

◆ conn

xcb_connection_t* conn

XCB connection and root screen.

Definition at line 54 of file main.c.

Referenced by _x_con_kill(), allow_replay_pointer(), con_set_fullscreen_mode(), create_drop_indicator(), create_window(), display_running_version(), drag_pointer(), DRAGGING_CB(), DRAGGING_CB(), DRAGGING_CB(), drain_drag_events(), ewmh_setup_hints(), ewmh_update_active_window(), ewmh_update_client_list(), ewmh_update_client_list_stacking(), ewmh_update_current_desktop(), ewmh_update_desktop_names(), ewmh_update_desktop_viewport(), ewmh_update_focused(), ewmh_update_number_of_desktops(), ewmh_update_sticky(), ewmh_update_visible_name(), ewmh_update_wm_desktop_recursively(), ewmh_update_workarea(), fake_absolute_configure_notify(), fill_rmlvo_from_root(), floating_move_to_pointer(), floating_set_hint_atom(), free_configuration(), get_resource(), grab_all_keys(), handle_button_press(), handle_client_message(), handle_configure_request(), handle_event(), handle_expose_event(), handle_map_request(), handle_mapping_notify(), handle_output(), handle_screen_change(), handle_signal(), handle_unmap_notify_event(), i3_exit(), load_configuration(), load_keymap(), main(), manage_existing_windows(), manage_window(), property_notify(), query_screens(), randr_init(), randr_query_outputs(), randr_query_outputs_14(), randr_query_outputs_15(), regrab_all_buttons(), remanage_window(), resize_graphical_handler(), restore_geometry(), route_click(), send_take_focus(), set_hidden_state(), set_maximized_state(), sighandler_create_dialogs(), sighandler_destroy_dialogs(), sighandler_handle_expose(), startup_sequence_delete_by_window(), startup_sequence_get(), switch_mode(), sync_respond(), tiling_drag(), tree_close_internal(), ungrab_all_keys(), update_shmlog_atom(), use_root_output(), window_supports_protocol(), window_update_normal_hints(), x_con_init(), x_con_kill(), x_mask_event_mask(), x_push_changes(), x_push_node(), x_push_node_unmaps(), x_set_i3_atoms(), x_set_shape(), x_shape_frame(), x_unshape_frame(), x_window_kill(), xcb_add_property_atom(), xcb_grab_buttons(), xcb_prepare_cb(), xcb_remove_property_atom(), xcb_set_window_rect(), xcursor_load_cursors(), xcursor_set_root_cursor(), and xinerama_init().

◆ conn_screen

int conn_screen

Definition at line 56 of file main.c.

Referenced by display_running_version(), main(), property_handlers_init(), and start_application().

◆ current_binding_mode

const char* current_binding_mode = NULL

Definition at line 88 of file main.c.

Referenced by IPC_HANDLER(), load_configuration(), run_binding(), and switch_mode().

◆ default_shmlog_size

const int default_shmlog_size = 25 * 1024 * 1024

Definition at line 84 of file main.c.

Referenced by cmd_shmlog(), and main().

◆ force_xinerama

bool force_xinerama = false

Definition at line 107 of file main.c.

Referenced by handle_configure_notify(), and main().

◆ keysyms

xcb_key_symbols_t* keysyms

Definition at line 81 of file main.c.

Referenced by handle_event(), handle_mapping_notify(), main(), and sighandler_handle_key_press().

◆ last_timestamp

xcb_timestamp_t last_timestamp = XCB_CURRENT_TIME

The last timestamp we got from X11 (timestamps are included in some events and are used for some things, like determining a unique ID in startup notification).

Definition at line 64 of file main.c.

Referenced by handle_button_press(), handle_client_message(), handle_enter_notify(), handle_event(), handle_key_press(), handle_motion_notify(), main(), start_application(), and x_push_changes().

◆ listen_fds

int listen_fds

The number of file descriptors passed via socket activation.

Definition at line 46 of file main.c.

Referenced by main(), and start_application().

◆ main_loop

◆ original_rlimit_core

struct rlimit original_rlimit_core

The original value of RLIMIT_CORE when i3 was started.

We need to restore this before starting any other process, since we set RLIMIT_CORE to RLIM_INFINITY for i3 debugging versions.

Definition at line 43 of file main.c.

Referenced by main(), and start_application().

◆ root

◆ root_depth

uint8_t root_depth

Definition at line 75 of file main.c.

Referenced by con_new_skeleton(), main(), sighandler_create_dialogs(), x_con_init(), and x_push_node().

◆ root_screen

◆ shape_supported

bool shape_supported = true

Definition at line 105 of file main.c.

Referenced by handle_event(), main(), manage_window(), set_shape_state(), and tree_close_internal().

◆ sndisplay

SnDisplay* sndisplay

Definition at line 59 of file main.c.

Referenced by handle_client_message(), main(), property_handlers_init(), and start_application().

◆ start_argv

char** start_argv

Definition at line 52 of file main.c.

Referenced by exec_i3_utility(), i3_restart(), and main().

◆ visual_type

xcb_visualtype_t* visual_type

Definition at line 76 of file main.c.

Referenced by main().

◆ wm_sn

xcb_atom_t wm_sn

Definition at line 70 of file main.c.

Referenced by handle_selection_clear(), and main().

◆ wm_sn_selection_owner

xcb_window_t wm_sn_selection_owner

Definition at line 69 of file main.c.

Referenced by main().

◆ ws_assignments

struct ws_assignments_head ws_assignments = TAILQ_HEAD_INITIALIZER(ws_assignments)

◆ xcb_prepare

struct ev_prepare* xcb_prepare
static

Definition at line 50 of file main.c.

Referenced by main(), main_set_x11_cb(), and restore_connect().

◆ xkb_supported

bool xkb_supported = true

Definition at line 104 of file main.c.

Referenced by load_keymap(), and main().