i3
libi3.h File Reference
#include <config.h>
#include <stdbool.h>
#include <stdarg.h>
#include <stdio.h>
#include <sys/stat.h>
#include <xcb/xcb.h>
#include <xcb/xproto.h>
#include <xcb/xcb_keysyms.h>
#include <pango/pango.h>
#include <cairo/cairo-xcb.h>
Include dependency graph for libi3.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Font
 Data structure for cached font information: More...
 
struct  color_t
 
struct  placeholder_t
 Helper structure for usage in format_placeholders(). More...
 
struct  surface_t
 

Macros

#define DEFAULT_DIR_MODE   (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
 
#define XCB_BUTTON_CLICK_LEFT   XCB_BUTTON_INDEX_1
 Mouse buttons.
 
#define XCB_BUTTON_CLICK_MIDDLE   XCB_BUTTON_INDEX_2
 
#define XCB_BUTTON_CLICK_RIGHT   XCB_BUTTON_INDEX_3
 
#define XCB_BUTTON_SCROLL_UP   XCB_BUTTON_INDEX_4
 
#define XCB_BUTTON_SCROLL_DOWN   XCB_BUTTON_INDEX_5
 
#define XCB_BUTTON_SCROLL_LEFT   6
 
#define XCB_BUTTON_SCROLL_RIGHT   7
 
#define LOG(fmt, ...)
 
#define ELOG(fmt, ...)
 
#define DLOG(fmt, ...)
 
#define I3STRING_FREE(str)
 Securely i3string_free by setting the pointer to NULL to prevent accidentally using freed memory.
 
#define HAS_G_UTF8_MAKE_VALID   GLIB_CHECK_VERSION(2, 52, 0)
 
#define COLOR_TRANSPARENT   ((color_t){.red = 0.0, .green = 0.0, .blue = 0.0, .colorpixel = 0})
 
#define CAIRO_SURFACE_FLUSH(surface)
 

Typedefs

typedef struct _i3String i3String
 Opaque data structure for storing strings.
 
typedef struct Font i3Font
 
typedef struct color_t color_t
 
typedef struct placeholder_t placeholder_t
 Helper structure for usage in format_placeholders().
 
typedef struct surface_t surface_t
 

Functions

