i3
libi3.h
Go to the documentation of this file.
1 /*
2  * vim:ts=4:sw=4:expandtab
3  *
4  * i3 - an improved dynamic tiling window manager
5  * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
6  *
7  * libi3: contains functions which are used by i3 *and* accompanying tools such
8  * as i3-msg, i3-config-wizard, …
9  *
10  */
11 #ifndef _LIBI3_H
12 #define _LIBI3_H
13 
14 #include <stdbool.h>
15 #include <stdarg.h>
16 #include <stdio.h>
17 #include <xcb/xcb.h>
18 #include <xcb/xproto.h>
19 #include <xcb/xcb_keysyms.h>
20 
21 typedef struct Font i3Font;
22 
29 struct Font {
31  xcb_font_t id;
32 
34  xcb_query_font_reply_t *info;
35 
37  xcb_charinfo_t *table;
38 
40  int height;
41 };
42 
43 /* Since this file also gets included by utilities which don’t use the i3 log
44  * infrastructure, we define a fallback. */
45 #if !defined(ELOG)
46 #define ELOG(fmt, ...) fprintf(stderr, "ERROR: " fmt, ##__VA_ARGS__)
47 #endif
48 
57 char *root_atom_contents(const char *atomname);
58 
64 void *smalloc(size_t size);
65 
71 void *scalloc(size_t size);
72 
78 void *srealloc(void *ptr, size_t size);
79 
85 char *sstrdup(const char *str);
86 
92 int sasprintf(char **strp, const char *fmt, ...);
93 
99 int ipc_connect(const char *socket_path);
100 
109 int ipc_send_message(int sockfd, uint32_t message_size,
110  uint32_t message_type, const uint8_t *payload);
111 
123 int ipc_recv_message(int sockfd, uint32_t message_type,
124  uint32_t *reply_length, uint8_t **reply);
125 
132 void fake_configure_notify(xcb_connection_t *conn, xcb_rectangle_t r, xcb_window_t window, int border_width);
133 
148 uint32_t get_colorpixel(const char *hex) __attribute__((const));
149 
150 #if defined(__APPLE__)
151 
152 /*
153  * Taken from FreeBSD
154  * Returns a pointer to a new string which is a duplicate of the
155  * string, but only copies at most n characters.
156  *
157  */
158 char *strndup(const char *str, size_t n);
159 
160 #endif
161 
170 uint32_t aio_get_mod_mask_for(uint32_t keysym, xcb_key_symbols_t *symbols);
171 
179 uint32_t get_mod_mask_for(uint32_t keysym,
180  xcb_key_symbols_t *symbols,
181  xcb_get_modifier_mapping_reply_t *modmap_reply);
182 
188 i3Font load_font(const char *pattern, const bool fallback);
189 
194 void set_font(i3Font *font);
195 
200 void free_font(void);
201 
207 char *convert_ucs2_to_utf8(xcb_char2b_t *text, size_t num_glyphs);
208 
216 xcb_char2b_t *convert_utf8_to_ucs2(char *input, size_t *real_strlen);
217 
222 void set_font_colors(xcb_gcontext_t gc, uint32_t foreground, uint32_t background);
223 
235 void draw_text(char *text, size_t text_len, bool is_ucs2, xcb_drawable_t drawable,
236  xcb_gcontext_t gc, int x, int y, int max_width);
237 
243 int predict_text_width(char *text, size_t text_len, bool is_ucs2);
244 
245 #endif