14 #ifdef I3_ASAN_ENABLED 15 #include <sanitizer/lsan_interface.h> 18 #define TEXT_PADDING logical_px(2) 39 static xcb_connection_t *restore_conn;
41 static struct ev_io *xcb_watcher;
47 static
void restore_xcb_got_event(EV_P_ struct ev_io *w,
int revents) {
51 xcb_generic_event_t *event;
53 if (xcb_connection_has_error(restore_conn)) {
54 DLOG(
"restore X11 connection has an error, reconnecting\n");
59 while ((event = xcb_poll_for_event(restore_conn)) != NULL) {
60 if (event->response_type == 0) {
61 xcb_generic_error_t *error = (xcb_generic_error_t *)event;
62 DLOG(
"X11 Error received (probably harmless)! sequence 0x%x, error_code = %d\n",
63 error->sequence, error->error_code);
69 int type = (
event->response_type & 0x7F);
76 xcb_flush(restore_conn);
87 if (restore_conn != NULL) {
104 xcb_disconnect(restore_conn);
110 restore_conn = xcb_connect(NULL, &screen);
111 if (restore_conn == NULL || xcb_connection_has_error(restore_conn)) {
112 if (restore_conn != NULL) {
113 xcb_disconnect(restore_conn);
115 #ifdef I3_ASAN_ENABLED 116 __lsan_do_leak_check();
118 errx(EXIT_FAILURE,
"Cannot open display\n");
121 xcb_watcher =
scalloc(1,
sizeof(
struct ev_io));
124 ev_io_init(xcb_watcher, restore_xcb_got_event, xcb_get_file_descriptor(restore_conn), EV_READ);
138 xcb_flush(restore_conn);
139 xcb_aux_sync(restore_conn);
144 char *serialized = NULL;
146 #define APPEND_REGEX(re_name) \ 148 if (swallows->re_name != NULL) { \ 149 sasprintf(&serialized, "%s%s" #re_name "=\"%s\"", (serialized ? serialized : "["), (serialized ? " " : ""), swallows->re_name->pattern); \ 158 if (serialized == NULL) {
159 DLOG(
"This swallows specification is not serializable?!\n");
163 sasprintf(&serialized,
"%s]", serialized);
164 DLOG(
"con %p (placeholder 0x%08x) line %d: %s\n", state->
con, state->
window, n, serialized);
179 int x = (state->
rect.
width / 2) - (text_width / 2);
191 con->
type == CT_CON) {
195 XCB_COPY_FROM_PARENT,
196 XCB_COPY_FROM_PARENT,
197 XCB_WINDOW_CLASS_INPUT_OUTPUT,
200 XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK,
202 config.client.placeholder.background.colorpixel,
203 XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY,
206 xcb_icccm_wm_hints_t hints;
207 xcb_icccm_wm_hints_set_none(&hints);
208 xcb_icccm_wm_hints_set_input(&hints, 0);
209 xcb_icccm_set_wm_hints(restore_conn, placeholder, &hints);
213 if (con->
name != NULL)
214 xcb_change_property(restore_conn, XCB_PROP_MODE_REPLACE, placeholder,
215 A__NET_WM_NAME, A_UTF8_STRING, 8, strlen(con->
name), con->
name);
216 DLOG(
"Created placeholder window 0x%08x for leaf container %p / %s\n",
217 placeholder, con, con->
name);
220 state->
window = placeholder;
231 temp_id->
dock = M_DONTCHECK;
232 temp_id->
id = placeholder;
261 xcb_flush(restore_conn);
274 if (state->
window != placeholder)
277 xcb_destroy_window(restore_conn, state->
window);
281 DLOG(
"placeholder window 0x%08x destroyed.\n", placeholder);
285 DLOG(
"0x%08x is not a placeholder window, ignoring.\n", placeholder);
292 if (state->
window != event->window)
295 DLOG(
"refreshing window 0x%08x contents (con %p)\n", state->
window, state->
con);
302 ELOG(
"Received ExposeEvent for unknown window 0x%08x\n", event->window);
314 if (state->
window != event->window)
317 DLOG(
"ConfigureNotify: window 0x%08x has now width=%d, height=%d (con %p)\n",
318 state->
window, event->width, event->height, state->
con);
330 ELOG(
"Received ConfigureNotify for unknown window 0x%08x\n", event->window);
336 if (((xcb_expose_event_t *)event)->count == 0) {
341 case XCB_CONFIGURE_NOTIFY:
345 DLOG(
"Received unhandled X11 event of type %d\n", type);
struct _i3String i3String
Opaque data structure for storing strings.
int sasprintf(char **strp, const char *fmt,...)
Safe-wrapper around asprintf which exits if it returns -1 (meaning that there is no more memory avail...
#define TAILQ_INSERT_HEAD(head, elm, field)
surface_t surface
The drawable surface.
#define TAILQ_HEAD_INITIALIZER(head)
Con * con
The container to which this placeholder window belongs.
struct Colortriple placeholder
#define TAILQ_EMPTY(head)
A 'Con' represents everything from the X11 root window down to a single X11 window.
i3String * i3string_from_utf8(const char *from_utf8)
Build an i3String from an UTF-8 encoded string.
xcb_connection_t * conn
XCB connection and root screen.
void draw_util_surface_set_size(surface_t *surface, int width, int height)
Resize the surface to the given size.
#define TAILQ_INSERT_TAIL(head, elm, field)
bool con_is_leaf(Con *con)
Returns true when this node is a leaf node (has no children)
void draw_util_clear_surface(surface_t *surface, color_t color)
Clears a surface with the given color.
xcb_screen_t * root_screen
Rect rect
Current size of the placeholder window (to detect size changes).
xcb_visualtype_t * get_visualtype(xcb_screen_t *screen)
Returns the visual type associated with the given screen.
xcb_window_t create_window(xcb_connection_t *conn, Rect dims, uint16_t depth, xcb_visualid_t visual, uint16_t window_class, enum xcursor_cursor_t cursor, bool map, uint32_t mask, uint32_t *values)
Convenience wrapper around xcb_create_window which takes care of depth, generating an ID and checking...
xcb_window_t window
The X11 placeholder window.
int predict_text_width(i3String *text)
Predict the text width in pixels for the given text.
void i3string_free(i3String *str)
Free an i3String.
int height
The height of the font, built from font_ascent + font_descent.
static struct ev_prepare * xcb_prepare
struct Config::config_client client
#define TAILQ_FOREACH(var, head, field)
#define APPEND_REGEX(re_name)
#define TAILQ_FIRST(head)
static void restore_handle_event(int type, xcb_generic_event_t *event)
bool restore_kill_placeholder(xcb_window_t placeholder)
Kill the placeholder window, if placeholder refers to a placeholder window.
#define TAILQ_REMOVE(head, elm, field)
static void configure_notify(xcb_configure_notify_event_t *event)
void * smalloc(size_t size)
Safe-wrapper around malloc which exits if malloc returns NULL (meaning that there is no more memory a...
void * scalloc(size_t num, size_t size)
Safe-wrapper around calloc which exits if malloc returns NULL (meaning that there is no more memory a...
void restore_connect(void)
Opens a separate connection to X11 for placeholder windows when restoring layouts.
void draw_util_surface_free(xcb_connection_t *conn, surface_t *surface)
Destroys the surface.
static void open_placeholder_window(Con *con)
void restore_open_placeholder_windows(Con *parent)
Open placeholder windows for all children of parent.
static void restore_xcb_prepare_cb(EV_P_ ev_prepare *w, int revents)
static TAILQ_HEAD(state_head, placeholder_state)
A "match" is a data structure which acts like a mask or expression to match certain windows or not...
struct ev_loop * main_loop
static void update_placeholder_contents(placeholder_state *state)
void draw_util_text(i3String *text, surface_t *surface, color_t fg_color, color_t bg_color, int x, int y, int max_width)
Draw the given text using libi3.
#define TAILQ_ENTRY(type)
static void expose_event(xcb_expose_event_t *event)
void match_init(Match *match)
Stores a rectangle, for example the size of a window, the child window etc.
void draw_util_surface_init(xcb_connection_t *conn, surface_t *surface, xcb_drawable_t drawable, xcb_visualtype_t *visual, int width, int height)
Initialize the surface to represent the given drawable.