i3
|
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/wait.h>
#include <stdarg.h>
#include <assert.h>
#include <iconv.h>
#include <xcb/xcb_icccm.h>
#include "i3.h"
#include "data.h"
#include "table.h"
#include "layout.h"
#include "util.h"
#include "xcb.h"
#include "client.h"
#include "log.h"
#include "ewmh.h"
#include "manage.h"
#include "workspace.h"
#include "ipc.h"
Go to the source code of this file.
Functions | |
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(). | |
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. | |
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. | |
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. | |
static char ** | append_argument (char **original, char *argument) |
void | i3_restart () |
Variables | |
static iconv_t | conversion_descriptor = 0 |
struct keyvalue_table_head | by_parent = TAILQ_HEAD_INITIALIZER(by_parent) |
struct keyvalue_table_head | by_child = TAILQ_HEAD_INITIALIZER(by_child) |
static char** append_argument | ( | char ** | original, |
char * | argument | ||
) | [static] |
Definition at line 492 of file util.c.
References DLOG, and smalloc().
Referenced by i3_restart().
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().
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().
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().
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 | ||
) |
Definition at line 48 of file util.c.
Referenced by client_min_height(), client_min_width(), DRAGGING_CB(), render_container(), reparent_window(), and switch_layout_mode().
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 | ||
) |
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)
Definition at line 232 of file util.c.
References c_ws, Client::child, client_is_floating(), CLIENT_LOG, Container::col, Client::container, current_col, Workspace::current_col, current_row, Workspace::current_row, Container::currently_focused, DLOG, Client::dock, ewmh_update_active_window(), ewmh_update_current_desktop(), Client::frame, Workspace::fullscreen_client, get_last_focused_client(), Container::mode, redecorate_window(), Container::row, SLIST_FIRST, SLIST_FOREACH, SLIST_INSERT_HEAD, SLIST_REMOVE, Client::urgent, Container::workspace, Client::workspace, and workspace_update_urgent_flag().
Referenced by button_press_stackwin(), check_crossing_screen_boundary(), cleanup_table(), floating_focus_direction(), floating_toggle_hide(), focus_thing(), focus_window_in_container(), handle_button_press(), handle_enter_notify(), handle_unmap_notify_event(), jump_to_container(), jump_to_mark(), jump_to_window(), move_current_window(), move_current_window_to_workspace(), move_floating_window_to_workspace(), parse_command(), reposition_client(), switch_layout_mode(), travel_focus_stack(), and workspace_show().
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_config_path(), 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 | ||
) |
Switches the layout of the given container taking care of the necessary house-keeping.
Definition at line 347 of file util.c.
References CIRCLEQ_FOREACH, Stack_Window::container, create_window(), Container::currently_focused, DLOG, Client::force_reconfigure, Client::frame, get_last_focused_client(), Rect::height, leave_stack_mode(), max(), Container::mode, Stack_Window::pixmap, Stack_Window::rect, Cached_Pixmap::referred_drawable, Cached_Pixmap::referred_rect, render_layout(), set_focus(), SLIST_INSERT_HEAD, Container::stack_win, stack_wins, Container::width, Stack_Window::window, Container::x, XCB_CURSOR_LEFT_PTR, and Container::y.
Referenced by expand_table_cols(), expand_table_rows(), new_container(), parse_command(), and yyparse().
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.
Definition at line 114 of file util.c.
References keyvalue_element::key, TAILQ_FOREACH, and keyvalue_element::value.
Referenced by handle_button_press(), handle_client_message(), handle_clientleader_change(), handle_configure_request(), handle_enter_notify(), handle_expose_event(), handle_hints(), handle_normal_hints(), handle_transient_for(), handle_unmap_notify_event(), handle_windowclass_change(), handle_windowname_change(), handle_windowname_change_legacy(), manage_window(), and reparent_window().
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().
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().
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().
Definition at line 42 of file util.c.
Referenced by handle_button_press(), handle_client_message(), handle_clientleader_change(), handle_configure_request(), handle_enter_notify(), handle_hints(), handle_normal_hints(), handle_transient_for(), handle_unmap_notify_event(), handle_windowclass_change(), handle_windowname_change(), handle_windowname_change_legacy(), manage_window(), and reparent_window().
Definition at line 41 of file util.c.
Referenced by handle_button_press(), handle_enter_notify(), handle_expose_event(), handle_unmap_notify_event(), and reparent_window().
iconv_t conversion_descriptor = 0 [static] |
Definition at line 40 of file util.c.
Referenced by convert_utf8_to_ucs2().