include/util.h File Reference

#include <xcb/xcb.h>
#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.

Defines

#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 FREE(pointer)

Functions

 TAILQ_HEAD (keyvalue_table_head, keyvalue_element)
int min (int a, int b)
int max (int a, int b)
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.
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 size)
 Safe-wrapper around calloc which exits if malloc 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).
bool table_put (struct keyvalue_table_head *head, uint32_t key, void *value)
 Inserts an element into the given keyvalue-table using the given key.
void * table_remove (struct keyvalue_table_head *head, uint32_t key)
 Removes the element from the given keyvalue-table with the given key and returns its value;.
void * table_get (struct keyvalue_table_head *head, uint32_t key)
 Returns the value of the element of the given keyvalue-table with the given key.
void start_application (const char *command)
 Starts the given application by passing it through a shell.
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.
char * convert_utf8_to_ucs2 (char *input, int *real_strlen)
 Converts the given string to UCS-2 big endian for use with xcb_image_text_16().
Clientget_last_focused_client (xcb_connection_t *conn, Container *container, Client *exclude)
 Returns the client which comes next in focus stack (= was selected before) for the given container, optionally excluding the given client.
void set_focus (xcb_connection_t *conn, Client *client, bool set_anyways)
 Sets the given client as focused by updating the data structures correctly, updating the X input focus and finally re-decorating both windows (to signalize the user the new focus situation).
void leave_stack_mode (xcb_connection_t *conn, Container *container)
 Called when the user switches to another mode or when the container is destroyed and thus needs to be cleaned up.
void switch_layout_mode (xcb_connection_t *conn, Container *container, int mode)
 Switches the layout of the given container taking care of the necessary house-keeping.
Clientget_matching_client (xcb_connection_t *conn, const char *window_classtitle, Client *specific)
 Gets the first matching client for the given window class/window title.
void i3_restart ()

Variables

struct keyvalue_table_head by_parent
struct keyvalue_table_head by_child

Define Documentation

#define CIRCLEQ_NEXT_OR_NULL ( head,
elm,
field   ) 
Value:
(CIRCLEQ_NEXT(elm, field) != CIRCLEQ_END(head) ? \
                                                CIRCLEQ_NEXT(elm, field) : NULL)

Definition at line 22 of file util.h.

Referenced by focus_window_in_container(), move_current_window(), and move_current_window_to_workspace().

#define CIRCLEQ_PREV_OR_NULL ( head,
elm,
field   ) 
Value:
(CIRCLEQ_PREV(elm, field) != CIRCLEQ_END(head) ? \
                                                CIRCLEQ_PREV(elm, field) : NULL)

Definition at line 24 of file util.h.

Referenced by focus_window_in_container(), move_current_window(), and move_current_window_to_workspace().

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

Definition at line 20 of file util.h.

Referenced by scalloc(), smalloc(), sstrdup(), and TAILQ_HEAD().

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

Definition at line 26 of file util.h.

Referenced by dump_table(), fix_colrowspan(), ignore_enter_notify_forall(), render_workspace(), workspace_map_clients(), and workspace_unmap_clients().

#define FREE ( pointer   ) 
Value:
do { \
        if (pointer != NULL) { \
                free(pointer); \
                pointer = NULL; \
        } \
} \
while (0)

Definition at line 29 of file util.h.

Referenced by drag_pointer(), get_matching_client(), handle_output(), handle_unmap_notify_event(), handle_windowclass_change(), handle_windowname_change(), initialize_xinerama(), load_configuration(), parse_file(), and workspace_set_name().

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

Definition at line 21 of file util.h.

Referenced by parse_command(), and parse_resize_command().


Function Documentation

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 159 of file util.c.

Referenced by main(), and TAILQ_HEAD().

