#include <X11/keysym.h>
#include <X11/XKBlib.h>
#include <X11/Xatom.h>
-#include <X11/Xlib.h>
+#include <X11/Xlib-xcb.h>
#include <X11/Xproto.h>
#include <X11/Xutil.h>
#include <X11/extensions/Xrandr.h>
int xrandr_eventbase;
unsigned int numlockmask = 0;
Display *display;
+xcb_connection_t *conn;
int cycle_empty = 0;
int cycle_visible = 0;
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);
}
}
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)
}
} else
errx(1, "invalid screen index: %d out of bounds (maximum %d)",
- i, ScreenCount(display));
+ i, num_screens);
}
void
bar_extra_stop();
bar_extra = 1;
unmap_all();
+ xcb_disconnect(conn);
XCloseDisplay(display);
execvp(start_argv[0], start_argv);
warn("execvp failed");
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");
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);
if (!(display = XOpenDisplay(0)))
errx(1, "can not open display");
+ if (!(conn = XGetXCBConnection(display)))
+ errx(1, "can not get XCB connection");
+
if (active_wm())
errx(1, "other wm running");
XFreeGC(display, screens[i].bar_gc);
XFreeFontSet(display, bar_fs);
+ xcb_disconnect(conn);
XCloseDisplay(display);
return (0);