]> git.sur5r.net Git - i3/i3/blob - include/util.h
Bugfix: Don’t free xinerama-reply if it is NULL, implement FREE()-macro (Thanks Igor)
[i3/i3] / include / util.h
1 /*
2  * vim:ts=8:expandtab
3  *
4  * i3 - an improved dynamic tiling window manager
5  *
6  * (c) 2009 Michael Stapelberg and contributors
7  *
8  * See file LICENSE for license information.
9  *
10  */
11 #include <xcb/xcb.h>
12
13 #include "data.h"
14
15 #ifndef _UTIL_H
16 #define _UTIL_H
17
18 #define exit_if_null(pointer, ...) { if (pointer == NULL) die(__VA_ARGS__); }
19 #define STARTS_WITH(string, needle) (strncasecmp(string, needle, strlen(needle)) == 0)
20 #define CIRCLEQ_NEXT_OR_NULL(head, elm, field) (CIRCLEQ_NEXT(elm, field) != CIRCLEQ_END(head) ? \
21                                                 CIRCLEQ_NEXT(elm, field) : NULL)
22 #define CIRCLEQ_PREV_OR_NULL(head, elm, field) (CIRCLEQ_PREV(elm, field) != CIRCLEQ_END(head) ? \
23                                                 CIRCLEQ_PREV(elm, field) : NULL)
24 #define FOR_TABLE(workspace) \
25                         for (int cols = 0; cols < workspace->cols; cols++) \
26                                 for (int rows = 0; rows < workspace->rows; rows++)
27 #define FREE(pointer) do { \
28         if (pointer == NULL) { \
29                 free(pointer); \
30                 pointer = NULL; \
31         } \
32 } \
33 while (0)
34
35 /* ##__VA_ARGS__ means: leave out __VA_ARGS__ completely if it is empty, that is,
36    delete the preceding comma */
37 #define LOG(fmt, ...) slog("%s:%s:%d - " fmt, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
38
39
40 int min(int a, int b);
41 int max(int a, int b);
42 void slog(char *fmt, ...);
43 void die(char *fmt, ...);
44 void *smalloc(size_t size);
45 void *scalloc(size_t size);
46 char *sstrdup(const char *str);
47 void start_application(const char *command);
48 void check_error(xcb_connection_t *conn, xcb_void_cookie_t cookie, char *err_message);
49 char *convert_utf8_to_ucs2(char *input, int *real_strlen);
50 void remove_client_from_container(xcb_connection_t *conn, Client *client, Container *container);
51 void set_focus(xcb_connection_t *conn, Client *client);
52 void leave_stack_mode(xcb_connection_t *conn, Container *container);
53 void switch_layout_mode(xcb_connection_t *conn, Container *container, int mode);
54 void warp_pointer_into(xcb_connection_t *conn, Client *client);
55 void toggle_fullscreen(xcb_connection_t *conn, Client *client);
56 void kill_window(xcb_connection_t *conn, Client *window);
57
58 #endif