i3
|
00001 /* 00002 * vim:ts=4:sw=4:expandtab 00003 * 00004 * i3 - an improved dynamic tiling window manager 00005 * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE) 00006 * 00007 * libi3: contains functions which are used by i3 *and* accompanying tools such 00008 * as i3-msg, i3-config-wizard, … 00009 * 00010 */ 00011 #ifndef _LIBI3_H 00012 #define _LIBI3_H 00013 00014 #include <stdbool.h> 00015 #include <stdarg.h> 00016 #include <stdio.h> 00017 #include <xcb/xcb.h> 00018 #include <xcb/xproto.h> 00019 #include <xcb/xcb_keysyms.h> 00020 00021 typedef struct Font i3Font; 00022 00029 struct Font { 00031 xcb_font_t id; 00032 00034 xcb_query_font_reply_t *info; 00035 00037 xcb_charinfo_t *table; 00038 00040 int height; 00041 }; 00042 00043 /* Since this file also gets included by utilities which don’t use the i3 log 00044 * infrastructure, we define a fallback. */ 00045 #if !defined(ELOG) 00046 #define ELOG(fmt, ...) fprintf(stderr, "ERROR: " fmt, ##__VA_ARGS__) 00047 #endif 00048 00057 char *root_atom_contents(const char *atomname); 00058 00064 void *smalloc(size_t size); 00065 00071 void *scalloc(size_t size); 00072 00078 void *srealloc(void *ptr, size_t size); 00079 00085 char *sstrdup(const char *str); 00086 00092 int sasprintf(char **strp, const char *fmt, ...); 00093 00099 int ipc_connect(const char *socket_path); 00100 00109 int ipc_send_message(int sockfd, uint32_t message_size, 00110 uint32_t message_type, const uint8_t *payload); 00111 00123 int ipc_recv_message(int sockfd, uint32_t message_type, 00124 uint32_t *reply_length, uint8_t **reply); 00125 00132 void fake_configure_notify(xcb_connection_t *conn, xcb_rectangle_t r, xcb_window_t window, int border_width); 00133 00148 uint32_t get_colorpixel(const char *hex) __attribute__((const)); 00149 00150 #if defined(__APPLE__) 00151 00152 /* 00153 * Taken from FreeBSD 00154 * Returns a pointer to a new string which is a duplicate of the 00155 * string, but only copies at most n characters. 00156 * 00157 */ 00158 char *strndup(const char *str, size_t n); 00159 00160 #endif 00161 00170 uint32_t aio_get_mod_mask_for(uint32_t keysym, xcb_key_symbols_t *symbols); 00171 00179 uint32_t get_mod_mask_for(uint32_t keysym, 00180 xcb_key_symbols_t *symbols, 00181 xcb_get_modifier_mapping_reply_t *modmap_reply); 00182 00188 i3Font load_font(const char *pattern, const bool fallback); 00189 00194 void set_font(i3Font *font); 00195 00200 void free_font(void); 00201 00207 char *convert_ucs2_to_utf8(xcb_char2b_t *text, size_t num_glyphs); 00208 00216 xcb_char2b_t *convert_utf8_to_ucs2(char *input, size_t *real_strlen); 00217 00222 void set_font_colors(xcb_gcontext_t gc, uint32_t foreground, uint32_t background); 00223 00235 void draw_text(char *text, size_t text_len, bool is_ucs2, xcb_drawable_t drawable, 00236 xcb_gcontext_t gc, int x, int y, int max_width); 00237 00243 int predict_text_width(char *text, size_t text_len, bool is_ucs2); 00244 00245 #endif