i3
|
00001 /* 00002 * vim:ts=8:expandtab 00003 * 00004 * i3 - an improved dynamic tiling window manager 00005 * 00006 * © 2009 Michael Stapelberg and contributors 00007 * 00008 * See file LICENSE for license information. 00009 * 00010 */ 00011 #include <xcb/xcb.h> 00012 #include <err.h> 00013 00014 #include "data.h" 00015 00016 #ifndef _UTIL_H 00017 #define _UTIL_H 00018 00019 #define die(...) errx(EXIT_FAILURE, __VA_ARGS__); 00020 #define exit_if_null(pointer, ...) { if (pointer == NULL) die(__VA_ARGS__); } 00021 #define STARTS_WITH(string, needle) (strncasecmp(string, needle, strlen(needle)) == 0) 00022 #define CIRCLEQ_NEXT_OR_NULL(head, elm, field) (CIRCLEQ_NEXT(elm, field) != CIRCLEQ_END(head) ? \ 00023 CIRCLEQ_NEXT(elm, field) : NULL) 00024 #define CIRCLEQ_PREV_OR_NULL(head, elm, field) (CIRCLEQ_PREV(elm, field) != CIRCLEQ_END(head) ? \ 00025 CIRCLEQ_PREV(elm, field) : NULL) 00026 #define FOR_TABLE(workspace) \ 00027 for (int cols = 0; cols < (workspace)->cols; cols++) \ 00028 for (int rows = 0; rows < (workspace)->rows; rows++) 00029 #define FREE(pointer) do { \ 00030 if (pointer != NULL) { \ 00031 free(pointer); \ 00032 pointer = NULL; \ 00033 } \ 00034 } \ 00035 while (0) 00036 00037 TAILQ_HEAD(keyvalue_table_head, keyvalue_element); 00038 extern struct keyvalue_table_head by_parent; 00039 extern struct keyvalue_table_head by_child; 00040 00041 int min(int a, int b); 00042 int max(int a, int b); 00043 00049 bool update_if_necessary(uint32_t *destination, const uint32_t new_value); 00050 00056 void *smalloc(size_t size); 00057 00063 void *scalloc(size_t size); 00064 00070 char *sstrdup(const char *str); 00071 00076 bool table_put(struct keyvalue_table_head *head, uint32_t key, void *value); 00077 00083 void *table_remove(struct keyvalue_table_head *head, uint32_t key); 00084 00090 void *table_get(struct keyvalue_table_head *head, uint32_t key); 00091 00102 void start_application(const char *command); 00103 00109 void check_error(xcb_connection_t *conn, xcb_void_cookie_t cookie, 00110 char *err_message); 00111 00119 char *convert_utf8_to_ucs2(char *input, int *real_strlen); 00120 00126 Client *get_last_focused_client(xcb_connection_t *conn, Container *container, 00127 Client *exclude); 00128 00135 void set_focus(xcb_connection_t *conn, Client *client, bool set_anyways); 00136 00142 void leave_stack_mode(xcb_connection_t *conn, Container *container); 00143 00149 void switch_layout_mode(xcb_connection_t *conn, Container *container, int mode); 00150 00157 Client *get_matching_client(xcb_connection_t *conn, 00158 const char *window_classtitle, Client *specific); 00159 00160 /* 00161 * Restart i3 in-place 00162 * appends -a to argument list to disable autostart 00163 * 00164 */ 00165 void i3_restart(); 00166 00167 #if defined(__OpenBSD__) 00168 /* OpenBSD does not provide memmem(), so we provide FreeBSD’s implementation */ 00169 void *memmem(const void *l, size_t l_len, const void *s, size_t s_len); 00170 #endif 00171 00172 #endif