#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;
struct workspace;
struct swm_bar {
- Window id;
- Pixmap buffer;
+ xcb_window_t id;
+ xcb_pixmap_t buffer;
struct swm_geometry g;
};
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 */
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);
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 */
};
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 *);
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,
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);
}
}
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)
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 */
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
custom_region(char *val)
{
unsigned int sidx, x, y, w, h;
+ int num_screens;
+ num_screens = xcb_setup_roots_length(xcb_get_setup(conn));
if (sscanf(val, "screen[%u]:%ux%u+%u+%u", &sidx, &w, &h, &x, &y) != 5)
errx(1, "invalid custom region, "
"should be 'screen[<n>]:<n>x<n>+<n>+<n>");
- if (sidx < 1 || sidx > ScreenCount(display))
+ if (sidx < 1 || sidx > num_screens)
errx(1, "invalid screen index: %d out of bounds (maximum %d)",
- sidx, ScreenCount(display));
+ sidx, num_screens);
sidx--;
if (w < 1 || h < 1)
{
if (r->bar == NULL)
return;
- XDestroyWindow(display, r->bar->id);
- XFreePixmap(display, r->bar->buffer);
+ xcb_destroy_window(conn, r->bar->id);
+ xcb_free_pixmap(conn, r->bar->buffer);
free(r->bar);
r->bar = NULL;
}
}
long
-getstate(Window w)
+getstate(xcb_window_t w)
{
long result = -1;
unsigned char *p = NULL;
bar_extra_stop();
bar_extra = 1;
unmap_all();
+ xcb_disconnect(conn);
XCloseDisplay(display);
execvp(start_argv[0], start_argv);
warn("execvp failed");
}
struct ws_win *
-find_window(Window id)
+find_window(xcb_window_t id)
{
struct ws_win *win;
Window wrr, wpr, *wcr = NULL;
{
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];
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));
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);
}
unsigned char *
-get_win_name(Window win)
+get_win_name(xcb_window_t win)
{
unsigned char *prop = NULL;
unsigned long nbytes, nitems;
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);
}
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;
}
{ 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[] = {
" 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;
}
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;
}
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;
}
}
long
window_get_pid(Window win)
{
- Atom actual_type_return;
- int actual_format_return = 0;
- unsigned long nitems_return = 0;
- unsigned long bytes_after_return = 0;
- long *pid = NULL;
- long ret = 0;
- const char *errstr;
- unsigned char *prop = NULL;
-
- if (XGetWindowProperty(display, win,
- XInternAtom(display, "_NET_WM_PID", False), 0, 1, False,
- XA_CARDINAL, &actual_type_return, &actual_format_return,
- &nitems_return, &bytes_after_return,
- (unsigned char**)(void*)&pid) != Success)
+ long ret = 0;
+ const char *errstr;
+ xcb_atom_t apid;
+ 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_WM_PID"), "_NET_WM_PID");
+ r = xcb_intern_atom_reply(conn, c, NULL);
+ if (r) {
+ apid = r->atom;
+ free(r);
+ } else
goto tryharder;
- if (actual_type_return != XA_CARDINAL)
+
+ pc = xcb_get_property(conn, False, win, apid, XCB_ATOM_CARDINAL, 0, 1);
+ pr = xcb_get_property_reply(conn, pc, NULL);
+ if (!pr)
goto tryharder;
- if (pid == NULL)
+ if (pr->type != XCB_ATOM_CARDINAL)
goto tryharder;
- ret = *pid;
- XFree(pid);
+ ret = *(long *)xcb_get_property_value(pr);
+ free(pr);
return (ret);
tryharder:
- if (XGetWindowProperty(display, win,
- XInternAtom(display, "_SWM_PID", False), 0, SWM_PROPLEN, False,
- XA_STRING, &actual_type_return, &actual_format_return,
- &nitems_return, &bytes_after_return, &prop) != Success)
- return (0);
- if (actual_type_return != XA_STRING)
+ c = xcb_intern_atom(conn, False, strlen("_SWM_PID"), "_SWM_PID");
+ r = xcb_intern_atom_reply(conn, c, NULL);
+ if (r) {
+ apid = r->atom;
+ free(r);
+ }
+ pc = xcb_get_property(conn, False, win, apid, XCB_ATOM_STRING,
+ 0, SWM_PROPLEN);
+ pr = xcb_get_property_reply(conn, pc, NULL);
+ if (!pr)
return (0);
- if (prop == NULL)
+ if (pr->type != XCB_ATOM_STRING)
+ free(pr);
return (0);
-
- ret = strtonum((const char *)prop, 0, UINT_MAX, &errstr);
- /* ignore error because strtonum returns 0 anyway */
- XFree(prop);
+ ret = strtonum(xcb_get_property_value(pr), 0, UINT_MAX, &errstr);
+ free(pr);
return (ret);
}
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);