X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=spectrwm.c;h=bad65b5534ca52f12171b1e565423171131f6a73;hb=f049b883c13a8374e294fc55bc7ee6b64d4cbc6f;hp=225029bd13cd15d374b6b6009bef8a0efb45468e;hpb=e876d7de1335a16124065cabde4d51fd10cfca6f;p=spectrwm.git diff --git a/spectrwm.c b/spectrwm.c index 225029b..bad65b5 100644 --- a/spectrwm.c +++ b/spectrwm.c @@ -650,69 +650,97 @@ get_property(Window id, Atom atom, long count, Atom type, unsigned long *nitems, void update_iconic(struct ws_win *win, int newv) { - int32_t v = newv; - Atom iprop; + int32_t v = newv; + xcb_atom_t iprop; + xcb_intern_atom_cookie_t c; + xcb_intern_atom_reply_t *r; win->iconic = newv; - iprop = XInternAtom(display, "_SWM_ICONIC", False); - if (!iprop) + c = xcb_intern_atom(conn, False, strlen("_SWM_ICONIC"), "_SWM_ICONIC"); + r = xcb_intern_atom_reply(conn, c, NULL); + if (r) { + iprop = r->atom; + free(r); + } else return; + if (newv) - XChangeProperty(display, win->id, iprop, XA_INTEGER, 32, - PropModeReplace, (unsigned char *)&v, 1); + xcb_change_property(conn, XCB_PROP_MODE_REPLACE, win->id, + iprop, XCB_ATOM_INTEGER, 32, 1, &v); else - XDeleteProperty(display, win->id, iprop); + xcb_delete_property(conn, win->id, iprop); } int get_iconic(struct ws_win *win) { - int32_t v = 0; - int retfmt, status; - Atom iprop, rettype; - unsigned long nitems, extra; - unsigned char *prop = NULL; - - iprop = XInternAtom(display, "_SWM_ICONIC", False); - if (!iprop) - goto out; - status = XGetWindowProperty(display, win->id, iprop, 0L, 1L, - False, XA_INTEGER, &rettype, &retfmt, &nitems, &extra, &prop); - if (status != Success) - goto out; - if (rettype != XA_INTEGER || retfmt != 32) - goto out; - if (nitems != 1) + int32_t v = 0, *vtmp; + xcb_atom_t iprop; + 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("_SWM_ICONIC"), "_SWM_ICONIC"); + r = xcb_intern_atom_reply(conn, c, NULL); + if (r) { + iprop = r->atom; + free(r); + } else goto out; - v = *((int32_t *)prop); + pc = xcb_get_property(conn, False, win->id, iprop, XCB_ATOM_INTEGER, + 0, 1); + pr = xcb_get_property_reply(conn, pc, NULL); + if (!pr) + goto out; + if (pr->type != XCB_ATOM_INTEGER || pr->format != 32) + goto out; + vtmp = xcb_get_property_value(pr); + v = *vtmp; out: - if (prop != NULL) - XFree(prop); + if (pr != NULL) + free(pr); return (v); } void setup_ewmh(void) { - int i,j; - Atom sup_list; - - sup_list = XInternAtom(display, "_NET_SUPPORTED", False); - - for (i = 0; i < LENGTH(ewmh); i++) - ewmh[i].atom = XInternAtom(display, ewmh[i].name, False); + xcb_atom_t sup_list; + xcb_intern_atom_cookie_t c; + xcb_intern_atom_reply_t *r; + int i, j, num_screens; + + 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 < LENGTH(ewmh); i++) { + c = xcb_intern_atom(conn, False, strlen(ewmh[i].name), + ewmh[i].name); + r = xcb_intern_atom_reply(conn, c, NULL); + if (r) { + ewmh[i].atom = 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++) { /* Support check window will be created by workaround(). */ /* Report supported atoms */ - XDeleteProperty(display, screens[i].root, sup_list); + xcb_delete_property(conn, screens[i].root, sup_list); for (j = 0; j < LENGTH(ewmh); j++) - XChangeProperty(display, screens[i].root, - sup_list, XA_ATOM, 32, - PropModeAppend, (unsigned char *)&ewmh[j].atom, 1); + xcb_change_property(conn, XCB_PROP_MODE_APPEND, + screens[i].root, sup_list, XCB_ATOM_ATOM, 32, 1, + &ewmh[j].atom); } } @@ -1249,13 +1277,16 @@ name_to_color(char *colorname) void setscreencolor(char *val, int i, int c) { - if (i > 0 && i <= ScreenCount(display)) { + int num_screens; + + num_screens = xcb_setup_roots_length(xcb_get_setup(conn)); + if (i > 0 && i <= num_screens) { screens[i - 1].c[c].color = name_to_color(val); free(screens[i - 1].c[c].name); if ((screens[i - 1].c[c].name = strdup(val)) == NULL) err(1, "strdup"); } else if (i == -1) { - for (i = 0; i < ScreenCount(display); i++) { + for (i = 0; i < num_screens; i++) { screens[i].c[c].color = name_to_color(val); free(screens[i].c[c].name); if ((screens[i].c[c].name = strdup(val)) == NULL) @@ -1263,7 +1294,7 @@ setscreencolor(char *val, int i, int c) } } else errx(1, "invalid screen index: %d out of bounds (maximum %d)", - i, ScreenCount(display)); + i, num_screens); } void @@ -7289,12 +7320,13 @@ grab_windows(void) void setup_screens(void) { - int i, j, k; + int i, j, k, num_screens; int errorbase, major, minor; struct workspace *ws; XGCValues gcv; - if ((screens = calloc(ScreenCount(display), + num_screens = xcb_setup_roots_length(xcb_get_setup(conn)); + if ((screens = calloc(num_screens, sizeof(struct swm_screen))) == NULL) err(1, "setup_screens: calloc: failed to allocate memory for " "screens"); @@ -7307,7 +7339,7 @@ setup_screens(void) xrandr_support = 0; /* map physical screens */ - for (i = 0; i < ScreenCount(display); i++) { + for (i = 0; i < num_screens; i++) { DNPRINTF(SWM_D_WS, "setup_screens: init screen: %d\n", i); screens[i].idx = i; TAILQ_INIT(&screens[i].rl);