X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=spectrwm.c;h=781cdd98bd1c296ddaabb7139bf9947286342278;hb=b086f741a61b80d021c0ea7aa0ba8e65049a91d4;hp=c912e3f57e690df03c731680ccac694dc670ffb5;hpb=ff9fc42a008c56f255e9eabe5f79151c0232cf73;p=spectrwm.git diff --git a/spectrwm.c b/spectrwm.c index c912e3f..781cdd9 100644 --- a/spectrwm.c +++ b/spectrwm.c @@ -354,8 +354,8 @@ TAILQ_HEAD(swm_region_list, swm_region); struct ws_win { TAILQ_ENTRY(ws_win) entry; - Window id; - Window transient; + xcb_window_t id; + xcb_window_t transient; struct ws_win *child_trans; /* transient child window */ struct swm_geometry g; /* current geometry */ struct swm_geometry g_float; /* region coordinates */ @@ -402,12 +402,12 @@ void max_stack(struct workspace *, struct swm_geometry *); void plain_stacker(struct workspace *); void fancy_stacker(struct workspace *); -struct ws_win *find_window(Window); +struct ws_win *find_window(xcb_window_t); void grabbuttons(struct ws_win *, int); void new_region(struct swm_screen *, int, int, int, int); void unmanage_window(struct ws_win *); -long getstate(Window); +long getstate(xcb_window_t); int conf_load(char *, int); @@ -479,7 +479,7 @@ struct swm_screen { int idx; /* screen index */ struct swm_region_list rl; /* list of regions on this screen */ struct swm_region_list orl; /* list of old regions */ - Window root; + xcb_window_t root; struct workspace ws[SWM_WS_MAX]; /* colors */ @@ -587,34 +587,34 @@ enum { }; struct ewmh_hint { - char *name; - Atom atom; + char *name; + xcb_atom_t atom; } ewmh[SWM_EWMH_HINT_MAX] = { /* must be in same order as in the enum */ - {"_NET_ACTIVE_WINDOW", None}, - {"_NET_CLOSE_WINDOW", None}, - {"_NET_MOVERESIZE_WINDOW", None}, - {"_NET_WM_ACTION_CLOSE", None}, - {"_NET_WM_ACTION_FULLSCREEN", None}, - {"_NET_WM_ACTION_MOVE", None}, - {"_NET_WM_ACTION_RESIZE", None}, - {"_NET_WM_ALLOWED_ACTIONS", None}, - {"_NET_WM_STATE", None}, - {"_NET_WM_STATE_ABOVE", None}, - {"_NET_WM_STATE_FULLSCREEN", None}, - {"_NET_WM_STATE_HIDDEN", None}, - {"_NET_WM_STATE_MAXIMIZED_HORZ", None}, - {"_NET_WM_STATE_MAXIMIZED_VERT", None}, - {"_NET_WM_STATE_SKIP_PAGER", None}, - {"_NET_WM_STATE_SKIP_TASKBAR", None}, - {"_NET_WM_WINDOW_TYPE", None}, - {"_NET_WM_WINDOW_TYPE_DIALOG", None}, - {"_NET_WM_WINDOW_TYPE_DOCK", None}, - {"_NET_WM_WINDOW_TYPE_NORMAL", None}, - {"_NET_WM_WINDOW_TYPE_SPLASH", None}, - {"_NET_WM_WINDOW_TYPE_TOOLBAR", None}, - {"_NET_WM_WINDOW_TYPE_UTILITY", None}, - {"_SWM_WM_STATE_MANUAL", None}, + {"_NET_ACTIVE_WINDOW", XCB_ATOM_NONE}, + {"_NET_CLOSE_WINDOW", XCB_ATOM_NONE}, + {"_NET_MOVERESIZE_WINDOW", XCB_ATOM_NONE}, + {"_NET_WM_ACTION_CLOSE", XCB_ATOM_NONE}, + {"_NET_WM_ACTION_FULLSCREEN", XCB_ATOM_NONE}, + {"_NET_WM_ACTION_MOVE", XCB_ATOM_NONE}, + {"_NET_WM_ACTION_RESIZE", XCB_ATOM_NONE}, + {"_NET_WM_ALLOWED_ACTIONS", XCB_ATOM_NONE}, + {"_NET_WM_STATE", XCB_ATOM_NONE}, + {"_NET_WM_STATE_ABOVE", XCB_ATOM_NONE}, + {"_NET_WM_STATE_FULLSCREEN", XCB_ATOM_NONE}, + {"_NET_WM_STATE_HIDDEN", XCB_ATOM_NONE}, + {"_NET_WM_STATE_MAXIMIZED_HORZ", XCB_ATOM_NONE}, + {"_NET_WM_STATE_MAXIMIZED_VERT", XCB_ATOM_NONE}, + {"_NET_WM_STATE_SKIP_PAGER", XCB_ATOM_NONE}, + {"_NET_WM_STATE_SKIP_TASKBAR", XCB_ATOM_NONE}, + {"_NET_WM_WINDOW_TYPE", XCB_ATOM_NONE}, + {"_NET_WM_WINDOW_TYPE_DIALOG", XCB_ATOM_NONE}, + {"_NET_WM_WINDOW_TYPE_DOCK", XCB_ATOM_NONE}, + {"_NET_WM_WINDOW_TYPE_NORMAL", XCB_ATOM_NONE}, + {"_NET_WM_WINDOW_TYPE_SPLASH", XCB_ATOM_NONE}, + {"_NET_WM_WINDOW_TYPE_TOOLBAR", XCB_ATOM_NONE}, + {"_NET_WM_WINDOW_TYPE_UTILITY", XCB_ATOM_NONE}, + {"_SWM_WM_STATE_MANUAL", XCB_ATOM_NONE}, }; void store_float_geom(struct ws_win *, struct swm_region *); @@ -622,7 +622,7 @@ int floating_toggle_win(struct ws_win *); void constrain_window(struct ws_win *, struct swm_region *, int); void update_window(struct ws_win *); void spawn_select(struct swm_region *, union arg *, char *, int *); -unsigned char *get_win_name(Window); +unsigned char *get_win_name(xcb_window_t); int get_property(Window id, Atom atom, long count, Atom type, unsigned long *nitems, @@ -747,48 +747,67 @@ setup_ewmh(void) void teardown_ewmh(void) { - int i, success; - unsigned char *data = NULL; - unsigned long n; - Atom sup_check, sup_list; - Window id; + int i, num_screens; + xcb_atom_t sup_check, sup_list; + xcb_window_t id; - sup_check = XInternAtom(display, "_NET_SUPPORTING_WM_CHECK", False); - sup_list = XInternAtom(display, "_NET_SUPPORTED", False); + xcb_intern_atom_cookie_t c; + xcb_intern_atom_reply_t *r; + xcb_get_property_cookie_t pc; + xcb_get_property_reply_t *pr; + + c = xcb_intern_atom(conn, False, strlen("_NET_SUPPORTING_WM_CHECK"), + "_NET_SUPPORTING_WM_CHECK"); + r = xcb_intern_atom_reply(conn, c, NULL); + if (r) { + sup_check = r->atom; + free(r); + } + c = xcb_intern_atom(conn, False, strlen("_NET_SUPPORTED"), + "_NET_SUPPORTED"); + r = xcb_intern_atom_reply(conn, c, NULL); + if (r) { + sup_list = r->atom; + free(r); + } - for (i = 0; i < ScreenCount(display); i++) { + num_screens = xcb_setup_roots_length(xcb_get_setup(conn)); + for (i = 0; i < num_screens; i++) { /* Get the support check window and destroy it */ - success = get_property(screens[i].root, sup_check, 1, XA_WINDOW, - &n, NULL, &data); - - if (success) { - id = data[0]; - XDestroyWindow(display, id); - XDeleteProperty(display, screens[i].root, sup_check); - XDeleteProperty(display, screens[i].root, sup_list); + pc = xcb_get_property(conn, False, screens[i].root, sup_check, + XCB_ATOM_WINDOW, 0, 1); + pr = xcb_get_property_reply(conn, pc, NULL); + if (pr) { + id = *((xcb_window_t *)xcb_get_property_value(pr)); + + xcb_destroy_window(conn, id); + xcb_delete_property(conn, screens[i].root, sup_check); + xcb_delete_property(conn, screens[i].root, sup_list); + + free(pr); } - - XFree(data); } } void ewmh_autoquirk(struct ws_win *win) { - int success, i; - unsigned long *data = NULL, n; - Atom type; + int i; + unsigned long n; + xcb_atom_t type; - success = get_property(win->id, ewmh[_NET_WM_WINDOW_TYPE].atom, (~0L), - XA_ATOM, &n, NULL, (void *)&data); + xcb_get_property_cookie_t c; + xcb_get_property_reply_t *r; - if (!success) { - XFree(data); + c = xcb_get_property(conn, False, win->id, + ewmh[_NET_WM_WINDOW_TYPE].atom, XCB_ATOM_ATOM, 0, (~0L)); + r = xcb_get_property_reply(conn, c, NULL); + if (!r) return; - } + n = xcb_get_property_value_length(r); for (i = 0; i < n; i++) { - type = data[i]; + type = *((xcb_atom_t *)xcb_get_property_value(r)); if (type == ewmh[_NET_WM_WINDOW_TYPE_NORMAL].atom) break; if (type == ewmh[_NET_WM_WINDOW_TYPE_DOCK].atom || @@ -805,8 +824,7 @@ ewmh_autoquirk(struct ws_win *win) break; } } - - XFree(data); + free(r); } #define SWM_EWMH_ACTION_COUNT_MAX (6) @@ -850,7 +868,7 @@ ewmh_set_win_fullscreen(struct ws_win *win, int fs) void ewmh_update_actions(struct ws_win *win) { - Atom actions[SWM_EWMH_ACTION_COUNT_MAX]; + xcb_atom_t actions[SWM_EWMH_ACTION_COUNT_MAX]; int n = 0; if (win == NULL) @@ -863,8 +881,9 @@ ewmh_update_actions(struct ws_win *win) actions[n++] = ewmh[_NET_WM_ACTION_RESIZE].atom; } - XChangeProperty(display, win->id, ewmh[_NET_WM_ALLOWED_ACTIONS].atom, - XA_ATOM, 32, PropModeReplace, (unsigned char *)actions, n); + xcb_change_property(conn, XCB_PROP_MODE_REPLACE, win->id, + ewmh[_NET_WM_ALLOWED_ACTIONS].atom, XCB_ATOM_ATOM, 32, 1, + actions); } #define _NET_WM_STATE_REMOVE 0 /* remove/unset property */ @@ -922,36 +941,37 @@ ewmh_update_win_state(struct ws_win *win, long state, long action) win->ewmh_flags & EWMH_F_FULLSCREEN)) win->ewmh_flags = orig_flags; /* revert */ - XDeleteProperty(display, win->id, ewmh[_NET_WM_STATE].atom); + xcb_delete_property(conn, win->id, ewmh[_NET_WM_STATE].atom); if (win->ewmh_flags & EWMH_F_FULLSCREEN) - XChangeProperty(display, win->id, ewmh[_NET_WM_STATE].atom, - XA_ATOM, 32, PropModeAppend, - (unsigned char *)&ewmh[_NET_WM_STATE_FULLSCREEN].atom, 1); + xcb_change_property(conn, XCB_PROP_MODE_APPEND, win->id, + ewmh[_NET_WM_STATE].atom, XCB_ATOM_ATOM, 32, 1, + &ewmh[_NET_WM_STATE_FULLSCREEN].atom); if (win->ewmh_flags & EWMH_F_SKIP_PAGER) - XChangeProperty(display, win->id, ewmh[_NET_WM_STATE].atom, - XA_ATOM, 32, PropModeAppend, - (unsigned char *)&ewmh[_NET_WM_STATE_SKIP_PAGER].atom, 1); + xcb_change_property(conn, XCB_PROP_MODE_APPEND, win->id, + ewmh[_NET_WM_STATE].atom, XCB_ATOM_ATOM, 32, 1, + &ewmh[_NET_WM_STATE_SKIP_PAGER].atom); if (win->ewmh_flags & EWMH_F_SKIP_TASKBAR) - XChangeProperty(display, win->id, ewmh[_NET_WM_STATE].atom, - XA_ATOM, 32, PropModeAppend, - (unsigned char *)&ewmh[_NET_WM_STATE_SKIP_TASKBAR].atom, 1); + xcb_change_property(conn, XCB_PROP_MODE_APPEND, win->id, + ewmh[_NET_WM_STATE].atom, XCB_ATOM_ATOM, 32, 1, + &ewmh[_NET_WM_STATE_SKIP_TASKBAR].atom); if (win->ewmh_flags & EWMH_F_ABOVE) - XChangeProperty(display, win->id, ewmh[_NET_WM_STATE].atom, - XA_ATOM, 32, PropModeAppend, - (unsigned char *)&ewmh[_NET_WM_STATE_ABOVE].atom, 1); + xcb_change_property(conn, XCB_PROP_MODE_APPEND, win->id, + ewmh[_NET_WM_STATE].atom, XCB_ATOM_ATOM, 32, 1, + &ewmh[_NET_WM_STATE_ABOVE].atom); if (win->ewmh_flags & SWM_F_MANUAL) - XChangeProperty(display, win->id, ewmh[_NET_WM_STATE].atom, - XA_ATOM, 32, PropModeAppend, - (unsigned char *)&ewmh[_SWM_WM_STATE_MANUAL].atom, 1); + xcb_change_property(conn, XCB_PROP_MODE_APPEND, win->id, + ewmh[_NET_WM_STATE].atom, XCB_ATOM_ATOM, 32, 1, + &ewmh[_SWM_WM_STATE_MANUAL].atom); } void ewmh_get_win_state(struct ws_win *win) { - int success, i; - unsigned long n; - Atom *states; + xcb_atom_t *states; + xcb_get_property_cookie_t c; + xcb_get_property_reply_t *r; + int i, n; if (win == NULL) return; @@ -962,16 +982,19 @@ ewmh_get_win_state(struct ws_win *win) if (win->manual) win->ewmh_flags |= SWM_F_MANUAL; - success = get_property(win->id, ewmh[_NET_WM_STATE].atom, - (~0L), XA_ATOM, &n, NULL, (void *)&states); - - if (!success) + c = xcb_get_property(conn, False, win->id, ewmh[_NET_WM_STATE].atom, + XCB_ATOM_ATOM, 0, (~0L)); + r = xcb_get_property_reply(conn, c, NULL); + if (!r) return; + + states = xcb_get_property_value(r); + n = xcb_get_property_value_length(r); + + free(r); for (i = 0; i < n; i++) ewmh_update_win_state(win, states[i], _NET_WM_STATE_ADD); - - XFree(states); } /* events */ @@ -1249,26 +1272,34 @@ find_pid(long pid) return (NULL); } -unsigned long -name_to_color(char *colorname) +uint32_t +name_to_color(const char *colorname) { - Colormap cmap; - Status status; - XColor screen_def, exact_def; - unsigned long result = 0; - char cname[32] = "#"; + uint32_t result = 0; + char cname[32] = "#"; + xcb_screen_t *screen; + xcb_colormap_t cmap; + xcb_alloc_named_color_cookie_t c; + xcb_alloc_named_color_reply_t *r; - cmap = DefaultColormap(display, screens[0].idx); - status = XAllocNamedColor(display, cmap, colorname, - &screen_def, &exact_def); - if (!status) { + /* XXX - does not support rgb:/RR/GG/BB + * will need to use xcb_alloc_color + */ + screen = xcb_setup_roots_iterator(xcb_get_setup(conn)).data; + cmap = screen->default_colormap; + + c = xcb_alloc_named_color(conn, cmap, strlen(colorname), colorname); + r = xcb_alloc_named_color_reply(conn, c, NULL); + if (!r) { strlcat(cname, colorname + 2, sizeof cname - 1); - status = XAllocNamedColor(display, cmap, cname, &screen_def, - &exact_def); + c = xcb_alloc_named_color(conn, cmap, strlen(cname), + cname); + r = xcb_alloc_named_color_reply(conn, c, NULL); } - if (status) - result = screen_def.pixel; - else + if (r) { + result = r->pixel; + free(r); + } else warnx("color '%s' not found", colorname); return (result); @@ -1481,13 +1512,14 @@ bar_urgent(char *s, size_t sz) { XWMHints *wmh = NULL; struct ws_win *win; - int i, j; + int i, j, num_screens; char b[8]; for (i = 0; i < workspace_limit; i++) urgent[i] = 0; - for (i = 0; i < ScreenCount(display); i++) + num_screens = xcb_setup_roots_length(xcb_get_setup(conn)); + for (i = 0; i < num_screens; i++) for (j = 0; j < workspace_limit; j++) TAILQ_FOREACH(win, &screens[i].ws[j].winlist, entry) { wmh = XGetWMHints(display, win->id); @@ -1730,13 +1762,14 @@ bar_fmt_print(void) { char fmtexp[SWM_BAR_MAX], fmtnew[SWM_BAR_MAX]; char fmtrep[SWM_BAR_MAX]; - int i; + int i, num_screens; struct swm_region *r; /* expand the format by first passing it through strftime(3) */ bar_fmt_expand(fmtexp, sizeof fmtexp); - for (i = 0; i < ScreenCount(display); i++) { + num_screens = xcb_setup_roots_length(xcb_get_setup(conn)); + for (i = 0; i < num_screens; i++) { TAILQ_FOREACH(r, &screens[i].rl, entry) { if (r->bar == NULL) continue; @@ -1783,17 +1816,18 @@ void bar_toggle(struct swm_region *r, union arg *args) { struct swm_region *tmpr; - int i, sc = ScreenCount(display); + int i, num_screens; DNPRINTF(SWM_D_BAR, "bar_toggle\n"); + num_screens = xcb_setup_roots_length(xcb_get_setup(conn)); if (bar_enabled) { - for (i = 0; i < sc; i++) + for (i = 0; i < num_screens; i++) TAILQ_FOREACH(tmpr, &screens[i].rl, entry) if (tmpr->bar) XUnmapWindow(display, tmpr->bar->id); } else { - for (i = 0; i < sc; i++) + for (i = 0; i < num_screens; i++) TAILQ_FOREACH(tmpr, &screens[i].rl, entry) if (tmpr->bar) XMapRaised(display, tmpr->bar->id); @@ -1809,9 +1843,9 @@ bar_toggle(struct swm_region *r, union arg *args) void bar_refresh(void) { - XSetWindowAttributes wa; struct swm_region *r; - int i; + uint32_t wa[2]; + int i, num_screens; /* do this here because the conf file is in memory */ if (bar_extra && bar_extra_running == 0 && bar_argv[0]) { @@ -1842,17 +1876,15 @@ bar_refresh(void) } } - bzero(&wa, sizeof wa); - for (i = 0; i < ScreenCount(display); i++) + num_screens = xcb_setup_roots_length(xcb_get_setup(conn)); + for (i = 0; i < num_screens; i++) TAILQ_FOREACH(r, &screens[i].rl, entry) { if (r->bar == NULL) continue; - wa.border_pixel = - screens[i].c[SWM_S_COLOR_BAR_BORDER].color; - wa.background_pixel = - screens[i].c[SWM_S_COLOR_BAR].color; - XChangeWindowAttributes(display, r->bar->id, - CWBackPixel | CWBorderPixel, &wa); + wa[0] = screens[i].c[SWM_S_COLOR_BAR].color; + wa[1] = screens[i].c[SWM_S_COLOR_BAR_BORDER].color; + xcb_change_window_attributes(conn, r->bar->id, + XCB_CW_BACK_PIXEL | XCB_CW_BORDER_PIXEL, wa); } bar_update(); } @@ -1957,29 +1989,32 @@ drain_enter_notify(void) void set_win_state(struct ws_win *win, long state) { - long data[] = {state, None}; + long data[] = {state, XCB_ATOM_NONE}; DNPRINTF(SWM_D_EVENT, "set_win_state: window: 0x%lx\n", win->id); if (win == NULL) return; - XChangeProperty(display, win->id, astate, astate, 32, PropModeReplace, - (unsigned char *)data, 2); + xcb_change_property(conn, XCB_PROP_MODE_REPLACE, win->id, astate, + astate, 32, 2, data); } long -getstate(Window w) +getstate(xcb_window_t w) { - long result = -1; - unsigned char *p = NULL; - unsigned long n; + long result = -1; + xcb_get_property_cookie_t c; + xcb_get_property_reply_t *r; - if (!get_property(w, astate, 2L, astate, &n, NULL, &p)) - return (-1); - if (n != 0) - result = *((long *)p); - XFree(p); + c = xcb_get_property(conn, False, w, astate, astate, 0L, 2L); + r = xcb_get_property_reply(conn, c, NULL); + + if (r) { + result = *((long *)xcb_get_property_value(r)); + free(r); + } + return (result); } @@ -2141,9 +2176,9 @@ void unmap_all(void) { struct ws_win *win; - int i, j; + int i, j, num_screens; - for (i = 0; i < ScreenCount(display); i++) + for (i = 0; i < num_screens; i++) for (j = 0; j < workspace_limit; j++) TAILQ_FOREACH(win, &screens[i].ws[j].winlist, entry) unmap_window(win); @@ -2193,7 +2228,6 @@ restart(struct swm_region *r, union arg *args) bar_extra_stop(); bar_extra = 1; unmap_all(); - xcb_disconnect(conn); XCloseDisplay(display); execvp(start_argv[0], start_argv); warn("execvp failed"); @@ -2205,12 +2239,13 @@ root_to_region(Window root) { struct swm_region *r = NULL; Window rr, cr; - int i, x, y, wx, wy; + int i, x, y, wx, wy, num_screens; unsigned int mask; DNPRINTF(SWM_D_MISC, "root_to_region: window: 0x%lx\n", root); - for (i = 0; i < ScreenCount(display); i++) + num_screens = xcb_setup_roots_length(xcb_get_setup(conn)); + for (i = 0; i < num_screens; i++) if (screens[i].root == root) break; @@ -2235,9 +2270,10 @@ struct ws_win * find_unmanaged_window(Window id) { struct ws_win *win; - int i, j; + int i, j, num_screens; - for (i = 0; i < ScreenCount(display); i++) + num_screens = xcb_setup_roots_length(xcb_get_setup(conn)); + for (i = 0; i < num_screens; i++) for (j = 0; j < workspace_limit; j++) TAILQ_FOREACH(win, &screens[i].ws[j].unmanagedlist, entry) @@ -2247,14 +2283,15 @@ find_unmanaged_window(Window id) } struct ws_win * -find_window(Window id) +find_window(xcb_window_t id) { struct ws_win *win; Window wrr, wpr, *wcr = NULL; - int i, j; + int i, j, num_screens; unsigned int nc; - for (i = 0; i < ScreenCount(display); i++) + num_screens = xcb_setup_roots_length(xcb_get_setup(conn)); + for (i = 0; i < num_screens; i++) for (j = 0; j < workspace_limit; j++) TAILQ_FOREACH(win, &screens[i].ws[j].winlist, entry) if (id == win->id) @@ -2271,7 +2308,7 @@ find_window(Window id) return (NULL); /* look for parent */ - for (i = 0; i < ScreenCount(display); i++) + for (i = 0; i < num_screens; i++) for (j = 0; j < workspace_limit; j++) TAILQ_FOREACH(win, &screens[i].ws[j].winlist, entry) if (wpr == win->id) @@ -2339,14 +2376,15 @@ spawn(int ws_idx, union arg *args, int close_fd) void kill_refs(struct ws_win *win) { - int i, x; + int i, x, num_screens; struct swm_region *r; struct workspace *ws; if (win == NULL) return; - for (i = 0; i < ScreenCount(display); i++) + num_screens = xcb_setup_roots_length(xcb_get_setup(conn)); + for (i = 0; i < num_screens; i++) TAILQ_FOREACH(r, &screens[i].rl, entry) for (x = 0; x < workspace_limit; x++) { ws = &r->s->ws[x]; @@ -2363,12 +2401,13 @@ validate_win(struct ws_win *testwin) struct ws_win *win; struct workspace *ws; struct swm_region *r; - int i, x; + int i, x, num_screens; if (testwin == NULL) return (0); - for (i = 0; i < ScreenCount(display); i++) + num_screens = xcb_setup_roots_length(xcb_get_setup(conn)); + for (i = 0; i < num_screens; i++) TAILQ_FOREACH(r, &screens[i].rl, entry) for (x = 0; x < workspace_limit; x++) { ws = &r->s->ws[x]; @@ -2384,10 +2423,11 @@ validate_ws(struct workspace *testws) { struct swm_region *r; struct workspace *ws; - int i, x; + int i, x, num_screens; /* validate all ws */ - for (i = 0; i < ScreenCount(display); i++) + num_screens = xcb_setup_roots_length(xcb_get_setup(conn)); + for (i = 0; i < num_screens; i++) TAILQ_FOREACH(r, &screens[i].rl, entry) for (x = 0; x < workspace_limit; x++) { ws = &r->s->ws[x]; @@ -2401,7 +2441,7 @@ void unfocus_win(struct ws_win *win) { XEvent cne; - Window none = None; + xcb_window_t none = XCB_WINDOW_NONE; DNPRINTF(SWM_D_FOCUS, "unfocus_win: window: 0x%lx\n", WINID(win)); @@ -2443,20 +2483,21 @@ unfocus_win(struct ws_win *win) XSetWindowBorder(display, win->id, win->ws->r->s->c[SWM_S_COLOR_UNFOCUS].color); - XChangeProperty(display, win->s->root, - ewmh[_NET_ACTIVE_WINDOW].atom, XA_WINDOW, 32, - PropModeReplace, (unsigned char *)&none, 1); + xcb_change_property(conn, XCB_PROP_MODE_REPLACE, win->s->root, + ewmh[_NET_ACTIVE_WINDOW].atom, XCB_ATOM_WINDOW, 32, 1, + &none); } void unfocus_all(void) { struct ws_win *win; - int i, j; + int i, j, num_screens; DNPRINTF(SWM_D_FOCUS, "unfocus_all\n"); - for (i = 0; i < ScreenCount(display); i++) + num_screens = xcb_setup_roots_length(xcb_get_setup(conn)); + for (i = 0; i < num_screens; i++) for (j = 0; j < workspace_limit; j++) TAILQ_FOREACH(win, &screens[i].ws[j].winlist, entry) unfocus_win(win); @@ -2650,10 +2691,11 @@ cyclescr(struct swm_region *r, union arg *args) { struct swm_region *rr = NULL; union arg a; - int i, x, y; + int i, x, y, num_screens; + num_screens = xcb_setup_roots_length(xcb_get_setup(conn)); /* do nothing if we don't have more than one screen */ - if (!(ScreenCount(display) > 1 || outputs > 1)) + if (!(num_screens > 1 || outputs > 1)) return; i = r->s->idx; @@ -3013,14 +3055,15 @@ void stack(void) { struct swm_geometry g; struct swm_region *r; - int i; + int i, num_screens; #ifdef SWM_DEBUG int j; #endif DNPRINTF(SWM_D_STACK, "stack: begin\n"); - - for (i = 0; i < ScreenCount(display); i++) { + + num_screens = xcb_setup_roots_length(xcb_get_setup(conn)); + for (i = 0; i < num_screens; i++) { #ifdef SWM_DEBUG j = 0; #endif @@ -3482,7 +3525,7 @@ max_stack(struct workspace *ws, struct swm_geometry *g) { struct swm_geometry gg = *g; struct ws_win *win, *wintrans = NULL, *parent = NULL; - int winno; + int winno, num_screens; DNPRINTF(SWM_D_STACK, "max_stack: workspace: %d\n", ws->idx); @@ -3493,6 +3536,7 @@ max_stack(struct workspace *ws, struct swm_geometry *g) if (winno == 0 && count_win(ws, 1) == 0) return; + num_screens = xcb_setup_roots_length(xcb_get_setup(conn)); TAILQ_FOREACH(win, &ws->winlist, entry) { if (win->transient) { wintrans = win; @@ -3525,7 +3569,7 @@ max_stack(struct workspace *ws, struct swm_geometry *g) } /* unmap only if we don't have multi screen */ if (win != ws->focus) - if (!(ScreenCount(display) > 1 || outputs > 1)) + if (!(num_screens > 1 || outputs > 1)) unmap_window(win); } @@ -3636,7 +3680,7 @@ iconify(struct swm_region *r, union arg *args) } unsigned char * -get_win_name(Window win) +get_win_name(xcb_window_t win) { unsigned char *prop = NULL; unsigned long nbytes, nitems; @@ -3701,7 +3745,7 @@ uniconify(struct swm_region *r, union arg *args) name = get_win_name(win->id); if (name == NULL) continue; - fprintf(lfile, "%s.%lu\n", name, win->id); + fprintf(lfile, "%s.%u\n", name, win->id); XFree(name); } @@ -3858,7 +3902,7 @@ search_resp_uniconify(char *resp, unsigned long len) name = get_win_name(win->id); if (name == NULL) continue; - if (asprintf(&s, "%s.%lu", name, win->id) == -1) { + if (asprintf(&s, "%s.%u", name, win->id) == -1) { XFree(name); continue; } @@ -4139,23 +4183,23 @@ constrain_window(struct ws_win *win, struct swm_region *r, int resizable) void update_window(struct ws_win *win) { - unsigned int mask; - XWindowChanges wc; - - bzero(&wc, sizeof wc); - mask = CWBorderWidth | CWWidth | CWHeight | CWX | CWY; + uint16_t mask; + uint32_t wc[5]; - wc.border_width = BORDER(win); - wc.x = X(win); - wc.y = Y(win); - wc.width = WIDTH(win); - wc.height = HEIGHT(win); + mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | + XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT | + XCB_CONFIG_WINDOW_BORDER_WIDTH; + wc[0] = X(win); + wc[1] = Y(win); + wc[2] = WIDTH(win); + wc[3] = HEIGHT(win); + wc[4] = BORDER(win); - DNPRINTF(SWM_D_EVENT, "update_window: window: 0x%lx, (x,y) w x h: " - "(%d,%d) %d x %d, bordered: %s\n", win->id, wc.x, wc.y, wc.width, - wc.height, YESNO(win->bordered)); + DNPRINTF(SWM_D_EVENT, "update_window: window: 0x%x, (x,y) w x h: " + "(%d,%d) %d x %d, bordered: %s\n", win->id, wc[0], wc[1], wc[2], + wc[3], YESNO(win->bordered)); - XConfigureWindow(display, win->id, mask, &wc); + xcb_configure_window(conn, win->id, mask, wc); } #define SWM_RESIZE_STEPS (50) @@ -5365,6 +5409,7 @@ updatenumlockmask(void) void grabkeys(void) { + int num_screens; unsigned int j, k; KeyCode code; unsigned int modifiers[] = @@ -5374,10 +5419,12 @@ grabkeys(void) DNPRINTF(SWM_D_MISC, "grabkeys\n"); updatenumlockmask(); - for (k = 0; k < ScreenCount(display); k++) { + num_screens = xcb_setup_roots_length(xcb_get_setup(conn)); + for (k = 0; k < num_screens; k++) { if (TAILQ_EMPTY(&screens[k].rl)) continue; - XUngrabKey(display, AnyKey, AnyModifier, screens[k].root); + xcb_ungrab_key(conn, XCB_GRAB_ANY, screens[k].root, + XCB_MOD_MASK_ANY); RB_FOREACH(kp, key_tree, &keys) { if ((code = XKeysymToKeycode(display, kp->keysym))) for (j = 0; j < LENGTH(modifiers); j++) @@ -5397,19 +5444,25 @@ grabbuttons(struct ws_win *win, int focused) { 0, LockMask, numlockmask, numlockmask|LockMask }; updatenumlockmask(); - XUngrabButton(display, AnyButton, AnyModifier, win->id); + xcb_ungrab_button(conn, XCB_BUTTON_INDEX_ANY, win->id, + XCB_BUTTON_MASK_ANY); if (focused) { for (i = 0; i < LENGTH(buttons); i++) if (buttons[i].action == client_click) for (j = 0; j < LENGTH(modifiers); j++) - XGrabButton(display, buttons[i].button, - buttons[i].mask | modifiers[j], - win->id, False, BUTTONMASK, - GrabModeAsync, GrabModeSync, None, - None); + xcb_grab_button(conn, False, win->id, + BUTTONMASK, + XCB_GRAB_MODE_ASYNC, + XCB_GRAB_MODE_SYNC, + XCB_WINDOW_NONE, + XCB_CURSOR_NONE, + buttons[i].button, + buttons[i].mask); } else - XGrabButton(display, AnyButton, AnyModifier, win->id, False, - BUTTONMASK, GrabModeAsync, GrabModeSync, None, None); + xcb_grab_button(conn, False, win->id, BUTTONMASK, + XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC, + XCB_WINDOW_NONE, XCB_CURSOR_NONE, XCB_BUTTON_INDEX_ANY, + XCB_BUTTON_MASK_ANY); } const char *quirkname[] = { @@ -5881,7 +5934,7 @@ int setlayout(char *selector, char *value, int flags) { int ws_id, i, x, mg, ma, si, raise, f = 0; - int st = SWM_V_STACK; + int st = SWM_V_STACK, num_screens; char s[1024]; struct workspace *ws; @@ -5915,7 +5968,8 @@ setlayout(char *selector, char *value, int flags) "::::" "'"); - for (i = 0; i < ScreenCount(display); i++) { + num_screens = xcb_setup_roots_length(xcb_get_setup(conn)); + for (i = 0; i < num_screens; i++) { ws = (struct workspace *)&screens[i].ws; ws[ws_id].cur_layout = &layouts[st]; @@ -6137,7 +6191,7 @@ set_child_transient(struct ws_win *win, Window *trans) " for 0x%lx trans 0x%lx\n", win->id, win->transient); if (win->hints == NULL) { - warnx("no hints for 0x%lx", win->id); + warnx("no hints for 0x%x", win->id); return; } @@ -6149,7 +6203,7 @@ set_child_transient(struct ws_win *win, Window *trans) XFree(wmh); if ((wmh = XGetWMHints(display, w->id)) == NULL) { - warnx("can't get hints for 0x%lx", w->id); + warnx("can't get hints for 0x%x", w->id); continue; } @@ -6160,7 +6214,7 @@ set_child_transient(struct ws_win *win, Window *trans) win->transient = w->id; *trans = w->id; DNPRINTF(SWM_D_MISC, "set_child_transient: asjusting " - "transient to 0x%lx\n", win->transient); + "transient to 0x%x\n", win->transient); break; } } @@ -7007,16 +7061,19 @@ unmapnotify(XEvent *e) void visibilitynotify(XEvent *e) { - int i; + int i, num_screens; struct swm_region *r; DNPRINTF(SWM_D_EVENT, "visibilitynotify: window: 0x%lx\n", e->xvisibility.window); - if (e->xvisibility.state == VisibilityUnobscured) - for (i = 0; i < ScreenCount(display); i++) + + if (e->xvisibility.state == VisibilityUnobscured) { + num_screens = xcb_setup_roots_length(xcb_get_setup(conn)); + for (i = 0; i < num_screens; i++) TAILQ_FOREACH(r, &screens[i].rl, entry) if (e->xvisibility.window == WINID(r->bar)) bar_update(); + } } void @@ -7201,9 +7258,10 @@ scan_xrandr(int i) int ncrtc = 0; #endif /* SWM_XRR_HAS_CRTC */ struct swm_region *r; + int num_screens; - - if (i >= ScreenCount(display)) + num_screens = xcb_setup_roots_length(xcb_get_setup(conn)); + if (i >= num_screens) errx(1, "scan_xrandr: invalid screen"); /* remove any old regions */ @@ -7254,25 +7312,26 @@ void screenchange(XEvent *e) { XRRScreenChangeNotifyEvent *xe = (XRRScreenChangeNotifyEvent *)e; struct swm_region *r; - int i; + int i, num_screens; DNPRINTF(SWM_D_EVENT, "screenchange: root: 0x%lx\n", xe->root); if (!XRRUpdateConfiguration(e)) return; + num_screens = xcb_setup_roots_length(xcb_get_setup(conn)); /* silly event doesn't include the screen index */ - for (i = 0; i < ScreenCount(display); i++) + for (i = 0; i < num_screens; i++) if (screens[i].root == xe->root) break; - if (i >= ScreenCount(display)) + if (i >= num_screens) errx(1, "screenchange: screen not found"); /* brute force for now, just re-enumerate the regions */ scan_xrandr(i); /* add bars to all regions */ - for (i = 0; i < ScreenCount(display); i++) + for (i = 0; i < num_screens; i++) TAILQ_FOREACH(r, &screens[i].rl, entry) bar_setup(r); stack(); @@ -7286,10 +7345,11 @@ grab_windows(void) Window d1, d2, *wins = NULL; XWindowAttributes wa; unsigned int no; - int i, j; + int i, j, num_screens; long state, manage; - for (i = 0; i < ScreenCount(display); i++) { + num_screens = xcb_setup_roots_length(xcb_get_setup(conn)); + for (i = 0; i < num_screens; i++) { if (!XQueryTree(display, screens[i].root, &d1, &d2, &wins, &no)) continue; @@ -7411,7 +7471,7 @@ setup_globals(void) void workaround(void) { - int i; + int i, num_screens; Atom netwmcheck, netwmname, utf8_string; Window root, win; @@ -7419,7 +7479,9 @@ workaround(void) netwmcheck = XInternAtom(display, "_NET_SUPPORTING_WM_CHECK", False); netwmname = XInternAtom(display, "_NET_WM_NAME", False); utf8_string = XInternAtom(display, "UTF8_STRING", False); - for (i = 0; i < ScreenCount(display); i++) { + + num_screens = xcb_setup_roots_length(xcb_get_setup(conn)); + for (i = 0; i < num_screens; i++) { root = screens[i].root; win = XCreateSimpleWindow(display,root, 0, 0, 1, 1, 0, screens[i].c[SWM_S_COLOR_UNFOCUS].color, @@ -7444,7 +7506,7 @@ main(int argc, char *argv[]) char conf[PATH_MAX], *cfile = NULL; struct stat sb; XEvent e; - int xfd, i; + int xfd, i, num_screens; fd_set rd; struct sigaction sact; @@ -7551,7 +7613,8 @@ noconfig: setenv("SWM_STARTED", "YES", 1); /* setup all bars */ - for (i = 0; i < ScreenCount(display); i++) + num_screens = xcb_setup_roots_length(xcb_get_setup(conn)); + for (i = 0; i < num_screens; i++) TAILQ_FOREACH(r, &screens[i].rl, entry) { if (winfocus == NULL) winfocus = TAILQ_FIRST(&r->ws->winlist); @@ -7604,7 +7667,7 @@ noconfig: continue; } /* move pointer to first screen if multi screen */ - if (ScreenCount(display) > 1 || outputs > 1) + if (num_screens > 1 || outputs > 1) XWarpPointer(display, None, rr->s[0].root, 0, 0, 0, 0, X(rr), Y(rr) + (bar_enabled ? bar_height : 0)); @@ -7637,7 +7700,7 @@ done: teardown_ewmh(); bar_extra_stop(); - for (i = 0; i < ScreenCount(display); ++i) + for (i = 0; i < num_screens; ++i) if (screens[i].bar_gc != NULL) XFreeGC(display, screens[i].bar_gc);