Added some error handling for xcb
This commit is contained in:
parent
60da522e13
commit
ddf8bd63c7
|
@ -184,14 +184,14 @@ void xcb_io_cb(struct ev_loop *loop, ev_io *watcher, int revents) {
|
||||||
int get_string_width(xcb_char2b_t *string, int glyph_len) {
|
int get_string_width(xcb_char2b_t *string, int glyph_len) {
|
||||||
xcb_query_text_extents_cookie_t cookie;
|
xcb_query_text_extents_cookie_t cookie;
|
||||||
xcb_query_text_extents_reply_t *reply;
|
xcb_query_text_extents_reply_t *reply;
|
||||||
xcb_generic_error_t *error;
|
xcb_generic_error_t *error = NULL;
|
||||||
int width;
|
int width;
|
||||||
|
|
||||||
cookie = xcb_query_text_extents(xcb_connection, xcb_font, glyph_len, string);
|
cookie = xcb_query_text_extents(xcb_connection, xcb_font, glyph_len, string);
|
||||||
reply = xcb_query_text_extents_reply(xcb_connection, cookie, &error);
|
reply = xcb_query_text_extents_reply(xcb_connection, cookie, &error);
|
||||||
if (reply == NULL) {
|
if (error != NULL) {
|
||||||
printf("ERROR: Could not get text extents!");
|
printf("ERROR: Could not get text extents! XCB-errorcode: %d\n", error->error_code);
|
||||||
return 7;
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
width = reply->overall_width;
|
width = reply->overall_width;
|
||||||
|
@ -221,14 +221,23 @@ void init_xcb(char *fontname) {
|
||||||
|
|
||||||
/* We load and allocate the font */
|
/* We load and allocate the font */
|
||||||
xcb_font = xcb_generate_id(xcb_connection);
|
xcb_font = xcb_generate_id(xcb_connection);
|
||||||
xcb_open_font(xcb_connection,
|
xcb_void_cookie_t open_font_cookie;
|
||||||
|
open_font_cookie = xcb_open_font_checked(xcb_connection,
|
||||||
xcb_font,
|
xcb_font,
|
||||||
strlen(fontname),
|
strlen(fontname),
|
||||||
fontname);
|
fontname);
|
||||||
|
|
||||||
|
xcb_generic_error_t *err = xcb_request_check(xcb_connection,
|
||||||
|
open_font_cookie);
|
||||||
|
|
||||||
|
if (err != NULL) {
|
||||||
|
printf("ERROR: Could not open font! XCB-Error-Code: %d\n", err->error_code);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
/* We also need the fontheight to configure our bars accordingly */
|
/* We also need the fontheight to configure our bars accordingly */
|
||||||
xcb_list_fonts_with_info_cookie_t cookie;
|
xcb_list_fonts_with_info_cookie_t font_info_cookie;
|
||||||
cookie = xcb_list_fonts_with_info(xcb_connection,
|
font_info_cookie = xcb_list_fonts_with_info(xcb_connection,
|
||||||
1,
|
1,
|
||||||
strlen(fontname),
|
strlen(fontname),
|
||||||
fontname);
|
fontname);
|
||||||
|
@ -252,7 +261,7 @@ void init_xcb(char *fontname) {
|
||||||
/* Now we calculate the font-height */
|
/* Now we calculate the font-height */
|
||||||
xcb_list_fonts_with_info_reply_t *reply;
|
xcb_list_fonts_with_info_reply_t *reply;
|
||||||
reply = xcb_list_fonts_with_info_reply(xcb_connection,
|
reply = xcb_list_fonts_with_info_reply(xcb_connection,
|
||||||
cookie,
|
font_info_cookie,
|
||||||
NULL);
|
NULL);
|
||||||
font_height = reply->font_ascent + reply->font_descent;
|
font_height = reply->font_ascent + reply->font_descent;
|
||||||
FREE(reply);
|
FREE(reply);
|
||||||
|
@ -290,6 +299,10 @@ void clean_xcb() {
|
||||||
void get_atoms() {
|
void get_atoms() {
|
||||||
xcb_intern_atom_reply_t *reply;
|
xcb_intern_atom_reply_t *reply;
|
||||||
#define ATOM_DO(name) reply = xcb_intern_atom_reply(xcb_connection, atom_cookies[name], NULL); \
|
#define ATOM_DO(name) reply = xcb_intern_atom_reply(xcb_connection, atom_cookies[name], NULL); \
|
||||||
|
if (reply == NULL) { \
|
||||||
|
printf("ERROR: Could not get atom %s\n", #name); \
|
||||||
|
exit(EXIT_FAILURE); \
|
||||||
|
} \
|
||||||
atoms[name] = reply->atom; \
|
atoms[name] = reply->atom; \
|
||||||
free(reply);
|
free(reply);
|
||||||
|
|
||||||
|
@ -320,6 +333,9 @@ void reconfig_windows() {
|
||||||
uint32_t mask;
|
uint32_t mask;
|
||||||
uint32_t values[4];
|
uint32_t values[4];
|
||||||
|
|
||||||
|
xcb_void_cookie_t cookie;
|
||||||
|
xcb_generic_error_t *err;
|
||||||
|
|
||||||
i3_output *walk;
|
i3_output *walk;
|
||||||
SLIST_FOREACH(walk, outputs, slist) {
|
SLIST_FOREACH(walk, outputs, slist) {
|
||||||
if (!walk->active) {
|
if (!walk->active) {
|
||||||
|
@ -339,7 +355,7 @@ void reconfig_windows() {
|
||||||
/* The events we want to receive */
|
/* The events we want to receive */
|
||||||
values[1] = XCB_EVENT_MASK_EXPOSURE |
|
values[1] = XCB_EVENT_MASK_EXPOSURE |
|
||||||
XCB_EVENT_MASK_BUTTON_PRESS;
|
XCB_EVENT_MASK_BUTTON_PRESS;
|
||||||
xcb_create_window(xcb_connection,
|
cookie = xcb_create_window_checked(xcb_connection,
|
||||||
xcb_screens->root_depth,
|
xcb_screens->root_depth,
|
||||||
walk->bar,
|
walk->bar,
|
||||||
xcb_root,
|
xcb_root,
|
||||||
|
@ -350,6 +366,10 @@ void reconfig_windows() {
|
||||||
xcb_screens->root_visual,
|
xcb_screens->root_visual,
|
||||||
mask,
|
mask,
|
||||||
values);
|
values);
|
||||||
|
if ((err = xcb_request_check(xcb_connection, cookie)) != NULL) {
|
||||||
|
printf("ERROR: Could not create Window. XCB-errorcode: %d\n", err->error_code);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
/* We want dock-windows (for now) */
|
/* We want dock-windows (for now) */
|
||||||
xcb_change_property(xcb_connection,
|
xcb_change_property(xcb_connection,
|
||||||
|
@ -360,19 +380,33 @@ void reconfig_windows() {
|
||||||
32,
|
32,
|
||||||
1,
|
1,
|
||||||
(unsigned char*) &atoms[_NET_WM_WINDOW_TYPE_DOCK]);
|
(unsigned char*) &atoms[_NET_WM_WINDOW_TYPE_DOCK]);
|
||||||
|
if ((err = xcb_request_check(xcb_connection, cookie)) != NULL) {
|
||||||
|
printf("ERROR: Could not set dock mode. XCB-errorcode: %d\n", err->error_code);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
/* We also want a graphics-context (the "canvas" on which we draw) */
|
/* We also want a graphics-context (the "canvas" on which we draw) */
|
||||||
walk->bargc = xcb_generate_id(xcb_connection);
|
walk->bargc = xcb_generate_id(xcb_connection);
|
||||||
mask = XCB_GC_FONT;
|
mask = XCB_GC_FONT;
|
||||||
values[0] = xcb_font;
|
values[0] = xcb_font;
|
||||||
xcb_create_gc(xcb_connection,
|
cookie = xcb_create_gc_checked(xcb_connection,
|
||||||
walk->bargc,
|
walk->bargc,
|
||||||
walk->bar,
|
walk->bar,
|
||||||
mask,
|
mask,
|
||||||
values);
|
values);
|
||||||
|
|
||||||
|
if ((err = xcb_request_check(xcb_connection, cookie)) != NULL) {
|
||||||
|
printf("ERROR: Could not create graphical context. XCB-errorcode: %d\n", err->error_code);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
/* We finally map the bar (display it on screen) */
|
/* We finally map the bar (display it on screen) */
|
||||||
xcb_map_window(xcb_connection, walk->bar);
|
cookie = xcb_map_window_checked(xcb_connection, walk->bar);
|
||||||
|
|
||||||
|
if ((err = xcb_request_check(xcb_connection, cookie)) != NULL) {
|
||||||
|
printf("ERROR: Could not map window. XCB-errorcode: %d\n", err->error_code);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
/* We already have a bar, so we just reconfigure it */
|
/* We already have a bar, so we just reconfigure it */
|
||||||
mask = XCB_CONFIG_WINDOW_X |
|
mask = XCB_CONFIG_WINDOW_X |
|
||||||
|
@ -384,10 +418,15 @@ void reconfig_windows() {
|
||||||
values[2] = walk->rect.w;
|
values[2] = walk->rect.w;
|
||||||
values[3] = font_height + 6;
|
values[3] = font_height + 6;
|
||||||
printf("Reconfiguring Window for output %s to %d,%d\n", walk->name, values[0], values[1]);
|
printf("Reconfiguring Window for output %s to %d,%d\n", walk->name, values[0], values[1]);
|
||||||
xcb_configure_window(xcb_connection,
|
cookie = xcb_configure_window_checked(xcb_connection,
|
||||||
walk->bar,
|
walk->bar,
|
||||||
mask,
|
mask,
|
||||||
values);
|
values);
|
||||||
|
|
||||||
|
if ((err = xcb_request_check(xcb_connection, cookie)) != NULL) {
|
||||||
|
printf("ERROR: Could not reconfigure window. XCB-errorcode: %d\n", err->error_code);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue