void
teardown_ewmh(void)
{
- int i, success, num_screens;
- 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);
+ }
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);
}
}
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;
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 */
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);
void
bar_refresh(void)
{
- XSetWindowAttributes wa;
struct swm_region *r;
+ uint32_t wa[2];
int i, num_screens;
/* do this here because the conf file is in memory */
}
}
- bzero(&wa, sizeof wa);
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();
}
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(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);
}
bar_extra_stop();
bar_extra = 1;
unmap_all();
- xcb_disconnect(conn);
XCloseDisplay(display);
execvp(start_argv[0], start_argv);
warn("execvp failed");
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)
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++)