char* convert_utf8_to_ucs2 ( char *  input,
int *  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.

Definition at line 175 of file util.c.

References conversion_descriptor, and smalloc().

Referenced by get_matching_client(), handle_signal(), handle_windowname_change(), sig_draw_window(), and workspace_set_name().

Here is the call graph for this function:

Client* get_last_focused_client ( xcb_connection_t *  conn,
Container container,
Client exclude 
)

Returns the client which comes next in focus stack (= was selected before) for the given container, optionally excluding the given client.

Definition at line 217 of file util.c.

References Client::container, SLIST_FOREACH, and Container::workspace.

Referenced by handle_unmap_notify_event(), move_current_window(), set_focus(), switch_layout_mode(), and toggle_floating_mode().

Client* get_matching_client ( xcb_connection_t *  conn,
const char *  window_classtitle,
Client specific 
)

Gets the first matching client for the given window class/window title.

If the paramater specific is set to a specific client, only this one will be checked.

Definition at line 440 of file util.c.

References client_matches_class_name(), convert_utf8_to_ucs2(), DLOG, FREE, Client::name, Workspace::output, SLIST_FOREACH, sstrdup(), TAILQ_FOREACH, Client::window_class_class, Client::window_class_instance, and workspaces.

Referenced by jump_to_window(), and reparent_window().

Here is the call graph for this function:

void i3_restart (  ) 

Definition at line 514 of file util.c.

References append_argument(), global_conn, ipc_shutdown(), LOG, restore_geometry(), and start_argv.

Referenced by parse_command(), and sig_handle_key_press().

Here is the call graph for this function:

void leave_stack_mode ( xcb_connection_t *  conn,
Container container 
)

Called when the user switches to another mode or when the container is destroyed and thus needs to be cleaned up.

Definition at line 329 of file util.c.

References Cached_Pixmap::gc, Rect::height, Cached_Pixmap::id, Stack_Window::pixmap, Stack_Window::rect, SLIST_REMOVE, Container::stack_win, stack_wins, Rect::width, and Stack_Window::window.

Referenced by free_container(), and switch_layout_mode().

int max ( int  a,
int  b 
)
int min ( int  a,
int  b 
)

Definition at line 44 of file util.c.

Referenced by query_screens(), randr_query_outputs(), render_container(), and reparent_window().

void* scalloc ( size_t  size  ) 

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

Definition at line 74 of file util.c.

References exit_if_null.

Referenced by add_subscription(), disable_randr(), expand_table_cols(), expand_table_cols_at_head(), handle_output(), init_table(), IPC_HANDLER(), ipc_new_client(), load_configuration(), main(), new_container(), parse_file(), query_screens(), reparent_window(), table_put(), workspace_get(), and yyparse().

void set_focus ( xcb_connection_t *  conn,
Client client,
bool  set_anyways 
)
void* smalloc ( size_t  size  ) 

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

Definition at line 68 of file util.c.

References exit_if_null.

Referenced by append_argument(), convert_utf8_to_ucs2(), ewmh_update_workarea(), manage_existing_windows(), parse_file(), SLIST_HEAD(), TAILQ_HEAD(), translate_keysyms(), and yyparse().

char* sstrdup ( const char *  str  ) 

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

Definition at line 80 of file util.c.

References exit_if_null.

Referenced by client_mark(), get_matching_client(), glob_path(), ipc_create_socket(), jump_to_window(), load_configuration(), main(), parse_file(), TAILQ_HEAD(), and yyparse().

void start_application ( const char *  command  ) 

Starts the given application by passing it through a shell.

We use double fork to avoid zombie processes. As the started application’s parent exits (immediately), the application is reparented to init (process-id 1), which correctly handles childs, so we don’t have to do it :-).

The shell is determined by looking for the SHELL environment variable. If it does not exist, /bin/sh is used.

Definition at line 134 of file util.c.

Referenced by main(), and parse_command().

void switch_layout_mode ( xcb_connection_t *  conn,
Container container,
int  mode 
)
void* table_get ( struct keyvalue_table_head *  head,
uint32_t  key 
)
bool table_put ( struct keyvalue_table_head *  head,
uint32_t  key,
void *  value 
)

Inserts an element into the given keyvalue-table using the given key.

Definition at line 91 of file util.c.

References keyvalue_element::key, scalloc(), TAILQ_INSERT_TAIL, and keyvalue_element::value.

Referenced by reparent_window().

Here is the call graph for this function:

void* table_remove ( struct keyvalue_table_head *  head,
uint32_t  key 
)

Removes the element from the given keyvalue-table with the given key and returns its value;.

Definition at line 100 of file util.c.

References keyvalue_element::key, TAILQ_FOREACH, TAILQ_REMOVE, and keyvalue_element::value.

Referenced by handle_unmap_notify_event().

TAILQ_HEAD ( keyvalue_table_head  ,
keyvalue_element   
)
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 57 of file util.c.

Referenced by handle_output(), randr_query_outputs(), render_bars(), and render_container().


Variable Documentation

struct keyvalue_table_head by_child
struct keyvalue_table_head by_parent

Generated on 16 Apr 2010 for i3 by  doxygen 1.6.1