#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
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
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
strlcat(fmtnew, "+4<+A+4<+V", sz);
}
+void
+bar_replace_pad(char *tmp, int *limit, size_t sz)
+{
+ /* special case; no limit given, pad one space, instead */
+ if (*limit == sz - 1)
+ *limit = 1;
+ snprintf(tmp, sz, "%*s", *limit, " ");
+}
+
/* replaces the bar format character sequences (like in tmux(1)) */
char *
bar_replace_seq(char *fmt, char *fmtrep, struct swm_region *r, size_t *offrep,
size_t sz)
{
char *ptr;
- char num[8], tmp[SWM_BAR_MAX];
- int limit;
- size_t len, numoff = 0;
+ char tmp[SWM_BAR_MAX];
+ int limit, size;
+ size_t len;
/* reset strlcat(3) buffer */
*tmp = '\0';
/* get number, if any */
fmt++;
- while (*fmt != '\0' && isdigit((unsigned char) *fmt)) {
- if (numoff >= sizeof num - 1)
- break;
- num[numoff++] = *fmt++;
- }
- num[numoff] = '\0';
-
- if ((limit = strtonum(num, 1, sizeof tmp - 1, NULL)) == 0)
+ size = 0;
+ if (sscanf(fmt, "%d%n", &limit, &size) != 1)
+ limit = sizeof tmp - 1;
+ if (limit <= 0 || limit >= sizeof tmp)
limit = sizeof tmp - 1;
- /* if number is too big, skip to the first non-digit */
- if (numoff >= sizeof num - 1) {
- while (*fmt != '\0' && isdigit((unsigned char) *fmt))
- fmt++;
- }
/* there is nothing to replace (ie EOL) */
+ fmt += size;
if (*fmt == '\0')
return (fmt);
switch (*fmt) {
case '<':
- /* special case; no limit given, pad one space, instead */
- if (limit == sizeof tmp - 1)
- limit = 1;
- snprintf(tmp, sizeof tmp, "%*s", limit, " ");
+ bar_replace_pad(tmp, &limit, sizeof tmp);
break;
case 'A':
snprintf(tmp, sizeof tmp, "%s", bar_ext);
bar_extra_stop();
bar_extra = 1;
unmap_all();
+ xcb_disconnect(conn);
XCloseDisplay(display);
execvp(start_argv[0], start_argv);
warn("execvp failed");
setup_spawn(void)
{
setconfspawn("term", "xterm", 0);
+ setconfspawn("spawn_term", "xterm", 0);
setconfspawn("screenshot_all", "screenshot.sh full", 0);
setconfspawn("screenshot_wind", "screenshot.sh window", 0);
setconfspawn("lock", "xlock", 0);
break;
case SWM_S_SPAWN_TERM:
setconfspawn("term", value, 0);
+ setconfspawn("spawn_term", value, 0);
break;
case SWM_S_SS_APP:
break;
TAILQ_INSERT_AFTER(&win->ws->winlist, ww, win, entry);
else if ((ww = win->ws->focus) &&
spawn_position == SWM_STACK_ABOVE)
- TAILQ_INSERT_AFTER(&win->ws->winlist, win->ws->focus, win, entry);
+ TAILQ_INSERT_AFTER(&win->ws->winlist, win->ws->focus,
+ win, entry);
else if (ww && spawn_position == SWM_STACK_BELOW)
- TAILQ_INSERT_AFTER(&win->ws->winlist, win->ws->focus, win, entry);
+ TAILQ_INSERT_BEFORE(win->ws->focus, win, entry);
else switch (spawn_position) {
default:
case SWM_STACK_TOP:
win->s = r->s; /* this never changes */
if (trans && (ww = find_window(trans)))
TAILQ_INSERT_AFTER(&ws->winlist, ww, win, entry);
- else if (spawn_position == SWM_STACK_ABOVE && win->ws->focus)
- TAILQ_INSERT_AFTER(&win->ws->winlist, win->ws->focus, win, entry);
- else
- TAILQ_INSERT_TAIL(&ws->winlist, win, entry);
+ else if (win->ws->focus && spawn_position == SWM_STACK_ABOVE)
+ TAILQ_INSERT_AFTER(&win->ws->winlist, win->ws->focus, win,
+ entry);
+ else if (win->ws->focus && spawn_position == SWM_STACK_BELOW)
+ TAILQ_INSERT_BEFORE(win->ws->focus, win, entry);
+ else switch (spawn_position) {
+ default:
+ case SWM_STACK_TOP:
+ case SWM_STACK_ABOVE:
+ TAILQ_INSERT_TAIL(&win->ws->winlist, win, entry);
+ break;
+ case SWM_STACK_BOTTOM:
+ case SWM_STACK_BELOW:
+ TAILQ_INSERT_HEAD(&win->ws->winlist, win, entry);
+ }
/* ignore window border if there is one. */
WIDTH(win) = win->wa.width;
void
clientmessage(XEvent *e)
{
- XClientMessageEvent *ev;
- struct ws_win *win;
+ XClientMessageEvent *ev;
+ struct ws_win *win;
ev = &e->xclient;
win = find_window(ev->window);
- if (win == NULL)
+ if (win == NULL) {
+ if (ev->message_type == ewmh[_NET_ACTIVE_WINDOW].atom) {
+ DNPRINTF(SWM_D_EVENT, "clientmessage: request focus on "
+ "unmanaged window.\n");
+ e->xmaprequest.window = ev->window;
+ maprequest(e);
+ }
return;
+ }
DNPRINTF(SWM_D_EVENT, "clientmessage: window: 0x%lx, type: %ld\n",
ev->window, ev->message_type);
/* map virtual screens onto physical screens */
#ifdef SWM_XRR_HAS_CRTC
if (xrandr_support) {
- sr = XRRGetScreenResources(display, screens[i].root);
+ sr = XRRGetScreenResourcesCurrent(display, screens[i].root);
if (sr == NULL)
new_region(&screens[i], 0, 0,
DisplayWidth(display, i),
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);