void verboselog (char *fmt,...) __attribute__((format(printf
 
void errorlog (char *fmt,...) __attribute__((format(printf
 
void debuglog (char *fmt,...) __attribute__((format(printf
 
char * root_atom_contents (const char *atomname, xcb_connection_t *provided_conn, int screen)
 Try to get the contents of the given atom (for example I3_SOCKET_PATH) from the X11 root window and return NULL if it doesn’t work.
 
void * smalloc (size_t size)
 Safe-wrapper around malloc which exits if malloc returns NULL (meaning that there is no more memory available)
 
void * scalloc (size_t num, size_t size)
 Safe-wrapper around calloc which exits if malloc returns NULL (meaning that there is no more memory available)
 
void * srealloc (void *ptr, size_t size)
 Safe-wrapper around realloc which exits if realloc returns NULL (meaning that there is no more memory available).
 
char * sstrdup (const char *str)
 Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory available)
 
char * sstrndup (const char *str, size_t size)
 Safe-wrapper around strndup which exits if strndup returns NULL (meaning that there is no more memory available)
 
int sasprintf (char **strp, const char *fmt,...)
 Safe-wrapper around asprintf which exits if it returns -1 (meaning that there is no more memory available)
 
ssize_t writeall (int fd, const void *buf, size_t count)
 Wrapper around correct write which returns -1 (meaning that write failed) or count (meaning that all bytes were written)
 
ssize_t writeall_nonblock (int fd, const void *buf, size_t count)
 Like writeall, but instead of retrying upon EAGAIN (returned when a write would block), the function stops and returns the total number of bytes written so far.
 
ssize_t swrite (int fd, const void *buf, size_t count)
 Safe-wrapper around writeall which exits if it returns -1 (meaning that write failed)
 
int strcasecmp_nullable (const char *a, const char *b)
 Like strcasecmp but considers the case where either string is NULL.
 
i3Stringi3string_from_utf8 (const char *from_utf8)
 Build an i3String from an UTF-8 encoded string.
 
i3Stringi3string_from_markup (const char *from_markup)
 Build an i3String from an UTF-8 encoded string in Pango markup.
 
i3Stringi3string_from_utf8_with_length (const char *from_utf8, ssize_t num_bytes)
 Build an i3String from an UTF-8 encoded string with fixed length.
 
i3Stringi3string_from_markup_with_length (const char *from_markup, size_t num_bytes)
 Build an i3String from an UTF-8 encoded string in Pango markup with fixed length.
 
i3Stringi3string_from_ucs2 (const xcb_char2b_t *from_ucs2, size_t num_glyphs)
 Build an i3String from an UCS-2 encoded string.
 
i3Stringi3string_copy (i3String *str)
 Copies the given i3string.
 
void i3string_free (i3String *str)
 Free an i3String.
 
const char * i3string_as_utf8 (i3String *str)
 Returns the UTF-8 encoded version of the i3String.
 
const xcb_char2b_t * i3string_as_ucs2 (i3String *str)
 Returns the UCS-2 encoded version of the i3String.
 
size_t i3string_get_num_bytes (i3String *str)
 Returns the number of bytes (UTF-8 encoded) in an i3String.
 
bool i3string_is_markup (i3String *str)
 Whether the given i3String is in Pango markup.
 
void i3string_set_markup (i3String *str, bool pango_markup)
 Set whether the i3String should use Pango markup.
 
i3Stringi3string_escape_markup (i3String *str)
 Escape pango markup characters in the given string.
 
size_t i3string_get_num_glyphs (i3String *str)
 Returns the number of glyphs in an i3String.
 
int ipc_connect (const char *socket_path)
 Connects to the i3 IPC socket and returns the file descriptor for the socket.
 
int ipc_connect_impl (const char *socket_path)
 Connects to the socket at the given path with no fallback paths.
 
int ipc_send_message (int sockfd, const uint32_t message_size, const uint32_t message_type, const uint8_t *payload)
 Formats a message (payload) of the given size and type and sends it to i3 via the given socket file descriptor.
 
int ipc_recv_message (int sockfd, uint32_t *message_type, uint32_t *reply_length, uint8_t **reply)
 Reads a message from the given socket file descriptor and stores its length (reply_length) as well as a pointer to its contents (reply).
 
void fake_configure_notify (xcb_connection_t *conn, xcb_rectangle_t r, xcb_window_t window, int border_width)
 Generates a configure_notify event and sends it to the given window Applications need this to think they’ve configured themselves correctly.
 
gchar * g_utf8_make_valid (const gchar *str, gssize len)
 
uint32_t get_colorpixel (const char *hex) __attribute__((const))
 Returns the colorpixel to use for the given hex color (think of HTML).
 
char * strndup (const char *str, size_t n)
 Taken from FreeBSD Returns a pointer to a new string which is a duplicate of the string, but only copies at most n characters.
 
uint32_t aio_get_mod_mask_for (uint32_t keysym, xcb_key_symbols_t *symbols)
 All-in-one function which returns the modifier mask (XCB_MOD_MASK_*) for the given keysymbol, for example for XCB_NUM_LOCK (usually configured to mod2).
 
uint32_t get_mod_mask_for (uint32_t keysym, xcb_key_symbols_t *symbols, xcb_get_modifier_mapping_reply_t *modmap_reply)
 Returns the modifier mask (XCB_MOD_MASK_*) for the given keysymbol, for example for XCB_NUM_LOCK (usually configured to mod2).
 
i3Font load_font (const char *pattern, const bool fallback)
 Loads a font for usage, also getting its height.
 
void set_font (i3Font *font)
 Defines the font to be used for the forthcoming calls.
 
void free_font (void)
 Frees the resources taken by the current font.
 
char * convert_ucs2_to_utf8 (xcb_char2b_t *text, size_t num_glyphs)
 Converts the given string to UTF-8 from UCS-2 big endian.
 
xcb_char2b_t * convert_utf8_to_ucs2 (char *input, size_t *real_strlen)
 Converts the given string to UCS-2 big endian for use with xcb_image_text_16().
 
void set_font_colors (xcb_gcontext_t gc, color_t foreground, color_t background)
 Defines the colors to be used for the forthcoming draw_text calls.
 
bool font_is_pango (void)
 Returns true if and only if the current font is a pango font.
 
void draw_text (i3String *text, xcb_drawable_t drawable, xcb_gcontext_t gc, cairo_surface_t *surface, int x, int y, int max_width)
 Draws text onto the specified X drawable (normally a pixmap) at the specified coordinates (from the top left corner of the leftmost, uppermost glyph) and using the provided gc.
 
int predict_text_width (i3String *text)
 Predict the text width in pixels for the given text.
 
xcb_visualtype_t * get_visualtype (xcb_screen_t *screen)
 Returns the visual type associated with the given screen.
 
bool is_debug_build (void) __attribute__((const))
 Returns true if this version of i3 is a debug build (anything which is not a release version), based on the git version number.
 
char * get_process_filename (const char *prefix)
 Returns the name of a temporary file with the specified prefix.
 
char * get_exe_path (const char *argv0)
 This function returns the absolute path to the executable it is running in.
 
void init_dpi (void)
 Initialize the DPI setting.
 
long get_dpi_value (void)
 This function returns the value of the DPI setting.
 
int logical_px (const int logical)
 Convert a logical amount of pixels (e.g.
 
char * resolve_tilde (const char *path)
 This function resolves ~ in pathnames.
 
char * get_config_path (const char *override_configpath, bool use_system_paths)
 Get the path of the first configuration file found.
 
int mkdirp (const char *path, mode_t mode)
 Emulates mkdir -p (creates any missing folders)
 
char * format_placeholders (char *format, placeholder_t *placeholders, int num)
 Replaces occurrences of the defined placeholders in the format string.
 
void draw_util_surface_init (xcb_connection_t *conn, surface_t *surface, xcb_drawable_t drawable, xcb_visualtype_t *visual, int width, int height)
 Initialize the surface to represent the given drawable.
 
void draw_util_surface_set_size (surface_t *surface, int width, int height)
 Resize the surface to the given size.
 
void draw_util_surface_free (xcb_connection_t *conn, surface_t *surface)
 Destroys the surface.
 
color_t draw_util_hex_to_color (const char *color)
 Parses the given color in hex format to an internal color representation.
 
void draw_util_text (i3String *text, surface_t *surface, color_t fg_color, color_t bg_color, int x, int y, int max_width)
 Draw the given text using libi3.
 
void draw_util_image (cairo_surface_t *image, surface_t *surface, int x, int y, int width, int height)
 Draw the given image using libi3.
 
void draw_util_rectangle (surface_t *surface, color_t color, double x, double y, double w, double h)
 Draws a filled rectangle.
 
void draw_util_clear_surface (surface_t *surface, color_t color)
 Clears a surface with the given color.
 
void draw_util_copy_surface (surface_t *src, surface_t *dest, double src_x, double src_y, double dest_x, double dest_y, double width, double height)
 Copies a surface onto another surface.
 
void set_nonblock (int sockfd)
 Puts the given socket file descriptor into non-blocking mode or dies if setting O_NONBLOCK failed.
 
int create_socket (const char *filename, char **out_socketpath)
 Creates the UNIX domain socket at the given path, sets it to non-blocking mode, bind()s and listen()s on it.
 
bool path_exists (const char *path)
 Checks if the given path exists by calling stat().
 
void set_screenshot_as_wallpaper (xcb_connection_t *conn, xcb_screen_t *screen)
 Grab a screenshot of the screen's root window and set it as the wallpaper.
 
bool is_background_set (xcb_connection_t *conn, xcb_screen_t *screen)
 Test whether the screen's root window has a background set.
 
bool boolstr (const char *str)
 Reports whether str represents the enabled state (1, yes, true, …).
 
uint16_t get_visual_depth (xcb_visualid_t visual_id)
 Get depth of visual specified by visualid.
 

Variables

xcb_connection_t * conn
 XCB connection and root screen.
 
xcb_screen_t * root_screen
 

Macro Definition Documentation

◆ CAIRO_SURFACE_FLUSH

#define CAIRO_SURFACE_FLUSH ( surface)
Value:
do { \
cairo_surface_flush(surface); \
cairo_surface_flush(surface); \
} while (0)

Definition at line 561 of file libi3.h.

◆ COLOR_TRANSPARENT

#define COLOR_TRANSPARENT   ((color_t){.red = 0.0, .green = 0.0, .blue = 0.0, .colorpixel = 0})

Definition at line 436 of file libi3.h.

◆ DEFAULT_DIR_MODE

#define DEFAULT_DIR_MODE   (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)

Definition at line 26 of file libi3.h.

Referenced by store_restart_layout().

◆ DLOG

#define DLOG ( fmt,
... )
Value:
debuglog("%s:%s:%d - " fmt, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
void debuglog(char *fmt,...) __attribute__((format(printf

Definition at line 105 of file libi3.h.

Referenced by _con_attach(), _con_move_to_con(), _create___i3(), _workspace_apply_default_orientation(), add_keycode_if_matches(), add_subscription(), assignment_for(), CFGFUN(), CFGFUN(), CFGFUN(), CFGFUN(), CFGFUN(), CFGFUN(), CFGFUN(), CFGFUN(), CFGFUN(), CFGFUN(), CFGFUN(), cmd_append_layout(), cmd_bar_hidden_state(), cmd_bar_mode(), cmd_border(), cmd_criteria_match_windows(), cmd_exec(), cmd_floating(), cmd_focus(), cmd_focus_level(), cmd_focus_window_mode(), cmd_fullscreen(), cmd_kill(), cmd_layout(), cmd_layout_toggle(), cmd_mark(), cmd_mode(), cmd_move_con_to_mark(), cmd_move_con_to_workspace(), cmd_move_direction(), cmd_move_scratchpad(), cmd_move_window_to_center(), cmd_move_window_to_mouse(), cmd_move_window_to_position(), cmd_resize(), cmd_resize_set(), cmd_scratchpad_show(), cmd_split(), cmd_sticky(), cmd_swap(), cmd_title_format(), cmd_title_window_icon(), cmd_workspace(), cmd_workspace_name(), con_accepts_window(), con_border_style(), con_border_style_rect_without_title(), con_close(), con_descend_direction(), con_disable_fullscreen(), con_enable_fullscreen(), con_find_transient_for_window(), con_focus(), con_free(), con_mark(), con_mark_toggle(), con_minimum_size(), con_move_to_mark(), con_move_to_output(), con_move_to_target(), con_move_to_workspace(), con_new_skeleton(), con_next_focused(), con_on_remove_child(), con_parent_with_orientation(), con_set_fullscreen_mode(), con_set_layout(), con_set_urgency(), con_swap(), con_toggle_fullscreen(), con_toggle_layout(), con_unmark(), configure_binding(), configure_notify(), create_gaps_assignment(), create_workspace_on_output(), dlog_padding(), DRAGGING_CB(), drain_drag_events(), dump_node(), ewmh_update_focused(), ewmh_update_sticky(), ewmh_update_wm_desktop_recursively(), expose_event(), extract_workspace_names_from_bindings(), fake_absolute_configure_notify(), fake_outputs_init(), fill_rmlvo_from_root(), floating_check_size(), floating_drag_window(), floating_enable(), floating_fix_coordinates(), floating_maybe_reassign_ws(), floating_mod_on_tiled_client(), floating_raise_con(), floating_resize(), floating_resize_window(), free_ipc_client(), gaps_reapply_workspace_assignments(), gaps_update(), get_assigned_output(), get_binding(), get_binding_from_xcb_event(), get_output_containing(), get_output_next(), get_output_next_wrap(), get_output_with_dimensions(), get_tree_next_workspace(), grab_all_keys(), grab_keycode_for_binding(), handle_button_press(), handle_client_message(), handle_configure_notify(), handle_configure_request(), handle_destroy_notify_event(), handle_enter_notify(), handle_event(), handle_expose_event(), handle_focus_in(), handle_focus_out(), handle_i3_floating(), handle_key_press(), handle_map_request(), handle_mapping_notify(), handle_motif_hints_change(), handle_motion_notify(), handle_net_wm_state_change(), handle_output(), handle_screen_change(), handle_selection_clear(), handle_signal(), handle_strut_partial_change(), handle_unmap_notify_event(), init_ws_for_output(), insert_con_into(), ipc_confirm_restart(), IPC_HANDLER(), IPC_HANDLER(), ipc_new_client_on_fd(), ipc_receive_message(), ipc_send_barconfig_update_event(), ipc_send_binding_event(), ipc_send_window_event(), ipc_socket_writeable_cb(), json_determine_content_string(), json_end_map(), json_int(), json_string(), level_down(), main(), main_set_x11_cb(), manage_window(), match_parse_property(), maybe_auto_back_and_forth_workspace(), maybe_back_and_forth(), move_content(), move_matches_to_workspace(), move_to_output_directed(), nagbar_exited(), open_placeholder_window(), output_change_mode(), output_containing_rect(), output_init_con(), parse_command(), parse_config(), parse_file(), property_notify(), query_screens(), randr_disable_output(), randr_init(), randr_query_outputs(), randr_query_outputs_14(), randr_query_outputs_15(), remanage_window(), render_con(), render_output(), render_root(), resize_find_tiling_participants(), resize_graphical_handler(), restore_geometry(), restore_handle_event(), restore_kill_placeholder(), restore_xcb_prepare_cb(), route_click(), run_assignments(), scratchpad_fix_resolution(), scratchpad_move(), scratchpad_show(), send_take_focus(), set_hidden_state(), set_maximized_state(), sighandler_handle_key_press(), start_nagbar(), startup_monitor_event(), startup_sequence_delete(), startup_sequence_get(), startup_sequence_rename_workspace(), startup_workspace_for_window(), store_restart_layout(), switch_mode(), sync_respond(), TAILQ_HEAD(), tiling_drag(), tiling_resize(), tiling_resize_for_border(), translate_keysyms(), tree_append_json(), tree_close_internal(), tree_flatten(), tree_move(), tree_open_con(), tree_render(), tree_restore(), tree_split(), ungrab_all_keys(), update_placeholder_contents(), upsert_variable(), window_update_class(), window_update_hints(), window_update_icon(), window_update_leader(), window_update_machine(), window_update_name(), window_update_name_legacy(), window_update_normal_hints(), window_update_role(), window_update_strut_partial(), window_update_transient_for(), window_update_type(), workspace_attach_to(), workspace_back_and_forth(), workspace_back_and_forth_get(), workspace_defer_update_urgent_hint_cb(), workspace_encapsulate(), workspace_move_to_output(), workspace_prev_on_output(), workspace_show(), workspace_update_urgent_flag(), ws_force_orientation(), x_con_init(), x_draw_decoration(), x_move_win(), x_push_changes(), x_push_node(), x_push_node_unmaps(), x_reinit(), xcb_prepare_cb(), and xinerama_init().

◆ ELOG

#define ELOG ( fmt,
... )
Value:
errorlog("[libi3] ERROR: " fmt, ##__VA_ARGS__)
void errorlog(char *fmt,...) __attribute__((format(printf

Definition at line 100 of file libi3.h.

Referenced by _con_move_to_con(), bar_configure_binding(), binding_in_current_group(), bindings_get_buttons_to_grab(), CFGFUN(), CFGFUN(), CFGFUN(), CFGFUN(), CFGFUN(), CFGFUN(), CFGFUN(), CFGFUN(), CFGFUN(), CFGFUN(), CFGFUN(), check_crossing_screen_boundary(), check_for_duplicate_bindings(), cmd_append_layout(), cmd_bar_hidden_state(), cmd_bar_mode(), cmd_focus(), cmd_focus_level(), cmd_gaps(), cmd_layout(), cmd_move_window_to_center(), cmd_move_window_to_position(), cmd_restart(), cmd_split(), cmd_sticky(), con_get_tree_representation(), con_minimum_size(), con_move_to_output_name(), con_orientation(), con_swap(), con_toggle_layout(), configure_binding(), configure_notify(), create_window(), drag_pointer(), DRAGGING_CB(), ewmh_update_wm_desktop_recursively(), expose_event(), fake_outputs_init(), floating_maybe_reassign_ws(), floating_move_to_pointer(), floating_reposition(), gaps_scope_to_mask(), gaps_update(), get_resource(), handle_button_press(), handle_client_message(), handle_screen_change(), insert_con_into(), ipc_client_timeout(), IPC_HANDLER(), IPC_HANDLER(), json_determine_content(), json_end_map(), json_int(), json_string(), json_validate(), level_up(), load_configuration(), load_keymap(), main(), match_parse_property(), nagbar_exited(), parse_command(), parse_config(), parse_direction(), parse_file(), parse_restart_fd(), print_config_path(), query_screens(), randr_init(), randr_query_outputs_14(), randr_query_outputs_15(), regex_matches(), regex_new(), set_shape_state(), setup_signal_handler(), slurp(), store_restart_layout(), switch_mode(), tiling_drag(), tiling_resize_for_border(), toggle_floating_mode(), translate_keysyms(), tree_append_json(), workspace_encapsulate(), x_draw_decoration(), x_move_win(), x_push_changes(), x_reinit(), x_reparent_child(), x_set_name(), and x_set_shape().

◆ HAS_G_UTF8_MAKE_VALID

#define HAS_G_UTF8_MAKE_VALID   GLIB_CHECK_VERSION(2, 52, 0)

Definition at line 336 of file libi3.h.

◆ I3STRING_FREE

#define I3STRING_FREE ( str)
Value:
do { \
if (str != NULL) { \
i3string_free(str); \
str = NULL; \
} \
} while (0)

Securely i3string_free by setting the pointer to NULL to prevent accidentally using freed memory.

Definition at line 243 of file libi3.h.

Referenced by cmd_title_format(), window_update_name(), window_update_name_legacy(), and x_draw_decoration().

◆ LOG

◆ XCB_BUTTON_CLICK_LEFT

#define XCB_BUTTON_CLICK_LEFT   XCB_BUTTON_INDEX_1

Mouse buttons.

Definition at line 29 of file libi3.h.

Referenced by route_click().

◆ XCB_BUTTON_CLICK_MIDDLE

#define XCB_BUTTON_CLICK_MIDDLE   XCB_BUTTON_INDEX_2

Definition at line 30 of file libi3.h.

◆ XCB_BUTTON_CLICK_RIGHT

#define XCB_BUTTON_CLICK_RIGHT   XCB_BUTTON_INDEX_3

Definition at line 31 of file libi3.h.

Referenced by route_click().

◆ XCB_BUTTON_SCROLL_DOWN

#define XCB_BUTTON_SCROLL_DOWN   XCB_BUTTON_INDEX_5

Definition at line 33 of file libi3.h.

Referenced by route_click().

◆ XCB_BUTTON_SCROLL_LEFT

#define XCB_BUTTON_SCROLL_LEFT   6

Definition at line 35 of file libi3.h.

Referenced by route_click().

◆ XCB_BUTTON_SCROLL_RIGHT

#define XCB_BUTTON_SCROLL_RIGHT   7

Definition at line 36 of file libi3.h.

Referenced by route_click().

◆ XCB_BUTTON_SCROLL_UP

#define XCB_BUTTON_SCROLL_UP   XCB_BUTTON_INDEX_4

Definition at line 32 of file libi3.h.

Referenced by route_click().

Typedef Documentation

◆ color_t

typedef struct color_t color_t

◆ i3Font

typedef struct Font i3Font

Definition at line 51 of file libi3.h.

◆ i3String

typedef struct _i3String i3String

Opaque data structure for storing strings.

Definition at line 49 of file libi3.h.

◆ placeholder_t

typedef struct placeholder_t placeholder_t

Helper structure for usage in format_placeholders().

◆ surface_t

typedef struct surface_t surface_t

Function Documentation

◆ aio_get_mod_mask_for()

uint32_t aio_get_mod_mask_for ( uint32_t keysym,
xcb_key_symbols_t * symbols )

All-in-one function which returns the modifier mask (XCB_MOD_MASK_*) for the given keysymbol, for example for XCB_NUM_LOCK (usually configured to mod2).

This function initiates one round-trip. Use get_mod_mask_for() directly if you already have the modifier mapping and key symbols.

Referenced by handle_mapping_notify(), and main().

◆ boolstr()

bool boolstr ( const char * str)

Reports whether str represents the enabled state (1, yes, true, …).

Referenced by CFGFUN(), CFGFUN(), CFGFUN(), CFGFUN(), CFGFUN(), CFGFUN(), CFGFUN(), CFGFUN(), CFGFUN(), CFGFUN(), CFGFUN(), CFGFUN(), CFGFUN(), CFGFUN(), CFGFUN(), and cmd_title_window_icon().

◆ convert_ucs2_to_utf8()

char * convert_ucs2_to_utf8 ( xcb_char2b_t * text,
size_t num_glyphs )

Converts the given string to UTF-8 from UCS-2 big endian.

The return value must be freed after use.

◆ convert_utf8_to_ucs2()

xcb_char2b_t * convert_utf8_to_ucs2 ( char * input,
size_t * real_strlen )

Converts the given string to UCS-2 big endian for use with xcb_image_text_16().

The amount of real glyphs is stored in real_strlen, a buffer containing the UCS-2 encoded string (16 bit per glyph) is returned. It has to be freed when done.

◆ create_socket()

int create_socket ( const char * filename,
char ** out_socketpath )

Creates the UNIX domain socket at the given path, sets it to non-blocking mode, bind()s and listen()s on it.

The full path to the socket is stored in the char* that out_socketpath points to.

Referenced by main().

◆ debuglog()

void debuglog ( char * fmt,
... )

◆ draw_text()

void draw_text ( i3String * text,
xcb_drawable_t drawable,
xcb_gcontext_t gc,
cairo_surface_t * surface,
int x,
int y,
int max_width )

Draws text onto the specified X drawable (normally a pixmap) at the specified coordinates (from the top left corner of the leftmost, uppermost glyph) and using the provided gc.

The given cairo surface must refer to the specified X drawable.

Text must be specified as an i3String.

◆ draw_util_clear_surface()

void draw_util_clear_surface ( surface_t * surface,
color_t color )

Clears a surface with the given color.

Referenced by sighandler_draw_dialog(), update_placeholder_contents(), x_draw_decoration(), and x_push_node().

◆ draw_util_copy_surface()

void draw_util_copy_surface ( surface_t * src,
surface_t * dest,
double src_x,
double src_y,
double dest_x,
double dest_y,
double width,
double height )

Copies a surface onto another surface.

Referenced by handle_expose_event(), x_deco_recurse(), x_draw_decoration(), and x_push_node().

◆ draw_util_hex_to_color()

color_t draw_util_hex_to_color ( const char * color)

Parses the given color in hex format to an internal color representation.

Note that the input must begin with a hash sign, e.g., "#3fbc59".

Referenced by CFGFUN(), load_configuration(), and sighandler_draw_dialog().

◆ draw_util_image()

void draw_util_image ( cairo_surface_t * image,
surface_t * surface,
int x,
int y,
int width,
int height )

Draw the given image using libi3.

Referenced by x_draw_decoration().

◆ draw_util_rectangle()

void draw_util_rectangle ( surface_t * surface,
color_t color,
double x,
double y,
double w,
double h )

Draws a filled rectangle.

This function is a convenience wrapper and takes care of flushing the surface as well as restoring the cairo state.

Referenced by sighandler_draw_dialog(), x_draw_decoration(), x_draw_decoration_after_title(), and x_draw_title_border().

◆ draw_util_surface_free()

void draw_util_surface_free ( xcb_connection_t * conn,
surface_t * surface )

◆ draw_util_surface_init()

void draw_util_surface_init ( xcb_connection_t * conn,
surface_t * surface,
xcb_drawable_t drawable,
xcb_visualtype_t * visual,
int width,
int height )

Initialize the surface to represent the given drawable.

Referenced by open_placeholder_window(), sighandler_create_dialogs(), x_con_init(), and x_push_node().

◆ draw_util_surface_set_size()

void draw_util_surface_set_size ( surface_t * surface,
int width,
int height )

Resize the surface to the given size.

Referenced by configure_notify(), and x_push_node().

◆ draw_util_text()

void draw_util_text ( i3String * text,
surface_t * surface,
color_t fg_color,
color_t bg_color,
int x,
int y,
int max_width )

Draw the given text using libi3.

This function also marks the surface dirty which is needed if other means of drawing are used. This will be the case when using XCB to draw text.

Referenced by sighandler_draw_dialog(), update_placeholder_contents(), and x_draw_decoration().

◆ errorlog()

void errorlog ( char * fmt,
... )

◆ fake_configure_notify()

void fake_configure_notify ( xcb_connection_t * conn,
xcb_rectangle_t r,
xcb_window_t window,
int border_width )

Generates a configure_notify event and sends it to the given window Applications need this to think they’ve configured themselves correctly.

The truth is, however, that we will manage them.

Referenced by fake_absolute_configure_notify().

◆ font_is_pango()

bool font_is_pango ( void )

Returns true if and only if the current font is a pango font.

Referenced by con_parse_title_format(), pango_escape_markup(), and x_draw_decoration_after_title().

◆ format_placeholders()

char * format_placeholders ( char * format,
placeholder_t * placeholders,
int num )

Replaces occurrences of the defined placeholders in the format string.

Referenced by con_parse_title_format().

◆ free_font()

void free_font ( void )

Frees the resources taken by the current font.

If no font was previously loaded, it simply returns.

Referenced by free_configuration().

◆ g_utf8_make_valid()

gchar * g_utf8_make_valid ( const gchar * str,
gssize len )

◆ get_colorpixel()

uint32_t get_colorpixel ( const char * hex) const

Returns the colorpixel to use for the given hex color (think of HTML).

Only works for true-color (vast majority of cases) at the moment, avoiding a roundtrip to X11.

The hex_color has to start with #, for example #FF00FF.

NOTE that get_colorpixel() does NOT check the given color code for validity. This has to be done by the caller.

NOTE that this function may in the future rely on a global xcb_connection_t variable called 'conn' to be present.

◆ get_config_path()

char * get_config_path ( const char * override_configpath,
bool use_system_paths )

Get the path of the first configuration file found.

If override_configpath is specified, that path is returned and saved for further calls. Otherwise, checks the home directory first, then the system directory, always taking into account the XDG Base Directory Specification ($XDG_CONFIG_HOME, $XDG_CONFIG_DIRS).

Referenced by load_configuration().

◆ get_dpi_value()

long get_dpi_value ( void )

This function returns the value of the DPI setting.

◆ get_exe_path()

char * get_exe_path ( const char * argv0)

This function returns the absolute path to the executable it is running in.

The implementation follows https://stackoverflow.com/a/933996/712014

Returned value must be freed by the caller.

◆ get_mod_mask_for()

uint32_t get_mod_mask_for ( uint32_t keysym,
xcb_key_symbols_t * symbols,
xcb_get_modifier_mapping_reply_t * modmap_reply )

Returns the modifier mask (XCB_MOD_MASK_*) for the given keysymbol, for example for XCB_NUM_LOCK (usually configured to mod2).

This function does not initiate any round-trips.

◆ get_process_filename()

char * get_process_filename ( const char * prefix)

Returns the name of a temporary file with the specified prefix.

Referenced by init_logging(), main(), and store_restart_layout().

◆ get_visual_depth()

uint16_t get_visual_depth ( xcb_visualid_t visual_id)

Get depth of visual specified by visualid.

Referenced by manage_window().

◆ get_visualtype()

xcb_visualtype_t * get_visualtype ( xcb_screen_t * screen)

Returns the visual type associated with the given screen.

Referenced by main(), and open_placeholder_window().

◆ i3string_as_ucs2()

const xcb_char2b_t * i3string_as_ucs2 ( i3String * str)

Returns the UCS-2 encoded version of the i3String.

◆ i3string_as_utf8()

const char * i3string_as_utf8 ( i3String * str)

◆ i3string_copy()

i3String * i3string_copy ( i3String * str)

Copies the given i3string.

Note that this will not free the source string.

◆ i3string_escape_markup()

i3String * i3string_escape_markup ( i3String * str)

Escape pango markup characters in the given string.

◆ i3string_free()

void i3string_free ( i3String * str)

◆ i3string_from_markup()

i3String * i3string_from_markup ( const char * from_markup)

Build an i3String from an UTF-8 encoded string in Pango markup.

◆ i3string_from_markup_with_length()

i3String * i3string_from_markup_with_length ( const char * from_markup,
size_t num_bytes )

Build an i3String from an UTF-8 encoded string in Pango markup with fixed length.

◆ i3string_from_ucs2()

i3String * i3string_from_ucs2 ( const xcb_char2b_t * from_ucs2,
size_t num_glyphs )

Build an i3String from an UCS-2 encoded string.

Returns the newly-allocated i3String.

◆ i3string_from_utf8()

i3String * i3string_from_utf8 ( const char * from_utf8)

Build an i3String from an UTF-8 encoded string.

Returns the newly-allocated i3String.

Referenced by con_parse_title_format(), sighandler_setup(), update_placeholder_contents(), window_update_name(), window_update_name_legacy(), and x_draw_decoration().

◆ i3string_from_utf8_with_length()

i3String * i3string_from_utf8_with_length ( const char * from_utf8,
ssize_t num_bytes )

Build an i3String from an UTF-8 encoded string with fixed length.

To be used when no proper NULL-termination is available. Returns the newly-allocated i3String.

◆ i3string_get_num_bytes()

size_t i3string_get_num_bytes ( i3String * str)

Returns the number of bytes (UTF-8 encoded) in an i3String.

◆ i3string_get_num_glyphs()

size_t i3string_get_num_glyphs ( i3String * str)

Returns the number of glyphs in an i3String.

◆ i3string_is_markup()

bool i3string_is_markup ( i3String * str)

Whether the given i3String is in Pango markup.

◆ i3string_set_markup()

void i3string_set_markup ( i3String * str,
bool pango_markup )

Set whether the i3String should use Pango markup.

Referenced by con_parse_title_format().

◆ init_dpi()

void init_dpi ( void )

Initialize the DPI setting.

This will use the 'Xft.dpi' X resource if available and fall back to guessing the correct value otherwise.

Referenced by main().

◆ ipc_connect()

int ipc_connect ( const char * socket_path)

Connects to the i3 IPC socket and returns the file descriptor for the socket.

die()s if anything goes wrong.

Referenced by display_running_version().

◆ ipc_connect_impl()

int ipc_connect_impl ( const char * socket_path)

Connects to the socket at the given path with no fallback paths.

Returns -1 if connect() fails and die()s for other errors.

◆ ipc_recv_message()

int ipc_recv_message ( int sockfd,
uint32_t * message_type,
uint32_t * reply_length,
uint8_t ** reply )

Reads a message from the given socket file descriptor and stores its length (reply_length) as well as a pointer to its contents (reply).

Returns -1 when read() fails, errno will remain. Returns -2 when the IPC protocol is violated (invalid magic, unexpected message type, EOF instead of a message). Additionally, the error will be printed to stderr. Returns 0 on success.

Referenced by display_running_version(), ipc_receive_message(), and main().

◆ ipc_send_message()

int ipc_send_message ( int sockfd,
const uint32_t message_size,
const uint32_t message_type,
const uint8_t * payload )

Formats a message (payload) of the given size and type and sends it to i3 via the given socket file descriptor.

Returns -1 when write() fails, errno will remain. Returns 0 on success.

Referenced by display_running_version(), and main().

◆ is_background_set()

bool is_background_set ( xcb_connection_t * conn,
xcb_screen_t * screen )

Test whether the screen's root window has a background set.

This opens & closes a window and test whether the root window still shows the content of the window.

Referenced by main().

◆ is_debug_build()

bool is_debug_build ( void ) const

Returns true if this version of i3 is a debug build (anything which is not a release version), based on the git version number.

Referenced by main().

◆ load_font()

i3Font load_font ( const char * pattern,
const bool fallback )

Loads a font for usage, also getting its height.

If fallback is true, the fonts 'fixed' or '-misc-*' will be loaded instead of exiting. If any font was previously loaded, it will be freed.

Referenced by CFGFUN(), and load_configuration().

◆ logical_px()

int logical_px ( const int logical)

Convert a logical amount of pixels (e.g.

2 pixels on a “standard” 96 DPI screen) to a corresponding amount of physical pixels on a standard or retina screen, e.g. 5 pixels on a 227 DPI MacBook Pro 13" Retina screen.

Referenced by border_width_from_style(), CFGFUN(), CFGFUN(), cmd_gaps(), DRAGGING_CB(), load_configuration(), main(), resize_graphical_handler(), sighandler_setup(), threshold_exceeded(), window_update_icon(), x_draw_decoration(), and x_draw_decoration_after_title().

◆ mkdirp()

int mkdirp ( const char * path,
mode_t mode )

Emulates mkdir -p (creates any missing folders)

Referenced by store_restart_layout().

◆ path_exists()

bool path_exists ( const char * path)

Checks if the given path exists by calling stat().

Referenced by tree_restore().

◆ predict_text_width()

int predict_text_width ( i3String * text)

Predict the text width in pixels for the given text.

Text must be specified as an i3String.

Referenced by sighandler_setup(), update_placeholder_contents(), and x_draw_decoration().

◆ resolve_tilde()

char * resolve_tilde ( const char * path)

This function resolves ~ in pathnames.

It may resolve wildcards in the first part of the path, but if no match or multiple matches are found, it just returns a copy of path as given.

Referenced by cmd_append_layout(), store_restart_layout(), and tree_restore().

◆ root_atom_contents()

char * root_atom_contents ( const char * atomname,
xcb_connection_t * provided_conn,
int screen )

Try to get the contents of the given atom (for example I3_SOCKET_PATH) from the X11 root window and return NULL if it doesn’t work.

If the provided XCB connection is NULL, a new connection will be established.

The memory for the contents is dynamically allocated and has to be free()d by the caller.

Referenced by display_running_version(), and main().

◆ sasprintf()

◆ scalloc()

◆ set_font()

void set_font ( i3Font * font)

Defines the font to be used for the forthcoming calls.

Referenced by CFGFUN(), and load_configuration().

◆ set_font_colors()

void set_font_colors ( xcb_gcontext_t gc,
color_t foreground,
color_t background )

Defines the colors to be used for the forthcoming draw_text calls.

◆ set_nonblock()

void set_nonblock ( int sockfd)

Puts the given socket file descriptor into non-blocking mode or dies if setting O_NONBLOCK failed.

Non-blocking sockets are a good idea for our IPC model because we should by no means block the window manager.

Referenced by ipc_new_client_on_fd().

◆ set_screenshot_as_wallpaper()

void set_screenshot_as_wallpaper ( xcb_connection_t * conn,
xcb_screen_t * screen )

Grab a screenshot of the screen's root window and set it as the wallpaper.

Referenced by main().

◆ smalloc()

void * smalloc ( size_t size)

◆ srealloc()

void * srealloc ( void * ptr,
size_t size )

Safe-wrapper around realloc which exits if realloc returns NULL (meaning that there is no more memory available).

Referenced by add_subscription(), CFGFUN(), display_running_version(), extract_workspace_names_from_bindings(), ipc_push_pending(), ipc_send_client_message(), json_string(), main(), run_assignments(), and x_push_changes().

◆ sstrdup()

◆ sstrndup()

char * sstrndup ( const char * str,
size_t size )

Safe-wrapper around strndup which exits if strndup returns NULL (meaning that there is no more memory available)

Referenced by IPC_HANDLER(), json_string(), window_update_class(), window_update_machine(), window_update_name(), and window_update_name_legacy().

◆ strcasecmp_nullable()

int strcasecmp_nullable ( const char * a,
const char * b )

Like strcasecmp but considers the case where either string is NULL.

Referenced by _con_attach().

◆ strndup()

char * strndup ( const char * str,
size_t n )

Taken from FreeBSD Returns a pointer to a new string which is a duplicate of the string, but only copies at most n characters.

◆ swrite()

ssize_t swrite ( int fd,
const void * buf,
size_t count )

Safe-wrapper around writeall which exits if it returns -1 (meaning that write failed)

◆ verboselog()

void verboselog ( char * fmt,
... )

◆ writeall()

ssize_t writeall ( int fd,
const void * buf,
size_t count )

Wrapper around correct write which returns -1 (meaning that write failed) or count (meaning that all bytes were written)

Referenced by log_broadcast_to_clients(), and store_restart_layout().

◆ writeall_nonblock()

ssize_t writeall_nonblock ( int fd,
const void * buf,
size_t count )

Like writeall, but instead of retrying upon EAGAIN (returned when a write would block), the function stops and returns the total number of bytes written so far.

Referenced by ipc_push_pending().

Variable Documentation

◆ conn

xcb_connection_t* conn
extern

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().

◆ root_screen