diff --git a/Makefile.am b/Makefile.am index b96bfc6..7c8057c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -107,7 +107,11 @@ AWESOME_CFLAGS = -std=gnu99 -pipe \ -Wunused -Winit-self -Wpointer-arith -Wredundant-decls \ -Wmissing-prototypes -Wmissing-format-attribute -Wmissing-noreturn endif -AM_CPPFLAGS = $(X_CFLAGS) $(PANGOCAIRO_CFLAGS) $(CONFUSE_CFLAGS) $(XRANDR_CFLAGS) $(XINERAMA_CFLAGS) $(AWESOME_CFLAGS) +AM_CPPFLAGS = $(PANGOCAIRO_CFLAGS) $(CONFUSE_CFLAGS) $(AWESOME_CFLAGS) \ + $(XCB_CFLAGS) $(XCB_EVENT_CFLAGS) \ + $(XCB_RANDR_CFLAGS) $(XCB_XINERAMA_CFLAGS) $(XCB_SHAPE_CFLAGS) \ + $(XCB_AUX_CFLAGS) $(XCB_ATOM_CFLAGS) $(XCB_KEYSYMS_CFLAGS) \ + $(XCB_ICCCM_CFLAGS) bin_PROGRAMS += awesome awesome_SOURCES = \ @@ -137,10 +141,13 @@ awesome_SOURCES = \ rules.c rules.h \ mouse.c mouse.h \ widget.c widget.h \ + xcb_event_handler.c xcb_event_handler.h \ ewmh.c ewmh.h awesome_SOURCES += $(LAYOUTS) awesome_SOURCES += $(WIDGETS) -awesome_LDADD = $(X_LIBS) $(PANGOCAIRO_LIBS) $(CONFUSE_LIBS) $(XRANDR_LIBS) $(XINERAMA_LIBS) +awesome_LDADD = $(PANGOCAIRO_LIBS) $(CONFUSE_LIBS) $(XCB_LIBS) $(XCB_EVENT_LIBS) \ + $(XCB_RANDR_LIBS) $(XCB_XINERAMA_LIBS) $(XCB_SHAPE_LIBS) $(XCB_AUX_LIBS) \ + $(XCB_ATOM_LIBS) $(XCB_KEYSYMS_LIBS) $(XCB_ICCCM_LIBS) bin_PROGRAMS += awesome-client awesome_client_SOURCES = \ @@ -157,9 +164,11 @@ awesome_message_SOURCES = \ common/version.h common/version.c \ common/configopts.h common/configopts.c \ common/xscreen.h common/xscreen.c \ + common/xutil.c common/xutil.h \ awesome-message.c -awesome_message_LDADD = $(X_LIBS) $(PANGOCAIRO_LIBS) $(CONFUSE_LIBS) $(XINERAMA_LIBS) +awesome_message_LDADD = $(XCB_LIBS) $(XCB_ATOM_LIBS) $(XCB_KEYSYMS_LIBS) $(XCB_AUX_LIBS) \ + $(PANGOCAIRO_LIBS) $(CONFUSE_LIBS) $(XCB_XINERAMA_LIBS) bin_PROGRAMS += awesome-menu awesome_menu_SOURCES = \ @@ -168,10 +177,11 @@ awesome_menu_SOURCES = \ common/util.h common/util.c \ common/version.h common/version.c \ common/configopts.h common/configopts.c \ - common/xutil.h common/xutil.c \ + common/xutil.c common/xutil.h \ awesome-menu.c -awesome_menu_LDADD = $(X_LIBS) $(PANGOCAIRO_LIBS) $(CONFUSE_LIBS) $(XINERAMA_LIBS) +awesome_menu_LDADD = $(XCB_LIBS) $(XCB_ATOM_LIBS) $(XCB_KEYSYMS_LIBS) $(XCB_AUX_LIBS) \ + $(PANGOCAIRO_LIBS) $(CONFUSE_LIBS) $(XCB_XINERAMA_LIBS) if HAVE_XMLTO if HAVE_ASCIIDOC diff --git a/awesome-menu.c b/awesome-menu.c index 09ffe7a..0a152a3 100644 --- a/awesome-menu.c +++ b/awesome-menu.c @@ -36,7 +36,12 @@ #include #include -#include +#include +#include +#include + +/* XKeysymToString() */ +#include #include "common/swindow.h" #include "common/util.h" @@ -47,7 +52,7 @@ #define PROGNAME "awesome-menu" -#define CLEANMASK(mask) (mask & ~(globalconf.numlockmask | LockMask)) +#define CLEANMASK(mask) (mask & ~(globalconf.numlockmask | XCB_MOD_MASK_LOCK)) typedef enum { @@ -66,7 +71,7 @@ struct item_t { char *data; item_t *prev, *next; - Bool match; + bool match; }; static void @@ -81,8 +86,10 @@ DO_SLIST(item_t, item, item_delete) /** awesome-run global configuration structure */ typedef struct { - /** Display ref */ - Display *display; + /** Connection ref */ + xcb_connection_t *connection; + /** Default screen number */ + int default_screen; /** The window */ SimpleWindow *sw; /** The draw contet */ @@ -174,11 +181,11 @@ config_parse(int screen, const char *confpatharg, && (cfg_styles = cfg_getsec(cfg_screen, "styles"))) { /* Grab default styles */ - draw_style_init(globalconf.display, DefaultScreen(globalconf.display), + draw_style_init(globalconf.connection, globalconf.default_screen, cfg_getsec(cfg_styles, "normal"), &globalconf.styles.normal, NULL); - draw_style_init(globalconf.display, DefaultScreen(globalconf.display), + draw_style_init(globalconf.connection, globalconf.default_screen, cfg_getsec(cfg_styles, "focus"), &globalconf.styles.focus, &globalconf.styles.normal); } @@ -186,11 +193,11 @@ config_parse(int screen, const char *confpatharg, /* Now grab menu styles if any */ if(cfg_menu_styles) { - draw_style_init(globalconf.display, DefaultScreen(globalconf.display), + draw_style_init(globalconf.connection, globalconf.default_screen, cfg_getsec(cfg_menu_styles, "normal"), &globalconf.styles.normal, NULL); - draw_style_init(globalconf.display, DefaultScreen(globalconf.display), + draw_style_init(globalconf.connection, globalconf.default_screen, cfg_getsec(cfg_menu_styles, "focus"), &globalconf.styles.focus, &globalconf.styles.normal); } @@ -216,7 +223,7 @@ get_last_word(char *text) return last_word; } -static Bool +static bool item_list_fill_file(const char *directory) { char *cwd, *home, *user, *filename; @@ -254,7 +261,7 @@ item_list_fill_file(const char *directory) else { p_delete(&user); - return False; + return false; } } } @@ -264,7 +271,7 @@ item_list_fill_file(const char *directory) if(!(dir = opendir(cwd))) { p_delete(&cwd); - return False; + return false; } while((dirinfo = readdir(dir))) @@ -296,11 +303,11 @@ item_list_fill_file(const char *directory) closedir(dir); p_delete(&cwd); - return True; + return true; } static void -complete(Bool reverse) +complete(bool reverse) { char *word; int loop = 2; @@ -352,16 +359,16 @@ compute_match(const char *word) for(item = globalconf.items; item; item = item->next) if(!a_strncmp(word, item->data, a_strlen(word))) - item->match = True; + item->match = true; else - item->match = False; + item->match = false; } else { if(a_strlen(globalconf.text)) item_list_fill_file(NULL); for(item = globalconf.items; item; item = item->next) - item->match = True; + item->match = true; } } @@ -373,7 +380,7 @@ redraw(void) { item_t *item; area_t geometry = { 0, 0, 0, 0, NULL, NULL }; - Bool selected_item_is_drawn = False; + bool selected_item_is_drawn = false; int len, prompt_len, x_of_previous_item; style_t style; @@ -385,7 +392,8 @@ redraw(void) draw_text(globalconf.ctx, geometry, AlignLeft, MARGIN, globalconf.prompt, globalconf.styles.focus); - len = MARGIN * 2 + draw_textwidth(globalconf.display, globalconf.styles.focus.font, globalconf.prompt); + len = MARGIN * 2 + draw_textwidth(globalconf.connection, globalconf.default_screen, + globalconf.styles.focus.font, globalconf.prompt); geometry.x += len; geometry.width -= len; } @@ -393,7 +401,8 @@ redraw(void) draw_text(globalconf.ctx, geometry, AlignLeft, MARGIN, globalconf.text, globalconf.styles.normal); - len = MARGIN * 2 + MAX(draw_textwidth(globalconf.display, globalconf.styles.normal.font, globalconf.text), + len = MARGIN * 2 + MAX(draw_textwidth(globalconf.connection, globalconf.default_screen, + globalconf.styles.normal.font, globalconf.text), geometry.width / 20); geometry.x += len; geometry.width -= len; @@ -403,13 +412,14 @@ redraw(void) if(item->match) { style = item == globalconf.item_selected ? globalconf.styles.focus : globalconf.styles.normal; - len = MARGIN + draw_textwidth(globalconf.display, style.font, item->data); + len = MARGIN + draw_textwidth(globalconf.connection, globalconf.default_screen, + style.font, item->data); if(item == globalconf.item_selected) { if(len > geometry.width) break; else - selected_item_is_drawn = True; + selected_item_is_drawn = true; } draw_text(globalconf.ctx, geometry, AlignLeft, MARGIN / 2, item->data, style); @@ -427,7 +437,8 @@ redraw(void) { style = item == globalconf.item_selected ? globalconf.styles.focus : globalconf.styles.normal; x_of_previous_item = geometry.x; - geometry.width = MARGIN + draw_textwidth(globalconf.display, style.font, item->data); + geometry.width = MARGIN + draw_textwidth(globalconf.connection, globalconf.default_screen, + style.font, item->data); geometry.x -= geometry.width; if(geometry.x < prompt_len) @@ -441,28 +452,34 @@ redraw(void) { geometry.x = prompt_len; geometry.width = x_of_previous_item - prompt_len; - draw_rectangle(globalconf.ctx, geometry, True, globalconf.styles.normal.bg); + draw_rectangle(globalconf.ctx, geometry, true, globalconf.styles.normal.bg); } } else if(geometry.width) - draw_rectangle(globalconf.ctx, geometry, True, globalconf.styles.normal.bg); + draw_rectangle(globalconf.ctx, geometry, true, globalconf.styles.normal.bg); - simplewindow_refresh_drawable(globalconf.sw, DefaultScreen(globalconf.display)); - XSync(globalconf.display, False); + simplewindow_refresh_drawable(globalconf.sw, globalconf.default_screen); + xcb_aux_sync(globalconf.connection); } static void -handle_kpress(XKeyEvent *e) +handle_kpress(xcb_key_press_event_t *e) { - char buf[32]; - KeySym ksym; + char *buf; + xcb_key_symbols_t *keysyms = xcb_key_symbols_alloc(globalconf.connection); + xcb_keysym_t ksym; int num; ssize_t len; size_t text_dst_len; len = a_strlen(globalconf.text); - num = XLookupString(e, buf, sizeof(buf), &ksym, 0); - if(e->state & ControlMask) + /* TODO: check whether 'col' (last parameter) is correct */ + ksym = xcb_key_press_lookup_keysym(keysyms, e, 1); + + /* TODO: remove this call in favor of XCB */ + buf = XKeysymToString(ksym); + num = strlen(buf); + if(e->state & XCB_MOD_MASK_CONTROL) switch(ksym) { default: @@ -501,7 +518,7 @@ handle_kpress(XKeyEvent *e) } return; } - else if(CLEANMASK(e->state) & Mod1Mask) + else if(CLEANMASK(e->state) & XCB_MOD_MASK_1) switch(ksym) { default: @@ -546,12 +563,12 @@ handle_kpress(XKeyEvent *e) break; case XK_ISO_Left_Tab: case XK_Left: - complete(True); + complete(true); redraw(); break; case XK_Right: case XK_Tab: - complete(False); + complete(false); redraw(); break; case XK_Escape: @@ -563,7 +580,7 @@ handle_kpress(XKeyEvent *e) } } -static Bool +static bool item_list_fill_stdin(void) { char *buf = NULL; @@ -571,12 +588,12 @@ item_list_fill_stdin(void) ssize_t line_len; item_t *newitem; - Bool has_entry = False; + bool has_entry = false; item_list_init(&globalconf.items); if((line_len = getline(&buf, &len, stdin)) != -1) - has_entry = True; + has_entry = true; if(has_entry) do @@ -584,7 +601,7 @@ item_list_fill_stdin(void) buf[line_len - 1] = '\0'; newitem = p_new(item_t, 1); newitem->data = a_strdup(buf); - newitem->match = True; + newitem->match = true; item_list_append(&globalconf.items, newitem); } while((line_len = getline(&buf, &len, stdin)) != -1); @@ -598,16 +615,17 @@ item_list_fill_stdin(void) int main(int argc, char **argv) { - Display *disp; - XEvent ev; - int opt, ret, x, y, i, screen = 0; + xcb_connection_t *conn; + xcb_generic_event_t *ev; + int opt, ret, screen = 0; + xcb_query_pointer_reply_t *xqp = NULL; + xcb_grab_keyboard_reply_t *xgb = NULL; char *configfile = NULL, *cmd; ssize_t len; const char *shell = getenv("SHELL"); area_t geometry = { 0, 0, 0, 0, NULL, NULL }; ScreensInfo *si; - unsigned int ui; - Window dummy; + const uint32_t map_raised_val = XCB_STACK_MODE_ABOVE; static struct option long_options[] = { {"help", 0, NULL, 'h'}, @@ -616,10 +634,11 @@ main(int argc, char **argv) {NULL, 0, NULL, 0} }; - if(!(disp = XOpenDisplay(NULL))) + conn = xcb_connect(NULL, &globalconf.default_screen); + if(xcb_connection_has_error(conn)) eprint("unable to open display"); - globalconf.display = disp; + globalconf.connection = conn; while((opt = getopt_long(argc, argv, "vhf:b:x:y:n:c:e:", long_options, NULL)) != -1) @@ -643,15 +662,18 @@ main(int argc, char **argv) globalconf.prompt = a_strdup(argv[optind]); /* Get the numlock mask */ - globalconf.numlockmask = get_numlockmask(disp); + globalconf.numlockmask = get_numlockmask(conn); - si = screensinfo_new(disp); + si = screensinfo_new(conn); if(si->xinerama_is_active) { - if(XQueryPointer(disp, RootWindow(disp, DefaultScreen(disp)), - &dummy, &dummy, &x, &y, &i, &i, &ui)) + if((xqp = xcb_query_pointer_reply(conn, + xcb_query_pointer(conn, + root_window(conn, globalconf.default_screen)), + NULL)) != NULL) { - screen = screen_get_bycoord(si, 0, x, y); + screen = screen_get_bycoord(si, 0, xqp->root_x, xqp->root_y); + p_delete(&xqp); geometry.x = si->geometry[screen].x; geometry.y = si->geometry[screen].y; @@ -660,9 +682,9 @@ main(int argc, char **argv) } else { - screen = DefaultScreen(disp); + screen = globalconf.default_screen; if(!geometry.width) - geometry.width = DisplayWidth(disp, DefaultScreen(disp)); + geometry.width = xcb_aux_get_screen(conn, globalconf.default_screen)->width_in_pixels; } if((ret = config_parse(screen, configfile, globalconf.prompt, &geometry))) @@ -676,14 +698,16 @@ main(int argc, char **argv) screensinfo_delete(&si); /* Create the window */ - globalconf.sw = simplewindow_new(disp, DefaultScreen(disp), + globalconf.sw = simplewindow_new(conn, globalconf.default_screen, geometry.x, geometry.y, geometry.width, geometry.height, 0); - XStoreName(disp, globalconf.sw->window, PROGNAME); - XMapRaised(disp, globalconf.sw->window); + xcb_change_property(conn, XCB_PROP_MODE_REPLACE, globalconf.sw->window, WM_NAME, STRING, + 8, strlen(PROGNAME), PROGNAME); + xcb_configure_window(conn, globalconf.sw->window, XCB_CONFIG_WINDOW_STACK_MODE, + &map_raised_val); /* Create the drawing context */ - globalconf.ctx = draw_context_new(disp, DefaultScreen(disp), + globalconf.ctx = draw_context_new(conn, globalconf.default_screen, geometry.width, geometry.height, globalconf.sw->drawable); @@ -701,9 +725,16 @@ main(int argc, char **argv) for(opt = 1000; opt; opt--) { - if(XGrabKeyboard(disp, DefaultRootWindow(disp), True, - GrabModeAsync, GrabModeAsync, CurrentTime) == GrabSuccess) + if((xgb = xcb_grab_keyboard_reply(conn, + xcb_grab_keyboard(conn, true, + xcb_aux_get_screen(conn, globalconf.default_screen)->root, + XCB_CURRENT_TIME, XCB_GRAB_MODE_ASYNC, + XCB_GRAB_MODE_ASYNC), + NULL)) != NULL) + { + p_delete(&xgb); break; + } usleep(1000); } if(!opt) @@ -713,21 +744,29 @@ main(int argc, char **argv) while(status == RUN) { - XNextEvent(disp, &ev); - switch(ev.type) + while((ev = xcb_poll_for_event(conn))) { - case ButtonPress: - status = CANCEL; - break; - case KeyPress: - handle_kpress(&ev.xkey); - break; - case Expose: - if(!ev.xexpose.count) - simplewindow_refresh_drawable(globalconf.sw, DefaultScreen(disp)); - break; - default: - break; + /* Skip errors */ + if(ev->response_type == 0) + continue; + + switch(ev->response_type & 0x7f) + { + case XCB_BUTTON_PRESS: + status = CANCEL; + break; + case XCB_KEY_PRESS: + handle_kpress((xcb_key_press_event_t *) ev); + break; + case XCB_EXPOSE: + if(!((xcb_expose_event_t *) ev)->count) + simplewindow_refresh_drawable(globalconf.sw, globalconf.default_screen); + break; + default: + break; + } + + p_delete(&ev); } } @@ -750,7 +789,7 @@ main(int argc, char **argv) p_delete(&globalconf.text); draw_context_delete(globalconf.ctx); simplewindow_delete(globalconf.sw); - XCloseDisplay(disp); + xcb_disconnect(conn); return EXIT_SUCCESS; } diff --git a/awesome-message.c b/awesome-message.c index e79eb3d..2d74a41 100644 --- a/awesome-message.c +++ b/awesome-message.c @@ -26,8 +26,11 @@ #include #include #include +#include -#include +#include +#include +#include #include "common/swindow.h" #include "common/util.h" @@ -37,7 +40,7 @@ #define PROGNAME "awesome-message" -static Bool running = True; +static bool running = true; /** Import awesome config file format */ extern cfg_opt_t awesome_opts[]; @@ -46,7 +49,9 @@ extern cfg_opt_t awesome_opts[]; typedef struct { /** Display ref */ - Display *display; + xcb_connection_t *connection; + /** Default screen number */ + int default_screen; /** Style */ style_t style; } AwesomeMsgConf; @@ -95,7 +100,7 @@ config_parse(int screen, const char *confpatharg) eprint("parsing configuration file failed, no screen section found\n"); /* style */ - draw_style_init(globalconf.display, DefaultScreen(globalconf.display), + draw_style_init(globalconf.connection, globalconf.default_screen, cfg_getsec(cfg_getsec(cfg_screen, "styles"), "normal"), &globalconf.style, NULL); @@ -110,23 +115,23 @@ config_parse(int screen, const char *confpatharg) static void exit_on_signal(int sig __attribute__ ((unused))) { - running = False; + running = false; } int main(int argc, char **argv) { - Display *disp; + xcb_connection_t *conn; SimpleWindow *sw; DrawCtx *ctx; - XEvent ev; + xcb_generic_event_t *ev; area_t geometry = { 0, 0, 200, 50, NULL, NULL }, icon_geometry = { -1, -1, -1, -1, NULL, NULL }; - int opt, i, x, y, ret, screen = 0, delay = 0; - unsigned int ui; + int opt, ret, screen = 0, delay = 0; + xcb_query_pointer_reply_t *xqp = NULL; char *configfile = NULL; ScreensInfo *si; - Window dummy; + const uint32_t map_raised_val = XCB_STACK_MODE_ABOVE; static struct option long_options[] = { {"help", 0, NULL, 'h'}, @@ -134,10 +139,11 @@ main(int argc, char **argv) {NULL, 0, NULL, 0} }; - if(!(disp = XOpenDisplay(NULL))) + conn = xcb_connect(NULL, &globalconf.default_screen); + if(xcb_connection_has_error(conn)) eprint("unable to open display"); - globalconf.display = disp; + globalconf.connection = conn; while((opt = getopt_long(argc, argv, "vhf:b:x:y:n:c:d:", long_options, NULL)) != -1) @@ -166,20 +172,26 @@ main(int argc, char **argv) if(argc - optind < 1) exit_help(EXIT_FAILURE); - si = screensinfo_new(disp); + si = screensinfo_new(conn); if(si->xinerama_is_active) { - if(XQueryPointer(disp, RootWindow(disp, DefaultScreen(disp)), - &dummy, &dummy, &x, &y, &i, &i, &ui)) - screen = screen_get_bycoord(si, 0, x, y); + if((xqp = xcb_query_pointer_reply(conn, + xcb_query_pointer(conn, + root_window(conn, globalconf.default_screen)), + NULL)) != NULL) + { + screen = screen_get_bycoord(si, 0, xqp->root_x, xqp->root_y); + p_delete(&xqp); + } } else - screen = DefaultScreen(disp); + screen = globalconf.default_screen; if((ret = config_parse(screen, configfile))) return ret; - geometry.width = draw_textwidth(disp, globalconf.style.font, argv[optind]); + geometry.width = draw_textwidth(conn, globalconf.default_screen, + globalconf.style.font, argv[optind]); geometry.height = globalconf.style.font->height * 1.5; if(argc - optind >= 2) @@ -192,12 +204,13 @@ main(int argc, char **argv) * ((double) globalconf.style.font->height / (double) icon_geometry.height); } - sw = simplewindow_new(disp, DefaultScreen(disp), + sw = simplewindow_new(conn, globalconf.default_screen, geometry.x, geometry.y, geometry.width, geometry.height, 0); - XStoreName(disp, sw->window, PROGNAME); + xcb_change_property(conn, XCB_PROP_MODE_REPLACE, sw->window, WM_NAME, STRING, + 8, strlen(PROGNAME), PROGNAME); - ctx = draw_context_new(disp, DefaultScreen(disp), + ctx = draw_context_new(conn, globalconf.default_screen, geometry.width, geometry.height, sw->drawable); geometry.x = geometry.y = 0; @@ -209,36 +222,42 @@ main(int argc, char **argv) p_delete(&ctx); - simplewindow_refresh_drawable(sw, DefaultScreen(disp)); + simplewindow_refresh_drawable(sw, globalconf.default_screen); - XMapRaised(disp, sw->window); - XSync(disp, False); + xcb_configure_window(conn, sw->window, XCB_CONFIG_WINDOW_STACK_MODE, + &map_raised_val); + xcb_aux_sync(conn); signal(SIGALRM, &exit_on_signal); alarm(delay); while(running) { - if(XPending(disp)) + while((ev = xcb_poll_for_event(conn))) { - XNextEvent(disp, &ev); - switch(ev.type) + /* Skip errors */ + if(ev->response_type == 0) + continue; + + switch(ev->response_type & 0x7f) { - case ButtonPress: - case KeyPress: - running = False; - case Expose: - simplewindow_refresh_drawable(sw, DefaultScreen(disp)); + case XCB_BUTTON_PRESS: + case XCB_KEY_PRESS: + running = false; + case XCB_EXPOSE: + simplewindow_refresh_drawable(sw, globalconf.default_screen); break; default: break; } + + p_delete(&ev); } sleep(0.1); } simplewindow_delete(sw); - XCloseDisplay(disp); + xcb_disconnect(conn); return EXIT_SUCCESS; } diff --git a/awesome.c b/awesome.c index b53f676..1e26675 100644 --- a/awesome.c +++ b/awesome.c @@ -33,13 +33,14 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include +#include + +#include +#include +#include +#include +#include +#include #include "config.h" #include "awesome.h" @@ -52,71 +53,174 @@ #include "client.h" #include "focus.h" #include "ewmh.h" +#include "xcb_event_handler.h" #include "tag.h" #include "common/socket.h" #include "common/util.h" #include "common/version.h" #include "common/configopts.h" #include "common/xscreen.h" +#include "common/xutil.h" -static int (*xerrorxlib) (Display *, XErrorEvent *); -static Bool running = True; +static bool running = true; AwesomeConf globalconf; +/** Get geometry informations like XCB version, and also set 'x' and + * 'y' parameter on its parent window like Xlib does + * + * TODO: improve round-trip time? + */ +static xcb_get_geometry_reply_t * +x_get_geometry(xcb_connection_t *c, xcb_window_t w, xcb_get_geometry_reply_t *parent) +{ + xcb_get_geometry_reply_t *win_geom; + + win_geom = xcb_get_geometry_reply(c, xcb_get_geometry(c, w), NULL); + + if(win_geom) + return NULL; + + /* Unlike XCB, Xlib set 'x' and 'y' as parent window position */ + win_geom->x = parent->x; + win_geom->y = parent->y; + + return win_geom; +} + +typedef struct +{ + xcb_get_geometry_cookie_t geom; + xcb_query_tree_cookie_t tree; +} screen_win_t; + /** Scan X to find windows to manage */ static void scan() { - unsigned int i, num; + unsigned int i; int screen, real_screen; - Window *wins = NULL, d1, d2; - XWindowAttributes wa; + xcb_window_t w; + xcb_window_t *wins = NULL; + xcb_query_tree_reply_t *r_query_tree; + xcb_get_geometry_reply_t *parent_geom, *win_geom; + xcb_get_window_attributes_reply_t *reply_win; + xcb_get_window_attributes_cookie_t *cookies_win; + const int screen_max = xcb_setup_roots_length (xcb_get_setup (globalconf.connection)); + screen_win_t *parents = alloca(sizeof(screen_win_t) * screen_max); + + for(screen = 0; screen < screen_max; screen++) + { + w = root_window(globalconf.connection, screen); + + /* Get parent geometry informations, useful to get the real + * coordinates of the window because Xlib set 'x' and 'y' + * fields to the relative position within the parent window */ + parents[screen].geom = xcb_get_geometry(globalconf.connection, w); + + /* Get the window tree */ + parents[screen].tree = xcb_query_tree_unchecked(globalconf.connection, w); + } - for(screen = 0; screen < ScreenCount(globalconf.display); screen++) + for(screen = 0; screen < screen_max; screen++) { - if(XQueryTree(globalconf.display, RootWindow(globalconf.display, screen), &d1, &d2, &wins, &num)) + parent_geom = xcb_get_geometry_reply (globalconf.connection, + parents[screen].geom, NULL); + + if(!parent_geom) + continue; + + r_query_tree = xcb_query_tree_reply(globalconf.connection, + parents[screen].tree, NULL); + + if(!r_query_tree) { - for(i = 0; i < num; i++) + p_delete(&parent_geom); + continue; + } + + wins = xcb_query_tree_children(r_query_tree); + + /* Store the answers of 'xcb_get_window_attributes' for all + * child windows */ + cookies_win = p_new(xcb_get_window_attributes_cookie_t, + r_query_tree->children_len); + + /* Send all the requests at the same time */ + for(i = 0; i < r_query_tree->children_len; i++) + cookies_win[i] = xcb_get_window_attributes(globalconf.connection, wins[i]); + + /* Now process the answers */ + for(i = 0; i < r_query_tree->children_len; i++) + { + reply_win = xcb_get_window_attributes_reply(globalconf.connection, + cookies_win[i], + NULL); + + if(reply_win && !reply_win->override_redirect && + (reply_win->map_state == XCB_MAP_STATE_VIEWABLE || + window_getstate(wins[i]) == xcb_wm_iconic_state_t)) { - /* XGetWindowAttributes return 1 on success */ - if(!XGetWindowAttributes(globalconf.display, wins[i], &wa) - || wa.override_redirect - || XGetTransientForHint(globalconf.display, wins[i], &d1)) - continue; - if(wa.map_state == IsViewable || window_getstate(wins[i]) == IconicState) + /* TODO: should maybe be asynchronous */ + win_geom = x_get_geometry(globalconf.connection, w, parent_geom); + if(!win_geom) { - real_screen = screen_get_bycoord(globalconf.screens_info, screen, wa.x, wa.y); - client_manage(wins[i], &wa, real_screen); - } - } - /* now the transients */ - for(i = 0; i < num; i++) - { - if(!XGetWindowAttributes(globalconf.display, wins[i], &wa)) + p_delete(&reply_win); continue; - if(XGetTransientForHint(globalconf.display, wins[i], &d1) - && (wa.map_state == IsViewable || window_getstate(wins[i]) == IconicState)) - { - real_screen = screen_get_bycoord(globalconf.screens_info, screen, wa.x, wa.y); - client_manage(wins[i], &wa, real_screen); } + + real_screen = screen_get_bycoord(globalconf.screens_info, screen, win_geom->x, win_geom->y); + client_manage(wins[i], win_geom, real_screen); + + /* win_geom is not useful anymore */ + p_delete(&win_geom); } + + if(reply_win) + p_delete(&reply_win); } - if(wins) - XFree(wins); + + p_delete(&parent_geom); + p_delete(&r_query_tree); + p_delete(&cookies_win); } } +/** Equivalent to 'XCreateFontCursor()', error are handled by the + * default current error handler + * \param cursor_font type of cursor to use + * \return allocated cursor font + */ +static xcb_cursor_t +create_font_cursor(unsigned int cursor_font) +{ + xcb_font_t font; + xcb_cursor_t cursor; + + /* Get the font for the cursor*/ + font = xcb_generate_id(globalconf.connection); + xcb_open_font(globalconf.connection, font, strlen ("cursor"), "cursor"); + + cursor = xcb_generate_id(globalconf.connection); + xcb_create_glyph_cursor (globalconf.connection, cursor, font, font, + cursor_font, cursor_font + 1, + 0, 0, 0, + 0, 0, 0); + + return cursor; +} + /** Startup Error handler to check if another window manager * is already running. - * \param disp Display - * \param ee Error event + * \param data Additional optional parameters data + * \param c X connection + * \param error Error event */ static int __attribute__ ((noreturn)) -xerrorstart(Display * disp __attribute__ ((unused)), - XErrorEvent * ee __attribute__ ((unused))) +xerrorstart(void * data __attribute__ ((unused)), + xcb_connection_t * c __attribute__ ((unused)), + xcb_generic_error_t * error __attribute__ ((unused))) { eprint("another window manager is already running\n"); } @@ -129,13 +233,13 @@ xerrorstart(Display * disp __attribute__ ((unused)), void uicb_quit(int screen __attribute__ ((unused)), char *arg __attribute__ ((unused))) { - running = False; + running = false; } static void exit_on_signal(int sig __attribute__ ((unused))) { - running = False; + running = false; } /** \brief awesome xerror function @@ -147,15 +251,39 @@ exit_on_signal(int sig __attribute__ ((unused))) * \return 0 if no error, or xerror's xlib return status */ static int -xerror(Display *edpy, XErrorEvent *ee) +xerror(void *data __attribute__ ((unused)), + xcb_connection_t *c __attribute__ ((unused)), + xcb_generic_error_t *e) { - if(ee->error_code == BadWindow - || (ee->error_code == BadMatch && ee->request_code == X_SetInputFocus) - || (ee->error_code == BadValue && ee->request_code == X_KillClient) - || (ee->request_code == X_ConfigureWindow && ee->error_code == BadMatch)) + /* + * Get the request code, taken from 'xcb-util/wm'. I can't figure + * out how it works BTW, seems to get a byte in 'pad' member + * (second byte in second element of the array) + */ + uint8_t request_code = (e->response_type == 0 ? *((uint8_t *) e + 10) : e->response_type); + + if(e->error_code == BadWindow + || (e->error_code == BadMatch && request_code == XCB_SET_INPUT_FOCUS) + || (e->error_code == BadValue && request_code == XCB_KILL_CLIENT) + || (request_code == XCB_CONFIGURE_WINDOW && e->error_code == BadMatch)) return 0; - warn("fatal error: request code=%d, error code=%d\n", ee->request_code, ee->error_code); - return xerrorxlib(edpy, ee); /* may call exit */ + + warn("fatal error: request=%s, error=%s\n", + x_label_request[request_code], x_label_error[e->error_code]); + + /* + * Xlib code was using default X error handler, namely + * '_XDefaultError()', which displays more informations about the + * error and also exit if 'error_code'' equals to + * 'BadImplementation' + * + * TODO: display more informations about the error (like the Xlib + * default error handler) + */ + if(e->error_code == BadImplementation) + exit(1); + + return 0; } /** Print help and exit(2) with given exit_code. @@ -179,23 +307,20 @@ exit_help(int exit_code) * \param argv who knows * \return EXIT_SUCCESS I hope */ -typedef void event_handler (XEvent *); int main(int argc, char *argv[]) { char buf[1024]; const char *confpath = NULL; - int r, xfd, e_dummy, csfd, shape_event, randr_event_base, i, screen, opt; + int r, xfd, csfd, i, screen_nbr, opt; ssize_t cmdlen = 1; + const xcb_query_extension_reply_t *shape_query, *randr_query; Statusbar *statusbar; fd_set rd; - XEvent ev; - Display * dpy; - event_handler **handler; + xcb_generic_event_t *ev; + xcb_connection_t *conn; struct sockaddr_un *addr; Client *c; - XSetWindowAttributes wa; - Bool xsync = False; static struct option long_options[] = { {"help", 0, NULL, 'h'}, @@ -239,42 +364,54 @@ main(int argc, char *argv[]) case 'k': return config_check(confpath); break; - case 's': - xsync = True; - break; } /* Text won't be printed correctly otherwise */ setlocale(LC_CTYPE, ""); /* X stuff */ - if(!(dpy = XOpenDisplay(NULL))) + conn = xcb_connect(NULL, &(globalconf.default_screen)); + if(xcb_connection_has_error(conn)) eprint("cannot open display\n"); - xfd = ConnectionNumber(dpy); + xfd = xcb_get_file_descriptor(conn); + + /* Allocate a handler which will holds all errors and events */ + globalconf.evenths = alloc_event_handlers(conn); + set_error_handler_catch_all(globalconf.evenths, xerrorstart, NULL); + + for(screen_nbr = 0; + screen_nbr < xcb_setup_roots_length(xcb_get_setup(conn)); + screen_nbr++) + { + /* this causes an error if some other window manager is + * running */ + x_select_input(conn, root_window(conn, screen_nbr), + XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT); + } + + /* need to xcb_flush to validate error handler */ + xcb_aux_sync(conn); - XSetErrorHandler(xerrorstart); - for(screen = 0; screen < ScreenCount(dpy); screen++) - /* this causes an error if some other window manager is running */ - XSelectInput(dpy, RootWindow(dpy, screen), SubstructureRedirectMask); + /* process all errors in the queue if any */ + xcb_poll_for_event_loop(globalconf.evenths); - /* need to XSync to validate errorhandler */ - XSync(dpy, False); - XSetErrorHandler(NULL); - xerrorxlib = XSetErrorHandler(xerror); - XSync(dpy, False); + /* set the default xerror handler */ + set_error_handler_catch_all(globalconf.evenths, xerror, NULL); + /* TODO if(xsync) - XSynchronize(dpy, True); + XSynchronize(dpy, true); + */ /* store display */ - globalconf.display = dpy; + globalconf.connection = conn; /* init EWMH atoms */ ewmh_init_atoms(); /* init screens struct */ - globalconf.screens_info = screensinfo_new(dpy); + globalconf.screens_info = screensinfo_new(conn); globalconf.screens = p_new(VirtScreen, globalconf.screens_info->nscreen); focus_add_client(NULL); @@ -282,74 +419,81 @@ main(int argc, char *argv[]) config_parse(confpath); /* init cursors */ - globalconf.cursor[CurNormal] = XCreateFontCursor(globalconf.display, XC_left_ptr); - globalconf.cursor[CurResize] = XCreateFontCursor(globalconf.display, XC_sizing); - globalconf.cursor[CurMove] = XCreateFontCursor(globalconf.display, XC_fleur); + globalconf.cursor[CurNormal] = create_font_cursor(CURSOR_LEFT_PTR); + globalconf.cursor[CurResize] = create_font_cursor(CURSOR_SIZING); + globalconf.cursor[CurMove] = create_font_cursor(CURSOR_FLEUR); /* for each virtual screen */ - for(screen = 0; screen < globalconf.screens_info->nscreen; screen++) + for(screen_nbr = 0; screen_nbr < globalconf.screens_info->nscreen; screen_nbr++) { /* view at least one tag */ - tag_view(globalconf.screens[screen].tags, True); + tag_view(globalconf.screens[screen_nbr].tags, true); - for(statusbar = globalconf.screens[screen].statusbar; statusbar; statusbar = statusbar->next) + for(statusbar = globalconf.screens[screen_nbr].statusbar; statusbar; statusbar = statusbar->next) statusbar_init(statusbar); } /* select for events */ - wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask - | EnterWindowMask | LeaveWindowMask | StructureNotifyMask | PointerMotionMask; - wa.cursor = globalconf.cursor[CurNormal]; + const uint32_t change_win_vals[] = { + XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY + | XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW + | XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_POINTER_MOTION, + globalconf.cursor[CurNormal] + }; /* do this only for real screen */ - for(screen = 0; screen < ScreenCount(dpy); screen++) + for(screen_nbr = 0; + screen_nbr < xcb_setup_roots_length(xcb_get_setup(conn)); + screen_nbr++) { - XChangeWindowAttributes(globalconf.display, - RootWindow(globalconf.display, screen), - CWEventMask | CWCursor, &wa); - XSelectInput(globalconf.display, - RootWindow(globalconf.display, screen), - wa.event_mask); - ewmh_set_supported_hints(screen); + xcb_change_window_attributes(globalconf.connection, + root_window(globalconf.connection, screen_nbr), + XCB_CW_EVENT_MASK | XCB_CW_CURSOR, + change_win_vals); + x_select_input(globalconf.connection, + root_window(globalconf.connection, screen_nbr), + change_win_vals[0]); + ewmh_set_supported_hints(screen_nbr); /* call this to at least grab root window clicks */ - window_root_grabbuttons(screen); - window_root_grabkeys(screen); + window_root_grabbuttons(screen_nbr); + window_root_grabkeys(screen_nbr); } /* scan existing windows */ scan(); - handler = p_new(event_handler *, LASTEvent); - handler[ButtonPress] = event_handle_buttonpress; - handler[ConfigureRequest] = event_handle_configurerequest; - handler[ConfigureNotify] = event_handle_configurenotify; - handler[DestroyNotify] = event_handle_destroynotify; - handler[EnterNotify] = event_handle_enternotify; - handler[LeaveNotify] = event_handle_leavenotify; - handler[MotionNotify] = event_handle_motionnotify; - handler[Expose] = event_handle_expose; - handler[KeyPress] = event_handle_keypress; - handler[MappingNotify] = event_handle_mappingnotify; - handler[MapRequest] = event_handle_maprequest; - handler[PropertyNotify] = event_handle_propertynotify; - handler[UnmapNotify] = event_handle_unmapnotify; - handler[ClientMessage] = event_handle_clientmessage; + /* process all errors in the queue if any */ + xcb_poll_for_event_loop(globalconf.evenths); + + set_button_press_event_handler(globalconf.evenths, event_handle_buttonpress, NULL); + set_configure_request_event_handler(globalconf.evenths, event_handle_configurerequest, NULL); + set_configure_notify_event_handler(globalconf.evenths, event_handle_configurenotify, NULL); + set_destroy_notify_event_handler(globalconf.evenths, event_handle_destroynotify, NULL); + set_enter_notify_event_handler(globalconf.evenths, event_handle_enternotify, NULL); + set_leave_notify_event_handler(globalconf.evenths, event_handle_leavenotify, NULL); + set_motion_notify_event_handler(globalconf.evenths, event_handle_motionnotify, NULL); + set_expose_event_handler(globalconf.evenths, event_handle_expose, NULL); + set_key_press_event_handler(globalconf.evenths, event_handle_keypress, NULL); + set_mapping_notify_event_handler(globalconf.evenths, event_handle_mappingnotify, NULL); + set_map_request_event_handler(globalconf.evenths, event_handle_maprequest, NULL); + set_property_notify_event_handler(globalconf.evenths, event_handle_propertynotify, NULL); + set_unmap_notify_event_handler(globalconf.evenths, event_handle_unmapnotify, NULL); + set_client_message_event_handler(globalconf.evenths, event_handle_clientmessage, NULL); /* check for shape extension */ - if((globalconf.have_shape = XShapeQueryExtension(dpy, &shape_event, &e_dummy))) - { - p_realloc(&handler, shape_event + 1); - handler[shape_event] = event_handle_shape; - } + shape_query = xcb_get_extension_data(conn, &xcb_shape_id); + if((globalconf.have_shape = shape_query->present)) + set_event_handler(globalconf.evenths, (shape_query->first_event + XCB_SHAPE_NOTIFY), + (generic_event_handler) event_handle_shape, NULL); /* check for randr extension */ - if((globalconf.have_randr = XRRQueryExtension(dpy, &randr_event_base, &e_dummy))) - { - p_realloc(&handler, randr_event_base + RRScreenChangeNotify + 1); - handler[randr_event_base + RRScreenChangeNotify] = event_handle_randr_screen_change_notify; - } + randr_query = xcb_get_extension_data(conn, &xcb_randr_id); + if((globalconf.have_randr = randr_query->present)) + set_event_handler(globalconf.evenths, (randr_query->first_event + XCB_RANDR_SCREEN_CHANGE_NOTIFY), + (generic_event_handler) event_handle_randr_screen_change_notify, + NULL); - XSync(dpy, False); + xcb_aux_sync(conn); /* get socket fd */ csfd = get_client_socket(); @@ -414,23 +558,21 @@ main(int argc, char *argv[]) * are available and select() won't tell us, so let's check * with XPending() again. */ - while(XPending(dpy)) + while((ev = xcb_poll_for_event(conn))) { - while(XPending(dpy)) + do { - XNextEvent(dpy, &ev); - if(handler[ev.type]) - handler[ev.type](&ev); + handle_event(globalconf.evenths, ev); /* need to resync */ - XSync(dpy, False); - } + xcb_aux_sync(conn); + } while((ev = xcb_poll_for_event(conn))); statusbar_refresh(); layout_refresh(); /* need to resync */ - XSync(dpy, False); + xcb_aux_sync(conn); } } @@ -445,9 +587,9 @@ main(int argc, char *argv[]) for(c = globalconf.clients; c; c = c->next) client_unban(c); - XSync(globalconf.display, False); + xcb_aux_sync(globalconf.connection); - XCloseDisplay(dpy); + xcb_disconnect(conn); return EXIT_SUCCESS; } diff --git a/client.c b/client.c index fdbbdef..720f958 100644 --- a/client.c +++ b/client.c @@ -20,8 +20,12 @@ */ #include -#include -#include +#include + +#include +#include +#include +#include #include "client.h" #include "tag.h" @@ -45,28 +49,28 @@ extern AwesomeConf globalconf; * \param screen Screen ID * \return true if client had property */ -static Bool +static bool client_loadprops(Client * c, int screen) { int i, ntags = 0; Tag *tag; char *prop; - Bool result = False; + bool result = false; for(tag = globalconf.screens[screen].tags; tag; tag = tag->next) ntags++; prop = p_new(char, ntags + 2); - if(xgettextprop(globalconf.display, c->win, - XInternAtom(globalconf.display, "_AWESOME_PROPERTIES", False), + if(xgettextprop(globalconf.connection, c->win, + x_intern_atom(globalconf.connection, "_AWESOME_PROPERTIES"), prop, ntags + 2)) { for(i = 0, tag = globalconf.screens[screen].tags; tag && i < ntags && prop[i]; i++, tag = tag->next) if(prop[i] == '1') { tag_client(c, tag); - result = True; + result = true; } else untag_client(c, tag); @@ -83,21 +87,21 @@ client_loadprops(Client * c, int screen) /** Check if client supports protocol WM_DELETE_WINDOW * \param disp the display * \param win the Window - * \return True if client has WM_DELETE_WINDOW + * \return true if client has WM_DELETE_WINDOW */ -static Bool -client_isprotodel(Display *disp, Window win) +static bool +client_isprotodel(xcb_connection_t *c, xcb_window_t win) { - int i, n; - Atom *protocols; - Bool ret = False; + uint32_t i, n; + xcb_atom_t *protocols; + bool ret = false; - if(XGetWMProtocols(disp, win, &protocols, &n)) + if(get_wm_protocols(c, win, &n, &protocols)) { for(i = 0; !ret && i < n; i++) - if(protocols[i] == XInternAtom(disp, "WM_DELETE_WINDOW", False)) - ret = True; - XFree(protocols); + if(protocols[i] == x_intern_atom(c, "WM_DELETE_WINDOW")) + ret = true; + p_delete(&protocols); } return ret; } @@ -108,7 +112,7 @@ client_isprotodel(Display *disp, Window win) * \return client */ Client * -client_get_bywin(Client *list, Window w) +client_get_bywin(Client *list, xcb_window_t w) { Client *c; @@ -139,10 +143,10 @@ client_get_byname(Client *list, char *name) void client_updatetitle(Client *c) { - if(!xgettextprop(globalconf.display, c->win, - XInternAtom(globalconf.display, "_NET_WM_NAME", False), c->name, sizeof(c->name))) - xgettextprop(globalconf.display, c->win, - XInternAtom(globalconf.display, "WM_NAME", False), c->name, sizeof(c->name)); + if(!xgettextprop(globalconf.connection, c->win, + x_intern_atom(globalconf.connection, "_NET_WM_NAME"), c->name, sizeof(c->name))) + xgettextprop(globalconf.connection, c->win, + x_intern_atom(globalconf.connection, "WM_NAME"), c->name, sizeof(c->name)); titlebar_update(c); @@ -155,8 +159,8 @@ client_unfocus(Client *c) if(globalconf.screens[c->screen].opacity_unfocused != -1) window_settrans(c->win, globalconf.screens[c->screen].opacity_unfocused); focus_add_client(NULL); - XSetWindowBorder(globalconf.display, c->win, - globalconf.screens[c->screen].styles.normal.border.pixel); + xcb_change_window_attributes(globalconf.connection, c->win, XCB_CW_BORDER_PIXEL, + &globalconf.screens[c->screen].styles.normal.border.pixel); widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS); titlebar_update(c); } @@ -169,10 +173,10 @@ client_ban(Client *c) { if(globalconf.focus->client == c) client_unfocus(c); - XUnmapWindow(globalconf.display, c->win); - window_setstate(c->win, IconicState); + xcb_unmap_window(globalconf.connection, c->win); + window_setstate(c->win, xcb_wm_iconic_state_t); if(c->titlebar.position) - XUnmapWindow(globalconf.display, c->titlebar.sw->window); + xcb_unmap_window(globalconf.connection, c->titlebar.sw->window); } /** Give focus to client, or to first client if c is NULL @@ -180,7 +184,7 @@ client_ban(Client *c) * \param screen Screen ID */ void -client_focus(Client *c, int screen, Bool raise) +client_focus(Client *c, int screen, bool raise) { int phys_screen = get_phys_screen(screen); @@ -207,57 +211,72 @@ client_focus(Client *c, int screen, Bool raise) /* save sel in focus history */ focus_add_client(c); if(globalconf.screens[c->screen].opacity_unfocused != -1) - window_settrans(c->win, -1); - XSetWindowBorder(globalconf.display, c->win, - globalconf.screens[screen].styles.focus.border.pixel); + window_settrans(c->win, globalconf.screens[screen].opacity_unfocused); + xcb_change_window_attributes(globalconf.connection, c->win, XCB_CW_BORDER_PIXEL, + &globalconf.screens[screen].styles.focus.border.pixel); titlebar_update(c); - XSetInputFocus(globalconf.display, c->win, RevertToPointerRoot, CurrentTime); + xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_POINTER_ROOT, + c->win, XCB_CURRENT_TIME); if(raise) { - XWindowChanges wc; + uint32_t config_win_vals[2]; Layout *curlay = layout_get_current(screen); + const uint32_t raise_window_val = XCB_STACK_MODE_ABOVE; if(c->isfloating || curlay->arrange == layout_floating) { - XRaiseWindow(globalconf.display, c->win); + xcb_configure_window(globalconf.connection, c->win, + XCB_CONFIG_WINDOW_STACK_MODE, + &raise_window_val); if(c->titlebar.position && c->titlebar.sw) - XRaiseWindow(globalconf.display, c->titlebar.sw->window); + xcb_configure_window(globalconf.connection, c->titlebar.sw->window, + XCB_CONFIG_WINDOW_STACK_MODE, &raise_window_val); } else { Client *client; - wc.stack_mode = Below; - wc.sibling = None; + config_win_vals[0] = XCB_NONE; + config_win_vals[1] = XCB_STACK_MODE_BELOW; for(client = globalconf.clients; client; client = client->next) if(client != c && client_isvisible(client, c->screen) && client->isfloating) { if(client->titlebar.position && client->titlebar.sw) { - XConfigureWindow(globalconf.display, client->titlebar.sw->window, - CWSibling | CWStackMode, &wc); - wc.sibling = client->titlebar.sw->window; + xcb_configure_window(globalconf.connection, + client->titlebar.sw->window, + XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE, + config_win_vals); + config_win_vals[0] = client->titlebar.sw->window; } - XConfigureWindow(globalconf.display, client->win, CWSibling | CWStackMode, &wc); - wc.sibling = client->win; + xcb_configure_window(globalconf.connection, client->win, + XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE, + config_win_vals); + config_win_vals[0] = client->win; } if(c->titlebar.position && c->titlebar.sw) { - XConfigureWindow(globalconf.display, c->titlebar.sw->window, - CWSibling | CWStackMode, &wc); - wc.sibling = c->titlebar.sw->window; + xcb_configure_window(globalconf.connection, c->titlebar.sw->window, + XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE, + config_win_vals); + config_win_vals[0] = c->titlebar.sw->window; } - XConfigureWindow(globalconf.display, c->win, CWSibling | CWStackMode, &wc); - wc.sibling = c->win; + xcb_configure_window(globalconf.connection, c->win, + XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE, + config_win_vals); + config_win_vals[0] = c->win; for(client = globalconf.clients; client; client = client->next) if(client != c && IS_TILED(client, c->screen)) { if(client->titlebar.position && client->titlebar.sw) { - XConfigureWindow(globalconf.display, client->titlebar.sw->window, - CWSibling | CWStackMode, &wc); - wc.sibling = client->titlebar.sw->window; + xcb_configure_window(globalconf.connection, client->titlebar.sw->window, + XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE, + config_win_vals); + config_win_vals[0] = client->titlebar.sw->window; } - XConfigureWindow(globalconf.display, client->win, CWSibling | CWStackMode, &wc); - wc.sibling = client->win; + xcb_configure_window(globalconf.connection, client->win, + XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE, + config_win_vals); + config_win_vals[0] = client->win; } } } @@ -266,9 +285,10 @@ client_focus(Client *c, int screen, Bool raise) window_grabbuttons(phys_screen, c->win); } else - XSetInputFocus(globalconf.display, - RootWindow(globalconf.display, phys_screen), - RevertToPointerRoot, CurrentTime); + xcb_set_input_focus(globalconf.connection, + XCB_INPUT_FOCUS_POINTER_ROOT, + root_window(globalconf.connection, phys_screen), + XCB_CURRENT_TIME); widget_invalidate_cache(screen, WIDGET_CACHE_CLIENTS); ewmh_update_net_active_window(phys_screen); @@ -280,17 +300,18 @@ client_focus(Client *c, int screen, Bool raise) * \param screen Screen ID */ void -client_manage(Window w, XWindowAttributes *wa, int screen) +client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wa, int screen) { Client *c, *t = NULL; - Window trans; - Bool rettrans, retloadprops; - XWindowChanges wc; + xcb_window_t trans; + bool rettrans, retloadprops; + uint32_t config_win_val; + uint32_t move_resize_win_values[4]; Tag *tag; Rule *rule; area_t screen_geom; int phys_screen = get_phys_screen(screen); - long flags; + size_hints_t *u_size_hints; c = p_new(Client, 1); @@ -306,12 +327,14 @@ client_manage(Window w, XWindowAttributes *wa, int screen) c->geometry.width = c->f_geometry.width = c->m_geometry.width = wa->width; c->geometry.height = c->f_geometry.height = c->m_geometry.height = wa->height; c->oldborder = wa->border_width; - c->newcomer = True; + c->newcomer = true; /* Set windows borders */ - wc.border_width = c->border = globalconf.screens[screen].borderpx; - XConfigureWindow(globalconf.display, w, CWBorderWidth, &wc); - XSetWindowBorder(globalconf.display, w, c->border); + config_win_val = c->border = globalconf.screens[screen].borderpx; + xcb_configure_window(globalconf.connection, w, XCB_CONFIG_WINDOW_BORDER_WIDTH, + &config_win_val); + xcb_configure_window(globalconf.connection, w, XCB_CONFIG_WINDOW_STACK_MODE, + &config_win_val); /* propagates border_width, if size doesn't change */ window_configure(c->win, c->geometry, c->border); @@ -319,7 +342,7 @@ client_manage(Window w, XWindowAttributes *wa, int screen) client_updatetitle(c); /* update hints */ - flags = client_updatesizehints(c); + u_size_hints = client_updatesizehints(c); client_updatewmhints(c); /* Try to load props if any */ @@ -344,9 +367,9 @@ client_manage(Window w, XWindowAttributes *wa, int screen) if(rule) { if(rule->screen != RULE_NOSCREEN) - move_client_to_screen(c, rule->screen, True); + move_client_to_screen(c, rule->screen, true); else - move_client_to_screen(c, screen, True); + move_client_to_screen(c, screen, true); tag_client_with_rule(c, rule); switch(rule->isfloating) @@ -354,10 +377,10 @@ client_manage(Window w, XWindowAttributes *wa, int screen) case Maybe: break; case Yes: - client_setfloating(c, True); + client_setfloating(c, true); break; case No: - client_setfloating(c, False); + client_setfloating(c, false); break; } @@ -365,13 +388,11 @@ client_manage(Window w, XWindowAttributes *wa, int screen) window_settrans(c->win, rule->opacity); } else - move_client_to_screen(c, screen, True); + move_client_to_screen(c, screen, true); } - /* check for transient and set tags like its parent, - * XGetTransientForHint returns 1 on success - */ - if((rettrans = XGetTransientForHint(globalconf.display, w, &trans)) + /* check for transient and set tags like its parent */ + if((rettrans = x_get_transient_for_hint(globalconf.connection, w, &trans)) && (t = client_get_bywin(globalconf.clients, trans))) for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next) if(is_client_tagged(t, tag)) @@ -387,19 +408,24 @@ client_manage(Window w, XWindowAttributes *wa, int screen) titlebar_init(c); - if(!retloadprops && !(flags & (USPosition | PPosition))) - c->f_geometry = globalconf.screens[c->screen].floating_placement(c); + if(u_size_hints) + { + if(!(size_hints_is_us_position(u_size_hints) | size_hints_is_p_position(u_size_hints))) + c->f_geometry = globalconf.screens[c->screen].floating_placement(c); + + free_size_hints(u_size_hints); + } /* update titlebar with real floating info now */ if(c->isfloating) titlebar_update_geometry_floating(c); - XSelectInput(globalconf.display, w, StructureNotifyMask | PropertyChangeMask | EnterWindowMask); + x_select_input(globalconf.connection, w, XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_PROPERTY_CHANGE | XCB_EVENT_MASK_ENTER_WINDOW); /* handle xshape */ if(globalconf.have_shape) { - XShapeSelectInput(globalconf.display, w, ShapeNotifyMask); + xcb_shape_select_input(globalconf.connection, w, true); window_setshape(phys_screen, c->win); } @@ -427,8 +453,16 @@ client_manage(Window w, XWindowAttributes *wa, int screen) } /* some windows require this */ - XMoveResizeWindow(globalconf.display, c->win, c->geometry.x, c->geometry.y, - c->geometry.width, c->geometry.height); + move_resize_win_values[0] = c->geometry.x; + move_resize_win_values[1] = c->geometry.y; + move_resize_win_values[2] = c->geometry.width; + move_resize_win_values[3] = c->geometry.height; + + /* some windows require this */ + xcb_configure_window(globalconf.connection, c->win, + XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | + XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, + move_resize_win_values); widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS); ewmh_update_net_client_list(phys_screen); @@ -485,16 +519,19 @@ client_geometry_hints(Client *c, area_t geometry) * \param c client to resize * \param geometry new window geometry * \param hints use resize hints - * \param return True if resize has been done + * \param return true if resize has been done */ -Bool -client_resize(Client *c, area_t geometry, Bool hints) +bool +client_resize(Client *c, area_t geometry, bool hints) { int new_screen; area_t area; - XWindowChanges wc; Layout *layout = layout_get_current(c->screen); + /* Values to configure a window is an array where values are + * stored according to 'value_mask' */ + uint32_t values[5]; + if(hints) geometry = client_geometry_hints(c, geometry); @@ -502,7 +539,7 @@ client_resize(Client *c, area_t geometry, Bool hints) geometry = titlebar_update_geometry(c, geometry); if(geometry.width <= 0 || geometry.height <= 0) - return False; + return false; /* offscreen appearance fixes */ area = get_display_area(get_phys_screen(c->screen), NULL, @@ -523,11 +560,11 @@ client_resize(Client *c, area_t geometry, Bool hints) new_screen = screen_get_bycoord(globalconf.screens_info, c->screen, geometry.x, geometry.y); - c->geometry.x = wc.x = geometry.x; - c->geometry.width = wc.width = geometry.width; - c->geometry.y = wc.y = geometry.y; - c->geometry.height = wc.height = geometry.height; - wc.border_width = c->border; + c->geometry.x = values[0] = geometry.x; + c->geometry.width = values[2] = geometry.width; + c->geometry.y = values[1] = geometry.y; + c->geometry.height = values[3] = geometry.height; + values[4] = c->border; /* save the floating geometry if the window is floating but not * maximized */ @@ -539,39 +576,47 @@ client_resize(Client *c, area_t geometry, Bool hints) titlebar_update_geometry_floating(c); } - XConfigureWindow(globalconf.display, c->win, - CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &wc); + xcb_configure_window(globalconf.connection, c->win, + XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | + XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT | + XCB_CONFIG_WINDOW_BORDER_WIDTH, + values); window_configure(c->win, geometry, c->border); if(c->screen != new_screen) - move_client_to_screen(c, new_screen, False); + move_client_to_screen(c, new_screen, false); - return True; + return true; } - return False; + return false; } void -client_setfloating(Client *c, Bool floating) +client_setfloating(Client *c, bool floating) { + const uint32_t raise_window_val = XCB_STACK_MODE_ABOVE; + const uint32_t lower_window_val = XCB_STACK_MODE_BELOW; + if(c->isfloating != floating) { if((c->isfloating = floating)) { - client_resize(c, c->f_geometry, False); - XRaiseWindow(globalconf.display, c->win); + client_resize(c, c->f_geometry, false); + xcb_configure_window(globalconf.connection, c->win, + XCB_CONFIG_WINDOW_STACK_MODE, &raise_window_val); } else { - XLowerWindow(globalconf.display, c->win); + xcb_configure_window(globalconf.connection, c->win, + XCB_CONFIG_WINDOW_STACK_MODE, &lower_window_val); if(c->ismax) { - c->ismax = False; - client_resize(c, c->m_geometry, False); + c->ismax = false; + client_resize(c, c->m_geometry, false); } } if(client_isvisible(c, c->screen)) - globalconf.screens[c->screen].need_arrange = True; + globalconf.screens[c->screen].need_arrange = true; widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS); client_saveprops(c); } @@ -600,9 +645,9 @@ client_saveprops(Client *c) prop[++i] = '\0'; - XChangeProperty(globalconf.display, c->win, - XInternAtom(globalconf.display, "_AWESOME_PROPERTIES", False), - XA_STRING, 8, PropModeReplace, (unsigned char *) prop, i); + xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, c->win, + x_intern_atom(globalconf.connection, "_AWESOME_PROPERTIES"), + STRING, 8, i, (unsigned char *) prop); p_delete(&prop); } @@ -610,24 +655,23 @@ client_saveprops(Client *c) void client_unban(Client *c) { - XMapWindow(globalconf.display, c->win); - window_setstate(c->win, NormalState); + xcb_map_window(globalconf.connection, c->win); + window_setstate(c->win, xcb_wm_normal_state_t); if(c->titlebar.sw && c->titlebar.position != Off) - XMapWindow(globalconf.display, c->titlebar.sw->window); + xcb_map_window(globalconf.connection, c->titlebar.sw->window); } void client_unmanage(Client *c) { - XWindowChanges wc; Tag *tag; - wc.border_width = c->oldborder; - /* The server grab construct avoids race conditions. */ - XGrabServer(globalconf.display); + xcb_grab_server(globalconf.connection); - XConfigureWindow(globalconf.display, c->win, CWBorderWidth, &wc); /* restore border */ + xcb_configure_window(globalconf.connection, c->win, + XCB_CONFIG_WINDOW_BORDER_WIDTH, + (uint32_t *) &c->oldborder); /* remove client everywhere */ client_list_detach(&globalconf.clients, c); @@ -638,13 +682,13 @@ client_unmanage(Client *c) untag_client(c, tag); if(globalconf.focus->client == c) - client_focus(NULL, c->screen, True); + client_focus(NULL, c->screen, true); - XUngrabButton(globalconf.display, AnyButton, AnyModifier, c->win); - window_setstate(c->win, WithdrawnState); + xcb_ungrab_button(globalconf.connection, XCB_BUTTON_INDEX_ANY, c->win, ANY_MODIFIER); + window_setstate(c->win, xcb_wm_withdrawn_state_t); - XSync(globalconf.display, False); - XUngrabServer(globalconf.display); + xcb_aux_sync(globalconf.connection); + xcb_ungrab_server(globalconf.connection); if(c->titlebar.sw) simplewindow_delete(c->titlebar.sw); @@ -655,107 +699,88 @@ client_unmanage(Client *c) void client_updatewmhints(Client *c) { - XWMHints *wmh; + wm_hints_t *wmh; - if((wmh = XGetWMHints(globalconf.display, c->win))) + if((wmh = get_wm_hints(globalconf.connection, c->win))) { - if((c->isurgent = ((wmh->flags & XUrgencyHint) && globalconf.focus->client != c))) + if((c->isurgent = (wm_hints_is_xu_hint(wmh) && globalconf.focus->client != c))) widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS); - if((wmh->flags & StateHint) && wmh->initial_state == WithdrawnState) + if(wm_hints_is_state_hint(wmh) && wm_hints_state_is_withdrawn(wmh)) { c->border = 0; - c->skip = True; + c->skip = true; } - XFree(wmh); + free(wmh); } } -long +size_hints_t * client_updatesizehints(Client *c) { long msize; - XSizeHints size; + size_hints_t *size = NULL; - if(!XGetWMNormalHints(globalconf.display, c->win, &size, &msize)) - return 0L; + if(!get_wm_normal_hints(globalconf.connection, c->win, size, &msize) || + size == NULL) + return NULL; - if(size.flags & PBaseSize) - { - c->basew = size.base_width; - c->baseh = size.base_height; - } - else if(size.flags & PMinSize) - { - c->basew = size.min_width; - c->baseh = size.min_height; - } + if(size_hints_is_p_size(size)) + size_hints_get_base_size(size, &c->basew, &c->baseh); + else if(size_hints_is_p_min_size(size)) + size_hints_get_min_size(size, &c->basew, &c->baseh); else c->basew = c->baseh = 0; - if(size.flags & PResizeInc) - { - c->incw = size.width_inc; - c->inch = size.height_inc; - } + if(size_hints_is_p_resize_inc(size)) + size_hints_get_increase(size, &c->incw, &c->inch); else c->incw = c->inch = 0; - if(size.flags & PMaxSize) - { - c->maxw = size.max_width; - c->maxh = size.max_height; - } + if(size_hints_is_p_max_size(size)) + size_hints_get_max_size(size, &c->maxw, &c->maxh); else c->maxw = c->maxh = 0; - if(size.flags & PMinSize) - { - c->minw = size.min_width; - c->minh = size.min_height; - } - else if(size.flags & PBaseSize) - { - c->minw = size.base_width; - c->minh = size.base_height; - } + if(size_hints_is_p_min_size(size)) + size_hints_get_min_size(size, &c->minw, &c->minh); + else if(size_hints_is_p_base_size(size)) + size_hints_get_base_size(size, &c->minw, &c->minh); else c->minw = c->minh = 0; - if(size.flags & PAspect) + if(size_hints_is_p_aspect(size)) { - c->minax = size.min_aspect.x; - c->maxax = size.max_aspect.x; - c->minay = size.min_aspect.y; - c->maxay = size.max_aspect.y; + size_hints_get_min_aspect(size, &c->minax, &c->minay); + size_hints_get_max_aspect(size, &c->maxax, &c->maxay); } else c->minax = c->maxax = c->minay = c->maxay = 0; if(c->maxw && c->minw && c->maxh && c->minh && c->maxw == c->minw && c->maxh == c->minh) - c->isfixed = True; + c->isfixed = true; - return size.flags; + return size; } -/** Returns True if a client is tagged +/** Returns true if a client is tagged * with one of the tags - * \return True or False + * \return true or false */ -Bool +bool client_isvisible(Client *c, int screen) { Tag *tag; if(!c || c->screen != screen) - return False; + return false; if(globalconf.scratch.client == c) return globalconf.scratch.isvisible; for(tag = globalconf.screens[screen].tags; tag; tag = tag->next) if(tag->selected && is_client_tagged(c, tag)) - return True; - return False; + return true; + return false; } /** Set selected client transparency @@ -767,26 +792,27 @@ void uicb_client_settrans(int screen __attribute__ ((unused)), char *arg) { double delta = 100.0, current_opacity = 100.0; - unsigned char *data; - Atom actual; - int format; - unsigned long n, left; unsigned int current_opacity_raw = 0; int set_prop = 0; Client *sel = globalconf.focus->client; + xcb_get_property_reply_t *prop_r; if(!sel) return; - XGetWindowProperty(globalconf.display, sel->win, - XInternAtom(globalconf.display, "_NET_WM_WINDOW_OPACITY", False), - 0L, 1L, False, XA_CARDINAL, &actual, &format, &n, &left, - (unsigned char **) &data); - if(data) + prop_r = xcb_get_property_reply(globalconf.connection, + xcb_get_property_unchecked(globalconf.connection, + false, sel->win, + x_intern_atom(globalconf.connection, "_NET_WM_WINDOW_OPACITY"), + CARDINAL, + 0, 1), + NULL); + + if(prop_r) { - memcpy(¤t_opacity_raw, data, sizeof(unsigned int)); - XFree(data); + memcpy(¤t_opacity_raw, xcb_get_property_value(prop_r), sizeof(unsigned int)); current_opacity = (current_opacity_raw * 100.0) / 0xffffffff; + p_delete(&prop_r); } else set_prop = 1; @@ -808,7 +834,7 @@ uicb_client_settrans(int screen __attribute__ ((unused)), char *arg) } static Client * -client_find_visible(Client *sel, Bool reverse) +client_find_visible(Client *sel, bool reverse) { Client *next; Client *(*client_iter)(Client **, Client *) = client_list_next_cycle; @@ -838,10 +864,10 @@ uicb_client_swapprev(int screen __attribute__ ((unused)), { Client *prev; - if((prev = client_find_visible(globalconf.focus->client, True))) + if((prev = client_find_visible(globalconf.focus->client, true))) { client_list_swap(&globalconf.clients, prev, globalconf.focus->client); - globalconf.screens[prev->screen].need_arrange = True; + globalconf.screens[prev->screen].need_arrange = true; } } @@ -856,10 +882,10 @@ uicb_client_swapnext(int screen __attribute__ ((unused)), { Client *next; - if((next = client_find_visible(globalconf.focus->client, False))) + if((next = client_find_visible(globalconf.focus->client, false))) { client_list_swap(&globalconf.clients, globalconf.focus->client, next); - globalconf.screens[next->screen].need_arrange = True; + globalconf.screens[next->screen].need_arrange = true; } } @@ -873,11 +899,10 @@ uicb_client_moveresize(int screen, char *arg) { int ox, oy, ow, oh; /* old geometry */ char x[8], y[8], w[8], h[8]; - int mx, my, dx, dy, nmx, nmy; - unsigned int dui; - Window dummy; + int nmx, nmy; area_t geometry; Client *sel = globalconf.focus->client; + xcb_query_pointer_reply_t *xqp; Layout *curlay = layout_get_current(screen); if(!sel || sel->isfixed || !arg || @@ -897,47 +922,51 @@ uicb_client_moveresize(int screen, char *arg) ow = sel->geometry.width; oh = sel->geometry.height; - Bool xqp = XQueryPointer(globalconf.display, - RootWindow(globalconf.display, - get_phys_screen(screen)), - &dummy, &dummy, &mx, &my, &dx, &dy, &dui); + xqp = xcb_query_pointer_reply(globalconf.connection, + xcb_query_pointer_unchecked(globalconf.connection, + root_window(globalconf.connection, get_phys_screen(screen))), + NULL); if(globalconf.screens[sel->screen].resize_hints) geometry = client_geometry_hints(sel, geometry); - client_resize(sel, geometry, False); - if (xqp && ox <= mx && (ox + 2 * sel->border + ow) >= mx && - oy <= my && (oy + 2 * sel->border + oh) >= my) + client_resize(sel, geometry, false); + if (xqp && ox <= xqp->root_x && (ox + 2 * sel->border + ow) >= xqp->root_x && + oy <= xqp->root_y && (oy + 2 * sel->border + oh) >= xqp->root_y) { - nmx = mx - (ox + sel->border) + sel->geometry.width - ow; - nmy = my - (oy + sel->border) + sel->geometry.height - oh; + nmx = xqp->root_x - (ox + sel->border) + sel->geometry.width - ow; + nmy = xqp->root_y - (oy + sel->border) + sel->geometry.height - oh; if(nmx < -sel->border) /* can happen on a resize */ nmx = -sel->border; if(nmy < -sel->border) nmy = -sel->border; - XWarpPointer(globalconf.display, - None, sel->win, - 0, 0, 0, 0, nmx, nmy); + xcb_warp_pointer(globalconf.connection, + XCB_NONE, sel->win, + 0, 0, 0, 0, nmx, nmy); } } void client_kill(Client *c) { - XEvent ev; + xcb_client_message_event_t ev; - if(client_isprotodel(globalconf.display, c->win)) + if(client_isprotodel(globalconf.connection, c->win)) { - ev.type = ClientMessage; - ev.xclient.window = c->win; - ev.xclient.message_type = XInternAtom(globalconf.display, "WM_PROTOCOLS", False); - ev.xclient.format = 32; - ev.xclient.data.l[0] = XInternAtom(globalconf.display, "WM_DELETE_WINDOW", False); - ev.xclient.data.l[1] = CurrentTime; - XSendEvent(globalconf.display, c->win, False, NoEventMask, &ev); + ev.window = c->win; + ev.type = x_intern_atom(globalconf.connection, "WM_PROTOCOLS"); + + ev.data.data32[0] = x_intern_atom(globalconf.connection, "WM_DELETE_WINDOW"); + ev.data.data32[1] = XCB_CURRENT_TIME; + + /* TODO: really useful? */ + ev.data.data32[2] = ev.data.data32[3] = ev.data.data32[4] = 0; + + xcb_send_event(globalconf.connection, false, c->win, + XCB_EVENT_MASK_NO_EVENT, (char *) &ev); } else - XKillClient(globalconf.display, c->win); + xcb_kill_client(globalconf.connection, c->win); } /** Kill selected client @@ -963,25 +992,25 @@ client_maximize(Client *c, area_t geometry) c->wasfloating = c->isfloating; c->m_geometry = c->geometry; if(layout_get_current(c->screen)->arrange != layout_floating) - client_setfloating(c, True); - client_focus(c, c->screen, True); - client_resize(c, geometry, False); + client_setfloating(c, true); + client_focus(c, c->screen, true); + client_resize(c, geometry, false); widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS); } else if(c->wasfloating) { - client_setfloating(c, True); - client_resize(c, c->m_geometry, False); + client_setfloating(c, true); + client_resize(c, c->m_geometry, false); widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS); } else if(layout_get_current(c->screen)->arrange == layout_floating) { - client_resize(c, c->m_geometry, False); + client_resize(c, c->m_geometry, false); widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS); } else { - client_setfloating(c, False); + client_setfloating(c, false); widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS); } } @@ -1073,7 +1102,7 @@ uicb_client_zoom(int screen, char *arg __attribute__ ((unused))) { client_list_detach(&globalconf.clients, sel); client_list_push(&globalconf.clients, sel); - globalconf.screens[screen].need_arrange = True; + globalconf.screens[screen].need_arrange = true; } } @@ -1087,8 +1116,8 @@ uicb_client_focusnext(int screen, char *arg __attribute__ ((unused))) { Client *next; - if((next = client_find_visible(globalconf.focus->client, False))) - client_focus(next, screen, True); + if((next = client_find_visible(globalconf.focus->client, false))) + client_focus(next, screen, true); } /** Send focus to previous client in stack @@ -1101,8 +1130,8 @@ uicb_client_focusprev(int screen, char *arg __attribute__ ((unused))) { Client *prev; - if((prev = client_find_visible(globalconf.focus->client, True))) - client_focus(prev, screen, True); + if((prev = client_find_visible(globalconf.focus->client, true))) + client_focus(prev, screen, true); } /** Toggle floating state of a client @@ -1136,7 +1165,7 @@ uicb_client_setscratch(int screen, globalconf.scratch.client = globalconf.focus->client; widget_invalidate_cache(screen, WIDGET_CACHE_CLIENTS | WIDGET_CACHE_TAGS); - globalconf.screens[screen].need_arrange = True; + globalconf.screens[screen].need_arrange = true; } /** Toggle scratch client visibility @@ -1152,8 +1181,8 @@ uicb_client_togglescratch(int screen, { globalconf.scratch.isvisible = !globalconf.scratch.isvisible; if(globalconf.scratch.isvisible) - client_focus(globalconf.scratch.client, screen, True); - globalconf.screens[globalconf.scratch.client->screen].need_arrange = True; + client_focus(globalconf.scratch.client, screen, true); + globalconf.screens[globalconf.scratch.client->screen].need_arrange = true; widget_invalidate_cache(globalconf.scratch.client->screen, WIDGET_CACHE_CLIENTS); } } diff --git a/client.h b/client.h index 4e43923..2864520 100644 --- a/client.h +++ b/client.h @@ -22,23 +22,27 @@ #ifndef AWESOME_CLIENT_H #define AWESOME_CLIENT_H +#include + +#include + #include "structs.h" -Bool client_isvisible(Client *, int); -Client * client_get_bywin(Client *, Window); +bool client_isvisible(Client *, int); +Client * client_get_bywin(Client *, xcb_window_t); Client * client_get_byname(Client *, char *); -void client_focus(Client *, int, Bool); +void client_focus(Client *, int, bool); void client_ban(Client *); void client_unban(Client *); -void client_manage(Window, XWindowAttributes *, int); -Bool client_resize(Client *, area_t, Bool); +void client_manage(xcb_window_t, xcb_get_geometry_reply_t *, int); +bool client_resize(Client *, area_t, bool); void client_unmanage(Client *); void client_updatewmhints(Client *); -long client_updatesizehints(Client *); +size_hints_t *client_updatesizehints(Client *); void client_updatetitle(Client *); void client_saveprops(Client *); void client_kill(Client *); -void client_setfloating(Client *, Bool); +void client_setfloating(Client *, bool); Uicb uicb_client_kill; Uicb uicb_client_moveresize; diff --git a/common/configopts.c b/common/configopts.c index f335ddc..aee8e66 100644 --- a/common/configopts.c +++ b/common/configopts.c @@ -197,14 +197,14 @@ cfg_opt_t styles_opts[] = cfg_opt_t mouse_taglist_opts[] = { CFG_STR_LIST((char *) "modkey", (char *) "{}", CFGF_NONE), - CFG_STR((char *) "button", (char *) "None", CFGF_NONE), + CFG_STR((char *) "button", (char *) "XCB_NONE", CFGF_NONE), CFG_STR((char *) "command", (char *) "", CFGF_NONE), CFG_AWESOME_END() }; cfg_opt_t mouse_generic_opts[] = { CFG_STR_LIST((char *) "modkey", (char *) "{}", CFGF_NONE), - CFG_STR((char *) "button", (char *) "None", CFGF_NONE), + CFG_STR((char *) "button", (char *) "XCB_NONE", CFGF_NONE), CFG_STR((char *) "command", (char *) "", CFGF_NONE), CFG_STR((char *) "arg", NULL, CFGF_NONE), CFG_AWESOME_END() @@ -387,7 +387,7 @@ cfg_opt_t rules_opts[] = cfg_opt_t key_opts[] = { CFG_STR_LIST((char *) "modkey", (char *) "", CFGF_NONE), - CFG_STR((char *) "key", (char *) "None", CFGF_NONE), + CFG_STR((char *) "key", (char *) "XCB_NONE", CFGF_NONE), CFG_STR((char *) "command", (char *) "", CFGF_NONE), CFG_STR((char *) "arg", NULL, CFGF_NONE), CFG_AWESOME_END() diff --git a/common/draw.c b/common/draw.c index 10e5e52..fc4100f 100644 --- a/common/draw.c +++ b/common/draw.c @@ -20,16 +20,20 @@ */ #include -#include +#include +#include +#include #include #include #include +#include #include #include "draw.h" #include "common/util.h" +#include "common/xutil.h" /** Convert text from any charset to UTF-8 using iconv * \param iso the ISO string to convert @@ -76,8 +80,27 @@ draw_iso2utf8(char *iso) return utf8p; } +static xcb_visualtype_t * +default_visual_from_screen(xcb_screen_t *s) +{ + xcb_depth_iterator_t depth_iter; + xcb_visualtype_iterator_t visual_iter; + + if(!s) + return NULL; + + for(depth_iter = xcb_screen_allowed_depths_iterator(s); + depth_iter.rem; xcb_depth_next (&depth_iter)) + for(visual_iter = xcb_depth_visuals_iterator (depth_iter.data); + visual_iter.rem; xcb_visualtype_next (&visual_iter)) + if (s->root_visual == visual_iter.data->visual_id) + return visual_iter.data; + + return NULL; +} + /** Get a draw context - * \param disp Display ref + * \param conn Connection ref * \param phys_screen physical screen id * \param width width * \param height height @@ -85,18 +108,19 @@ draw_iso2utf8(char *iso) * \return draw context ref */ DrawCtx * -draw_context_new(Display *disp, int phys_screen, int width, int height, Drawable dw) +draw_context_new(xcb_connection_t *conn, int phys_screen, int width, int height, xcb_drawable_t dw) { DrawCtx *d = p_new(DrawCtx, 1); + xcb_screen_t *s = xcb_aux_get_screen(conn, phys_screen); - d->display = disp; + d->connection = conn; d->phys_screen = phys_screen; d->width = width; d->height = height; - d->depth = DefaultDepth(disp, phys_screen); - d->visual = DefaultVisual(disp, phys_screen); + d->depth = s->root_depth; + d->visual = default_visual_from_screen(s); d->drawable = dw; - d->surface = cairo_xlib_surface_create(disp, dw, d->visual, width, height); + d->surface = cairo_xcb_surface_create(conn, dw, d->visual, width, height); d->cr = cairo_create(d->surface); d->layout = pango_cairo_create_layout(d->cr); @@ -116,24 +140,25 @@ draw_context_delete(DrawCtx *ctx) } /** Create a new Pango font - * \param disp Display ref + * \param conn Connection ref * \param fontname Pango fontname (e.g. [FAMILY-LIST] [STYLE-OPTIONS] [SIZE]) */ font_t * -draw_font_new(Display *disp, char *fontname) +draw_font_new(xcb_connection_t *conn, int phys_screen, char *fontname) { cairo_surface_t *surface; + xcb_screen_t *s = xcb_aux_get_screen(conn, phys_screen); cairo_t *cr; PangoLayout *layout; font_t *font = p_new(font_t, 1); /* Create a dummy cairo surface, cairo context and pango layout in * order to get font informations */ - surface = cairo_xlib_surface_create(disp, - DefaultScreen(disp), - DefaultVisual(disp, DefaultScreen(disp)), - DisplayWidth(disp, DefaultScreen(disp)), - DisplayHeight(disp, DefaultScreen(disp))); + surface = cairo_xcb_surface_create(conn, + phys_screen, + default_visual_from_screen(s), + s->width_in_pixels, + s->height_in_pixels); cr = cairo_create(surface); layout = pango_cairo_create_layout(cr); @@ -202,7 +227,7 @@ draw_text(DrawCtx *ctx, ssize_t len, olen; char *buf = NULL, *utf8 = NULL; - draw_rectangle(ctx, area, True, style.bg); + draw_rectangle(ctx, area, true, style.bg); if(!(len = olen = a_strlen(text))) return; @@ -217,7 +242,7 @@ draw_text(DrawCtx *ctx, buf = a_strdup(text); /* check that the text is not too long */ - while(len && (nw = (draw_textwidth(ctx->display, style.font, buf)) + padding * 2) > area.width) + while(len && (nw = (draw_textwidth(ctx->connection, ctx->default_screen, style.font, buf)) + padding * 2) > area.width) { len--; /* we can't blindly null the char, we need to check if it's not part of @@ -289,7 +314,7 @@ draw_text(DrawCtx *ctx, */ static cairo_pattern_t * draw_setup_cairo_color_source(DrawCtx *ctx, area_t rect, - XColor *pcolor, XColor *pcolor_center, XColor *pcolor_end) + xcolor_t *pcolor, xcolor_t *pcolor_center, xcolor_t *pcolor_end) { cairo_pattern_t *pat = NULL; @@ -326,7 +351,7 @@ draw_setup_cairo_color_source(DrawCtx *ctx, area_t rect, * \param color color to use */ void -draw_rectangle(DrawCtx *ctx, area_t geometry, Bool filled, XColor color) +draw_rectangle(DrawCtx *ctx, area_t geometry, bool filled, xcolor_t color) { cairo_set_antialias(ctx->cr, CAIRO_ANTIALIAS_NONE); cairo_set_line_width(ctx->cr, 1.0); @@ -353,8 +378,8 @@ draw_rectangle(DrawCtx *ctx, area_t geometry, Bool filled, XColor color) * \param pcolor_end color at pattern_start + pattern_width */ void -draw_rectangle_gradient(DrawCtx *ctx, area_t geometry, Bool filled, - area_t pattern_rect, XColor *pcolor, XColor *pcolor_center, XColor *pcolor_end) +draw_rectangle_gradient(DrawCtx *ctx, area_t geometry, bool filled, + area_t pattern_rect, xcolor_t *pcolor, xcolor_t *pcolor_center, xcolor_t *pcolor_end) { cairo_pattern_t *pat; @@ -405,7 +430,7 @@ draw_graph_setup(DrawCtx *ctx) */ void draw_graph(DrawCtx *ctx, area_t rect, int *from, int *to, int cur_index, Position grow, - area_t patt_rect, XColor *pcolor, XColor *pcolor_center, XColor *pcolor_end) + area_t patt_rect, xcolor_t *pcolor, xcolor_t *pcolor_center, xcolor_t *pcolor_end) { int i, x, y, w; cairo_pattern_t *pat; @@ -463,7 +488,7 @@ draw_graph(DrawCtx *ctx, area_t rect, int *from, int *to, int cur_index, Positio */ void draw_graph_line(DrawCtx *ctx, area_t rect, int *to, int cur_index, Position grow, - area_t patt_rect, XColor *pcolor, XColor *pcolor_center, XColor *pcolor_end) + area_t patt_rect, xcolor_t *pcolor, xcolor_t *pcolor_center, xcolor_t *pcolor_end) { int i, x, y, w; int flag = 0; /* used to prevent drawing a line from 0 to 0 values */ @@ -528,7 +553,7 @@ draw_graph_line(DrawCtx *ctx, area_t rect, int *to, int cur_index, Position grow * \param color color to use */ void -draw_circle(DrawCtx *ctx, int x, int y, int r, Bool filled, XColor color) +draw_circle(DrawCtx *ctx, int x, int y, int r, bool filled, xcolor_t color) { cairo_set_line_width(ctx->cr, 1.0); cairo_set_source_rgb(ctx->cr, color.red / 65535.0, color.green / 65535.0, color.blue / 65535.0); @@ -655,19 +680,20 @@ draw_get_image_size(const char *filename) * \param ty translate to this y coordinate * \return new rotated drawable */ -Drawable +xcb_drawable_t draw_rotate(DrawCtx *ctx, int phys_screen, double angle, int tx, int ty) { cairo_surface_t *surface, *source; cairo_t *cr; - Drawable newdrawable; - - newdrawable = XCreatePixmap(ctx->display, - RootWindow(ctx->display, phys_screen), - ctx->height, ctx->width, - ctx->depth); - surface = cairo_xlib_surface_create(ctx->display, newdrawable, ctx->visual, ctx->height, ctx->width); - source = cairo_xlib_surface_create(ctx->display, ctx->drawable, ctx->visual, ctx->width, ctx->height); + xcb_drawable_t newdrawable; + + newdrawable = xcb_generate_id(ctx->connection); + + xcb_create_pixmap(ctx->connection, ctx->depth, newdrawable, + root_window(ctx->connection, phys_screen), + ctx->height, ctx->width); + surface = cairo_xcb_surface_create(ctx->connection, newdrawable, ctx->visual, ctx->height, ctx->width); + source = cairo_xcb_surface_create(ctx->connection, ctx->drawable, ctx->visual, ctx->width, ctx->height); cr = cairo_create (surface); cairo_translate(cr, tx, ty); @@ -684,26 +710,27 @@ draw_rotate(DrawCtx *ctx, int phys_screen, double angle, int tx, int ty) } /** Return the width of a text in pixel - * \param disp Display ref + * \param conn Connection ref * \param font font to use * \param text the text * \return text width */ unsigned short -draw_textwidth(Display *disp, font_t *font, char *text) +draw_textwidth(xcb_connection_t *conn, int default_screen, font_t *font, char *text) { cairo_surface_t *surface; cairo_t *cr; PangoLayout *layout; PangoRectangle ext; + xcb_screen_t *s = xcb_aux_get_screen(conn, default_screen); if (!a_strlen(text)) return 0; - surface = cairo_xlib_surface_create(disp, DefaultScreen(disp), - DefaultVisual(disp, DefaultScreen(disp)), - DisplayWidth(disp, DefaultScreen(disp)), - DisplayHeight(disp, DefaultScreen(disp))); + surface = cairo_xcb_surface_create(conn, default_screen, + default_visual_from_screen(s), + s->width_in_pixels, + s->height_in_pixels); cr = cairo_create(surface); layout = pango_cairo_create_layout(cr); pango_layout_set_text(layout, text, -1); @@ -738,33 +765,44 @@ draw_align_get_from_str(const char *align) } /** Initialize an X color - * \param disp display ref + * \param conn Connection ref * \param phys_screen Physical screen number * \param colstr Color specification - * \param color XColor struct to store color to + * \param color xcolor_t struct to store color to * \return true if color allocation was successfull */ -Bool -draw_color_new(Display *disp, int phys_screen, const char *colstr, XColor *color) +bool +draw_color_new(xcb_connection_t *conn, int phys_screen, const char *colstr, xcolor_t *color) { - Bool ret; - XColor exactColor; + xcb_alloc_named_color_reply_t *c; + xcb_screen_t *s = xcb_aux_get_screen(conn, phys_screen); if(!a_strlen(colstr)) - return False; - - if(!(ret = XAllocNamedColor(disp, - DefaultColormap(disp, phys_screen), - colstr, - color, - &exactColor))) + return false; + + if((c = xcb_alloc_named_color_reply(conn, + xcb_alloc_named_color(conn, + s->default_colormap, + strlen(colstr), + colstr), + NULL)) == NULL) + { warn("awesome: error, cannot allocate color '%s'\n", colstr); + return false; + } + + color->pixel = c->pixel; + color->red = c->visual_red; + color->green = c->visual_green; + color->blue = c->visual_blue; + + p_delete(&c); - return ret; + return true; } void -draw_style_init(Display *disp, int phys_screen, cfg_t *cfg, +draw_style_init(xcb_connection_t *conn, int phys_screen, cfg_t *cfg, style_t *c, style_t *m) { char *buf; @@ -776,18 +814,18 @@ draw_style_init(Display *disp, int phys_screen, cfg_t *cfg, return; if((buf = cfg_getstr(cfg, "font"))) - c->font = draw_font_new(disp, buf); + c->font = draw_font_new(conn, phys_screen, buf); - draw_color_new(disp, phys_screen, + draw_color_new(conn, phys_screen, cfg_getstr(cfg, "fg"), &c->fg); - draw_color_new(disp, phys_screen, + draw_color_new(conn, phys_screen, cfg_getstr(cfg, "bg"), &c->bg); - draw_color_new(disp, phys_screen, + draw_color_new(conn, phys_screen, cfg_getstr(cfg, "border"), &c->border); - draw_color_new(disp, phys_screen, + draw_color_new(conn, phys_screen, cfg_getstr(cfg, "shadow"), &c->shadow); c->shadow_offset = cfg_getint(cfg, "shadow_offset"); diff --git a/common/draw.h b/common/draw.h index 4d2e2af..d4942f1 100644 --- a/common/draw.h +++ b/common/draw.h @@ -23,14 +23,15 @@ #define AWESOME_COMMON_DRAW_H #include +#include #include -#include -#include +#include #include "common/util.h" #include "common/list.h" +#include "common/xutil.h" typedef enum { @@ -59,7 +60,7 @@ DO_SLIST(area_t, area, p_delete) #define AREA_RIGHT(a) ((a).x + (a).width) #define AREA_BOTTOM(a) ((a).y + (a).height) -static inline Bool +static inline bool area_intersect_area(area_t a, area_t b) { return (b.x < a.x + a.width @@ -90,13 +91,13 @@ typedef struct typedef struct { /** Foreground color */ - XColor fg; + xcolor_t fg; /** Background color */ - XColor bg; + xcolor_t bg; /** Shadow color */ - XColor shadow; + xcolor_t shadow; /** Border color */ - XColor border; + xcolor_t border; /** Shadow offset */ int shadow_offset; /** Font */ @@ -105,9 +106,10 @@ typedef struct typedef struct { - Display *display; - Drawable drawable; - Visual *visual; + xcb_connection_t *connection; + int default_screen; + xcb_drawable_t drawable; + xcb_visualtype_t *visual; int width; int height; int phys_screen; @@ -117,27 +119,27 @@ typedef struct PangoLayout *layout; } DrawCtx; -DrawCtx *draw_context_new(Display *, int, int, int, Drawable); +DrawCtx *draw_context_new(xcb_connection_t *, int, int, int, xcb_drawable_t); void draw_context_delete(DrawCtx *); -font_t *draw_font_new(Display *disp, char *fontname); +font_t *draw_font_new(xcb_connection_t *, int, char *); void draw_font_free(font_t *); void draw_text(DrawCtx *, area_t, Alignment, int, char *, style_t); -void draw_rectangle(DrawCtx *, area_t, Bool, XColor); -void draw_rectangle_gradient(DrawCtx *, area_t, Bool, area_t, XColor *, XColor *, XColor *); +void draw_rectangle(DrawCtx *, area_t, bool, xcolor_t); +void draw_rectangle_gradient(DrawCtx *, area_t, bool, area_t, xcolor_t *, xcolor_t *, xcolor_t *); void draw_graph_setup(DrawCtx *); -void draw_graph(DrawCtx *, area_t, int *, int *, int, Position, area_t, XColor *, XColor *, XColor *); -void draw_graph_line(DrawCtx *, area_t, int *, int, Position, area_t, XColor *, XColor *, XColor *); -void draw_circle(DrawCtx *, int, int, int, Bool, XColor); +void draw_graph(DrawCtx *, area_t, int *, int *, int, Position, area_t, xcolor_t *, xcolor_t *, xcolor_t *); +void draw_graph_line(DrawCtx *, area_t, int *, int, Position, area_t, xcolor_t *, xcolor_t *, xcolor_t *); +void draw_circle(DrawCtx *, int, int, int, bool, xcolor_t); void draw_image(DrawCtx *, int, int, int, const char *); void draw_image_from_argb_data(DrawCtx *, int, int, int, int, int, unsigned char *); area_t draw_get_image_size(const char *filename); -Drawable draw_rotate(DrawCtx *, int, double, int, int); -unsigned short draw_textwidth(Display *, font_t *, char *); +xcb_drawable_t draw_rotate(DrawCtx *, int, double, int, int); +unsigned short draw_textwidth(xcb_connection_t *, int, font_t *, char *); Alignment draw_align_get_from_str(const char *); -Bool draw_color_new(Display *, int, const char *, XColor *); -void draw_style_init(Display *, int, cfg_t *, style_t *, style_t *); +bool draw_color_new(xcb_connection_t *, int, const char *, xcolor_t *); +void draw_style_init(xcb_connection_t *, int, cfg_t *, style_t *, style_t *); void area_list_remove(area_t **, area_t *); diff --git a/common/swindow.c b/common/swindow.c index cc1ad1b..c46db17 100644 --- a/common/swindow.c +++ b/common/swindow.c @@ -19,12 +19,14 @@ * */ +#include +#include #include "common/swindow.h" #include "common/util.h" /** Create a simple window - * \param disp Display ref + * \param conn Connection ref * \param phys_screen physical screen id * \param x x coordinate * \param y y coordinate @@ -34,12 +36,13 @@ * \return pointer to a SimpleWindow */ SimpleWindow * -simplewindow_new(Display *disp, int phys_screen, int x, int y, +simplewindow_new(xcb_connection_t *conn, int phys_screen, int x, int y, unsigned int w, unsigned int h, unsigned int border_width) { - XSetWindowAttributes wa; SimpleWindow *sw; + xcb_screen_t *s = xcb_aux_get_screen(conn, phys_screen); + uint32_t create_win_val[3]; sw = p_new(SimpleWindow, 1); @@ -47,30 +50,31 @@ simplewindow_new(Display *disp, int phys_screen, int x, int y, sw->geometry.y = y; sw->geometry.width = w; sw->geometry.height = h; - sw->display = disp; + sw->connection = conn; sw->phys_screen = phys_screen; - wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask - | EnterWindowMask | LeaveWindowMask | StructureNotifyMask - | ButtonPressMask | ExposureMask; - wa.override_redirect = 1; - wa.background_pixmap = ParentRelative; - sw->window = XCreateWindow(disp, - RootWindow(disp, phys_screen), - x, y, w, h, - border_width, - DefaultDepth(disp, phys_screen), - CopyFromParent, - DefaultVisual(disp, phys_screen), - CWOverrideRedirect | CWBackPixmap | CWEventMask, - &wa); - - XSelectInput(disp, sw->window, wa.event_mask); - - sw->drawable = XCreatePixmap(disp, - RootWindow(disp, phys_screen), - w, h, - DefaultDepth(disp, phys_screen)); + create_win_val[0] = XCB_BACK_PIXMAP_PARENT_RELATIVE; + create_win_val[1] = 1; + create_win_val[2] = XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | + XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_ENTER_WINDOW | + XCB_EVENT_MASK_LEAVE_WINDOW | XCB_EVENT_MASK_STRUCTURE_NOTIFY | + XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_EXPOSURE; + + sw->window = xcb_generate_id(conn); + xcb_create_window(conn, s->root_depth, sw->window, + root_window(conn, phys_screen), + x, y, w, h, border_width, + XCB_COPY_FROM_PARENT, + s->root_visual, + XCB_CW_BACK_PIXMAP | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK, + create_win_val); + + x_select_input(conn, sw->window, create_win_val[2]); + + sw->drawable = xcb_generate_id(conn); + xcb_create_pixmap(conn, s->root_depth, sw->drawable, + root_window(conn, phys_screen), w, h); + return sw; } @@ -80,8 +84,8 @@ simplewindow_new(Display *disp, int phys_screen, int x, int y, void simplewindow_delete(SimpleWindow *sw) { - XDestroyWindow(sw->display, sw->window); - XFreePixmap(sw->display, sw->drawable); + xcb_destroy_window(sw->connection, sw->window); + xcb_free_pixmap(sw->connection, sw->drawable); p_delete(&sw); } @@ -89,56 +93,71 @@ simplewindow_delete(SimpleWindow *sw) * \param sw the SimpleWindow to move * \param x x coordinate * \param y y coordinate - * \return status */ -int +void simplewindow_move(SimpleWindow *sw, int x, int y) { + const uint32_t move_win_vals[] = { x, y }; + sw->geometry.x = x; sw->geometry.y = y; - return XMoveWindow(sw->display, sw->window, x, y); + xcb_configure_window(sw->connection, sw->window, + XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, + move_win_vals); } /** Resize a simple window * \param sw the SimpleWindow to resize * \param w new width * \param h new height - * \return status */ -int +void simplewindow_resize(SimpleWindow *sw, unsigned int w, unsigned int h) { + xcb_screen_t *s = xcb_aux_get_screen(sw->connection, sw->phys_screen); + const uint32_t resize_win_vals[] = { w, h }; + sw->geometry.width = w; sw->geometry.height = h; - XFreePixmap(sw->display, sw->drawable); - sw->drawable = XCreatePixmap(sw->display, - RootWindow(sw->display, sw->phys_screen), - w, h, - DefaultDepth(sw->display, sw->phys_screen)); - return XResizeWindow(sw->display, sw->window, w, h); + xcb_free_pixmap(sw->connection, sw->drawable); + sw->drawable = xcb_generate_id(sw->connection); + xcb_create_pixmap(sw->connection, s->root_depth, sw->drawable, + root_window(sw->connection, sw->phys_screen), w, h); + xcb_configure_window(sw->connection, sw->window, + XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, + resize_win_vals); } -int simplewindow_move_resize(SimpleWindow *sw, int x, int y, +void +simplewindow_move_resize(SimpleWindow *sw, int x, int y, unsigned int w, unsigned int h) { - return (simplewindow_move(sw, x, y) - && simplewindow_resize(sw, w, h)); + simplewindow_move(sw, x, y); + simplewindow_resize(sw, w, h); } /** Refresh the window content * \param sw the SimpleWindow to refresh * \param phys_screen physical screen id - * \return status */ -int +void simplewindow_refresh_drawable(SimpleWindow *sw, int phys_screen) { - return XCopyArea(sw->display, sw->drawable, - sw->window, - DefaultGC(sw->display, phys_screen), 0, 0, - sw->geometry.width, - sw->geometry.height, - 0, 0); + xcb_screen_t *s = xcb_aux_get_screen(sw->connection, phys_screen); + + /* The default GC is just a newly created associated to the root + * window */ + xcb_drawable_t gc_draw = s->root; + xcb_gcontext_t gc = xcb_generate_id(sw->connection); + + const uint32_t gc_mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND; + const uint32_t gc_values[2] = { s->black_pixel, s->white_pixel }; + + xcb_create_gc(sw->connection, gc, gc_draw, gc_mask, gc_values); + xcb_copy_area(sw->connection, sw->drawable, + sw->window, gc, 0, 0, 0, 0, + sw->geometry.width, + sw->geometry.height); } // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/common/swindow.h b/common/swindow.h index f0dcc5d..62804f0 100644 --- a/common/swindow.h +++ b/common/swindow.h @@ -27,19 +27,19 @@ /** A simple window */ typedef struct SimpleWindow { - Display *display; + xcb_connection_t *connection; int phys_screen; - Window window; - Drawable drawable; + xcb_window_t window; + xcb_drawable_t drawable; area_t geometry; } SimpleWindow; -SimpleWindow * simplewindow_new(Display *, int, int, int, unsigned int, unsigned int, unsigned int); +SimpleWindow * simplewindow_new(xcb_connection_t *, int, int, int, unsigned int, unsigned int, unsigned int); void simplewindow_delete(SimpleWindow *); -int simplewindow_move(SimpleWindow *, int, int); -int simplewindow_resize(SimpleWindow *, unsigned int, unsigned int); -int simplewindow_refresh_drawable(SimpleWindow *, int); -int simplewindow_move_resize(SimpleWindow *, int, int, unsigned int, unsigned int); +void simplewindow_move(SimpleWindow *, int, int); +void simplewindow_resize(SimpleWindow *, unsigned int, unsigned int); +void simplewindow_refresh_drawable(SimpleWindow *, int); +void simplewindow_move_resize(SimpleWindow *, int, int, unsigned int, unsigned int); #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/common/xscreen.c b/common/xscreen.c index 568ae55..2cf18e3 100644 --- a/common/xscreen.c +++ b/common/xscreen.c @@ -19,7 +19,9 @@ * */ -#include +#include +#include +#include #include "common/xscreen.h" @@ -47,7 +49,7 @@ screen_get_bycoord(ScreensInfo *si, int screen, int x, int y) } static inline area_t -screen_xsi_to_area(XineramaScreenInfo si) +screen_xsi_to_area(xcb_xinerama_screen_info_t si) { area_t a; @@ -67,33 +69,57 @@ screensinfo_delete(ScreensInfo **si) p_delete(si); } +static xcb_xinerama_screen_info_t * +xinerama_query_screens(xcb_connection_t *c, int *screen_number) +{ + xcb_xinerama_query_screens_reply_t *reply; + xcb_xinerama_screen_info_t *si; + + reply = xcb_xinerama_query_screens_reply(c, + xcb_xinerama_query_screens_unchecked(c), + NULL); + + if(!reply) + { + *screen_number = 0; + return NULL; + } + + *screen_number = xcb_xinerama_query_screens_screen_info_length(reply); + si = xcb_xinerama_query_screens_screen_info(reply); + p_delete(&reply); + + return si; +} + ScreensInfo * -screensinfo_new(Display *disp) +screensinfo_new(xcb_connection_t *conn) { ScreensInfo *si; - XineramaScreenInfo *xsi; + xcb_xinerama_screen_info_t *xsi; int xinerama_screen_number, screen, screen_to_test; - Bool drop; + xcb_screen_t *s; + bool drop; si = p_new(ScreensInfo, 1); - if((si->xinerama_is_active = XineramaIsActive(disp))) + if((si->xinerama_is_active = xinerama_is_active(conn))) { - xsi = XineramaQueryScreens(disp, &xinerama_screen_number); + xsi = xinerama_query_screens(conn, &xinerama_screen_number); si->geometry = p_new(area_t, xinerama_screen_number); si->nscreen = 0; /* now check if screens overlaps (same x,y): if so, we take only the biggest one */ for(screen = 0; screen < xinerama_screen_number; screen++) { - drop = False; + drop = false; for(screen_to_test = 0; screen_to_test < si->nscreen; screen_to_test++) if(xsi[screen].x_org == si->geometry[screen_to_test].x && xsi[screen].y_org == si->geometry[screen_to_test].y) { /* we already have a screen for this area, just check if * it's not bigger and drop it */ - drop = True; + drop = true; si->geometry[screen_to_test].width = MAX(xsi[screen].width, xsi[screen_to_test].width); si->geometry[screen_to_test].height = @@ -112,18 +138,19 @@ screensinfo_new(Display *disp) si->geometry = newgeometry; } - XFree(xsi); + p_delete(&xsi); } else { - si->nscreen = ScreenCount(disp); + si->nscreen = xcb_setup_roots_length(xcb_get_setup(conn)); si->geometry = p_new(area_t, si->nscreen); for(screen = 0; screen < si->nscreen; screen++) { + s = xcb_aux_get_screen(conn, screen); si->geometry[screen].x = 0; si->geometry[screen].y = 0; - si->geometry[screen].width = DisplayWidth(disp, screen); - si->geometry[screen].height = DisplayHeight(disp, screen); + si->geometry[screen].width = s->width_in_pixels; + si->geometry[screen].height = s->height_in_pixels; } } diff --git a/common/xscreen.h b/common/xscreen.h index 5968ad2..e60436b 100644 --- a/common/xscreen.h +++ b/common/xscreen.h @@ -27,13 +27,13 @@ typedef struct { int nscreen; - Bool xinerama_is_active; + bool xinerama_is_active; area_t *geometry; } ScreensInfo; int screen_get_bycoord(ScreensInfo *, int, int, int); void screensinfo_delete(ScreensInfo **); -ScreensInfo * screensinfo_new(Display *); +ScreensInfo * screensinfo_new(xcb_connection_t *); #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/common/xutil.c b/common/xutil.c index b1ee741..fcfae53 100644 --- a/common/xutil.c +++ b/common/xutil.c @@ -19,60 +19,197 @@ * */ -#include -#include +/* strndup() */ +#define _GNU_SOURCE + +#include +#include +#include +#include +#include #include "common/util.h" #include "common/xutil.h" -Bool -xgettextprop(Display *disp, Window w, Atom atom, char *text, ssize_t textlen) +bool +xgettextprop(xcb_connection_t *conn, xcb_window_t w, xcb_atom_t atom, + char *text, ssize_t textlen) { - char **list = NULL; - int n; - XTextProperty name; + xcb_get_property_reply_t *name = NULL; + char *prop_val = NULL; if(!text || !textlen) - return False; + return false; text[0] = '\0'; - XGetTextProperty(disp, w, &name, atom); - - if(!name.nitems) - return False; + name = xcb_get_property_reply(conn, + xcb_get_property_unchecked(conn, false, + w, atom, + XCB_GET_PROPERTY_TYPE_ANY, + 0L, 1000000L), + NULL); + + if(!name->value_len) + return false; - if(name.encoding == XA_STRING) - a_strncpy(text, textlen, (char *) name.value, textlen - 1); + prop_val = (char *) xcb_get_property_value(name); + if(name->type == STRING) + a_strncpy(text, textlen, prop_val, textlen - 1); - else if(XmbTextPropertyToTextList(disp, &name, &list, &n) >= Success && n > 0 && *list) - { - a_strncpy(text, textlen, *list, textlen - 1); - XFreeStringList(list); - } + /* TODO: XCB doesn't provide a XmbTextPropertyToTextList(), check + * whether this code is correct (locales) */ + else if(name->format == 8) + a_strncpy(text, textlen, prop_val, textlen - 1); text[textlen - 1] = '\0'; - XFree(name.value); + p_delete(&name); - return True; + return true; } unsigned int -get_numlockmask(Display *disp) +get_numlockmask(xcb_connection_t *conn) { - XModifierKeymap *modmap; + xcb_get_modifier_mapping_reply_t *modmap_r; + xcb_keycode_t *modmap; + xcb_key_symbols_t *keysyms = xcb_key_symbols_alloc(conn); unsigned int mask = 0; int i, j; - modmap = XGetModifierMapping(disp); + modmap_r = xcb_get_modifier_mapping_reply(conn, + xcb_get_modifier_mapping_unchecked(conn), + NULL); + + modmap = xcb_get_modifier_mapping_keycodes(modmap_r); + for(i = 0; i < 8; i++) - for(j = 0; j < modmap->max_keypermod; j++) - if(modmap->modifiermap[i * modmap->max_keypermod + j] - == XKeysymToKeycode(disp, XK_Num_Lock)) + for(j = 0; j < modmap_r->keycodes_per_modifier; j++) + if(modmap[i * modmap_r->keycodes_per_modifier + j] + == xcb_key_symbols_get_keycode(keysyms, XK_Num_Lock)) mask = (1 << i); - XFreeModifiermap(modmap); + p_delete(&modmap_r); + xcb_key_symbols_free(keysyms); return mask; } +/** 'XSelectInput' from Xlib is only a function around + * 'ChangeWindowAttributes' which set the value mask to 'CWEventMask' + * \param c X connection + */ +void +x_select_input(xcb_connection_t *c, xcb_window_t w, + uint32_t event_mask) +{ + const uint32_t config_win_val[] = { event_mask }; + xcb_change_window_attributes_checked(c, w, XCB_CW_EVENT_MASK, config_win_val); +} + +/** Equivalent to 'XGetTransientForHint' which is actually a + * 'XGetWindowProperty' which gets the WM_TRANSIENT_FOR property of + * the specified window + * + * \param c X connection + * \param win get the property from this window + * \param prop_win returns the WM_TRANSIENT_FOR property of win + * \return return true if successfull + */ +bool +x_get_transient_for_hint(xcb_connection_t *c, xcb_window_t win, + xcb_window_t *prop_win) +{ + xcb_get_property_reply_t *r; + + /* Use checked because the error handler should not take care of + * this error as we only return a boolean */ + r = xcb_get_property_reply(c, + xcb_get_property(c, false, win, + WM_TRANSIENT_FOR, + WINDOW, 0, 1), + NULL); + + if(!r) + return false; + + *prop_win = *((xcb_window_t *) xcb_get_property_value(r)); + p_delete(&r); + + return true; +} + +bool +xinerama_is_active(xcb_connection_t *c) +{ + bool ret; + xcb_xinerama_is_active_reply_t *r = NULL; + + r = xcb_xinerama_is_active_reply(c, xcb_xinerama_is_active(c), NULL); + if(!r) + return false; + + ret = r->state; + p_delete(&r); + + return ret; +} + +xcb_window_t +root_window(xcb_connection_t *c, int screen_number) +{ + return xcb_aux_get_screen(c, screen_number)->root; +} + +xcb_atom_t +x_intern_atom(xcb_connection_t *c, const char *property) +{ + xcb_atom_t atom; + xcb_intern_atom_reply_t *r_atom; + + r_atom = xcb_intern_atom_reply(c, + xcb_intern_atom_unchecked(c, false, strlen(property), property), + NULL); + + if(!r_atom) + return 0; + + atom = r_atom->atom; + p_delete(&r_atom); + + return atom; +} + +class_hint_t * +x_get_class_hint(xcb_connection_t *conn, xcb_window_t win) +{ + xcb_get_property_reply_t *r = NULL; + char *data = NULL; + + int len_name, len_class; + + class_hint_t *ch = p_new(class_hint_t, 1); + + /* TODO: 2048? (BUFINC is declared as private in xcb.c) */ + r = xcb_get_property_reply(conn, + xcb_get_property_unchecked(conn, + false, win, WM_CLASS, + STRING, 0L, 2048), + NULL); + + if(!r || r->type != STRING || r->format == 8) + return NULL; + + data = xcb_get_property_value(r); + + len_name = strlen((char *) data); + len_class = strlen((char *) (data + len_name + 1)); + + ch->res_name = strndup(data, len_name); + ch->res_class = strndup(data + len_name + 1, len_class); + + p_delete(&r); + + return ch; +} + // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/common/xutil.h b/common/xutil.h index e7d6b85..dc8e060 100644 --- a/common/xutil.h +++ b/common/xutil.h @@ -22,10 +22,87 @@ #ifndef AWESOME_COMMON_XUTIL_H #define AWESOME_COMMON_XUTIL_H -#include +#include -Bool xgettextprop(Display *, Window, Atom, char *, ssize_t); -unsigned int get_numlockmask(Display *); +#include + +/* XCB doesn't provide keysyms definition */ +#include + +bool xgettextprop(xcb_connection_t *, xcb_window_t, xcb_atom_t, char *, ssize_t); +unsigned int get_numlockmask(xcb_connection_t *); + +/* See http://tronche.com/gui/x/xlib/appendix/b/ for values */ +#define CURSOR_FLEUR 52 +#define CURSOR_LEFT_PTR 68 +#define CURSOR_SIZING 120 + +#define ANY_KEY 0L /* special Key Code, passed to GrabKey */ +#define ANY_MODIFIER (1<<15) /* used in GrabButton, GrabKey */ + +/***************************************************************** + * ERROR CODES + *****************************************************************/ + +#define Success 0 /* everything's okay */ +#define BadRequest 1 /* bad request code */ +#define BadValue 2 /* int parameter out of range */ +#define BadWindow 3 /* parameter not a Window */ +#define BadPixmap 4 /* parameter not a Pixmap */ +#define BadAtom 5 /* parameter not an Atom */ +#define BadCursor 6 /* parameter not a Cursor */ +#define BadFont 7 /* parameter not a Font */ +#define BadMatch 8 /* parameter mismatch */ +#define BadDrawable 9 /* parameter not a Pixmap or Window */ +#define BadAccess 10 /* depending on context: + - key/button already grabbed + - attempt to free an illegal + cmap entry + - attempt to store into a read-only + color map entry. + - attempt to modify the access control + list from other than the local host. + */ +#define BadAlloc 11 /* insufficient resources */ +#define BadColor 12 /* no such colormap */ +#define BadGC 13 /* parameter not a GC */ +#define BadIDChoice 14 /* choice not in range or already used */ +#define BadName 15 /* font or color name doesn't exist */ +#define BadLength 16 /* Request length incorrect */ +#define BadImplementation 17 /* server is defective */ + +#define FirstExtensionError 128 +#define LastExtensionError 255 +/* End of macros not defined in XCB */ + +/* Common function defined in Xlib but not in XCB */ +void x_select_input(xcb_connection_t *, xcb_window_t, uint32_t); +bool x_get_transient_for_hint(xcb_connection_t *, xcb_window_t, xcb_window_t *); +bool xinerama_is_active(xcb_connection_t *); +xcb_window_t root_window(xcb_connection_t *, int); + +typedef struct _class_hint_t +{ + char *res_name; + char *res_class; +} class_hint_t; + +typedef struct +{ + uint32_t pixel; + uint16_t red; + uint16_t green; + uint16_t blue; +} xcolor_t; + +class_hint_t *x_get_class_hint(xcb_connection_t *, xcb_window_t); + +/* Equivalent call to XInternAtom + * + * WARNING: should not be used in loop, in this case, it should send + * the queries first and then treat the answer as late as possible) + */ +xcb_atom_t x_intern_atom(xcb_connection_t *, const char *); #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/config.c b/config.c index 5b20a18..3e96d6e 100644 --- a/config.c +++ b/config.c @@ -19,8 +19,11 @@ * */ +/* XStringToKeysym() */ +#include + +#include #include -#include #include "config.h" #include "statusbar.h" @@ -35,11 +38,11 @@ #include "common/xutil.h" /* Permit to use mouse with many more buttons */ -#ifndef Button6 -#define Button6 6 +#ifndef XCB_BUTTON_INDEX_6 +#define XCB_BUTTON_INDEX_6 6 #endif -#ifndef Button7 -#define Button7 7 +#ifndef XCB_BUTTON_INDEX_7 +#define XCB_BUTTON_INDEX_7 7 #endif extern AwesomeConf globalconf; @@ -49,7 +52,7 @@ extern cfg_opt_t awesome_opts[]; typedef struct { const char *name; - KeyCode keycode; + xcb_keycode_t keycode; } KeyMod; /** Link a name to a mouse button symbol */ @@ -74,15 +77,15 @@ key_mask_lookup(const char *keyname) /** List of keyname and corresponding X11 mask codes */ static const KeyMod KeyModList[] = { - {"Shift", ShiftMask}, - {"Lock", LockMask}, - {"Control", ControlMask}, - {"Mod1", Mod1Mask}, - {"Mod2", Mod2Mask}, - {"Mod3", Mod3Mask}, - {"Mod4", Mod4Mask}, - {"Mod5", Mod5Mask}, - {NULL, NoSymbol} + {"Shift", XCB_MOD_MASK_SHIFT}, + {"Lock", XCB_MOD_MASK_LOCK}, + {"Control", XCB_MOD_MASK_CONTROL}, + {"Mod1", XCB_MOD_MASK_1}, + {"Mod2", XCB_MOD_MASK_2}, + {"Mod3", XCB_MOD_MASK_3}, + {"Mod4", XCB_MOD_MASK_4}, + {"Mod5", XCB_MOD_MASK_5}, + {NULL, XCB_NO_SYMBOL} }; int i; @@ -104,13 +107,13 @@ mouse_button_lookup(const char *button) /** List of button name and corresponding X11 mask codes */ static const MouseButton MouseButtonList[] = { - {"1", Button1}, - {"2", Button2}, - {"3", Button3}, - {"4", Button4}, - {"5", Button5}, - {"6", Button6}, - {"7", Button7}, + {"1", XCB_BUTTON_INDEX_1}, + {"2", XCB_BUTTON_INDEX_2}, + {"3", XCB_BUTTON_INDEX_3}, + {"4", XCB_BUTTON_INDEX_4}, + {"5", XCB_BUTTON_INDEX_5}, + {"6", XCB_BUTTON_INDEX_6}, + {"7", XCB_BUTTON_INDEX_7}, {NULL, 0} }; int i; @@ -124,7 +127,7 @@ mouse_button_lookup(const char *button) } static Button * -parse_mouse_bindings(cfg_t * cfg, const char *secname, Bool handle_arg) +parse_mouse_bindings(cfg_t * cfg, const char *secname, bool handle_arg) { int i, j; cfg_t *cfgsectmp; @@ -166,17 +169,30 @@ set_key_info(Key *key, cfg_t *cfg) warn("unknown command %s\n", cfg_getstr(cfg, "command")); } -static KeyCode +static xcb_keycode_t key_to_keycode(char *str) { - KeyCode kc; + xcb_keycode_t kc; int ikc; + xcb_key_symbols_t *keysyms; if(a_strncmp(str, "#", 1)) - return XKeysymToKeycode(globalconf.display, XStringToKeysym(str)); + { + keysyms = xcb_key_symbols_alloc(globalconf.connection); + + /* XStringToKeySym() has not been ported yet to XCB because + * there is no existing equivalent. For further informations, + * see: + * http://lists.freedesktop.org/archives/xcb/2008-March/003344.html */ + kc = xcb_key_symbols_get_keycode(keysyms, + (xcb_keysym_t) XStringToKeysym(str)); + + xcb_key_symbols_free(keysyms); + return kc; + } ikc = atoi(str + 1); - memcpy(&kc, &ikc, sizeof(KeyCode)); + memcpy(&kc, &ikc, sizeof(xcb_keycode_t)); return kc; } @@ -266,7 +282,7 @@ create_widgets(cfg_t* cfg_statusbar, Statusbar *statusbar) { widget = widget_new(statusbar, wptr); widget_list_append(&statusbar->widgets, widget); - widget->buttons = parse_mouse_bindings(wptr, "mouse", a_strcmp(cfg_name(wptr), "taglist") ? True : False); + widget->buttons = parse_mouse_bindings(wptr, "mouse", a_strcmp(cfg_name(wptr), "taglist") ? true : false); } else warn("ignoring unknown widget: %s.\n", cfg_name(widgets + i)); @@ -357,11 +373,11 @@ config_parse_screen(cfg_t *cfg, int screen) if(!(cfg_styles_urgent = cfg_getsec(cfg_styles, "urgent"))) eprint("no urgent colors section found\n"); - draw_style_init(globalconf.display, phys_screen, + draw_style_init(globalconf.connection, phys_screen, cfg_styles_normal, &virtscreen->styles.normal, NULL); - draw_style_init(globalconf.display, phys_screen, + draw_style_init(globalconf.connection, phys_screen, cfg_styles_focus, &virtscreen->styles.focus, &virtscreen->styles.normal); - draw_style_init(globalconf.display, phys_screen, + draw_style_init(globalconf.connection, phys_screen, cfg_styles_urgent, &virtscreen->styles.urgent, &virtscreen->styles.normal); if(!virtscreen->styles.normal.font) @@ -444,8 +460,8 @@ config_parse_screen(cfg_t *cfg, int screen) ewmh_update_net_desktop_names(phys_screen); /* select first tag by default */ - virtscreen->tags[0].selected = True; - virtscreen->tags[0].was_selected = True; + virtscreen->tags[0].selected = true; + virtscreen->tags[0].was_selected = true; /* padding */ virtscreen->padding.top = cfg_getint(cfg_padding, "top"); @@ -529,16 +545,16 @@ config_parse(const char *confpatharg) } /* Mouse: root window click bindings */ - globalconf.buttons.root = parse_mouse_bindings(cfg_mouse, "root", True); + globalconf.buttons.root = parse_mouse_bindings(cfg_mouse, "root", true); /* Mouse: client windows click bindings */ - globalconf.buttons.client = parse_mouse_bindings(cfg_mouse, "client", True); + globalconf.buttons.client = parse_mouse_bindings(cfg_mouse, "client", true); /* Mouse: titlebar windows click bindings */ - globalconf.buttons.titlebar = parse_mouse_bindings(cfg_mouse, "titlebar", True); + globalconf.buttons.titlebar = parse_mouse_bindings(cfg_mouse, "titlebar", true); /* Keys */ - globalconf.numlockmask = get_numlockmask(globalconf.display); + globalconf.numlockmask = get_numlockmask(globalconf.connection); globalconf.keys = section_keys(cfg_keys); diff --git a/configure.ac b/configure.ac index 94ea525..7b388b6 100644 --- a/configure.ac +++ b/configure.ac @@ -110,13 +110,28 @@ PKG_CHECK_MODULES([PANGOCAIRO], [pangocairo],, [AC_MSG_ERROR([awesome requires pangocairo.])]) PKG_CHECK_MODULES([CONFUSE], [libconfuse >= 2.6],, [AC_MSG_ERROR([awesome requires libconfuse >= 2.6.])]) -PKG_CHECK_MODULES([XINERAMA], [xinerama],, - [AC_MSG_ERROR([awesome requires Xinerama.])]) -PKG_CHECK_MODULES([XRANDR], [xrandr],, - [AC_MSG_ERROR([awesome requires Xrandr.])]) +PKG_CHECK_MODULES([XCB], [xcb],, + [AC_MSG_ERROR([awesome requires xcb.])]) +PKG_CHECK_MODULES([XCB_EVENT], [xcb-event],, + [AC_MSG_ERROR([awesome requires xcb-event.])]) +PKG_CHECK_MODULES([XCB_RANDR], [xcb-randr],, + [AC_MSG_ERROR([awesome requires xcb-randr.])]) +PKG_CHECK_MODULES([XCB_XINERAMA], [xcb-xinerama],, + [AC_MSG_ERROR([awesome requires xcb-xinerama.])]) +PKG_CHECK_MODULES([XCB_SHAPE], [xcb-shape],, + [AC_MSG_ERROR([awesome requires xcb-shape.])]) +PKG_CHECK_MODULES([XCB_AUX], [xcb-aux],, + [AC_MSG_ERROR([awesome requires xcb-aux.])]) +PKG_CHECK_MODULES([XCB_ATOM], [xcb-atom],, + [AC_MSG_ERROR([awesome requires xcb-atom.])]) +PKG_CHECK_MODULES([XCB_KEYSYMS], [xcb-keysyms],, + [AC_MSG_ERROR([awesome requires xcb-keysyms.])]) +PKG_CHECK_MODULES([XCB_RENDER], [xcb-render],, + [AC_MSG_ERROR([awesome requires xcb-render.])]) +PKG_CHECK_MODULES([XCB_ICCCM], [xcb-icccm],, + [AC_MSG_ERROR([awesome requires xcb-icccm.])]) # Checks for header files. -AC_PATH_X AC_HEADER_STDC AC_HEADER_SYS_WAIT AC_CHECK_HEADERS([fcntl.h limits.h locale.h stdlib.h string.h sys/socket.h unistd.h]) @@ -134,6 +149,8 @@ AC_FUNC_SELECT_ARGTYPES AC_TYPE_SIGNAL AC_FUNC_VPRINTF AC_CHECK_FUNCS([memchr regcomp select setenv socket strchr strrchr strstr]) +AC_EGREP_HEADER(xcb_poll_for_event_loop, xcb/xcb_event.h, AC_DEFINE(HAVE_XCB_POLL_FOR_EVENT_LOOP)) +AC_EGREP_HEADER(handle_event, xcb/xcb_event.h, AC_DEFINE(HAVE_XCB_HANDLE_EVENT)) AC_CONFIG_FILES([Makefile]) AC_CONFIG_FILES([awesome.doxygen]) diff --git a/event.c b/event.c index 48f3c8b..690c4cf 100644 --- a/event.c +++ b/event.c @@ -19,11 +19,12 @@ * */ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include "screen.h" #include "event.h" @@ -39,6 +40,7 @@ #include "layouts/tile.h" #include "layouts/floating.h" #include "common/xscreen.h" +#include "common/xutil.h" extern AwesomeConf globalconf; @@ -51,7 +53,7 @@ extern AwesomeConf globalconf; */ static void event_handle_mouse_button_press(int screen, unsigned int button, unsigned int state, - Button *buttons, char *arg) + Button *buttons, char *arg) { Button *b; @@ -67,105 +69,109 @@ event_handle_mouse_button_press(int screen, unsigned int button, unsigned int st } /** Handle XButtonPressed events - * \param e XEvent + * \param connection connection to the X server + * \param ev ButtonPress event */ -void -event_handle_buttonpress(XEvent *e) +int +event_handle_buttonpress(void *data __attribute__ ((unused)), + xcb_connection_t *connection, xcb_button_press_event_t *ev) { - int i, screen, x = 0, y = 0; - unsigned int udummy; + int screen; Client *c; - Window wdummy; Widget *widget; Statusbar *statusbar; - XButtonPressedEvent *ev = &e->xbutton; + xcb_query_pointer_reply_t *qr; for(screen = 0; screen < globalconf.screens_info->nscreen; screen++) for(statusbar = globalconf.screens[screen].statusbar; statusbar; statusbar = statusbar->next) - if(statusbar->sw->window == ev->window || statusbar->sw->window == ev->subwindow) + if(statusbar->sw->window == ev->event || statusbar->sw->window == ev->child) { switch(statusbar->position) { case Top: case Bottom: for(widget = statusbar->widgets; widget; widget = widget->next) - if(ev->x >= widget->area.x && ev->x < widget->area.x + widget->area.width - && ev->y >= widget->area.y && ev->y < widget->area.y + widget->area.height) + if(ev->event_x >= widget->area.x && ev->event_x < widget->area.x + widget->area.width + && ev->event_y >= widget->area.y && ev->event_y < widget->area.y + widget->area.height) { widget->button_press(widget, ev); - return; + return 0; } break; case Right: for(widget = statusbar->widgets; widget; widget = widget->next) - if(ev->y >= widget->area.x && ev->y < widget->area.x + widget->area.width - && statusbar->sw->geometry.width - ev->x >= widget->area.y - && statusbar->sw->geometry.width - ev->x + if(ev->event_y >= widget->area.x && ev->event_y < widget->area.x + widget->area.width + && statusbar->sw->geometry.width - ev->event_x >= widget->area.y + && statusbar->sw->geometry.width - ev->event_x < widget->area.y + widget->area.height) { widget->button_press(widget, ev); - return; + return 0; } break; case Left: for(widget = statusbar->widgets; widget; widget = widget->next) - if(statusbar->sw->geometry.height - ev->y >= widget->area.x - && statusbar->sw->geometry.height - ev->y + if(statusbar->sw->geometry.height - ev->event_y >= widget->area.x + && statusbar->sw->geometry.height - ev->event_y < widget->area.x + widget->area.width - && ev->x >= widget->area.y && ev->x < widget->area.y + widget->area.height) + && ev->event_x >= widget->area.y && ev->event_x < widget->area.y + widget->area.height) { widget->button_press(widget, ev); - return; + return 0; } break; default: break; } /* return if no widget match */ - return; + return 0; } - if((c = client_get_bywin(globalconf.clients, ev->window))) + if((c = client_get_bywin(globalconf.clients, ev->event))) { - client_focus(c, c->screen, True); - if(CLEANMASK(ev->state) == NoSymbol - && ev->button == Button1) + client_focus(c, c->screen, true); + if(CLEANMASK(ev->state) == XCB_NO_SYMBOL + && ev->detail == XCB_BUTTON_INDEX_1) { - XAllowEvents(globalconf.display, ReplayPointer, CurrentTime); + xcb_allow_events(globalconf.connection, XCB_ALLOW_REPLAY_POINTER, XCB_CURRENT_TIME); window_grabbuttons(get_phys_screen(c->screen), c->win); + } else - event_handle_mouse_button_press(c->screen, ev->button, ev->state, globalconf.buttons.client, NULL); + event_handle_mouse_button_press(c->screen, ev->detail, ev->state, globalconf.buttons.client, NULL); } else { for(c = globalconf.clients; c; c = c->next) - if(c->titlebar.sw && c->titlebar.sw->window == ev->window) - event_handle_mouse_button_press(c->screen, ev->button, ev->state, globalconf.buttons.titlebar, NULL); - for(screen = 0; screen < ScreenCount(e->xany.display); screen++) - if(RootWindow(e->xany.display, screen) == ev->window - && XQueryPointer(e->xany.display, - ev->window, &wdummy, - &wdummy, &x, &y, &i, - &i, &udummy)) + if(c->titlebar.sw && c->titlebar.sw->window == ev->event) + event_handle_mouse_button_press(c->screen, ev->detail, ev->state, globalconf.buttons.titlebar, NULL); + for(screen = 0; screen < xcb_setup_roots_length(xcb_get_setup (connection)); screen++) + if(root_window(connection, screen) == ev->event + && (qr = xcb_query_pointer_reply(connection, + xcb_query_pointer(connection, ev->event), + NULL)) != NULL) { - screen = screen_get_bycoord(globalconf.screens_info, screen, x, y); - event_handle_mouse_button_press(screen, ev->button, ev->state, - globalconf.buttons.root, NULL); - return; + screen = screen_get_bycoord(globalconf.screens_info, screen, qr->root_x, qr->root_y); + event_handle_mouse_button_press(screen, ev->detail, ev->state, + globalconf.buttons.root, NULL); + + p_delete(&qr); + return 0; } } + + return 0; } /** Handle XConfigureRequest events - * \param e XEvent + * \param connection connection to the X server + * \param ev ConfigureRequest event */ -void -event_handle_configurerequest(XEvent * e) +int +event_handle_configurerequest(void *data __attribute__ ((unused)), + xcb_connection_t *connection, xcb_configure_request_event_t *ev) { Client *c; - XConfigureRequestEvent *ev = &e->xconfigurerequest; - XWindowChanges wc; int old_screen; area_t geometry; @@ -173,13 +179,13 @@ event_handle_configurerequest(XEvent * e) { geometry = c->geometry; - if(ev->value_mask & CWX) + if(ev->value_mask & XCB_CONFIG_WINDOW_X) geometry.x = ev->x; - if(ev->value_mask & CWY) + if(ev->value_mask & XCB_CONFIG_WINDOW_Y) geometry.y = ev->y; - if(ev->value_mask & CWWidth) + if(ev->value_mask & XCB_CONFIG_WINDOW_WIDTH) geometry.width = ev->width; - if(ev->value_mask & CWHeight) + if(ev->value_mask & XCB_CONFIG_WINDOW_HEIGHT) geometry.height = ev->height; if(geometry.x != c->geometry.x || geometry.y != c->geometry.y @@ -187,12 +193,12 @@ event_handle_configurerequest(XEvent * e) { old_screen = c->screen; - client_resize(c, geometry, False); + client_resize(c, geometry, false); tag_client_with_rule(c, rule_matching_client(c)); if(!c->isfloating) - globalconf.screens[c->screen].need_arrange = True; + globalconf.screens[c->screen].need_arrange = true; } else { @@ -202,71 +208,81 @@ event_handle_configurerequest(XEvent * e) } else { - wc.x = ev->x; - wc.y = ev->y; - wc.width = ev->width; - wc.height = ev->height; - wc.border_width = ev->border_width; - wc.sibling = ev->above; - wc.stack_mode = ev->detail; - XConfigureWindow(e->xany.display, ev->window, ev->value_mask, &wc); + const uint32_t configure_values[] = { + ev->x, ev->y, ev->width, ev->height, ev->border_width, + ev->sibling, ev->stack_mode }; + + xcb_configure_window(connection, ev->window, ev->value_mask, + configure_values); } + + return 0; } /** Handle XConfigure events - * \param e XEvent + * \param connection connection to the X server + * \param ev ConfigureNotify event */ -void -event_handle_configurenotify(XEvent * e) +int +event_handle_configurenotify(void *data __attribute__ ((unused)), + xcb_connection_t *connection, xcb_configure_notify_event_t *ev) { - XConfigureEvent *ev = &e->xconfigure; - int screen; - - for(screen = 0; screen < ScreenCount(e->xany.display); screen++) - if(ev->window == RootWindow(e->xany.display, screen) - && (ev->width != DisplayWidth(e->xany.display, screen) - || ev->height != DisplayHeight(e->xany.display, screen))) + int screen_nbr; + const xcb_screen_t *screen; + + for(screen_nbr = 0; screen_nbr < xcb_setup_roots_length (xcb_get_setup (connection)); screen_nbr++) + if(ev->window == root_window(connection, screen_nbr) + && (screen = xcb_aux_get_screen(connection, screen_nbr)) != NULL + && (ev->width != screen->width_in_pixels + || ev->height != screen->height_in_pixels)) /* it's not that we panic, but restart */ uicb_exec(0, globalconf.argv); + + return 0; } /** Handle XDestroyWindow events - * \param e XEvent + * \param connection connection to the X server + * \param ev DestroyNotify event */ -void -event_handle_destroynotify(XEvent *e) +int +event_handle_destroynotify(void *data __attribute__ ((unused)), + xcb_connection_t *connection __attribute__ ((unused)), + xcb_destroy_notify_event_t *ev) { Client *c; - XDestroyWindowEvent *ev = &e->xdestroywindow; if((c = client_get_bywin(globalconf.clients, ev->window))) client_unmanage(c); + + return 0; } -/** Handle XCrossing events on enter - * \param e XEvent +/** Handle XCrossing events + * \param connection connection to the X server + * \param ev Crossing event */ -void -event_handle_enternotify(XEvent *e) +int +event_handle_enternotify(void *data __attribute__ ((unused)), + xcb_connection_t *connection, xcb_enter_notify_event_t *ev) { Client *c; - XCrossingEvent *ev = &e->xcrossing; int screen; - if(ev->mode != NotifyNormal - || (ev->x_root == globalconf.pointer_x - && ev->y_root == globalconf.pointer_y)) - return; + if(ev->mode != XCB_NOTIFY_MODE_NORMAL + || (ev->root_x == globalconf.pointer_x + && ev->root_y == globalconf.pointer_y)) + return 0; /* the idea behing saving pointer_x and pointer_y is Bob Marley powered */ - globalconf.pointer_x = ev->x_root; - globalconf.pointer_y = ev->y_root; + globalconf.pointer_x = ev->root_x; + globalconf.pointer_y = ev->root_y; for(c = globalconf.clients; c; c = c->next) - if(c->titlebar.sw && c->titlebar.sw->window == ev->window) + if(c->titlebar.sw && c->titlebar.sw->window == ev->event) break; - if(c || (c = client_get_bywin(globalconf.clients, ev->window))) + if(c || (c = client_get_bywin(globalconf.clients, ev->event))) { window_grabbuttons(get_phys_screen(c->screen), c->win); if(globalconf.screens[c->screen].sloppy_focus) @@ -275,33 +291,38 @@ event_handle_enternotify(XEvent *e) && globalconf.screens[c->screen].sloppy_focus_raise)); } else - for(screen = 0; screen < ScreenCount(e->xany.display); screen++) - if(ev->window == RootWindow(e->xany.display, screen)) + for(screen = 0; screen < xcb_setup_roots_length(xcb_get_setup(connection)); screen++) + if(ev->event == root_window(connection, screen)) { window_root_grabbuttons(screen); - return; + return 0; } + + return 0; } /** Handle XMotion events - * \param e XEvent + * \param ev MotionNotify event */ -void -event_handle_motionnotify(XEvent *e) +int +event_handle_motionnotify(void *data __attribute__ ((unused)), + xcb_connection_t *connection __attribute__ ((unused)), + xcb_motion_notify_event_t *ev) { - XMotionEvent *ev = &e->xmotion; + globalconf.pointer_x = ev->root_x; + globalconf.pointer_y = ev->root_y; - globalconf.pointer_x = ev->x_root; - globalconf.pointer_y = ev->y_root; + return 0; } /** Handle XExpose events - * \param e XEvent + * \param ev Expose event */ -void -event_handle_expose(XEvent *e) +int +event_handle_expose(void *data __attribute__ ((unused)), + xcb_connection_t *connection __attribute__ ((unused)), + xcb_expose_event_t *ev) { - XExposeEvent *ev = &e->xexpose; int screen; Statusbar *statusbar; Client *c; @@ -313,185 +334,258 @@ event_handle_expose(XEvent *e) if(statusbar->sw->window == ev->window) { statusbar_display(statusbar); - return; + return 0; } for(c = globalconf.clients; c; c = c->next) if(c->titlebar.sw && c->titlebar.sw->window == ev->window) { simplewindow_refresh_drawable(c->titlebar.sw, get_phys_screen(c->screen)); - return; + return 0; } } + + return 0; } /** Handle XKey events - * \param e XEvent + * \param connection connection to the X server + * \param ev KeyPress event */ -void -event_handle_keypress(XEvent *e) +int +event_handle_keypress(void *data __attribute__ ((unused)), + xcb_connection_t *connection, xcb_key_press_event_t *ev) { - int screen, x, y, d; - unsigned int m; - XKeyEvent *ev = &e->xkey; - Window dummy; + int screen; + xcb_query_pointer_reply_t *qpr = NULL; Key *k; /* find the right screen for this event */ - for(screen = 0; screen < ScreenCount(e->xany.display); screen++) - if(XQueryPointer(e->xany.display, RootWindow(e->xany.display, screen), &dummy, &dummy, &x, &y, &d, &d, &m)) + for(screen = 0; screen < xcb_setup_roots_length (xcb_get_setup (connection)); screen++) + if((qpr = xcb_query_pointer_reply(connection, + xcb_query_pointer(connection, + root_window(connection, screen)), + NULL)) != NULL) { /* if screen is 0, we are on first Zaphod screen or on the * only screen in Xinerama, so we can ask for a better screen * number with screen_get_bycoord: we'll get 0 in Zaphod mode * so it's the same, or maybe the real Xinerama screen */ - screen = screen_get_bycoord(globalconf.screens_info, screen, x, y); + screen = screen_get_bycoord(globalconf.screens_info, screen, qpr->root_x, qpr->root_y); break; } for(k = globalconf.keys; k; k = k->next) - if(ev->keycode == k->keycode && - k->func && CLEANMASK(k->mod) == CLEANMASK(ev->state)) + if(ev->detail == k->keycode && + k->func && CLEANMASK(k->mod) == CLEANMASK(ev->state)) k->func(screen, k->arg); + + return 0; } /** Handle XCrossing events on leave - * \param e XEvent + * \param ev Crossing event */ -void -event_handle_leavenotify(XEvent * e) +int +event_handle_leavenotify(void *data __attribute__ ((unused)), + xcb_connection_t *connection, xcb_leave_notify_event_t *ev) { - XCrossingEvent *ev = &e->xcrossing; int screen; - for(screen = 0; screen < ScreenCount(e->xany.display); screen++) - if((ev->window == RootWindow(e->xany.display, screen)) && !ev->same_screen) - client_focus(NULL, screen, True); + for(screen = 0; screen < xcb_setup_roots_length (xcb_get_setup (connection)); screen++) + if((ev->event == root_window(connection, screen)) && !ev->same_screen_focus) + client_focus(NULL, screen, true); + + return 0; } /** Handle XMapping events - * \param e XEvent + * \param connection connection to the X server + * \param ev MappingNotify event */ -void -event_handle_mappingnotify(XEvent *e) +int +event_handle_mappingnotify(void *data __attribute__ ((unused)), + xcb_connection_t *connection, xcb_mapping_notify_event_t *ev) { - XMappingEvent *ev = &e->xmapping; int screen; + xcb_key_symbols_t *keysyms = xcb_key_symbols_alloc(connection); - XRefreshKeyboardMapping(ev); - if(ev->request == MappingKeyboard) - for(screen = 0; screen < ScreenCount(e->xany.display); screen++) + xcb_refresh_keyboard_mapping(keysyms, ev); + xcb_key_symbols_free(keysyms); + + if(ev->request == XCB_MAPPING_KEYBOARD) + for(screen = 0; screen < xcb_setup_roots_length(xcb_get_setup(connection)); screen++) window_root_grabkeys(screen); + + return 0; } /** Handle XMapRequest events - * \param e XEvent + * \param connection connection to the X server + * \param ev MapRequest event */ -void -event_handle_maprequest(XEvent *e) +int +event_handle_maprequest(void *data __attribute__ ((unused)), + xcb_connection_t *connection, xcb_map_request_event_t *ev) { - static XWindowAttributes wa; - XMapRequestEvent *ev = &e->xmaprequest; - int screen = 0, x, y, d; - unsigned int m; - Window dummy; - - if(!XGetWindowAttributes(e->xany.display, ev->window, &wa)) - return; - if(wa.override_redirect) - return; + static xcb_get_window_attributes_reply_t *wa; + int screen_nbr = 0; + xcb_query_pointer_reply_t *qpr = NULL; + xcb_get_geometry_reply_t *wgeom; + xcb_screen_iterator_t iter; + + if((wa = xcb_get_window_attributes_reply(connection, + xcb_get_window_attributes(connection, ev->window), + NULL)) == NULL) + return -1; + if(wa->override_redirect) + { + p_delete(&wa); + return 0; + } if(!client_get_bywin(globalconf.clients, ev->window)) { + if((wgeom = xcb_get_geometry_reply(connection, + xcb_get_geometry(connection, ev->window), NULL)) == NULL) + return -1; + if(globalconf.screens_info->xinerama_is_active - && XQueryPointer(e->xany.display, RootWindow(e->xany.display, screen), - &dummy, &dummy, &x, &y, &d, &d, &m)) - screen = screen_get_bycoord(globalconf.screens_info, screen, x, y); + && (qpr = xcb_query_pointer_reply(connection, + xcb_query_pointer(connection, + root_window(globalconf.connection, screen_nbr)), + NULL)) != NULL) + screen_nbr = screen_get_bycoord(globalconf.screens_info, screen_nbr, qpr->root_x, qpr->root_y); else - for(screen = 0; wa.screen != ScreenOfDisplay(e->xany.display, screen); screen++); + for (iter = xcb_setup_roots_iterator (xcb_get_setup (connection)), screen_nbr = 0; + iter.rem && iter.data->root != wgeom->root; xcb_screen_next (&iter), ++screen_nbr); - client_manage(ev->window, &wa, screen); + if(qpr) + p_delete(&qpr); + + client_manage(ev->window, wgeom, screen_nbr); + p_delete(&wgeom); } + + return 0; } /** Handle XProperty events - * \param e XEvent + * \param connection connection to the X server + * \param ev PropertyNotify event */ -void -event_handle_propertynotify(XEvent * e) +int +event_handle_propertynotify(void *data __attribute__ ((unused)), + xcb_connection_t *connection, xcb_property_notify_event_t *ev) { Client *c; - Window trans; - XPropertyEvent *ev = &e->xproperty; + xcb_window_t trans; - if(ev->state == PropertyDelete) - return; /* ignore */ + if(ev->state == XCB_PROPERTY_DELETE) + return 0; /* ignore */ if((c = client_get_bywin(globalconf.clients, ev->window))) { - switch (ev->atom) + if(ev->atom == WM_TRANSIENT_FOR) { - case XA_WM_TRANSIENT_FOR: - XGetTransientForHint(e->xany.display, c->win, &trans); + x_get_transient_for_hint(connection, c->win, &trans); if(!c->isfloating && (c->isfloating = (client_get_bywin(globalconf.clients, trans) != NULL))) - globalconf.screens[c->screen].need_arrange = True; - break; - case XA_WM_NORMAL_HINTS: + globalconf.screens[c->screen].need_arrange = true; + } + else if (ev->atom == WM_NORMAL_HINTS) client_updatesizehints(c); - break; - case XA_WM_HINTS: + else if (ev->atom == WM_HINTS) client_updatewmhints(c); - break; - } - if(ev->atom == XA_WM_NAME || ev->atom == XInternAtom(globalconf.display, "_NET_WM_NAME", False)) + + if(ev->atom == WM_NAME || ev->atom == x_intern_atom(globalconf.connection, "_NET_WM_NAME")) client_updatetitle(c); } + + return 0; } /** Handle XUnmap events - * \param e XEvent + * \param connection connection to the X server + * \param ev UnmapNotify event */ -void -event_handle_unmapnotify(XEvent * e) +int +event_handle_unmapnotify(void *data __attribute__ ((unused)), + xcb_connection_t *connection, xcb_unmap_notify_event_t *ev) { Client *c; - XUnmapEvent *ev = &e->xunmap; + + /* + * event->send_event (Xlib) is quivalent to (ev->response_type & + * 0x80) in XCB because the SendEvent bit is available in the + * response_type field + */ + bool send_event = ((ev->response_type & 0x80) >> 7); if((c = client_get_bywin(globalconf.clients, ev->window)) - && ev->event == RootWindow(e->xany.display, get_phys_screen(c->screen)) - && ev->send_event && window_getstate(c->win) == NormalState) + && ev->event == root_window(connection, get_phys_screen(c->screen)) + && send_event && window_getstate(c->win) == xcb_wm_normal_state_t) client_unmanage(c); + + return 0; } /** Handle XShape events - * \param e XEvent + * \param ev Shape event */ -void -event_handle_shape(XEvent * e) +int +event_handle_shape(void *data __attribute__ ((unused)), + xcb_connection_t *connection __attribute__ ((unused)), + xcb_shape_notify_event_t *ev) { - XShapeEvent *ev = (XShapeEvent *) e; - Client *c = client_get_bywin(globalconf.clients, ev->window); + Client *c = client_get_bywin(globalconf.clients, ev->affected_window); if(c) window_setshape(get_phys_screen(c->screen), c->win); + + return 0; } /** Handle XRandR events - * \param e XEvent + * \param ev RandrScreenChangeNotify event */ -void -event_handle_randr_screen_change_notify(XEvent *e) +int +event_handle_randr_screen_change_notify(void *data __attribute__ ((unused)), + xcb_connection_t *connection __attribute__ ((unused)), + xcb_randr_screen_change_notify_event_t *ev) { - XRRUpdateConfiguration(e); + if(!globalconf.have_randr) + return -1; + + /* Code of XRRUpdateConfiguration Xlib function ported to XCB + * (only the code relevant to RRScreenChangeNotify) as the latter + * doesn't provide this kind of function */ + if(ev->rotation & (XCB_RANDR_ROTATION_ROTATE_90 | XCB_RANDR_ROTATION_ROTATE_270)) + xcb_randr_set_screen_size(connection, ev->root, ev->height, ev->width, + ev->mheight, ev->mwidth); + else + xcb_randr_set_screen_size(connection, ev->root, ev->width, ev->height, + ev->mwidth, ev->mheight); + + /* TODO: + * XRRUpdateConfiguration also executes the following instruction + * but I don't know yet how to port it to XCB + * + * XRenderSetSubpixelOrder(dpy, snum, scevent->subpixel_order); + */ + uicb_exec(0, globalconf.argv); + return 0; } /** Handle XClientMessage events - * \param e XEvent + * \param ev ClientMessage event */ -void -event_handle_clientmessage(XEvent *e) +int +event_handle_clientmessage(void *data __attribute__ ((unused)), + xcb_connection_t *connection __attribute__ ((unused)), + xcb_client_message_event_t *ev) { - ewmh_process_client_message(&e->xclient); + ewmh_process_client_message(ev); + return 0; } // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/event.h b/event.h index d984ae7..28e89d7 100644 --- a/event.h +++ b/event.h @@ -22,26 +22,28 @@ #ifndef AWESOME_EVENT_H #define AWESOME_EVENT_H -#include +#include +#include +#include -#define CLEANMASK(mask) (mask & ~(globalconf.numlockmask | LockMask)) +#define CLEANMASK(mask) (mask & ~(globalconf.numlockmask | XCB_MOD_MASK_LOCK)) -void event_handle_buttonpress(XEvent *); -void event_handle_configurerequest(XEvent *); -void event_handle_configurenotify(XEvent *); -void event_handle_destroynotify(XEvent *); -void event_handle_enternotify(XEvent *); -void event_handle_motionnotify(XEvent *); -void event_handle_expose(XEvent *); -void event_handle_keypress(XEvent *); -void event_handle_leavenotify(XEvent *); -void event_handle_mappingnotify(XEvent *); -void event_handle_maprequest(XEvent *); -void event_handle_propertynotify(XEvent *); -void event_handle_unmapnotify(XEvent *); -void event_handle_shape(XEvent *); -void event_handle_randr_screen_change_notify(XEvent *); -void event_handle_clientmessage(XEvent *); +int event_handle_buttonpress(void *, xcb_connection_t *, xcb_button_press_event_t *); +int event_handle_configurerequest(void *, xcb_connection_t *, xcb_configure_request_event_t *); +int event_handle_configurenotify(void *, xcb_connection_t *, xcb_configure_notify_event_t *); +int event_handle_destroynotify(void *, xcb_connection_t *, xcb_destroy_notify_event_t *); +int event_handle_enternotify(void *, xcb_connection_t *, xcb_enter_notify_event_t *); +int event_handle_motionnotify(void *, xcb_connection_t *, xcb_motion_notify_event_t *); +int event_handle_expose(void *, xcb_connection_t *, xcb_expose_event_t *); +int event_handle_keypress(void *, xcb_connection_t *, xcb_key_press_event_t *); +int event_handle_leavenotify(void *, xcb_connection_t *, xcb_leave_notify_event_t *); +int event_handle_mappingnotify(void *, xcb_connection_t *, xcb_mapping_notify_event_t *); +int event_handle_maprequest(void *, xcb_connection_t *, xcb_map_request_event_t *); +int event_handle_propertynotify(void *, xcb_connection_t *, xcb_property_notify_event_t *); +int event_handle_unmapnotify(void *, xcb_connection_t *, xcb_unmap_notify_event_t *); +int event_handle_shape(void *, xcb_connection_t *, xcb_shape_notify_event_t *); +int event_handle_randr_screen_change_notify(void *, xcb_connection_t *, xcb_randr_screen_change_notify_event_t *); +int event_handle_clientmessage(void *, xcb_connection_t *, xcb_client_message_event_t *); #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/ewmh.c b/ewmh.c index 5b39641..7093363 100644 --- a/ewmh.c +++ b/ewmh.c @@ -19,8 +19,8 @@ * */ -#include -#include +#include +#include #include "ewmh.h" #include "tag.h" @@ -31,34 +31,31 @@ extern AwesomeConf globalconf; -static Atom net_supported; -static Atom net_client_list; -static Atom net_number_of_desktops; -static Atom net_current_desktop; -static Atom net_desktop_names; -static Atom net_active_window; - -static Atom net_close_window; - -static Atom net_wm_name; -static Atom net_wm_icon_name; -static Atom net_wm_window_type; -static Atom net_wm_window_type_normal; -static Atom net_wm_window_type_dock; -static Atom net_wm_window_type_splash; -static Atom net_wm_window_type_dialog; -static Atom net_wm_icon; -static Atom net_wm_state; -static Atom net_wm_state_sticky; -static Atom net_wm_state_skip_taskbar; -static Atom net_wm_state_fullscreen; - -static Atom utf8_string; +static xcb_atom_t net_supported; +static xcb_atom_t net_client_list; +static xcb_atom_t net_number_of_desktops; +static xcb_atom_t net_current_desktop; +static xcb_atom_t net_desktop_names; +static xcb_atom_t net_active_window; +static xcb_atom_t net_close_window; +static xcb_atom_t net_wm_name; +static xcb_atom_t net_wm_icon_name; +static xcb_atom_t net_wm_window_type; +static xcb_atom_t net_wm_window_type_normal; +static xcb_atom_t net_wm_window_type_dock; +static xcb_atom_t net_wm_window_type_splash; +static xcb_atom_t net_wm_window_type_dialog; +static xcb_atom_t net_wm_icon; +static xcb_atom_t net_wm_state; +static xcb_atom_t net_wm_state_sticky; +static xcb_atom_t net_wm_state_skip_taskbar; +static xcb_atom_t net_wm_state_fullscreen; +static xcb_atom_t utf8_string; typedef struct { const char *name; - Atom *atom; + xcb_atom_t *atom; } AtomItem; static AtomItem AtomNames[] = @@ -98,20 +95,35 @@ void ewmh_init_atoms(void) { unsigned int i; - char *names[ATOM_NUMBER]; - Atom atoms[ATOM_NUMBER]; + xcb_intern_atom_cookie_t cs[ATOM_NUMBER]; + xcb_intern_atom_reply_t *r; + /* + * Create the atom and get the reply in a XCB way (e.g. send all + * the requests at the same time and then get the replies) + */ for(i = 0; i < ATOM_NUMBER; i++) - names[i] = (char *) AtomNames[i].name; - XInternAtoms(globalconf.display, names, ATOM_NUMBER, False, atoms); + cs[i] = xcb_intern_atom_unchecked(globalconf.connection, + false, + strlen(AtomNames[i].name), + AtomNames[i].name); + for(i = 0; i < ATOM_NUMBER; i++) - *AtomNames[i].atom = atoms[i]; + { + r = xcb_intern_atom_reply(globalconf.connection, cs[i], NULL); + if(!r) + /* An error occured, get reply for next atom */ + continue; + + *AtomNames[i].atom = r->atom; + p_delete(&r); + } } void ewmh_set_supported_hints(int phys_screen) { - Atom atom[ATOM_NUMBER]; + xcb_atom_t atom[ATOM_NUMBER]; int i = 0; atom[i++] = net_supported; @@ -136,29 +148,30 @@ ewmh_set_supported_hints(int phys_screen) atom[i++] = net_wm_state_skip_taskbar; atom[i++] = net_wm_state_fullscreen; - XChangeProperty(globalconf.display, RootWindow(globalconf.display, phys_screen), - net_supported, XA_ATOM, 32, - PropModeReplace, (unsigned char *) atom, i); + xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, + root_window(globalconf.connection, phys_screen), + net_supported, ATOM, 32, i, atom); } void ewmh_update_net_client_list(int phys_screen) { - Window *wins; + xcb_window_t *wins; Client *c; int n = 0; for(c = globalconf.clients; c; c = c->next) n++; - wins = p_new(Window, n); + wins = p_new(xcb_window_t, n); for(n = 0, c = globalconf.clients; c; c = c->next, n++) if(get_phys_screen(c->screen) == phys_screen) wins[n] = c->win; - XChangeProperty(globalconf.display, RootWindow(globalconf.display, phys_screen), - net_client_list, XA_WINDOW, 32, PropModeReplace, (unsigned char *) wins, n); + xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, + root_window(globalconf.connection, phys_screen), + net_client_list, WINDOW, 32, n, wins); p_delete(&wins); } @@ -166,27 +179,29 @@ ewmh_update_net_client_list(int phys_screen) void ewmh_update_net_numbers_of_desktop(int phys_screen) { - CARD32 count = 0; + uint32_t count = 0; Tag *tag; for(tag = globalconf.screens[phys_screen].tags; tag; tag = tag->next) count++; - XChangeProperty(globalconf.display, RootWindow(globalconf.display, phys_screen), - net_number_of_desktops, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &count, 1); + xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, + root_window(globalconf.connection, phys_screen), + net_number_of_desktops, CARDINAL, 32, 1, &count); } void ewmh_update_net_current_desktop(int phys_screen) { - CARD32 count = 0; + uint32_t count = 0; Tag *tag, **curtags = tags_get_current(phys_screen); for(tag = globalconf.screens[phys_screen].tags; tag != curtags[0]; tag = tag->next) count++; - XChangeProperty(globalconf.display, RootWindow(globalconf.display, phys_screen), - net_current_desktop, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &count, 1); + xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, + root_window(globalconf.connection, phys_screen), + net_current_desktop, CARDINAL, 32, 1, &count); p_delete(&curtags); } @@ -208,25 +223,29 @@ ewmh_update_net_desktop_names(int phys_screen) len += curr_size + 1; } - XChangeProperty(globalconf.display, RootWindow(globalconf.display, phys_screen), - net_desktop_names, utf8_string, 8, PropModeReplace, (unsigned char *) buf, len); + xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, + root_window(globalconf.connection, phys_screen), + net_desktop_names, utf8_string, 8, len, buf); } void ewmh_update_net_active_window(int phys_screen) { - Window win; + xcb_window_t win; Client *sel = focus_get_current_client(phys_screen); - win = sel ? sel->win : None; + win = sel ? sel->win : XCB_NONE; - XChangeProperty(globalconf.display, RootWindow(globalconf.display, phys_screen), - net_active_window, XA_WINDOW, 32, PropModeReplace, (unsigned char *) &win, 1); + xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, + root_window(globalconf.connection, phys_screen), + net_active_window, WINDOW, 32, 1, &win); } static void -ewmh_process_state_atom(Client *c, Atom state, int set) +ewmh_process_state_atom(Client *c, xcb_atom_t state, int set) { + const uint32_t raise_window_val = XCB_STACK_MODE_ABOVE; + if(state == net_wm_state_sticky) { Tag *tag; @@ -237,13 +256,13 @@ ewmh_process_state_atom(Client *c, Atom state, int set) { if(set == _NET_WM_STATE_REMOVE) { - c->skiptb = False; - c->skip = False; + c->skiptb = false; + c->skip = false; } else if(set == _NET_WM_STATE_ADD) { - c->skiptb = True; - c->skip = True; + c->skiptb = true; + c->skip = true; } } else if(state == net_wm_state_fullscreen) @@ -254,7 +273,7 @@ ewmh_process_state_atom(Client *c, Atom state, int set) /* restore geometry */ geometry = c->m_geometry; c->border = c->oldborder; - c->ismax = False; + c->ismax = false; client_setfloating(c, c->wasfloating); } else if(set == _NET_WM_STATE_ADD) @@ -265,17 +284,17 @@ ewmh_process_state_atom(Client *c, Atom state, int set) c->wasfloating = c->isfloating; c->oldborder = c->border; c->border = 0; - c->ismax = True; - client_setfloating(c, True); + c->ismax = true; + client_setfloating(c, true); } widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS); - client_resize(c, geometry, False); - XRaiseWindow(globalconf.display, c->win); + client_resize(c, geometry, false); + xcb_configure_window(globalconf.connection, c->win, XCB_CONFIG_WINDOW_STACK_MODE, &raise_window_val); } } static void -ewmh_process_window_type_atom(Client *c, Atom state) +ewmh_process_window_type_atom(Client *c, xcb_atom_t state) { if(state == net_wm_window_type_normal) { @@ -285,37 +304,46 @@ ewmh_process_window_type_atom(Client *c, Atom state) || state == net_wm_window_type_splash) { c->border = 0; - c->skip = True; - c->isfixed = True; + c->skip = true; + c->isfixed = true; c->titlebar.position = Off; - client_setfloating(c, True); + client_setfloating(c, true); } else if (state == net_wm_window_type_dialog) - client_setfloating(c, True); + client_setfloating(c, true); } void -ewmh_process_client_message(XClientMessageEvent *ev) +ewmh_process_client_message(xcb_client_message_event_t *ev) { Client *c; int screen; - if(ev->message_type == net_current_desktop) - for(screen = 0; screen < ScreenCount(globalconf.display); screen++) - if(ev->window == RootWindow(globalconf.display, screen)) - tag_view_only_byindex(screen, ev->data.l[0]); + /* TODO: check whether it's correct to use 'type' this way */ + if(ev->type == net_current_desktop) + for(screen = 0; + screen < xcb_setup_roots_length(xcb_get_setup(globalconf.connection)); + screen++) + { + if(ev->window == root_window(globalconf.connection, screen)) + tag_view_only_byindex(screen, ev->data.data32[0]); + } - if(ev->message_type == net_close_window) + if(ev->type == net_close_window) { if((c = client_get_bywin(globalconf.clients, ev->window))) client_kill(c); } - else if(ev->message_type == net_wm_state) + else if(ev->type == net_wm_state) { if((c = client_get_bywin(globalconf.clients, ev->window))) { - ewmh_process_state_atom(c, (Atom) ev->data.l[1], ev->data.l[0]); - if(ev->data.l[2]) - ewmh_process_state_atom(c, (Atom) ev->data.l[2], ev->data.l[0]); + ewmh_process_state_atom(c, (xcb_atom_t) ev->data.data32[1], ev->data.data32[0]); + /* TODO: is data32[2] really useful because it doesn't + * seem to be used when sending a ClientMessage in + * event.c:897 */ + if(ev->data.data32[2]) + ewmh_process_state_atom(c, (xcb_atom_t) ev->data.data32[2], + ev->data.data32[0]); } } } @@ -323,52 +351,65 @@ ewmh_process_client_message(XClientMessageEvent *ev) void ewmh_check_client_hints(Client *c) { - int format; - Atom real, *state; - unsigned char *data = NULL; - unsigned long i, n, extra; - - if(XGetWindowProperty(globalconf.display, c->win, net_wm_state, 0L, LONG_MAX, False, - XA_ATOM, &real, &format, &n, &extra, - (unsigned char **) &data) == Success && data) + xcb_atom_t *state; + void *data = NULL; + int i; + + xcb_get_property_cookie_t c1, c2; + xcb_get_property_reply_t *reply; + + /* Send the GetProperty requests which will be processed later */ + c1 = xcb_get_property_unchecked(globalconf.connection, false, c->win, + net_wm_state, ATOM, 0, UINT32_MAX); + + c2 = xcb_get_property_unchecked(globalconf.connection, false, c->win, + net_wm_window_type, ATOM, 0, UINT32_MAX); + + reply = xcb_get_property_reply(globalconf.connection, c1, NULL); + if(reply && (data = xcb_get_property_value(reply))) { - state = (Atom *) data; - for(i = 0; i < n; i++) + state = (xcb_atom_t *) data; + for(i = 0; i < xcb_get_property_value_length(reply); i++) ewmh_process_state_atom(c, state[i], _NET_WM_STATE_ADD); - - XFree(data); } - if(XGetWindowProperty(globalconf.display, c->win, net_wm_window_type, 0L, LONG_MAX, False, - XA_ATOM, &real, &format, &n, &extra, - (unsigned char **) &data) == Success && data) + p_delete(&reply); + + reply = xcb_get_property_reply(globalconf.connection, c2, NULL); + if(reply && (data = xcb_get_property_value(reply))) { - state = (Atom *) data; - for(i = 0; i < n; i++) + state = (xcb_atom_t *) data; + for(i = 0; i < xcb_get_property_value_length(reply); i++) ewmh_process_window_type_atom(c, state[i]); - - XFree(data); } + + p_delete(&reply); } NetWMIcon * -ewmh_get_window_icon(Window w) +ewmh_get_window_icon(xcb_window_t w) { NetWMIcon *icon; - Atom type; - int format, size, i; - unsigned long items, rest, *data, pixel; + int size, i; + unsigned long *data, pixel; unsigned char *imgdata, *wdata; + xcb_get_property_reply_t *r; + + r = xcb_get_property_reply(globalconf.connection, + xcb_get_property_unchecked(globalconf.connection, false, w, + net_wm_icon, CARDINAL, 0, UINT32_MAX), + NULL); + if(!r || !(wdata = (unsigned char *) xcb_get_property_value(r))) + { + if(r) + p_delete(&r); - if(XGetWindowProperty(globalconf.display, w, - net_wm_icon, 0L, LONG_MAX, False, XA_CARDINAL, &type, &format, - &items, &rest, &wdata) != Success - || !wdata) return NULL; + } - if(type != XA_CARDINAL || format != 32 || items < 2) + if(r->type != CARDINAL || r->format != 32 || r->length < 2) { - XFree(wdata); + p_delete(&r); return NULL; } @@ -383,7 +424,7 @@ ewmh_get_window_icon(Window w) if(!size) { p_delete(&icon); - XFree(wdata); + p_delete(&r); return NULL; } @@ -397,7 +438,7 @@ ewmh_get_window_icon(Window w) imgdata[2] = pixel & 0xff; /* B */ } - XFree(wdata); + p_delete(&r); return icon; } diff --git a/ewmh.h b/ewmh.h index e7924f6..6cea088 100644 --- a/ewmh.h +++ b/ewmh.h @@ -38,9 +38,9 @@ void ewmh_update_net_numbers_of_desktop(int); void ewmh_update_net_current_desktop(int); void ewmh_update_net_desktop_names(int); void ewmh_update_net_active_window(int); -void ewmh_process_client_message(XClientMessageEvent *); +void ewmh_process_client_message(xcb_client_message_event_t *); void ewmh_check_client_hints(Client *); -NetWMIcon * ewmh_get_window_icon(Window); +NetWMIcon * ewmh_get_window_icon(xcb_window_t); #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/focus.c b/focus.c index 8c6a405..71df846 100644 --- a/focus.c +++ b/focus.c @@ -119,7 +119,7 @@ uicb_focus_history(int screen, char *arg) c = focus_get_latest_client_for_tags(curtags, i); p_delete(&curtags); if(c) - client_focus(c, screen, True); + client_focus(c, screen, true); } } } @@ -136,7 +136,7 @@ uicb_focus_client_byname(int screen, char *arg) if((c = client_get_byname(globalconf.clients, arg))) for(tag = curtags; *tag; tag++) if(is_client_tagged(c, *tag)) - client_focus(c, screen, True); + client_focus(c, screen, true); p_delete(&curtags); } } diff --git a/layout.c b/layout.c index f990972..bb86909 100644 --- a/layout.c +++ b/layout.c @@ -19,8 +19,8 @@ * */ -#include -#include +#include +#include #include "tag.h" #include "focus.h" @@ -45,9 +45,7 @@ arrange(int screen) { Client *c; Layout *curlay = layout_get_current(screen); - unsigned int dui; - int di, x, y; - Window rootwin, childwin; + xcb_query_pointer_reply_t *xqp; for(c = globalconf.clients; c; c = c->next) { @@ -63,26 +61,28 @@ arrange(int screen) for(c = globalconf.clients; c; c = c->next) if(c->newcomer && client_isvisible(c, screen)) { - c->newcomer = False; + c->newcomer = false; client_unban(c); if(globalconf.screens[screen].new_get_focus) - client_focus(c, screen, True); + client_focus(c, screen, true); } /* if we have a valid client that could be focused but currently no window * are focused, then set the focus on this window */ if((c = focus_get_current_client(screen)) && !globalconf.focus->client) - client_focus(c, screen, True); + client_focus(c, screen, true); /* check that the mouse is on a window or not */ - if(XQueryPointer(globalconf.display, RootWindow(globalconf.display, - get_phys_screen(screen)), - &rootwin, &childwin, &x, &y, &di, &di, &dui) - && (rootwin == None || childwin == None || childwin == rootwin)) + if((xqp = xcb_query_pointer_reply(globalconf.connection, + xcb_query_pointer_unchecked(globalconf.connection, + root_window(globalconf.connection, + get_phys_screen(screen))), + NULL)) != NULL + && (xqp->root == XCB_NONE || xqp->child == XCB_NONE || xqp->root == xqp->child)) window_root_grabbuttons(get_phys_screen(screen)); /* reset status */ - globalconf.screens[screen].need_arrange = False; + globalconf.screens[screen].need_arrange = false; } /** Refresh the screen disposition diff --git a/layout.h b/layout.h index 20a5b2c..3ec973b 100644 --- a/layout.h +++ b/layout.h @@ -22,8 +22,6 @@ #ifndef AWESOME_LAYOUT_H #define AWESOME_LAYOUT_H -#include - #include "uicb.h" #include "common/list.h" #include "common/util.h" diff --git a/layouts/fibonacci.c b/layouts/fibonacci.c index 3607b27..b8fd19d 100644 --- a/layouts/fibonacci.c +++ b/layouts/fibonacci.c @@ -43,7 +43,7 @@ layout_fibonacci(int screen, int shape) for(c = globalconf.clients; c; c = c->next) if(IS_TILED(c, screen)) { - c->ismax = False; + c->ismax = false; if((i % 2 && geometry.height / 2 > 2 * c->border) || (!(i % 2) && geometry.width / 2 > 2 * c->border)) { diff --git a/layouts/floating.c b/layouts/floating.c index a790ffd..ebabef6 100644 --- a/layouts/floating.c +++ b/layouts/floating.c @@ -32,6 +32,6 @@ layout_floating(int screen) for(c = globalconf.clients; c; c = c->next) if(client_isvisible(c, screen) && !c->ismax) - client_resize(c, c->f_geometry, False); + client_resize(c, c->f_geometry, false); } // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/layouts/max.c b/layouts/max.c index 67306ad..d098f8c 100644 --- a/layouts/max.c +++ b/layouts/max.c @@ -40,7 +40,7 @@ layout_max(int screen) { area.width -= 2 * c->border; area.height -= 2 * c->border; - client_resize(c, area, False); + client_resize(c, area, false); area.width += 2 * c->border; area.height += 2 * c->border; } diff --git a/layouts/tile.c b/layouts/tile.c index a73d656..15984b3 100644 --- a/layouts/tile.c +++ b/layouts/tile.c @@ -57,7 +57,7 @@ uicb_tag_setnmaster(int screen, char * arg) p_delete(&curtags); - globalconf.screens[screen].need_arrange = True; + globalconf.screens[screen].need_arrange = true; } void @@ -87,7 +87,7 @@ uicb_tag_setncol(int screen, char * arg) p_delete(&curtags); - globalconf.screens[screen].need_arrange = True; + globalconf.screens[screen].need_arrange = true; } void @@ -121,7 +121,7 @@ uicb_tag_setmwfact(int screen, char *arg) p_delete(&newarg); p_delete(&curtags); - globalconf.screens[screen].need_arrange = True; + globalconf.screens[screen].need_arrange = true; } static void diff --git a/mouse.c b/mouse.c index 8cb831a..4492015 100644 --- a/mouse.c +++ b/mouse.c @@ -32,7 +32,11 @@ #include "layouts/tile.h" #include "common/xscreen.h" -#define MOUSEMASK (ButtonPressMask | ButtonReleaseMask | PointerMotionMask) +#ifndef HAVE_XCB_HANDLE_EVENT +#include "xcb_event_handler.h" +#endif + +#define MOUSEMASK (XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION) extern AwesomeConf globalconf; @@ -44,13 +48,16 @@ extern AwesomeConf globalconf; void uicb_client_movemouse(int screen, char *arg __attribute__ ((unused))) { - int x, y, ocx, ocy, di, phys_screen, newscreen; - unsigned int dui; - Window dummy, child; - XEvent ev; + int ocx, ocy, phys_screen, newscreen; area_t area, geometry; Client *c = globalconf.focus->client, *target; Layout *layout = layout_get_current(screen); + bool ignore_motion_events = false; + xcb_generic_event_t *ev = NULL; + xcb_motion_notify_event_t *ev_motion = NULL; + xcb_grab_pointer_cookie_t grab_pointer_c; + xcb_grab_pointer_reply_t *grab_pointer_r = NULL; + xcb_query_pointer_reply_t *query_pointer_r = NULL, *mquery_pointer_r = NULL; if(!c) return; @@ -62,85 +69,112 @@ uicb_client_movemouse(int screen, char *arg __attribute__ ((unused))) ocx = geometry.x = c->geometry.x; ocy = geometry.y = c->geometry.y; phys_screen = get_phys_screen(c->screen); - if(XGrabPointer(globalconf.display, - RootWindow(globalconf.display, phys_screen), - False, MOUSEMASK, GrabModeAsync, GrabModeAsync, - RootWindow(globalconf.display, phys_screen), - globalconf.cursor[CurMove], CurrentTime) != GrabSuccess) + + grab_pointer_c = xcb_grab_pointer(globalconf.connection, false, + root_window(globalconf.connection, phys_screen), + MOUSEMASK, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, + root_window(globalconf.connection, phys_screen), + globalconf.cursor[CurMove], XCB_CURRENT_TIME); + + if((grab_pointer_r = xcb_grab_pointer_reply(globalconf.connection, + grab_pointer_c, NULL)) == NULL) return; - XQueryPointer(globalconf.display, - RootWindow(globalconf.display, phys_screen), - &dummy, &dummy, &x, &y, &di, &di, &dui); - c->ismax = False; + + p_delete(&grab_pointer_r); + + query_pointer_r = xcb_query_pointer_reply(globalconf.connection, + xcb_query_pointer_unchecked(globalconf.connection, + root_window(globalconf.connection, phys_screen)), + NULL); + c->ismax = false; for(;;) { - XMaskEvent(globalconf.display, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev); - switch (ev.type) + /* TODO: need a review + * + * XMaskEvent allows to retrieve only specified events from + * the queue and requeue the other events... + */ + while((ev = xcb_poll_for_event(globalconf.connection))) { - case ButtonRelease: - XUngrabPointer(globalconf.display, CurrentTime); - return; - case ConfigureRequest: - event_handle_configurerequest(&ev); - break; - case Expose: - event_handle_expose(&ev); - break; - case MapRequest: - event_handle_maprequest(&ev); - break; - case EnterNotify: - event_handle_enternotify(&ev); - break; - case MotionNotify: - if(c->isfloating || layout->arrange == layout_floating) - { - geometry.x = ocx + (ev.xmotion.x - x); - geometry.y = ocy + (ev.xmotion.y - y); - - if(abs(geometry.x) < globalconf.screens[screen].snap + area.x && geometry.x > area.x) - geometry.x = area.x; - else if(abs((area.x + area.width) - (geometry.x + c->geometry.width + 2 * c->border)) - < globalconf.screens[screen].snap) - geometry.x = area.x + area.width - c->geometry.width - 2 * c->border; - if(abs(geometry.y) < globalconf.screens[screen].snap + area.y && geometry.y > area.y) - geometry.y = area.y; - else if(abs((area.y + area.height) - (geometry.y + c->geometry.height + 2 * c->border)) - < globalconf.screens[screen].snap) - geometry.y = area.y + area.height - c->geometry.height - 2 * c->border; - - geometry.width = c->geometry.width; - geometry.height = c->geometry.height; - - c->ismoving = True; - client_resize(c, geometry, False); - c->ismoving = False; - } - else + switch((ev->response_type & 0x7f)) { - XQueryPointer(globalconf.display, - RootWindow(globalconf.display, phys_screen), - &dummy, &child, &x, &y, &di, &di, &dui); - if((newscreen = screen_get_bycoord(globalconf.screens_info, c->screen, x, y)) != c->screen) + case XCB_BUTTON_RELEASE: + xcb_ungrab_pointer(globalconf.connection, XCB_CURRENT_TIME); + + p_delete(&query_pointer_r); + p_delete(&ev); + return; + case XCB_MOTION_NOTIFY: + if(ignore_motion_events) + break; + + if(c->isfloating || layout->arrange == layout_floating) { - move_client_to_screen(c, newscreen, True); - globalconf.screens[c->screen].need_arrange = True; - if(layout_get_current(newscreen)->arrange != layout_floating) - globalconf.screens[newscreen].need_arrange = True; - layout_refresh(); + ev_motion = (xcb_motion_notify_event_t *) ev; + + geometry.x = ocx + (ev_motion->event_x - query_pointer_r->root_x); + geometry.y = ocy + (ev_motion->event_y - query_pointer_r->root_y); + + if(abs(geometry.x) < globalconf.screens[screen].snap + area.x && geometry.x > area.x) + geometry.x = area.x; + else if(abs((area.x + area.width) - (geometry.x + c->geometry.width + 2 * c->border)) < globalconf.screens[screen].snap) + geometry.x = area.x + area.width - c->geometry.width - 2 * c->border; + if(abs(geometry.y) < globalconf.screens[screen].snap + area.y && geometry.y > area.y) + geometry.y = area.y; + else if(abs((area.y + area.height) - (geometry.y + c->geometry.height + 2 * c->border)) < globalconf.screens[screen].snap) + geometry.y = area.y + area.height - c->geometry.height - 2 * c->border; + + geometry.width = c->geometry.width; + geometry.height = c->geometry.height; + + c->ismoving = true; + client_resize(c, geometry, false); + c->ismoving = false; + + p_delete(&ev); } - if((target = client_get_bywin(globalconf.clients, child)) - && target != c && !target->isfloating) + else { - client_list_swap(&globalconf.clients, c, target); - globalconf.screens[c->screen].need_arrange = True; - layout_refresh(); + mquery_pointer_r = xcb_query_pointer_reply(globalconf.connection, + xcb_query_pointer_unchecked(globalconf.connection, + root_window(globalconf.connection, phys_screen)), + NULL); + if((newscreen = screen_get_bycoord(globalconf.screens_info, c->screen, + mquery_pointer_r->root_x, + mquery_pointer_r->root_y)) != c->screen) + { + move_client_to_screen(c, newscreen, true); + globalconf.screens[c->screen].need_arrange = true; + globalconf.screens[newscreen].need_arrange = true; + layout_refresh(); + } + if((target = client_get_bywin(globalconf.clients, mquery_pointer_r->child)) + && target != c && !target->isfloating) + { + client_list_swap(&globalconf.clients, c, target); + globalconf.screens[c->screen].need_arrange = true; + layout_refresh(); + } + + p_delete(&mquery_pointer_r); } + ignore_motion_events = true; + break; + case XCB_CONFIGURE_REQUEST: + case XCB_EXPOSE: + case XCB_MAP_REQUEST: + case XCB_ENTER_NOTIFY: + /* Handle errors */ + case 0: + handle_event(globalconf.evenths, ev); + break; } - while(XCheckMaskEvent(globalconf.display, PointerMotionMask, &ev)); - break; + + p_delete(&ev); } } + + p_delete(&query_pointer_r); } /** Resize client with mouse @@ -152,12 +186,16 @@ void uicb_client_resizemouse(int screen, char *arg __attribute__ ((unused))) { int ocx = 0, ocy = 0, n; - XEvent ev; + xcb_generic_event_t *ev = NULL; + xcb_motion_notify_event_t *ev_motion = NULL; + bool ignore_motion_events = false; Client *c = globalconf.focus->client; Tag **curtags = tags_get_current(screen); Layout *layout = curtags[0]->layout; area_t area = { 0, 0, 0, 0, NULL, NULL }, geometry; double mwfact; + xcb_grab_pointer_cookie_t grab_pointer_c; + xcb_grab_pointer_reply_t *grab_pointer_r = NULL; /* only handle floating and tiled layouts */ if(c && !c->isfixed) @@ -166,7 +204,7 @@ uicb_client_resizemouse(int screen, char *arg __attribute__ ((unused))) { ocx = c->geometry.x; ocy = c->geometry.y; - c->ismax = False; + c->ismax = false; } else if (layout->arrange == layout_tile || layout->arrange == layout_tileleft || layout->arrange == layout_tilebottom || layout->arrange == layout_tiletop) @@ -188,73 +226,91 @@ uicb_client_resizemouse(int screen, char *arg __attribute__ ((unused))) else return; - if(XGrabPointer(globalconf.display, RootWindow(globalconf.display, - get_phys_screen(c->screen)), - False, MOUSEMASK, GrabModeAsync, GrabModeAsync, - RootWindow(globalconf.display,get_phys_screen(c->screen)), - globalconf.cursor[CurResize], CurrentTime) != GrabSuccess) + grab_pointer_c = xcb_grab_pointer(globalconf.connection, false, + root_window(globalconf.connection, get_phys_screen(c->screen)), + MOUSEMASK, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, + root_window(globalconf.connection, get_phys_screen(c->screen)), + globalconf.cursor[CurResize], XCB_CURRENT_TIME); + + if((grab_pointer_r = xcb_grab_pointer_reply(globalconf.connection, + grab_pointer_c, NULL)) == NULL) return; + p_delete(&grab_pointer_r); + if(curtags[0]->layout->arrange == layout_tileleft) - XWarpPointer(globalconf.display, None, c->win, 0, 0, 0, 0, 0, c->geometry.height + c->border - 1); + xcb_warp_pointer(globalconf.connection, XCB_NONE, c->win, 0, 0, 0, 0, 0, c->geometry.height + c->border - 1); else if(curtags[0]->layout->arrange == layout_tilebottom) - XWarpPointer(globalconf.display, None, c->win, 0, 0, 0, 0, c->geometry.width + c->border - 1, c->geometry.height + c->border - 1); + xcb_warp_pointer(globalconf.connection, XCB_NONE, c->win, 0, 0, 0, 0, c->geometry.width + c->border - 1, c->geometry.height + c->border - 1); else if(curtags[0]->layout->arrange == layout_tiletop) - XWarpPointer(globalconf.display, None, c->win, 0, 0, 0, 0, c->geometry.width + c->border - 1, 0); + xcb_warp_pointer(globalconf.connection, XCB_NONE, c->win, 0, 0, 0, 0, c->geometry.width + c->border - 1, 0); else - XWarpPointer(globalconf.display, None, c->win, 0, 0, 0, 0, c->geometry.width + c->border - 1, c->geometry.height + c->border - 1); + xcb_warp_pointer(globalconf.connection, XCB_NONE, c->win, 0, 0, 0, 0, c->geometry.width + c->border - 1, c->geometry.height + c->border - 1); for(;;) { - XMaskEvent(globalconf.display, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev); - switch (ev.type) + /* TODO: need a review + * + * XMaskEvent allows to retrieve only specified events from + * the queue and requeue the other events... + */ + while((ev = xcb_poll_for_event(globalconf.connection))) { - case ButtonRelease: - XUngrabPointer(globalconf.display, CurrentTime); - return; - case ConfigureRequest: - event_handle_configurerequest(&ev); - break; - case Expose: - event_handle_expose(&ev); - break; - case MapRequest: - event_handle_maprequest(&ev); - break; - case MotionNotify: - if(layout->arrange == layout_floating || c->isfloating) + switch((ev->response_type & 0x7f)) { - if((geometry.width = ev.xmotion.x - ocx - 2 * c->border + 1) <= 0) - geometry.width = 1; - if((geometry.height = ev.xmotion.y - ocy - 2 * c->border + 1) <= 0) - geometry.height = 1; - geometry.x = c->geometry.x; - geometry.y = c->geometry.y; - client_resize(c, geometry, True); - } - else if(layout->arrange == layout_tile || layout->arrange == layout_tileleft - || layout->arrange == layout_tiletop || layout->arrange == layout_tilebottom) - { - if(layout->arrange == layout_tile) - mwfact = (double) (ev.xmotion.x - area.x) / area.width; - else if(curtags[0]->layout->arrange == layout_tileleft) - mwfact = 1 - (double) (ev.xmotion.x - area.x) / area.width; - else if(curtags[0]->layout->arrange == layout_tilebottom) - mwfact = (double) (ev.xmotion.y - area.y) / area.height; - else - mwfact = 1 - (double) (ev.xmotion.y - area.y) / area.height; - if(mwfact < 0.1) mwfact = 0.1; - else if(mwfact > 0.9) mwfact = 0.9; - if(fabs(curtags[0]->mwfact - mwfact) >= 0.01) + case XCB_BUTTON_RELEASE: + xcb_ungrab_pointer(globalconf.connection, XCB_CURRENT_TIME); + p_delete(&ev); + return; + case XCB_MOTION_NOTIFY: + if(ignore_motion_events) + break; + + ev_motion = (xcb_motion_notify_event_t *) ev; + + if(layout->arrange == layout_floating || c->isfloating) { - curtags[0]->mwfact = mwfact; - globalconf.screens[screen].need_arrange = True; - layout_refresh(); - while(XCheckMaskEvent(globalconf.display, PointerMotionMask, &ev)); + if((geometry.width = ev_motion->event_x - ocx - 2 * c->border + 1) <= 0) + geometry.width = 1; + if((geometry.height = ev_motion->event_y - ocy - 2 * c->border + 1) <= 0) + geometry.height = 1; + geometry.x = c->geometry.x; + geometry.y = c->geometry.y; + client_resize(c, geometry, true); } + else if(layout->arrange == layout_tile || layout->arrange == layout_tileleft + || layout->arrange == layout_tiletop || layout->arrange == layout_tilebottom) + { + if(layout->arrange == layout_tile) + mwfact = (double) (ev_motion->event_x - area.x) / area.width; + else if(curtags[0]->layout->arrange == layout_tileleft) + mwfact = 1 - (double) (ev_motion->event_x - area.x) / area.width; + else if(curtags[0]->layout->arrange == layout_tilebottom) + mwfact = (double) (ev_motion->event_y - area.y) / area.height; + else + mwfact = 1 - (double) (ev_motion->event_y - area.y) / area.height; + if(mwfact < 0.1) mwfact = 0.1; + else if(mwfact > 0.9) mwfact = 0.9; + if(fabs(curtags[0]->mwfact - mwfact) >= 0.01) + { + curtags[0]->mwfact = mwfact; + globalconf.screens[screen].need_arrange = true; + layout_refresh(); + ignore_motion_events = true; + } + } + + break; + case XCB_CONFIGURE_REQUEST: + case XCB_EXPOSE: + case XCB_MAP_REQUEST: + /* Handle errors */ + case 0: + handle_event(globalconf.evenths, ev); + break; } - break; + p_delete(&ev); } } p_delete(&curtags); diff --git a/placement.c b/placement.c index ad881e9..06637cf 100644 --- a/placement.c +++ b/placement.c @@ -95,7 +95,7 @@ placement_smart(Client *c) Client *client; area_t newgeometry = { 0, 0, 0, 0, NULL, NULL }; area_t *screen_geometry, *arealist = NULL, *r; - Bool found = False; + bool found = false; screen_geometry = p_new(area_t, 1); @@ -124,7 +124,7 @@ placement_smart(Client *c) if(r->width >= c->f_geometry.width && r->height >= c->f_geometry.height && r->width * r->height > newgeometry.width * newgeometry.height) { - found = True; + found = true; newgeometry = *r; } @@ -154,16 +154,16 @@ placement_smart(Client *c) area_t placement_under_mouse(Client *c) { - Window dummy; - unsigned int m; - int x, y, d; + xcb_query_pointer_reply_t *xqp; area_t finalgeometry = c->f_geometry; - if(XQueryPointer(globalconf.display, RootWindow(globalconf.display, get_phys_screen(c->screen)), - &dummy, &dummy, &x, &y, &d, &d, &m)) + if((xqp = xcb_query_pointer_reply(globalconf.connection, + xcb_query_pointer(globalconf.connection, + root_window(globalconf.connection, get_phys_screen(c->screen))), + NULL)) != NULL) { - finalgeometry.x = x - c->f_geometry.width / 2; - finalgeometry.y = y - c->f_geometry.height / 2; + finalgeometry.x = xqp->root_x - c->f_geometry.width / 2; + finalgeometry.y = xqp->root_y - c->f_geometry.height / 2; } finalgeometry = placement_geometry_add_titlebar(&c->titlebar, finalgeometry); diff --git a/rules.c b/rules.c index 4aa8f15..33a5441 100644 --- a/rules.c +++ b/rules.c @@ -19,8 +19,6 @@ * */ -#include - #include "rules.h" #include "common/xutil.h" @@ -43,59 +41,63 @@ rules_compile_regex(char *val) return NULL; } -static Bool +static bool client_match_rule(Client *c, Rule *r) { char *prop, buf[512]; regmatch_t tmp; ssize_t len; - XClassHint ch = { 0, 0 }; - Bool ret = False; + class_hint_t *ch = NULL; + bool ret = false; if(r->prop_r) { /* first try to match on name */ - XGetClassHint(globalconf.display, c->win, &ch); + ch = x_get_class_hint(globalconf.connection, c->win); + if (!ch) + return false; - len = a_strlen(ch.res_class) + a_strlen(ch.res_name) + a_strlen(c->name); + len = a_strlen(ch->res_class) + a_strlen(ch->res_name) + a_strlen(c->name); prop = p_new(char, len + 3); /* rule matching */ snprintf(prop, len + 3, "%s:%s:%s", - ch.res_class ? ch.res_class : "", ch.res_name ? ch.res_name : "", c->name); + ch->res_class ? ch->res_class : "", ch->res_name ? ch->res_name : "", c->name); ret = !regexec(r->prop_r, prop, 1, &tmp, 0); p_delete(&prop); - if(ch.res_class) - XFree(ch.res_class); - if(ch.res_name) - XFree(ch.res_name); + if(ch->res_class) + p_delete(&ch->res_class); + if(ch->res_name) + p_delete(&ch->res_name); + + p_delete(&ch); if(ret) - return True; + return true; } if(r->xprop && r->xpropval_r - && xgettextprop(globalconf.display, c->win, - XInternAtom(globalconf.display, r->xprop, False), + && xgettextprop(globalconf.connection, c->win, + x_intern_atom(globalconf.connection, r->xprop), buf, ssizeof(buf))) ret = !regexec(r->xpropval_r, buf, 1, &tmp, 0); return ret; } -Bool +bool tag_match_rule(Tag *t, Rule *r) { regmatch_t tmp; if(r->tags_r && !regexec(r->tags_r, t->name, 1, &tmp, 0)) - return True; + return true; - return False; + return false; } Rule * diff --git a/rules.h b/rules.h index f6108be..54acabf 100644 --- a/rules.h +++ b/rules.h @@ -27,7 +27,7 @@ #define RULE_NOSCREEN -1 regex_t * rules_compile_regex(char *); -Bool tag_match_rule(Tag *, Rule *); +bool tag_match_rule(Tag *, Rule *); Fuzzy rules_get_fuzzy_from_str(const char *); Rule * rule_matching_client(Client *); diff --git a/screen.c b/screen.c index 5e65e0f..7173add 100644 --- a/screen.c +++ b/screen.c @@ -19,6 +19,11 @@ * */ +#include + +#include +#include + #include "screen.h" #include "tag.h" #include "focus.h" @@ -79,9 +84,10 @@ get_display_area(int screen, Statusbar *statusbar, Padding *padding) { area_t area = { 0, 0, 0, 0, NULL, NULL }; Statusbar *sb; + xcb_screen_t *s = xcb_aux_get_screen(globalconf.connection, screen); - area.width = DisplayWidth(globalconf.display, screen); - area.height = DisplayHeight(globalconf.display, screen); + area.width = s->width_in_pixels; + area.height = s->height_in_pixels; for(sb = statusbar; sb; sb = sb->next) { @@ -109,18 +115,18 @@ int get_phys_screen(int screen) { if(globalconf.screens_info->xinerama_is_active) - return DefaultScreen(globalconf.display); + return globalconf.default_screen; return screen; } /** Move a client to a virtual screen * \param c the client * \param new_screen The destinatiuon screen - * \param doresize set to True if we also move the client to the new x and + * \param doresize set to true if we also move the client to the new x and * y of the new screen */ void -move_client_to_screen(Client *c, int new_screen, Bool doresize) +move_client_to_screen(Client *c, int new_screen, bool doresize) { Tag *tag; int old_screen = c->screen; @@ -189,17 +195,17 @@ move_client_to_screen(Client *c, int new_screen, Bool doresize) if(c->m_geometry.y + c->m_geometry.height >= to.y + to.height) c->m_geometry.y = to.y + to.height - c->m_geometry.height - 2 * c->border; - client_resize(c, new_geometry, False); + client_resize(c, new_geometry, false); } /* if floating, move to this new coords */ else if(c->isfloating) - client_resize(c, new_f_geometry, False); + client_resize(c, new_f_geometry, false); /* otherwise just register them */ else { c->f_geometry = new_f_geometry; - globalconf.screens[old_screen].need_arrange = True; - globalconf.screens[c->screen].need_arrange = True; + globalconf.screens[old_screen].need_arrange = true; + globalconf.screens[c->screen].need_arrange = true; } } } @@ -210,19 +216,21 @@ move_client_to_screen(Client *c, int new_screen, Bool doresize) static void move_mouse_pointer_to_screen(int phys_screen) { + xcb_screen_t *s = xcb_aux_get_screen(globalconf.connection, phys_screen); + if(globalconf.screens_info->xinerama_is_active) { area_t area = screen_get_area(phys_screen, NULL, NULL); - XWarpPointer(globalconf.display, - None, - DefaultRootWindow(globalconf.display), - 0, 0, 0, 0, area.x, area.y); + xcb_warp_pointer(globalconf.connection, + XCB_NONE, + s->root, + 0, 0, 0, 0, area.x, area.y); } else - XWarpPointer(globalconf.display, - None, - RootWindow(globalconf.display, phys_screen), - 0, 0, 0, 0, 0, 0); + xcb_warp_pointer(globalconf.connection, + XCB_NONE, + root_window(globalconf.connection, phys_screen), + 0, 0, 0, 0, 0, 0); } @@ -246,7 +254,7 @@ uicb_screen_focus(int screen, char *arg) if (new_screen > (globalconf.screens_info->nscreen - 1)) new_screen = 0; - client_focus(NULL, new_screen, True); + client_focus(NULL, new_screen, true); move_mouse_pointer_to_screen(new_screen); } @@ -276,8 +284,8 @@ uicb_client_movetoscreen(int screen __attribute__ ((unused)), char *arg) new_screen = globalconf.screens_info->nscreen - 1; prev_screen = sel->screen; - move_client_to_screen(sel, new_screen, True); + move_client_to_screen(sel, new_screen, true); move_mouse_pointer_to_screen(new_screen); - client_focus(sel, sel->screen, True); + client_focus(sel, sel->screen, true); } // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/screen.h b/screen.h index 6a79f93..3ca71ab 100644 --- a/screen.h +++ b/screen.h @@ -27,7 +27,7 @@ area_t screen_get_area(int, Statusbar *, Padding *); area_t get_display_area(int, Statusbar *, Padding *); int get_phys_screen(int); -void move_client_to_screen(Client *, int, Bool); +void move_client_to_screen(Client *, int, bool); Uicb uicb_screen_focus; Uicb uicb_client_movetoscreen; diff --git a/statusbar.c b/statusbar.c index fbf502f..ec5b815 100644 --- a/statusbar.c +++ b/statusbar.c @@ -21,6 +21,8 @@ #include #include +#include +#include #include "statusbar.h" #include "screen.h" @@ -35,14 +37,16 @@ statusbar_position_update(Statusbar *statusbar) { Statusbar *sb; area_t area; + const uint32_t map_raised_val = XCB_STACK_MODE_ABOVE; if(statusbar->position == Off) { - XUnmapWindow(globalconf.display, statusbar->sw->window); + xcb_unmap_window(globalconf.connection, statusbar->sw->window); return; } - XMapRaised(globalconf.display, statusbar->sw->window); + xcb_configure_window(globalconf.connection, statusbar->sw->window, + XCB_CONFIG_WINDOW_STACK_MODE, &map_raised_val); /* Top and Bottom Statusbar have prio */ if(statusbar->position == Top || statusbar->position == Bottom) @@ -111,7 +115,8 @@ statusbar_draw(Statusbar *statusbar) Widget *widget; int left = 0, right = 0; area_t rectangle = { 0, 0, 0, 0, NULL, NULL }; - Drawable d; + xcb_drawable_t d; + xcb_screen_t *s = xcb_aux_get_screen(globalconf.connection, phys_screen); /* don't waste our time */ switch(statusbar->position) @@ -122,18 +127,19 @@ statusbar_draw(Statusbar *statusbar) case Right: case Left: /* we need a new pixmap this way [ ] to render */ - XFreePixmap(globalconf.display, statusbar->sw->drawable); - d = XCreatePixmap(globalconf.display, - RootWindow(globalconf.display, phys_screen), - statusbar->width, statusbar->height, - DefaultDepth(globalconf.display, phys_screen)); + xcb_free_pixmap(globalconf.connection, statusbar->sw->drawable); + d = xcb_generate_id(globalconf.connection); + xcb_create_pixmap(globalconf.connection, + s->root_depth, d, + root_window(globalconf.connection, phys_screen), + statusbar->width, statusbar->height); statusbar->sw->drawable = d; break; default: break; } - DrawCtx *ctx = draw_context_new(globalconf.display, + DrawCtx *ctx = draw_context_new(globalconf.connection, phys_screen, statusbar->width, statusbar->height, @@ -141,13 +147,13 @@ statusbar_draw(Statusbar *statusbar) rectangle.width = statusbar->width; rectangle.height = statusbar->height; - draw_rectangle(ctx, rectangle, True, + draw_rectangle(ctx, rectangle, true, globalconf.screens[statusbar->screen].styles.normal.bg); for(widget = statusbar->widgets; widget; widget = widget->next) if (widget->alignment == AlignLeft) { - widget->cache.needs_update = False; + widget->cache.needs_update = false; left += widget->draw(widget, ctx, left, (left + right)); } @@ -157,14 +163,14 @@ statusbar_draw(Statusbar *statusbar) widget = widget_list_prev(&statusbar->widgets, widget)) if (widget->alignment == AlignRight) { - widget->cache.needs_update = False; + widget->cache.needs_update = false; right += widget->draw(widget, ctx, right, (left + right)); } for(widget = statusbar->widgets; widget; widget = widget->next) if (widget->alignment == AlignFlex) { - widget->cache.needs_update = False; + widget->cache.needs_update = false; left += widget->draw(widget, ctx, left, (left + right)); } @@ -173,13 +179,13 @@ statusbar_draw(Statusbar *statusbar) case Right: d = draw_rotate(ctx, phys_screen, M_PI_2, statusbar->height, 0); - XFreePixmap(globalconf.display, statusbar->sw->drawable); + xcb_free_pixmap(globalconf.connection, statusbar->sw->drawable); statusbar->sw->drawable = d; break; case Left: d = draw_rotate(ctx, phys_screen, - M_PI_2, 0, statusbar->width); - XFreePixmap(globalconf.display, statusbar->sw->drawable); + xcb_free_pixmap(globalconf.connection, statusbar->sw->drawable); statusbar->sw->drawable = d; break; default: @@ -244,12 +250,12 @@ statusbar_init(Statusbar *statusbar) case Right: case Left: statusbar->sw = - simplewindow_new(globalconf.display, phys_screen, 0, 0, + simplewindow_new(globalconf.connection, phys_screen, 0, 0, statusbar->height, statusbar->width, 0); break; default: statusbar->sw = - simplewindow_new(globalconf.display, phys_screen, 0, 0, + simplewindow_new(globalconf.connection, phys_screen, 0, 0, statusbar->width, statusbar->height, 0); break; } @@ -300,7 +306,7 @@ statusbar_toggle(Statusbar *statusbar) else statusbar->position = Off; - globalconf.screens[statusbar->screen].need_arrange = True; + globalconf.screens[statusbar->screen].need_arrange = true; } /** Toggle statusbar diff --git a/structs.h b/structs.h index fc5e019..6a6da2c 100644 --- a/structs.h +++ b/structs.h @@ -22,6 +22,8 @@ #ifndef AWESOME_STRUCTS_H #define AWESOME_STRUCTS_H +#include + #include #include "layout.h" #include "common/draw.h" @@ -31,8 +33,8 @@ /** Rules for floating rule */ typedef enum { - No = False, - Yes = True, + No = false, + Yes = true, Maybe } Fuzzy; @@ -72,7 +74,7 @@ typedef struct Key Key; struct Key { unsigned long mod; - KeyCode keycode; + xcb_keycode_t keycode; Uicb *func; char *arg; /** Next and previous keys */ @@ -116,16 +118,16 @@ struct Widget /** Update function */ widget_tell_status_t (*tell)(Widget *, char *, char *); /** ButtonPressedEvent handler */ - void (*button_press)(Widget *, XButtonPressedEvent *); + void (*button_press)(Widget *, xcb_button_press_event_t *); /** Statusbar */ Statusbar *statusbar; /** Alignement */ Alignment alignment; /** Misc private data */ void *data; - /** True if user supplied coords */ - Bool user_supplied_x; - Bool user_supplied_y; + /** true if user supplied coords */ + bool user_supplied_x; + bool user_supplied_y; /** area_t */ area_t area; /** Buttons bindings */ @@ -133,7 +135,7 @@ struct Widget /** Cache */ struct { - Bool needs_update; + bool needs_update; int flags; } cache; /** Next and previous widgets */ @@ -179,29 +181,29 @@ struct Client int minax, maxax, minay, maxay; int border, oldborder; /** Has urgency hint */ - Bool isurgent; + bool isurgent; /** Store previous floating state before maximizing */ - Bool wasfloating; - /** True if the window is floating */ - Bool isfloating; - /** True if the window is fixed */ - Bool isfixed; - /** True if the window is maximized */ - Bool ismax; - /** True if the client must be skipped from client list */ - Bool skip; - /** True if the client is moving */ - Bool ismoving; - /** True if the client must be skipped from task bar client list */ - Bool skiptb; + bool wasfloating; + /** true if the window is floating */ + bool isfloating; + /** true if the window is fixed */ + bool isfixed; + /** true if the window is maximized */ + bool ismax; + /** true if the client must be skipped from client list */ + bool skip; + /** true if the client is moving */ + bool ismoving; + /** true if the client must be skipped from task bar client list */ + bool skiptb; /** Next and previous clients */ Client *prev, *next; /** Window of the client */ - Window win; + xcb_window_t win; /** Client logical screen */ int screen; - /** True if the client is a new one */ - Bool newcomer; + /** true if the client is a new one */ + bool newcomer; /** Titlebar */ Titlebar titlebar; }; @@ -222,10 +224,10 @@ struct Tag char *name; /** Screen */ int screen; - /** True if selected */ - Bool selected; - /** True if was selected before selecting others tags */ - Bool was_selected; + /** true if selected */ + bool selected; + /** true if was selected before selecting others tags */ + bool was_selected; /** Current tag layout */ Layout *layout; /** Master width factor */ @@ -275,17 +277,17 @@ typedef struct /** Floating window placement algo */ FloatingPlacement *floating_placement; /** Respect resize hints */ - Bool resize_hints; + bool resize_hints; /** Sloppy focus: focus follow mouse */ - Bool sloppy_focus; - /** True if we should raise windows on focus */ - Bool sloppy_focus_raise; + bool sloppy_focus; + /** true if we should raise windows on focus */ + bool sloppy_focus_raise; /** Focus new clients */ - Bool new_get_focus; - /** True if new clients should become master */ - Bool new_become_master; - /** True if we need to arrange() */ - Bool need_arrange; + bool new_get_focus; + /** true if new clients should become master */ + bool new_become_master; + /** true if we need to arrange() */ + bool need_arrange; /** Colors */ struct { @@ -309,8 +311,12 @@ typedef struct typedef struct AwesomeConf AwesomeConf; struct AwesomeConf { - /** Display ref */ - Display *display; + /** Connection ref */ + xcb_connection_t *connection; + /** Event and error handlers */ + event_handlers_t *evenths; + /** Default screen number */ + int default_screen; /** Logical screens */ VirtScreen *screens; /** Screens info */ @@ -329,18 +335,18 @@ struct AwesomeConf /** Numlock mask */ unsigned int numlockmask; /** Check for XShape extension */ - Bool have_shape; + bool have_shape; /** Check for XRandR extension */ - Bool have_randr; + bool have_randr; /** Cursors */ - Cursor cursor[CurLast]; + xcb_cursor_t cursor[CurLast]; /** Clients list */ Client *clients; /** Scratch client */ struct { Client *client; - Bool isvisible; + bool isvisible; } scratch; /** Path to config file */ char *configpath; diff --git a/tag.c b/tag.c index fc7ef14..2c20518 100644 --- a/tag.c +++ b/tag.c @@ -85,7 +85,7 @@ tag_client(Client *c, Tag *t) client_saveprops(c); widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS); - globalconf.screens[c->screen].need_arrange = True; + globalconf.screens[c->screen].need_arrange = true; } void @@ -103,22 +103,22 @@ untag_client(Client *c, Tag *t) client_saveprops(c); widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS); - globalconf.screens[c->screen].need_arrange = True; + globalconf.screens[c->screen].need_arrange = true; } -Bool +bool is_client_tagged(Client *c, Tag *t) { tag_client_node_t *tc; if(!c) - return False; + return false; for(tc = globalconf.tclink; tc; tc = tc->next) if(tc->client == c && tc->tag == t) - return True; + return true; - return False; + return false; } void @@ -138,7 +138,7 @@ void tag_client_with_rule(Client *c, Rule *r) { Tag *tag; - Bool matched = False; + bool matched = false; if(!r) return; @@ -146,7 +146,7 @@ tag_client_with_rule(Client *c, Rule *r) for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next) if(tag_match_rule(tag, r)) { - matched = True; + matched = true; break; } @@ -279,7 +279,7 @@ uicb_tag_toggleview(int screen, char *arg) /* check that there's at least one tag selected */ for(tag = globalconf.screens[screen].tags; tag && !tag->selected; tag = tag->next); if(!tag) - tag_view(target_tag, True); + tag_view(target_tag, true); } else for(tag = globalconf.screens[screen].tags; tag; tag = tag->next) @@ -298,7 +298,7 @@ tag_view_only(Tag *target) } void -tag_view_byindex(int screen, int dindex, Bool view) +tag_view_byindex(int screen, int dindex, bool view) { Tag *tag; @@ -324,13 +324,13 @@ tag_view_only_byindex(int screen, int dindex) } void -tag_view(Tag *tag, Bool view) +tag_view(Tag *tag, bool view) { tag->was_selected = tag->selected; tag->selected = view; ewmh_update_net_current_desktop(get_phys_screen(tag->screen)); widget_invalidate_cache(tag->screen, WIDGET_CACHE_TAGS); - globalconf.screens[tag->screen].need_arrange = True; + globalconf.screens[tag->screen].need_arrange = true; } /** View tag @@ -347,7 +347,7 @@ uicb_tag_view(int screen, char *arg) tag_view_only_byindex(screen, atoi(arg) - 1); else for(tag = globalconf.screens[screen].tags; tag; tag = tag->next) - tag_view(tag, True); + tag_view(tag, true); } /** View previously selected tags @@ -376,8 +376,8 @@ uicb_tag_viewnext(int screen, char *arg __attribute__ ((unused))) tag = tag_list_next_cycle(&globalconf.screens[screen].tags, curtags[0]); - tag_view(curtags[0], False); - tag_view(tag, True); + tag_view(curtags[0], false); + tag_view(tag, true); p_delete(&curtags); } @@ -394,8 +394,8 @@ uicb_tag_viewprev(int screen, char *arg __attribute__ ((unused))) tag = tag_list_prev_cycle(&globalconf.screens[screen].tags, curtags[0]); - tag_view(curtags[0], False); - tag_view(tag, True); + tag_view(curtags[0], false); + tag_view(tag, true); p_delete(&curtags); } diff --git a/tag.h b/tag.h index 79ef6fa..3f2caa5 100644 --- a/tag.h +++ b/tag.h @@ -28,13 +28,13 @@ #define IS_TILED(client, screen) (client && !client->isfloating && !client->ismax && client_isvisible(client, screen)) Tag * tag_new(const char *, Layout *, double, int, int); -void tag_view(Tag *, Bool); -void tag_view_byindex(int, int, Bool); +void tag_view(Tag *, bool); +void tag_view_byindex(int, int, bool); void tag_push_to_screen(Tag *, int); Tag ** tags_get_current(int); void tag_client(Client *, Tag *); void untag_client(Client *, Tag *); -Bool is_client_tagged(Client *, Tag *); +bool is_client_tagged(Client *, Tag *); void tag_client_with_rule(Client *, Rule *r); void tag_client_with_current_selected(Client *); void tag_view_only_byindex(int, int); diff --git a/titlebar.c b/titlebar.c index 46e5316..c222870 100644 --- a/titlebar.c +++ b/titlebar.c @@ -19,6 +19,9 @@ * */ +#include +#include + #include #include "titlebar.h" @@ -37,7 +40,7 @@ titlebar_init(Client *c) switch(c->titlebar.position) { case Top: - c->titlebar.sw = simplewindow_new(globalconf.display, + c->titlebar.sw = simplewindow_new(globalconf.connection, phys_screen, c->geometry.x, c->geometry.y - titlebar_height, @@ -46,7 +49,7 @@ titlebar_init(Client *c) 0); break; case Bottom: - c->titlebar.sw = simplewindow_new(globalconf.display, + c->titlebar.sw = simplewindow_new(globalconf.connection, phys_screen, c->geometry.x, c->geometry.y + c->geometry.height + 2 * c->border, @@ -55,7 +58,7 @@ titlebar_init(Client *c) 0); break; case Left: - c->titlebar.sw = simplewindow_new(globalconf.display, + c->titlebar.sw = simplewindow_new(globalconf.connection, phys_screen, c->geometry.x - titlebar_height, c->geometry.y, @@ -64,7 +67,7 @@ titlebar_init(Client *c) 0); break; case Right: - c->titlebar.sw = simplewindow_new(globalconf.display, + c->titlebar.sw = simplewindow_new(globalconf.connection, phys_screen, c->geometry.x + c->geometry.width + 2 * c->border, c->geometry.y, @@ -83,28 +86,32 @@ titlebar_init(Client *c) void titlebar_update(Client *c) { - Drawable d; + xcb_drawable_t d; DrawCtx *ctx; style_t style; area_t geometry; + xcb_screen_t *s; if(!c->titlebar.sw) return; + s = xcb_aux_get_screen(globalconf.connection, + c->titlebar.sw->phys_screen); + switch(c->titlebar.position) { case Off: return; case Right: case Left: - XFreePixmap(globalconf.display, c->titlebar.sw->drawable); - c->titlebar.sw->drawable = - XCreatePixmap(globalconf.display, - RootWindow(globalconf.display, c->titlebar.sw->phys_screen), + xcb_free_pixmap(globalconf.connection, c->titlebar.sw->drawable); + c->titlebar.sw->drawable = xcb_generate_id(globalconf.connection); + xcb_create_pixmap(globalconf.connection, s->root_depth, + c->titlebar.sw->drawable, + root_window(globalconf.connection, c->titlebar.sw->phys_screen), c->titlebar.sw->geometry.height, - c->titlebar.sw->geometry.width, - DefaultDepth(globalconf.display, c->titlebar.sw->phys_screen)); - ctx = draw_context_new(globalconf.display, c->titlebar.sw->phys_screen, + c->titlebar.sw->geometry.width); + ctx = draw_context_new(globalconf.connection, c->titlebar.sw->phys_screen, c->titlebar.sw->geometry.height, c->titlebar.sw->geometry.width, c->titlebar.sw->drawable); @@ -112,7 +119,7 @@ titlebar_update(Client *c) geometry.height = c->titlebar.sw->geometry.width; break; default: - ctx = draw_context_new(globalconf.display, c->titlebar.sw->phys_screen, + ctx = draw_context_new(globalconf.connection, c->titlebar.sw->phys_screen, c->titlebar.sw->geometry.width, c->titlebar.sw->geometry.height, c->titlebar.sw->drawable); @@ -138,13 +145,13 @@ titlebar_update(Client *c) case Left: d = draw_rotate(ctx, c->titlebar.sw->phys_screen, - M_PI_2, 0, c->titlebar.sw->geometry.height); - XFreePixmap(globalconf.display, c->titlebar.sw->drawable); + xcb_free_pixmap(globalconf.connection, c->titlebar.sw->drawable); c->titlebar.sw->drawable = d; break; case Right: d = draw_rotate(ctx, c->titlebar.sw->phys_screen, M_PI_2, c->titlebar.sw->geometry.width, 0); - XFreePixmap(globalconf.display, c->titlebar.sw->drawable); + xcb_free_pixmap(globalconf.connection, c->titlebar.sw->drawable); c->titlebar.sw->drawable = d; default: break; @@ -268,10 +275,10 @@ uicb_client_toggletitlebar(int screen __attribute__ ((unused)), else { c->titlebar.position = Off; - XUnmapWindow(globalconf.display, c->titlebar.sw->window); + xcb_unmap_window(globalconf.connection, c->titlebar.sw->window); } - globalconf.screens[c->screen].need_arrange = True; + globalconf.screens[c->screen].need_arrange = true; } // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/uicb.c b/uicb.c index 067b765..55153a7 100644 --- a/uicb.c +++ b/uicb.c @@ -31,6 +31,9 @@ #include #include +#include +#include + #include "awesome.h" #include "tag.h" #include "mouse.h" @@ -61,7 +64,7 @@ uicb_exec(int screen __attribute__ ((unused)), char *cmd) for(c = globalconf.clients; c; c = c->next) client_unban(c); - XSync(globalconf.display, False); + xcb_aux_sync(globalconf.connection); /* Ignore the leading spaces if any */ while(cmd[0] && cmd[0] == ' ') @@ -114,8 +117,8 @@ uicb_spawn(int screen, char *arg) { if(fork() == 0) { - if(globalconf.display) - close(ConnectionNumber(globalconf.display)); + if(globalconf.connection) + close(xcb_get_file_descriptor(globalconf.connection)); setsid(); execl(shell, shell, "-c", arg, NULL); warn("execl '%s -c %s' failed: %s\n", shell, arg, strerror(errno)); diff --git a/widget.c b/widget.c index 1650294..1aa879b 100644 --- a/widget.c +++ b/widget.c @@ -112,12 +112,12 @@ widget_find(char *name, int screen) * \param ev the XButtonPressedEvent the widget received */ static void -widget_common_button_press(Widget *widget, XButtonPressedEvent *ev) +widget_common_button_press(Widget *widget, xcb_button_press_event_t *ev) { Button *b; for(b = widget->buttons; b; b = b->next) - if(ev->button == b->button && CLEANMASK(ev->state) == b->mod && b->func) + if(ev->detail == b->button && CLEANMASK(ev->state) == b->mod && b->func) { b->func(widget->statusbar->screen, b->arg); break; @@ -173,7 +173,7 @@ widget_invalidate_cache(int screen, int flags) statusbar = statusbar->next) for(widget = statusbar->widgets; widget; widget = widget->next) if(widget->cache.flags & flags) - widget->cache.needs_update = True; + widget->cache.needs_update = true; } /** Send command to widget @@ -263,7 +263,7 @@ uicb_widget_tell(int screen, char *arg) else widget->tell(widget, property, NULL); - widget->cache.needs_update = True; + widget->cache.needs_update = true; return; } diff --git a/widgets/graph.c b/widgets/graph.c index c9d61b5..9fafe81 100644 --- a/widgets/graph.c +++ b/widgets/graph.c @@ -25,6 +25,7 @@ #include "common/util.h" #include "common/draw.h" #include "common/configopts.h" +#include "common/xutil.h" extern AwesomeConf globalconf; @@ -39,8 +40,8 @@ typedef struct int box_height; /** Height of the innerbox in pixels */ int padding_left; /** Left padding */ int size; /** Size of lines-array (also innerbox-lenght) */ - XColor bg; /** Background color */ - XColor bordercolor; /** Border color */ + xcolor_t bg; /** Background color */ + xcolor_t bordercolor; /** Border color */ Position grow; /** grow: Left or Right */ /* markers... */ @@ -57,24 +58,24 @@ typedef struct int **fillbottom; /** Data array pointer (like *lines) */ int **fillbottom_index; /** Points to some index[i] */ int fillbottom_total; /** Total of them */ - Bool *fillbottom_vertical_grad; /** Create a vertical color gradient */ - XColor *fillbottom_color; /** Color of them */ - XColor **fillbottom_pcolor_center; /** Color at middle of graph */ - XColor **fillbottom_pcolor_end; /** Color at end of graph */ + bool *fillbottom_vertical_grad; /** Create a vertical color gradient */ + xcolor_t *fillbottom_color; /** Color of them */ + xcolor_t **fillbottom_pcolor_center; /** Color at middle of graph */ + xcolor_t **fillbottom_pcolor_end; /** Color at end of graph */ int **filltop; /** Data array pointer (like *lines) */ int **filltop_index; /** Points to some index[i] */ int filltop_total; /** Total of them */ - Bool *filltop_vertical_grad; /** Create a vertical color gradient */ - XColor *filltop_color; /** Color of them */ - XColor **filltop_pcolor_center; /** Color at center of graph */ - XColor **filltop_pcolor_end; /** Color at end of graph */ + bool *filltop_vertical_grad; /** Create a vertical color gradient */ + xcolor_t *filltop_color; /** Color of them */ + xcolor_t **filltop_pcolor_center; /** Color at center of graph */ + xcolor_t **filltop_pcolor_end; /** Color at end of graph */ int **drawline; /** Data array pointer (like *lines) */ int **drawline_index; /** Points to some index[i] */ int drawline_total; /** Total of them */ - Bool *drawline_vertical_grad; /** Create a vertical color gradient */ - XColor *drawline_color; /** Color of them */ - XColor **drawline_pcolor_center; /** Color at middle of graph */ - XColor **drawline_pcolor_end; /** Color at end of graph */ + bool *drawline_vertical_grad; /** Create a vertical color gradient */ + xcolor_t *drawline_color; /** Color of them */ + xcolor_t **drawline_pcolor_center; /** Color at middle of graph */ + xcolor_t **drawline_pcolor_end; /** Color at end of graph */ int *draw_from; /** Preparation/tmp array for draw_graph(); */ int *draw_to; /** Preparation/tmp array for draw_graph(); */ @@ -113,13 +114,13 @@ graph_draw(Widget *widget, DrawCtx *ctx, int offset, rectangle.y = margin_top; rectangle.width = d->size + 2; rectangle.height = d->box_height + 2; - draw_rectangle(ctx, rectangle, False, d->bordercolor); + draw_rectangle(ctx, rectangle, false, d->bordercolor); rectangle.x++; rectangle.y++; rectangle.width = d->size; rectangle.height -= 2; - draw_rectangle(ctx, rectangle, True, d->bg); + draw_rectangle(ctx, rectangle, true, d->bg); /* for graph drawing */ rectangle.x = left_offset + 2; @@ -338,13 +339,13 @@ graph_tell(Widget *widget, char *property, char *command) d->height = atof(command); else if(!a_strcmp(property, "bg")) { - if(!draw_color_new(globalconf.display, get_phys_screen(widget->statusbar->screen), + if(!draw_color_new(globalconf.connection, get_phys_screen(widget->statusbar->screen), command, &d->bg)) return WIDGET_ERROR_FORMAT_COLOR; } else if(!a_strcmp(property, "bordercolor")) { - if(!draw_color_new(globalconf.display, get_phys_screen(widget->statusbar->screen), + if(!draw_color_new(globalconf.connection, get_phys_screen(widget->statusbar->screen), command, &d->bordercolor)) return WIDGET_ERROR_FORMAT_COLOR; } @@ -375,9 +376,9 @@ graph_new(Statusbar *statusbar, cfg_t *config) int phys_screen = get_phys_screen(statusbar->screen); int i; char *type; - XColor tmp_color = { 0, 0, 0, 0, 0, 0 }; - XColor *ptmp_color_center; - XColor *ptmp_color_end; + xcolor_t tmp_color = { 0, 0, 0, 0 }; + xcolor_t *ptmp_color_center; + xcolor_t *ptmp_color_end; w = p_new(Widget, 1); widget_common_new(w, statusbar, config); @@ -426,18 +427,18 @@ graph_new(Statusbar *statusbar, cfg_t *config) d->values = p_new(float *, d->data_items); d->lines = p_new(int *, d->data_items); - d->filltop_color = p_new(XColor, d->data_items); - d->filltop_pcolor_center = p_new(XColor *, d->data_items); - d->filltop_pcolor_end = p_new(XColor *, d->data_items); - d->filltop_vertical_grad = p_new(Bool, d->data_items); - d->fillbottom_color = p_new(XColor, d->data_items); - d->fillbottom_pcolor_center = p_new(XColor *, d->data_items); - d->fillbottom_pcolor_end = p_new(XColor *, d->data_items); - d->fillbottom_vertical_grad = p_new(Bool, d->data_items); - d->drawline_color = p_new(XColor, d->data_items); - d->drawline_pcolor_center = p_new(XColor *, d->data_items); - d->drawline_pcolor_end = p_new(XColor *, d->data_items); - d->drawline_vertical_grad = p_new(Bool, d->data_items); + d->filltop_color = p_new(xcolor_t, d->data_items); + d->filltop_pcolor_center = p_new(xcolor_t *, d->data_items); + d->filltop_pcolor_end = p_new(xcolor_t *, d->data_items); + d->filltop_vertical_grad = p_new(bool, d->data_items); + d->fillbottom_color = p_new(xcolor_t, d->data_items); + d->fillbottom_pcolor_center = p_new(xcolor_t *, d->data_items); + d->fillbottom_pcolor_end = p_new(xcolor_t *, d->data_items); + d->fillbottom_vertical_grad = p_new(bool, d->data_items); + d->drawline_color = p_new(xcolor_t, d->data_items); + d->drawline_pcolor_center = p_new(xcolor_t *, d->data_items); + d->drawline_pcolor_end = p_new(xcolor_t *, d->data_items); + d->drawline_vertical_grad = p_new(bool, d->data_items); d->max_index = p_new(int, d->data_items); d->index = p_new(int, d->data_items); @@ -454,20 +455,20 @@ graph_new(Statusbar *statusbar, cfg_t *config) d->data_title[i] = a_strdup(cfg_title(cfg)); if((color = cfg_getstr(cfg, "fg"))) - draw_color_new(globalconf.display, phys_screen, color, &tmp_color); + draw_color_new(globalconf.connection, phys_screen, color, &tmp_color); else tmp_color = globalconf.screens[statusbar->screen].styles.normal.fg; if((color = cfg_getstr(cfg, "fg_center"))) { - ptmp_color_center = p_new(XColor, 1); - draw_color_new(globalconf.display, phys_screen, color, ptmp_color_center); + ptmp_color_center = p_new(xcolor_t, 1); + draw_color_new(globalconf.connection, phys_screen, color, ptmp_color_center); } if((color = cfg_getstr(cfg, "fg_end"))) { - ptmp_color_end = p_new(XColor, 1); - draw_color_new(globalconf.display, phys_screen, color, ptmp_color_end); + ptmp_color_end = p_new(xcolor_t, 1); + draw_color_new(globalconf.connection, phys_screen, color, ptmp_color_end); } if (cfg_getbool(cfg, "scale")) @@ -522,12 +523,12 @@ graph_new(Statusbar *statusbar, cfg_t *config) } if((color = cfg_getstr(config, "bg"))) - draw_color_new(globalconf.display, phys_screen, color, &d->bg); + draw_color_new(globalconf.connection, phys_screen, color, &d->bg); else d->bg = globalconf.screens[statusbar->screen].styles.normal.bg; if((color = cfg_getstr(config, "bordercolor"))) - draw_color_new(globalconf.display, phys_screen, color, &d->bordercolor); + draw_color_new(globalconf.connection, phys_screen, color, &d->bordercolor); else d->bordercolor = tmp_color; diff --git a/widgets/iconbox.c b/widgets/iconbox.c index 3a3410f..79601fe 100644 --- a/widgets/iconbox.c +++ b/widgets/iconbox.c @@ -28,7 +28,7 @@ extern AwesomeConf globalconf; typedef struct { char *image; - Bool resize; + bool resize; } Data; static int @@ -67,7 +67,7 @@ iconbox_draw(Widget *widget, DrawCtx *ctx, int offset, static widget_tell_status_t iconbox_tell(Widget *widget, char *property, char *command) { - Bool b; + bool b; Data *d = widget->data; if(!property || !command) diff --git a/widgets/progressbar.c b/widgets/progressbar.c index 0a9bb37..f3a7a33 100644 --- a/widgets/progressbar.c +++ b/widgets/progressbar.c @@ -41,23 +41,23 @@ typedef struct /** Pixel between data_items (bars) */ int gap; /** reverse drawing */ - Bool *reverse; + bool *reverse; /** 90 Degree's turned */ - Bool vertical; + bool vertical; /** Number of data_items (bars) */ int data_items; /** Height 0-1, where 1 is height of statusbar */ float height; /** Foreground color */ - XColor *fg; + xcolor_t *fg; /** Foreground color when bar is half-full */ - XColor **pfg_center; + xcolor_t **pfg_center; /** Foreground color when bar is full */ - XColor **pfg_end; + xcolor_t **pfg_end; /** Background color */ - XColor *bg; + xcolor_t *bg; /** Border color */ - XColor *bordercolor; + xcolor_t *bordercolor; } Data; static int @@ -113,7 +113,7 @@ progressbar_draw(Widget *widget, DrawCtx *ctx, int offset, rectangle.y = pb_y; rectangle.width = pb_width; rectangle.height = pb_height; - draw_rectangle(ctx, rectangle, False, d->bordercolor[i]); + draw_rectangle(ctx, rectangle, false, d->bordercolor[i]); /* new value/progress in px + pattern setup */ if(!d->reverse[i]) @@ -145,10 +145,10 @@ progressbar_draw(Widget *widget, DrawCtx *ctx, int offset, /* fg color */ if(!d->reverse[i]) - draw_rectangle_gradient(ctx, rectangle, True, pattern_rect, + draw_rectangle_gradient(ctx, rectangle, true, pattern_rect, &(d->fg[i]), d->pfg_center[i], d->pfg_end[i]); else /*REV: bg */ - draw_rectangle(ctx, rectangle, True, d->bg[i]); + draw_rectangle(ctx, rectangle, true, d->bg[i]); } /* top part */ @@ -161,9 +161,9 @@ progressbar_draw(Widget *widget, DrawCtx *ctx, int offset, /* bg color */ if(!d->reverse[i]) - draw_rectangle(ctx, rectangle, True, d->bg[i]); + draw_rectangle(ctx, rectangle, true, d->bg[i]); else /* REV: bg */ - draw_rectangle_gradient(ctx, rectangle, True, pattern_rect, + draw_rectangle_gradient(ctx, rectangle, true, pattern_rect, &(d->fg[i]), d->pfg_center[i], d->pfg_end[i]); } pb_offset += pb_width + d->gap; @@ -178,7 +178,7 @@ progressbar_draw(Widget *widget, DrawCtx *ctx, int offset, rectangle.y = pb_y + pb_offset; rectangle.width = pb_width; rectangle.height = pb_height; - draw_rectangle(ctx, rectangle, False, d->bordercolor[i]); + draw_rectangle(ctx, rectangle, false, d->bordercolor[i]); /* new value/progress in px + pattern setup */ if(!d->reverse[i]) @@ -210,10 +210,10 @@ progressbar_draw(Widget *widget, DrawCtx *ctx, int offset, /* fg color */ if(!d->reverse[i]) - draw_rectangle_gradient(ctx, rectangle, True, pattern_rect, + draw_rectangle_gradient(ctx, rectangle, true, pattern_rect, &(d->fg[i]), d->pfg_center[i], d->pfg_end[i]); else /* REV: bg */ - draw_rectangle(ctx, rectangle, True, d->bg[i]); + draw_rectangle(ctx, rectangle, true, d->bg[i]); } /* right part */ @@ -226,9 +226,9 @@ progressbar_draw(Widget *widget, DrawCtx *ctx, int offset, /* bg color */ if(!d->reverse[i]) - draw_rectangle(ctx, rectangle, True, d->bg[i]); + draw_rectangle(ctx, rectangle, true, d->bg[i]); else /* REV: fg */ - draw_rectangle_gradient(ctx, rectangle, True, pattern_rect, + draw_rectangle_gradient(ctx, rectangle, true, pattern_rect, &(d->fg[i]), d->pfg_center[i], d->pfg_end[i]); } pb_offset += pb_height + d->gap; @@ -245,7 +245,7 @@ progressbar_tell(Widget *widget, char *property, char *command) { Data *d = widget->data; int i = 0, percent, tmp; - Bool flag; + bool flag; char *title, *setting; if(!d->data_items) @@ -276,7 +276,7 @@ progressbar_tell(Widget *widget, char *property, char *command) for(i = 0; i < d->data_items; i++) if(!a_strcmp(title, d->data_title[i])) { - if(draw_color_new(globalconf.display, get_phys_screen(widget->statusbar->screen), + if(draw_color_new(globalconf.connection, get_phys_screen(widget->statusbar->screen), setting, &d->fg[i])) return WIDGET_NOERROR; else @@ -292,7 +292,7 @@ progressbar_tell(Widget *widget, char *property, char *command) for(i = 0; i < d->data_items; i++) if(!a_strcmp(title, d->data_title[i])) { - if(draw_color_new(globalconf.display, get_phys_screen(widget->statusbar->screen), + if(draw_color_new(globalconf.connection, get_phys_screen(widget->statusbar->screen), setting, &d->bg[i])) return WIDGET_NOERROR; else @@ -308,13 +308,13 @@ progressbar_tell(Widget *widget, char *property, char *command) for(i = 0; i < d->data_items; i++) if(!a_strcmp(title, d->data_title[i])) { - flag = False; + flag = false; if(!d->pfg_center[i]) { - flag = True; /* p_delete && restore to NULL, if draw_color_new unsuccessful */ - d->pfg_center[i] = p_new(XColor, 1); + flag = true; /* p_delete && restore to NULL, if draw_color_new unsuccessful */ + d->pfg_center[i] = p_new(xcolor_t, 1); } - if(!(draw_color_new(globalconf.display, get_phys_screen(widget->statusbar->screen), + if(!(draw_color_new(globalconf.connection, get_phys_screen(widget->statusbar->screen), setting, d->pfg_center[i]))) { if(flag) /* restore */ @@ -336,13 +336,13 @@ progressbar_tell(Widget *widget, char *property, char *command) for(i = 0; i < d->data_items; i++) if(!a_strcmp(title, d->data_title[i])) { - flag = False; + flag = false; if(!d->pfg_end[i]) { - flag = True; - d->pfg_end[i] = p_new(XColor, 1); + flag = true; + d->pfg_end[i] = p_new(xcolor_t, 1); } - if(!(draw_color_new(globalconf.display, get_phys_screen(widget->statusbar->screen), + if(!(draw_color_new(globalconf.connection, get_phys_screen(widget->statusbar->screen), setting, d->pfg_end[i]))) { if(flag) /* restore */ @@ -363,7 +363,7 @@ progressbar_tell(Widget *widget, char *property, char *command) for(i = 0; i < d->data_items; i++) if(!a_strcmp(title, d->data_title[i])) { - if(draw_color_new(globalconf.display, get_phys_screen(widget->statusbar->screen), + if(draw_color_new(globalconf.connection, get_phys_screen(widget->statusbar->screen), setting, &d->bordercolor[i])) return WIDGET_NOERROR; else @@ -430,7 +430,7 @@ progressbar_new(Statusbar *statusbar, cfg_t *config) d->gap = cfg_getint(config, "gap"); d->padding = cfg_getint(config, "padding"); if(!(d->vertical = cfg_getbool(config, "vertical"))) - d->vertical = False; + d->vertical = false; w->alignment = cfg_getalignment(config, "align"); @@ -440,13 +440,13 @@ progressbar_new(Statusbar *statusbar, cfg_t *config) return w; } - d->fg = p_new(XColor, d->data_items); - d->pfg_end = p_new(XColor *, d->data_items); - d->pfg_center = p_new(XColor *, d->data_items); - d->bg = p_new(XColor, d->data_items); - d->bordercolor = p_new(XColor, d->data_items); + d->fg = p_new(xcolor_t, d->data_items); + d->pfg_end = p_new(xcolor_t *, d->data_items); + d->pfg_center = p_new(xcolor_t *, d->data_items); + d->bg = p_new(xcolor_t, d->data_items); + d->bordercolor = p_new(xcolor_t, d->data_items); d->percent = p_new(int, d->data_items); - d->reverse = p_new(Bool, d->data_items); + d->reverse = p_new(bool, d->data_items); d->data_title = p_new(char *, d->data_items); for(i = 0; i < d->data_items; i++) @@ -456,32 +456,32 @@ progressbar_new(Statusbar *statusbar, cfg_t *config) d->data_title[i] = a_strdup(cfg_title(cfg)); if(!(d->reverse[i] = cfg_getbool(cfg, "reverse"))) - d->reverse[i] = False; + d->reverse[i] = false; if((color = cfg_getstr(cfg, "fg"))) - draw_color_new(globalconf.display, phys_screen, color, &d->fg[i]); + draw_color_new(globalconf.connection, phys_screen, color, &d->fg[i]); else d->fg[i] = globalconf.screens[statusbar->screen].styles.normal.fg; if((color = cfg_getstr(cfg, "fg_center"))) { - d->pfg_center[i] = p_new(XColor, 1); - draw_color_new(globalconf.display, phys_screen, color, d->pfg_center[i]); + d->pfg_center[i] = p_new(xcolor_t, 1); + draw_color_new(globalconf.connection, phys_screen, color, d->pfg_center[i]); } if((color = cfg_getstr(cfg, "fg_end"))) { - d->pfg_end[i] = p_new(XColor, 1); - draw_color_new(globalconf.display, phys_screen, color, d->pfg_end[i]); + d->pfg_end[i] = p_new(xcolor_t, 1); + draw_color_new(globalconf.connection, phys_screen, color, d->pfg_end[i]); } if((color = cfg_getstr(cfg, "bg"))) - draw_color_new(globalconf.display, phys_screen, color, &d->bg[i]); + draw_color_new(globalconf.connection, phys_screen, color, &d->bg[i]); else d->bg[i] = globalconf.screens[statusbar->screen].styles.normal.bg; if((color = cfg_getstr(cfg, "bordercolor"))) - draw_color_new(globalconf.display, phys_screen, color, &d->bordercolor[i]); + draw_color_new(globalconf.connection, phys_screen, color, &d->bordercolor[i]); else d->bordercolor[i] = d->fg[i]; } diff --git a/widgets/taglist.c b/widgets/taglist.c index 571352d..ede66ba 100644 --- a/widgets/taglist.c +++ b/widgets/taglist.c @@ -33,30 +33,30 @@ extern AwesomeConf globalconf; * screen * \param screen screen number * \param t tag - * \return True or False + * \return true or false */ -static Bool +static bool isoccupied(Tag *t) { Client *c; for(c = globalconf.clients; c; c = c->next) if(is_client_tagged(c, t) && !c->skip && c != globalconf.scratch.client) - return True; + return true; - return False; + return false; } -static Bool +static bool isurgent(Tag *t) { Client *c; for(c = globalconf.clients; c; c = c->next) if(is_client_tagged(c, t) && c->isurgent) - return True; + return true; - return False; + return false; } static style_t @@ -90,7 +90,8 @@ taglist_draw(Widget *widget, for(tag = vscreen.tags; tag; tag = tag->next) { style = tag->selected ? vscreen.styles.focus : vscreen.styles.normal; - widget->area.width += draw_textwidth(ctx->display, style.font, tag->name) + widget->area.width += draw_textwidth(ctx->connection, ctx->default_screen, + style.font, tag->name) + style.font->height; } @@ -107,7 +108,8 @@ taglist_draw(Widget *widget, for(tag = vscreen.tags; tag; tag = tag->next) { style = taglist_style_get(vscreen, tag); - w = draw_textwidth(ctx->display, style.font, tag->name) + style.font->height; + w = draw_textwidth(ctx->connection, ctx->default_screen, + style.font, tag->name) + style.font->height; area.x = widget->area.x + widget->area.width; area.y = widget->area.y; area.width = w; @@ -135,7 +137,7 @@ taglist_draw(Widget *widget, } static void -taglist_button_press(Widget *widget, XButtonPressedEvent *ev) +taglist_button_press(Widget *widget, xcb_button_press_event_t *ev) { VirtScreen vscreen = globalconf.screens[widget->statusbar->screen]; Button *b; @@ -145,7 +147,7 @@ taglist_button_press(Widget *widget, XButtonPressedEvent *ev) style_t style; for(b = widget->buttons; b; b = b->next) - if(ev->button == b->button && CLEANMASK(ev->state) == b->mod && b->func) + if(ev->detail == b->button && CLEANMASK(ev->state) == b->mod && b->func) switch(widget->statusbar->position) { case Top: @@ -153,10 +155,11 @@ taglist_button_press(Widget *widget, XButtonPressedEvent *ev) for(tag = vscreen.tags; tag; tag = tag->next, i++) { style = taglist_style_get(vscreen, tag); - width = draw_textwidth(globalconf.display, style.font, tag->name) + width = draw_textwidth(globalconf.connection, globalconf.default_screen, + style.font, tag->name) + style.font->height; - if(ev->x >= widget->area.x + prev_width - && ev->x < widget->area.x + prev_width + width) + if(ev->event_x >= widget->area.x + prev_width + && ev->event_x < widget->area.x + prev_width + width) { snprintf(buf, sizeof(buf), "%d", i); b->func(widget->statusbar->screen, buf); @@ -169,9 +172,10 @@ taglist_button_press(Widget *widget, XButtonPressedEvent *ev) for(tag = vscreen.tags; tag; tag = tag->next, i++) { style = taglist_style_get(vscreen, tag); - width = draw_textwidth(globalconf.display, style.font, tag->name) + style.font->height; - if(ev->y >= widget->area.x + prev_width - && ev->y < widget->area.x + prev_width + width) + width = draw_textwidth(globalconf.connection, globalconf.default_screen, + style.font, tag->name) + style.font->height; + if(ev->event_y >= widget->area.x + prev_width + && ev->event_y < widget->area.x + prev_width + width) { snprintf(buf, sizeof(buf), "%d", i); b->func(widget->statusbar->screen, buf); @@ -184,9 +188,10 @@ taglist_button_press(Widget *widget, XButtonPressedEvent *ev) for(tag = vscreen.tags; tag; tag = tag->next, i++) { style = taglist_style_get(vscreen, tag); - width = draw_textwidth(globalconf.display, style.font, tag->name) + style.font->height; - if(widget->statusbar->width - ev->y >= widget->area.x + prev_width - && widget->statusbar->width - ev->y < widget->area.x + prev_width + width) + width = draw_textwidth(globalconf.connection, globalconf.default_screen, + style.font, tag->name) + style.font->height; + if(widget->statusbar->width - ev->event_y >= widget->area.x + prev_width + && widget->statusbar->width - ev->event_y < widget->area.x + prev_width + width) { snprintf(buf, sizeof(buf), "%d", i); b->func(widget->statusbar->screen, buf); diff --git a/widgets/tasklist.c b/widgets/tasklist.c index 2180008..30e7ac2 100644 --- a/widgets/tasklist.c +++ b/widgets/tasklist.c @@ -42,7 +42,7 @@ typedef enum typedef struct { ShowClient show; - Bool show_icons; + bool show_icons; Alignment align; struct { @@ -52,29 +52,29 @@ typedef struct } styles; } Data; -static inline Bool +static inline bool tasklist_isvisible(Client *c, int screen, ShowClient show) { if(c->skip || c->skiptb) - return False; + return false; switch(show) { case ShowAll: if(c->screen == screen) - return True; + return true; break; case ShowTags: if(client_isvisible(c, screen)) - return True; + return true; break; case ShowFocus: if(c == globalconf.focus->client) - return True; + return true; break; } - return False; + return false; } static int @@ -132,7 +132,7 @@ tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used) area.height = widget->statusbar->height; area.width = box_width; - draw_rectangle(ctx, area, True, style.bg); + draw_rectangle(ctx, area, true, style.bg); if((r = rule_matching_client(c)) && r->icon) { @@ -198,7 +198,7 @@ tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used) } static void -tasklist_button_press(Widget *widget, XButtonPressedEvent *ev) +tasklist_button_press(Widget *widget, xcb_button_press_event_t *ev) { Button *b; Client *c; @@ -207,7 +207,7 @@ tasklist_button_press(Widget *widget, XButtonPressedEvent *ev) int n = 0, box_width = 0, i, ci = 0; /* button1 give focus */ - if(ev->button == Button1 && CLEANMASK(ev->state) == NoSymbol) + if(ev->detail == XCB_BUTTON_INDEX_1 && CLEANMASK(ev->state) == XCB_NO_SYMBOL) { for(c = globalconf.clients; c; c = c->next) if(tasklist_isvisible(c, widget->statusbar->screen, d->show)) @@ -218,19 +218,19 @@ tasklist_button_press(Widget *widget, XButtonPressedEvent *ev) box_width = widget->area.width / n; - if(ev->button == Button1 && CLEANMASK(ev->state) == NoSymbol) + if(ev->detail == XCB_BUTTON_INDEX_1 && CLEANMASK(ev->state) == XCB_NO_SYMBOL) { switch(widget->statusbar->position) { case Top: case Bottom: - ci = (ev->x - widget->area.x) / box_width; + ci = (ev->event_x - widget->area.x) / box_width; break; case Right: - ci = (ev->y - widget->area.x) / box_width; + ci = (ev->event_y - widget->area.x) / box_width; break; default: - ci = ((widget->statusbar->width - ev->y) - widget->area.x) / box_width; + ci = ((widget->statusbar->width - ev->event_y) - widget->area.x) / box_width; break; } /* found first visible client */ @@ -250,7 +250,7 @@ tasklist_button_press(Widget *widget, XButtonPressedEvent *ev) for(i = 0, tag = globalconf.screens[c->screen].tags; tag; tag = tag->next, i++) if(is_client_tagged(c, tag)) tag_view_only_byindex(c->screen, i); - client_focus(c, widget->statusbar->screen, True); + client_focus(c, widget->statusbar->screen, true); } return; @@ -258,7 +258,7 @@ tasklist_button_press(Widget *widget, XButtonPressedEvent *ev) } for(b = widget->buttons; b; b = b->next) - if(ev->button == b->button && CLEANMASK(ev->state) == b->mod && b->func) + if(ev->detail == b->button && CLEANMASK(ev->state) == b->mod && b->func) { b->func(widget->statusbar->screen, b->arg); return; @@ -283,17 +283,17 @@ tasklist_new(Statusbar *statusbar, cfg_t *config) cfg_styles = cfg_getsec(config, "styles"); - draw_style_init(globalconf.display, phys_screen, + draw_style_init(globalconf.connection, phys_screen, cfg_getsec(cfg_styles, "normal"), &d->styles.normal, &globalconf.screens[statusbar->screen].styles.normal); - draw_style_init(globalconf.display, phys_screen, + draw_style_init(globalconf.connection, phys_screen, cfg_getsec(cfg_styles, "focus"), &d->styles.focus, &globalconf.screens[statusbar->screen].styles.focus); - draw_style_init(globalconf.display, phys_screen, + draw_style_init(globalconf.connection, phys_screen, cfg_getsec(cfg_styles, "urgent"), &d->styles.urgent, &globalconf.screens[statusbar->screen].styles.urgent); diff --git a/widgets/textbox.c b/widgets/textbox.c index 2fbd069..f9d5f61 100644 --- a/widgets/textbox.c +++ b/widgets/textbox.c @@ -44,7 +44,8 @@ textbox_draw(Widget *widget, DrawCtx *ctx, int offset, int used) else if(widget->alignment == AlignFlex) widget->area.width = widget->statusbar->width - used; else - widget->area.width = MIN(draw_textwidth(ctx->display, d->style.font, d->text), + widget->area.width = MIN(draw_textwidth(ctx->connection, ctx->default_screen, + d->style.font, d->text), widget->statusbar->width - used); widget->area.height = widget->statusbar->height; @@ -78,18 +79,18 @@ textbox_tell(Widget *widget, char *property, char *command) else if(!command) return WIDGET_ERROR_NOVALUE; else if(!a_strcmp(property, "fg")) - if(draw_color_new(globalconf.display, widget->statusbar->screen, command, &d->style.fg)) + if(draw_color_new(globalconf.connection, widget->statusbar->screen, command, &d->style.fg)) return WIDGET_NOERROR; else return WIDGET_ERROR_FORMAT_COLOR; else if(!a_strcmp(property, "bg")) - if(draw_color_new(globalconf.display, widget->statusbar->screen, command, &d->style.bg)) + if(draw_color_new(globalconf.connection, widget->statusbar->screen, command, &d->style.bg)) return WIDGET_NOERROR; else return WIDGET_ERROR_FORMAT_COLOR; else if(!a_strcmp(property, "font")) { - if((newfont = draw_font_new(globalconf.display, command))) + if((newfont = draw_font_new(globalconf.connection, globalconf.default_screen, command))) { if(d->style.font != globalconf.screens[widget->statusbar->screen].styles.normal.font) draw_font_free(d->style.font); @@ -123,7 +124,7 @@ textbox_new(Statusbar *statusbar, cfg_t *config) w->data = d = p_new(Data, 1); - draw_style_init(globalconf.display, phys_screen, + draw_style_init(globalconf.connection, phys_screen, cfg_getsec(config, "style"), &d->style, &globalconf.screens[statusbar->screen].styles.normal); diff --git a/window.c b/window.c index 7725020..ae4f9fb 100644 --- a/window.c +++ b/window.c @@ -19,8 +19,9 @@ * */ -#include -#include +#include +#include +#include #include "structs.h" #include "window.h" @@ -28,21 +29,22 @@ extern AwesomeConf globalconf; /** Mask shorthands */ -#define BUTTONMASK (ButtonPressMask | ButtonReleaseMask) +#define BUTTONMASK (XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE) /** Set client WM_STATE property * \param win Window * \param state state * \return XChangeProperty result */ -int -window_setstate(Window win, long state) +void +window_setstate(xcb_window_t win, long state) { - long data[] = { state, None }; + long data[] = { state, XCB_NONE }; - return XChangeProperty(globalconf.display, win, XInternAtom(globalconf.display, "WM_STATE", False), - XInternAtom(globalconf.display, "WM_STATE", False), 32, - PropModeReplace, (unsigned char *) data, 2); + xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, win, + x_intern_atom(globalconf.connection, "WM_STATE"), + x_intern_atom(globalconf.connection, "WM_STATE"), 32, + 2, data); } /** Get a window state (WM_STATE) @@ -50,20 +52,27 @@ window_setstate(Window win, long state) * \return state */ long -window_getstate(Window w) +window_getstate(xcb_window_t w) { - int format; long result = -1; unsigned char *p = NULL; - unsigned long n, extra; - Atom real; - if(XGetWindowProperty(globalconf.display, w, XInternAtom(globalconf.display, "WM_STATE", False), - 0L, 2L, False, XInternAtom(globalconf.display, "WM_STATE", False), - &real, &format, &n, &extra, (unsigned char **) &p) != Success) + xcb_get_property_cookie_t prop_c; + xcb_atom_t wm_state_atom = x_intern_atom(globalconf.connection, "WM_STATE"); + xcb_get_property_reply_t *prop_r; + + prop_c = xcb_get_property_unchecked(globalconf.connection, false, w, + wm_state_atom, wm_state_atom, + 0L, 2L); + + if((prop_r = xcb_get_property_reply(globalconf.connection, prop_c, NULL)) == NULL) return -1; - if(n != 0) + + p = xcb_get_property_value(prop_r); + if(xcb_get_property_value_length(prop_r) != 0) result = *p; - p_delete(&p); + + p_delete(&prop_r); + return result; } @@ -73,13 +82,12 @@ window_getstate(Window w) * \param border new border size * \return the XSendEvent() status */ -Status -window_configure(Window win, area_t geometry, int border) +void +window_configure(xcb_window_t win, area_t geometry, int border) { - XConfigureEvent ce; + xcb_configure_notify_event_t ce; - ce.type = ConfigureNotify; - ce.display = globalconf.display; + ce.response_type = XCB_CONFIGURE_NOTIFY; ce.event = win; ce.window = win; ce.x = geometry.x; @@ -87,9 +95,9 @@ window_configure(Window win, area_t geometry, int border) ce.width = geometry.width; ce.height = geometry.height; ce.border_width = border; - ce.above = None; - ce.override_redirect = False; - return XSendEvent(globalconf.display, win, False, StructureNotifyMask, (XEvent *) & ce); + ce.above_sibling = XCB_NONE; + ce.override_redirect = false; + xcb_send_event(globalconf.connection, false, win, XCB_EVENT_MASK_STRUCTURE_NOTIFY, (char *) &ce); } /** Grab or ungrab buttons on a window @@ -97,32 +105,41 @@ window_configure(Window win, area_t geometry, int border) * \param win The window */ void -window_grabbuttons(int phys_screen, Window win) +window_grabbuttons(int phys_screen, xcb_window_t win) { Button *b; - XGrabButton(globalconf.display, Button1, NoSymbol, - win, False, BUTTONMASK, GrabModeSync, GrabModeAsync, None, None); - XGrabButton(globalconf.display, Button1, NoSymbol | LockMask, - win, False, BUTTONMASK, GrabModeSync, GrabModeAsync, None, None); - XGrabButton(globalconf.display, Button1, NoSymbol | globalconf.numlockmask, - win, False, BUTTONMASK, GrabModeSync, GrabModeAsync, None, None); - XGrabButton(globalconf.display, Button1, NoSymbol | globalconf.numlockmask | LockMask, - win, False, BUTTONMASK, GrabModeSync, GrabModeAsync, None, None); + xcb_grab_button(globalconf.connection, false, win, BUTTONMASK, + XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE, + XCB_BUTTON_INDEX_1, XCB_NO_SYMBOL); + xcb_grab_button(globalconf.connection, false, win, BUTTONMASK, + XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE, + XCB_BUTTON_INDEX_1, XCB_NO_SYMBOL | XCB_MOD_MASK_LOCK); + xcb_grab_button(globalconf.connection, false, win, BUTTONMASK, + XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE, + XCB_BUTTON_INDEX_1, XCB_NO_SYMBOL | globalconf.numlockmask); + xcb_grab_button(globalconf.connection, false, win, BUTTONMASK, + XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE, + XCB_BUTTON_INDEX_1, XCB_NO_SYMBOL | globalconf.numlockmask | XCB_MOD_MASK_LOCK); for(b = globalconf.buttons.client; b; b = b->next) { - XGrabButton(globalconf.display, b->button, b->mod, - win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None); - XGrabButton(globalconf.display, b->button, b->mod | LockMask, - win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None); - XGrabButton(globalconf.display, b->button, b->mod | globalconf.numlockmask, - win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None); - XGrabButton(globalconf.display, b->button, b->mod | globalconf.numlockmask | LockMask, - win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None); + xcb_grab_button(globalconf.connection, false, win, BUTTONMASK, + XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC, XCB_NONE, XCB_NONE, + b->button, b->mod); + xcb_grab_button(globalconf.connection, false, win, BUTTONMASK, + XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC, XCB_NONE, XCB_NONE, + b->button, b->mod | XCB_MOD_MASK_LOCK); + xcb_grab_button(globalconf.connection, false, win, BUTTONMASK, + XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC, XCB_NONE, XCB_NONE, + b->button, b->mod | globalconf.numlockmask); + xcb_grab_button(globalconf.connection, false, win, BUTTONMASK, + XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC, XCB_NONE, XCB_NONE, + b->button, b->mod | globalconf.numlockmask | XCB_MOD_MASK_LOCK); } - XUngrabButton(globalconf.display, AnyButton, AnyModifier, RootWindow(globalconf.display, phys_screen)); + xcb_ungrab_button(globalconf.connection, XCB_BUTTON_INDEX_ANY, + root_window(globalconf.connection, phys_screen), ANY_MODIFIER); } /** Grab buttons on root window @@ -135,18 +152,22 @@ window_root_grabbuttons(int phys_screen) for(b = globalconf.buttons.root; b; b = b->next) { - XGrabButton(globalconf.display, b->button, b->mod, - RootWindow(globalconf.display, phys_screen), False, BUTTONMASK, - GrabModeAsync, GrabModeSync, None, None); - XGrabButton(globalconf.display, b->button, b->mod | LockMask, - RootWindow(globalconf.display, phys_screen), False, BUTTONMASK, - GrabModeAsync, GrabModeSync, None, None); - XGrabButton(globalconf.display, b->button, b->mod | globalconf.numlockmask, - RootWindow(globalconf.display, phys_screen), False, BUTTONMASK, - GrabModeAsync, GrabModeSync, None, None); - XGrabButton(globalconf.display, b->button, b->mod | globalconf.numlockmask | LockMask, - RootWindow(globalconf.display, phys_screen), False, BUTTONMASK, - GrabModeAsync, GrabModeSync, None, None); + xcb_grab_button(globalconf.connection, false, + root_window(globalconf.connection, phys_screen), BUTTONMASK, + XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC, XCB_NONE, XCB_NONE, + b->button, b->mod); + xcb_grab_button(globalconf.connection, false, + root_window(globalconf.connection, phys_screen), BUTTONMASK, + XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC, XCB_NONE, XCB_NONE, + b->button, b->mod | XCB_MOD_MASK_LOCK); + xcb_grab_button(globalconf.connection, false, + root_window(globalconf.connection, phys_screen), BUTTONMASK, + XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC, XCB_NONE, XCB_NONE, + b->button, b->mod | globalconf.numlockmask); + xcb_grab_button(globalconf.connection, false, + root_window(globalconf.connection, phys_screen), BUTTONMASK, + XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC, XCB_NONE, XCB_NONE, + b->button, b->mod | globalconf.numlockmask | XCB_MOD_MASK_LOCK); } } @@ -158,51 +179,58 @@ window_root_grabkeys(int phys_screen) { Key *k; - XUngrabKey(globalconf.display, AnyKey, AnyModifier, RootWindow(globalconf.display, phys_screen)); + xcb_ungrab_key(globalconf.connection, ANY_KEY, + root_window(globalconf.connection, phys_screen), ANY_MODIFIER); for(k = globalconf.keys; k; k = k->next) if(k->keycode) { - XGrabKey(globalconf.display, k->keycode, k->mod, - RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync); - XGrabKey(globalconf.display, k->keycode, k->mod | LockMask, - RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync); - XGrabKey(globalconf.display, k->keycode, k->mod | globalconf.numlockmask, - RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync); - XGrabKey(globalconf.display, k->keycode, k->mod | globalconf.numlockmask | LockMask, - RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync); + xcb_grab_key(globalconf.connection, true, root_window(globalconf.connection, phys_screen), + k->mod, k->keycode, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC); + xcb_grab_key(globalconf.connection, true, root_window(globalconf.connection, phys_screen), + k->mod | XCB_MOD_MASK_LOCK, k->keycode, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC); + xcb_grab_key(globalconf.connection, true, root_window(globalconf.connection, phys_screen), + k->mod | globalconf.numlockmask, k->keycode, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC); + xcb_grab_key(globalconf.connection, true, root_window(globalconf.connection, phys_screen), + k->mod | globalconf.numlockmask | XCB_MOD_MASK_LOCK, k->keycode, XCB_GRAB_MODE_ASYNC, + XCB_GRAB_MODE_ASYNC); } } void -window_setshape(int screen, Window win) +window_setshape(int screen, xcb_window_t win) { - int bounding_shaped; - int i, b; unsigned int u; /* dummies */ /* Logic to decide if we have a shaped window cribbed from fvwm-2.5.10. */ - if(XShapeQueryExtents(globalconf.display, win, &bounding_shaped, &i, &i, - &u, &u, &b, &i, &i, &u, &u) && bounding_shaped) - XShapeCombineShape(globalconf.display, RootWindow(globalconf.display, screen), ShapeBounding, 0, 0, win, ShapeBounding, ShapeSet); + xcb_shape_query_extents_reply_t *r; + + if((r = xcb_shape_query_extents_reply(globalconf.connection, + xcb_shape_query_extents_unchecked(globalconf.connection, win), + NULL)) && r->bounding_shaped) + { + xcb_shape_combine(globalconf.connection, XCB_SHAPE_SO_SET, + XCB_SHAPE_SK_BOUNDING, XCB_SHAPE_SK_BOUNDING, + root_window(globalconf.connection, screen), + 0, 0, win); + + p_delete(&r); + } } -int -window_settrans(Window win, double opacity) +void +window_settrans(xcb_window_t win, double opacity) { - int status; unsigned int real_opacity = 0xffffffff; if(opacity >= 0 && opacity <= 100) { real_opacity = ((opacity / 100.0) * 0xffffffff); - status = XChangeProperty(globalconf.display, win, - XInternAtom(globalconf.display, "_NET_WM_WINDOW_OPACITY", False), - XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &real_opacity, 1L); + xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, win, + x_intern_atom(globalconf.connection, "_NET_WM_WINDOW_OPACITY"), + CARDINAL, 32, 1L, &real_opacity); } else - status = XDeleteProperty(globalconf.display, win, - XInternAtom(globalconf.display, "_NET_WM_WINDOW_OPACITY", False)); - - return status; + xcb_delete_property(globalconf.connection, win, + x_intern_atom(globalconf.connection, "_NET_WM_WINDOW_OPACITY")); } // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/window.h b/window.h index 1febf3f..7da9291 100644 --- a/window.h +++ b/window.h @@ -24,14 +24,14 @@ #include "common/draw.h" -int window_setstate(Window, long); -long window_getstate(Window); -Status window_configure(Window, area_t, int); -void window_grabbuttons(int, Window); +void window_setstate(xcb_window_t, long); +long window_getstate(xcb_window_t); +void window_configure(xcb_window_t, area_t, int); +void window_grabbuttons(int, xcb_window_t); void window_root_grabbuttons(int); void window_root_grabkeys(int); -void window_setshape(int, Window); -int window_settrans(Window, double); +void window_setshape(int, xcb_window_t); +void window_settrans(xcb_window_t, double); #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/xcb_event_handler.c b/xcb_event_handler.c new file mode 100644 index 0000000..b9aa0e2 --- /dev/null +++ b/xcb_event_handler.c @@ -0,0 +1,242 @@ +#include +#include +#include + +#include "xcb_event_handler.h" +#include "common/util.h" + +const char *x_label_error[] = +{ + "Success", + "BadRequest", + "BadValue", + "BadWindow", + "BadPixmap", + "BadAtom", + "BadCursor", + "BadFont", + "BadMatch", + "BadDrawable", + "BadAccess", + "BadAlloc", + "BadColor", + "BadGC", + "BadIDChoice", + "BadName", + "BadLength", + "BadImplementation", +}; + +const char *x_label_request[] = +{ + "XCB_NONE", + "CreateWindow", + "ChangeWindowAttributes", + "GetWindowAttributes", + "DestroyWindow", + "DestroySubwindows", + "ChangeSaveSet", + "ReparentWindow", + "MapWindow", + "MapSubwindows", + "UnmapWindow", + "UnmapSubwindows", + "ConfigureWindow", + "CirculateWindow", + "GetGeometry", + "QueryTree", + "InternAtom", + "GetAtomName", + "ChangeProperty", + "DeleteProperty", + "GetProperty", + "ListProperties", + "SetSelectionOwner", + "GetSelectionOwner", + "ConvertSelection", + "SendEvent", + "GrabPointer", + "UngrabPointer", + "GrabButton", + "UngrabButton", + "ChangeActivePointerGrab", + "GrabKeyboard", + "UngrabKeyboard", + "GrabKey", + "UngrabKey", + "AllowEvents", + "GrabServer", + "UngrabServer", + "QueryPointer", + "GetMotionEvents", + "TranslateCoords", + "WarpPointer", + "SetInputFocus", + "GetInputFocus", + "QueryKeymap", + "OpenFont", + "CloseFont", + "QueryFont", + "QueryTextExtents", + "ListFonts", + "ListFontsWithInfo", + "SetFontPath", + "GetFontPath", + "CreatePixmap", + "FreePixmap", + "CreateGC", + "ChangeGC", + "CopyGC", + "SetDashes", + "SetClipRectangles", + "FreeGC", + "ClearArea", + "CopyArea", + "CopyPlane", + "PolyPoint", + "PolyLine", + "PolySegment", + "PolyRectangle", + "PolyArc", + "FillPoly", + "PolyFillRectangle", + "PolyFillArc", + "PutImage", + "GetImage", + "PolyText", + "PolyText", + "ImageText", + "ImageText", + "CreateColormap", + "FreeColormap", + "CopyColormapAndFree", + "InstallColormap", + "UninstallColormap", + "ListInstalledColormaps", + "AllocColor", + "AllocNamedColor", + "AllocColorCells", + "AllocColorPlanes", + "FreeColors", + "StoreColors", + "StoreNamedColor", + "QueryColors", + "LookupColor", + "CreateCursor", + "CreateGlyphCursor", + "FreeCursor", + "RecolorCursor", + "QueryBestSize", + "QueryExtension", + "ListExtensions", + "ChangeKeyboardMapping", + "GetKeyboardMapping", + "ChangeKeyboardControl", + "GetKeyboardControl", + "Bell", + "ChangePointerControl", + "GetPointerControl", + "SetScreenSaver", + "GetScreenSaver", + "ChangeHosts", + "ListHosts", + "SetAccessControl", + "SetCloseDownMode", + "KillClient", + "RotateProperties", + "ForceScreenSaver", + "SetPointerMapping", + "GetPointerMapping", + "SetModifierMapping", + "GetModifierMapping", + "major 120", + "major 121", + "major 122", + "major 123", + "major 124", + "major 125", + "major 126", + "NoOperation", +}; + +#ifndef HAVE_XCB_POLL_FOR_EVENT_LOOP +/* + * Private ``xcb_event'' interface needed in order to write a similar + * ``even_loop()'' function which doesn't block + * + * TODO: need to be remove as soon as it's fixed by xcb-util authors + */ +typedef struct event_handler event_handler_t; + +struct event_handler { + generic_event_handler handler; + void *data; +}; + +struct event_handlers { + event_handler_t event[EVENTS_NBR]; + event_handler_t error[ERRORS_NBR]; + xcb_connection_t *c; +}; + +static event_handler_t * +get_event_handler(event_handlers_t *evenths, int event) +{ + assert(event < ERRORS_NBR); + event &= 0x7f; + assert(event >= 2); + return &evenths->event[event - 2]; +} + +static event_handler_t * +get_error_handler(event_handlers_t *evenths, int error) +{ + assert(error >= 0 && error < ERRORS_NBR); + return &evenths->error[error]; +} +/* End of ``xcb_event'' private interface */ + +/** Process events in the queue without blocking + * \param evenths previously allocated event handlers + * + * TODO: cleanup + */ +void xcb_poll_for_event_loop(event_handlers_t *evenths) +{ + xcb_generic_event_t *event; + while ((event = xcb_poll_for_event(evenths->c))) + { + handle_event(evenths, event); +p_delete(&event); + } +} +#endif + +#ifndef HAVE_XCB_HANDLE_EVENT +int +handle_event(event_handlers_t *evenths, xcb_generic_event_t *event) +{ + event_handler_t *eventh = 0; + assert(event->response_type != 1); + + if(event->response_type == 0) + eventh = get_error_handler(evenths, ((xcb_generic_error_t *) event)->error_code); + else + eventh = get_event_handler(evenths, event->response_type); + + if(eventh->handler) + return eventh->handler(eventh->data, evenths->c, event); + return 0; +} +#endif + +/** Set the same handler for all errors + */ +void set_error_handler_catch_all(event_handlers_t *evenths, + generic_error_handler handler, + void *data) +{ + int err_num; + for(err_num = 0; err_num < ERRORS_NBR; err_num++) + set_error_handler(evenths, err_num, handler, data); +} diff --git a/xcb_event_handler.h b/xcb_event_handler.h new file mode 100644 index 0000000..0365372 --- /dev/null +++ b/xcb_event_handler.h @@ -0,0 +1,41 @@ +#ifndef XCB_EVENT_HANDLER_H +#define XCB_EVENT_HANDLER_H + +#include +#include +#include + +#ifndef HAVE_XCB_POLL_FOR_EVENT_LOOP +/* + * 'xcb_event' public interface only provide 'event_loop()' function + * which blocks until an event or an error arrive, or an I/O error + * occurs. Unfortunately, there is no function which doesn't block. + * + * TODO: check whether this function has already been defined in + * 'xcb_event.h' as this function has been sent to xcb-util mailing + * list + */ +void xcb_poll_for_event_loop(event_handlers_t *); +#endif + +/* Set the same handler for all errors */ +void set_error_handler_catch_all(event_handlers_t *, + generic_error_handler, void *); + +/* Number of different errors */ +#define ERRORS_NBR 256 + +/* Number of different events */ +#define EVENTS_NBR 126 + +/* Get the error name from its code */ +extern const char *x_label_error[]; + +/* Get a request name from its code */ +extern const char *x_label_request[]; + +#ifndef HAVE_XCB_HANDLE_EVENT +int handle_event(event_handlers_t *, xcb_generic_event_t *); +#endif + +#endif