i3
Macros | Functions
util.h File Reference
#include <err.h>
#include "data.h"
Include dependency graph for util.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define die(...)   errx(EXIT_FAILURE, __VA_ARGS__);
 
#define exit_if_null(pointer,...)   { if (pointer == NULL) die(__VA_ARGS__); }
 
#define STARTS_WITH(string, needle)   (strncasecmp(string, needle, strlen(needle)) == 0)
 
#define CIRCLEQ_NEXT_OR_NULL(head, elm, field)
 
#define CIRCLEQ_PREV_OR_NULL(head, elm, field)
 
#define FOR_TABLE(workspace)
 
#define NODES_FOREACH(head)
 
#define NODES_FOREACH_REVERSE(head)
 
#define GREP_FIRST(dest, head, condition)
 
#define FREE(pointer)
 
#define CALL(obj, member,...)   obj->member(obj, ## __VA_ARGS__)
 

Functions

int min (int a, int b)
 
int max (int a, int b)
 
bool rect_contains (Rect rect, uint32_t x, uint32_t y)
 
Rect rect_add (Rect a, Rect b)
 
Rect rect_sub (Rect a, Rect b)
 
 __attribute__ ((pure)) bool name_is_digits(const char *name)
 Returns true if the name consists of only digits. More...
 
long ws_name_to_number (const char *name)
 Parses the workspace name as a number. More...
 
bool update_if_necessary (uint32_t *destination, const uint32_t new_value)
 Updates *destination with new_value and returns true if it was changed or false if it was the same. More...
 
void exec_i3_utility (char *name, char *argv[])
 exec()s an i3 utility, for example the config file migration script or i3-nagbar. More...
 
void check_error (xcb_connection_t *conn, xcb_void_cookie_t cookie, char *err_message)
 Checks a generic cookie for errors and quits with the given message if there was an error. More...
 
char * resolve_tilde (const char *path)
 This function resolves ~ in pathnames. More...
 
bool path_exists (const char *path)
 Checks if the given path exists by calling stat(). More...
 
void i3_restart (bool forget_layout)
 Restart i3 in-place appends -a to argument list to disable autostart. More...
 
void start_nagbar (pid_t *nagbar_pid, char *argv[])
 Starts an i3-nagbar instance with the given parameters. More...
 
void kill_nagbar (pid_t *nagbar_pid, bool wait_for_it)
 Kills the i3-nagbar process, if *nagbar_pid != -1. More...
 

Macro Definition Documentation

#define CALL (   obj,
  member,
  ... 
)    obj->member(obj, ## __VA_ARGS__)
#define CIRCLEQ_NEXT_OR_NULL (   head,
  elm,
  field 
)
Value:
(CIRCLEQ_NEXT(elm, field) != CIRCLEQ_END(head) ? \
CIRCLEQ_NEXT(elm, field) : NULL)
#define CIRCLEQ_END(head)
Definition: queue.h:445
#define CIRCLEQ_NEXT(elm, field)
Definition: queue.h:446

Definition at line 20 of file util.h.

#define CIRCLEQ_PREV_OR_NULL (   head,
  elm,
  field 
)
Value:
(CIRCLEQ_PREV(elm, field) != CIRCLEQ_END(head) ? \
CIRCLEQ_PREV(elm, field) : NULL)
#define CIRCLEQ_PREV(elm, field)
Definition: queue.h:447
#define CIRCLEQ_END(head)
Definition: queue.h:445

Definition at line 22 of file util.h.

#define die (   ...)    errx(EXIT_FAILURE, __VA_ARGS__);

Definition at line 17 of file util.h.

Referenced by get_config_path(), get_first_output(), main(), parse_file(), and resolve_tilde().

#define exit_if_null (   pointer,
  ... 
)    { if (pointer == NULL) die(__VA_ARGS__); }

Definition at line 18 of file util.h.

#define FOR_TABLE (   workspace)
Value:
for (int cols = 0; cols < (workspace)->cols; cols++) \
for (int rows = 0; rows < (workspace)->rows; rows++)

Definition at line 24 of file util.h.

#define FREE (   pointer)
#define GREP_FIRST (   dest,
  head,
  condition 
)
#define NODES_FOREACH (   head)
Value:
for (Con *child = (Con*)-1; (child == (Con*)-1) && ((child = 0), true);) \
TAILQ_FOREACH(child, &((head)->nodes_head), nodes)
A 'Con' represents everything from the X11 root window down to a single X11 window.
Definition: data.h:479
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:334

Definition at line 28 of file util.h.

Referenced by workspace_next(), and workspace_next_on_output().

#define NODES_FOREACH_REVERSE (   head)
Value:
for (Con *child = (Con*)-1; (child == (Con*)-1) && ((child = 0), true);) \
TAILQ_FOREACH_REVERSE(child, &((head)->nodes_head), nodes_head, nodes)
#define TAILQ_FOREACH_REVERSE(var, head, headname, field)
Definition: queue.h:339
A 'Con' represents everything from the X11 root window down to a single X11 window.
Definition: data.h:479

Definition at line 32 of file util.h.

Referenced by workspace_prev(), and workspace_prev_on_output().

#define STARTS_WITH (   string,
  needle 
)    (strncasecmp(string, needle, strlen(needle)) == 0)

Definition at line 19 of file util.h.

Referenced by ewmh_update_current_desktop().

Function Documentation

__attribute__ ( (pure)  ) const

Returns true if the name consists of only digits.

void check_error ( xcb_connection_t *  conn,
xcb_void_cookie_t  cookie,
char *  err_message 
)

Checks a generic cookie for errors and quits with the given message if there was an error.

Definition at line 153 of file util.c.

Referenced by main().

void exec_i3_utility ( char *  name,
char *  argv[] 
)

exec()s an i3 utility, for example the config file migration script or i3-nagbar.

This function first searches $PATH for the given utility named, then falls back to the dirname() of the i3 executable path and then falls back to the dirname() of the target of /proc/self/exe (on linux).

This function should be called after fork()ing.

The first argument of the given argv vector will be overwritten with the executable name, so pass NULL.

If the utility cannot be found in any of these locations, it exits with return code 2.

Definition at line 116 of file util.c.

References sasprintf(), and start_argv.

Referenced by migrate_config(), and start_nagbar().

Here is the call graph for this function:

void i3_restart ( bool  forget_layout)

Restart i3 in-place appends -a to argument list to disable autostart.

Definition at line 294 of file util.c.

References append_argument(), command_error_nagbar_pid, config_error_nagbar_pid, ipc_shutdown(), kill_nagbar(), LOG, restore_geometry(), scalloc(), start_argv, and store_restart_layout().

Referenced by cmd_restart(), and sig_handle_key_press().

Here is the call graph for this function:

void kill_nagbar ( pid_t *  nagbar_pid,
bool  wait_for_it 
)

Kills the i3-nagbar process, if *nagbar_pid != -1.

If wait_for_it is set (restarting i3), this function will waitpid(), otherwise, ev is assumed to handle it (reloading).

Definition at line 460 of file util.c.

Referenced by cmd_reload(), and i3_restart().

int max ( int  a,
int  b 
)

Definition at line 33 of file util.c.

Referenced by con_minimum_size(), DRAGGING_CB(), floating_check_size(), and floating_enable().

int min ( int  a,
int  b 
)
bool path_exists ( const char *  path)

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

Definition at line 198 of file util.c.

Referenced by get_config_path(), ipc_create_socket(), and tree_restore().

Rect rect_add ( Rect  a,
Rect  b 
)

Definition at line 44 of file util.c.

References Rect::height, Rect::width, Rect::x, and Rect::y.

Referenced by con_set_border_style(), and render_con().

bool rect_contains ( Rect  rect,
uint32_t  x,
uint32_t  y 
)

Definition at line 37 of file util.c.

References Rect::height, Rect::width, Rect::x, and Rect::y.

Referenced by handle_button_press(), handle_enter_notify(), and handle_motion_notify().

Rect rect_sub ( Rect  a,
Rect  b 
)

Definition at line 51 of file util.c.

References Rect::height, Rect::width, Rect::x, and Rect::y.

Referenced by con_set_border_style().

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.

Definition at line 168 of file util.c.

References die, scalloc(), and sstrdup().

Referenced by get_config_path(), ipc_create_socket(), store_restart_layout(), and tree_restore().

Here is the call graph for this function:

void start_nagbar ( pid_t *  nagbar_pid,
char *  argv[] 
)

Starts an i3-nagbar instance with the given parameters.

Takes care of handling SIGCHLD and killing i3-nagbar when i3 exits.

The resulting PID will be stored in *nagbar_pid and can be used with kill_nagbar() to kill the bar later on.

Definition at line 420 of file util.c.

References DLOG, exec_i3_utility(), main_loop, nagbar_cleanup(), nagbar_exited(), and smalloc().

Referenced by parse_file(), and run_binding().

Here is the call graph for this function:

bool update_if_necessary ( uint32_t *  destination,
const uint32_t  new_value 
)

Updates *destination with new_value and returns true if it was changed or false if it was the same.

Definition at line 95 of file util.c.

Referenced by handle_output(), and randr_query_outputs().

long ws_name_to_number ( const char *  name)

Parses the workspace name as a number.

Returns -1 if the workspace should be interpreted as a "named workspace".

Definition at line 76 of file util.c.

Referenced by workspace_get().