void
teardown_ewmh(void)
{
- int i, success;
+ int i, success, num_screens;
unsigned char *data = NULL;
unsigned long n;
Atom sup_check, sup_list;
sup_check = XInternAtom(display, "_NET_SUPPORTING_WM_CHECK", False);
sup_list = XInternAtom(display, "_NET_SUPPORTED", False);
- for (i = 0; i < ScreenCount(display); i++) {
+ 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);
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
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);
{
XWMHints *wmh = NULL;
struct ws_win *win;
- int i, j;
+ int i, j, num_screens;
char b[8];
for (i = 0; i < workspace_limit; i++)
urgent[i] = 0;
- 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) {
wmh = XGetWMHints(display, win->id);
{
char fmtexp[SWM_BAR_MAX], fmtnew[SWM_BAR_MAX];
char fmtrep[SWM_BAR_MAX];
- int i;
+ int i, num_screens;
struct swm_region *r;
/* expand the format by first passing it through strftime(3) */
bar_fmt_expand(fmtexp, sizeof fmtexp);
- 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) {
if (r->bar == NULL)
continue;
bar_toggle(struct swm_region *r, union arg *args)
{
struct swm_region *tmpr;
- int i, sc = ScreenCount(display);
+ int i, num_screens;
DNPRINTF(SWM_D_BAR, "bar_toggle\n");
+ num_screens = xcb_setup_roots_length(xcb_get_setup(conn));
if (bar_enabled) {
- for (i = 0; i < sc; i++)
+ for (i = 0; i < num_screens; i++)
TAILQ_FOREACH(tmpr, &screens[i].rl, entry)
if (tmpr->bar)
XUnmapWindow(display, tmpr->bar->id);
} else {
- for (i = 0; i < sc; i++)
+ for (i = 0; i < num_screens; i++)
TAILQ_FOREACH(tmpr, &screens[i].rl, entry)
if (tmpr->bar)
XMapRaised(display, tmpr->bar->id);
{
XSetWindowAttributes wa;
struct swm_region *r;
- int i;
+ int i, num_screens;
/* do this here because the conf file is in memory */
if (bar_extra && bar_extra_running == 0 && bar_argv[0]) {
}
bzero(&wa, sizeof wa);
- 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) {
if (r->bar == NULL)
continue;
unmap_all(void)
{
struct ws_win *win;
- int i, j;
+ int i, j, num_screens;
- for (i = 0; i < ScreenCount(display); i++)
+ for (i = 0; i < num_screens; i++)
for (j = 0; j < workspace_limit; j++)
TAILQ_FOREACH(win, &screens[i].ws[j].winlist, entry)
unmap_window(win);
{
struct swm_region *r = NULL;
Window rr, cr;
- int i, x, y, wx, wy;
+ int i, x, y, wx, wy, num_screens;
unsigned int mask;
DNPRINTF(SWM_D_MISC, "root_to_region: window: 0x%lx\n", root);
- for (i = 0; i < ScreenCount(display); i++)
+ num_screens = xcb_setup_roots_length(xcb_get_setup(conn));
+ for (i = 0; i < num_screens; i++)
if (screens[i].root == root)
break;
find_unmanaged_window(Window id)
{
struct ws_win *win;
- int i, j;
+ int i, j, num_screens;
- 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].unmanagedlist,
entry)
{
struct ws_win *win;
Window wrr, wpr, *wcr = NULL;
- int i, j;
+ int i, j, num_screens;
unsigned int nc;
- 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)
if (id == win->id)
return (NULL);
/* look for parent */
- for (i = 0; i < ScreenCount(display); i++)
+ for (i = 0; i < num_screens; i++)
for (j = 0; j < workspace_limit; j++)
TAILQ_FOREACH(win, &screens[i].ws[j].winlist, entry)
if (wpr == win->id)
void
kill_refs(struct ws_win *win)
{
- int i, x;
+ int i, x, num_screens;
struct swm_region *r;
struct workspace *ws;
if (win == NULL)
return;
- 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];
struct ws_win *win;
struct workspace *ws;
struct swm_region *r;
- int i, x;
+ int i, x, num_screens;
if (testwin == NULL)
return (0);
- 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];
{
struct swm_region *rr = NULL;
union arg a;
- int i, x, y;
+ int i, x, y, num_screens;
+ num_screens = xcb_setup_roots_length(xcb_get_setup(conn));
/* do nothing if we don't have more than one screen */
- if (!(ScreenCount(display) > 1 || outputs > 1))
+ if (!(num_screens > 1 || outputs > 1))
return;
i = r->s->idx;
stack(void) {
struct swm_geometry g;
struct swm_region *r;
- int i;
+ int i, num_screens;
#ifdef SWM_DEBUG
int j;
#endif
DNPRINTF(SWM_D_STACK, "stack: begin\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++) {
#ifdef SWM_DEBUG
j = 0;
#endif
{
struct swm_geometry gg = *g;
struct ws_win *win, *wintrans = NULL, *parent = NULL;
- int winno;
+ int winno, num_screens;
DNPRINTF(SWM_D_STACK, "max_stack: workspace: %d\n", ws->idx);
if (winno == 0 && count_win(ws, 1) == 0)
return;
+ num_screens = xcb_setup_roots_length(xcb_get_setup(conn));
TAILQ_FOREACH(win, &ws->winlist, entry) {
if (win->transient) {
wintrans = win;
}
/* unmap only if we don't have multi screen */
if (win != ws->focus)
- if (!(ScreenCount(display) > 1 || outputs > 1))
+ if (!(num_screens > 1 || outputs > 1))
unmap_window(win);
}
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)
void
grabkeys(void)
{
+ int num_screens;
unsigned int j, k;
KeyCode code;
unsigned int modifiers[] =
DNPRINTF(SWM_D_MISC, "grabkeys\n");
updatenumlockmask();
- for (k = 0; k < ScreenCount(display); k++) {
+ num_screens = xcb_setup_roots_length(xcb_get_setup(conn));
+ for (k = 0; k < num_screens; k++) {
if (TAILQ_EMPTY(&screens[k].rl))
continue;
XUngrabKey(display, AnyKey, AnyModifier, screens[k].root);
setlayout(char *selector, char *value, int flags)
{
int ws_id, i, x, mg, ma, si, raise, f = 0;
- int st = SWM_V_STACK;
+ int st = SWM_V_STACK, num_screens;
char s[1024];
struct workspace *ws;
"<master_grow>:<master_add>:<stack_inc>:<always_raise>:"
"<type>'");
- for (i = 0; i < ScreenCount(display); i++) {
+ num_screens = xcb_setup_roots_length(xcb_get_setup(conn));
+ for (i = 0; i < num_screens; i++) {
ws = (struct workspace *)&screens[i].ws;
ws[ws_id].cur_layout = &layouts[st];
void
visibilitynotify(XEvent *e)
{
- int i;
+ int i, num_screens;
struct swm_region *r;
DNPRINTF(SWM_D_EVENT, "visibilitynotify: window: 0x%lx\n",
e->xvisibility.window);
- if (e->xvisibility.state == VisibilityUnobscured)
- for (i = 0; i < ScreenCount(display); i++)
+
+ if (e->xvisibility.state == VisibilityUnobscured) {
+ 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 (e->xvisibility.window == WINID(r->bar))
bar_update();
+ }
}
void
int ncrtc = 0;
#endif /* SWM_XRR_HAS_CRTC */
struct swm_region *r;
+ int num_screens;
-
- if (i >= ScreenCount(display))
+ num_screens = xcb_setup_roots_length(xcb_get_setup(conn));
+ if (i >= num_screens)
errx(1, "scan_xrandr: invalid screen");
/* remove any old regions */
screenchange(XEvent *e) {
XRRScreenChangeNotifyEvent *xe = (XRRScreenChangeNotifyEvent *)e;
struct swm_region *r;
- int i;
+ int i, num_screens;
DNPRINTF(SWM_D_EVENT, "screenchange: root: 0x%lx\n", xe->root);
if (!XRRUpdateConfiguration(e))
return;
+ num_screens = xcb_setup_roots_length(xcb_get_setup(conn));
/* silly event doesn't include the screen index */
- for (i = 0; i < ScreenCount(display); i++)
+ for (i = 0; i < num_screens; i++)
if (screens[i].root == xe->root)
break;
- if (i >= ScreenCount(display))
+ if (i >= num_screens)
errx(1, "screenchange: screen not found");
/* brute force for now, just re-enumerate the regions */
scan_xrandr(i);
/* add bars to all regions */
- for (i = 0; i < ScreenCount(display); i++)
+ for (i = 0; i < num_screens; i++)
TAILQ_FOREACH(r, &screens[i].rl, entry)
bar_setup(r);
stack();
Window d1, d2, *wins = NULL;
XWindowAttributes wa;
unsigned int no;
- int i, j;
+ int i, j, num_screens;
long state, manage;
- for (i = 0; i < ScreenCount(display); i++) {
+ num_screens = xcb_setup_roots_length(xcb_get_setup(conn));
+ for (i = 0; i < num_screens; i++) {
if (!XQueryTree(display, screens[i].root, &d1, &d2, &wins, &no))
continue;
void
workaround(void)
{
- int i;
+ int i, num_screens;
Atom netwmcheck, netwmname, utf8_string;
Window root, win;
netwmcheck = XInternAtom(display, "_NET_SUPPORTING_WM_CHECK", False);
netwmname = XInternAtom(display, "_NET_WM_NAME", False);
utf8_string = XInternAtom(display, "UTF8_STRING", False);
- for (i = 0; i < ScreenCount(display); i++) {
+
+ num_screens = xcb_setup_roots_length(xcb_get_setup(conn));
+ for (i = 0; i < num_screens; i++) {
root = screens[i].root;
win = XCreateSimpleWindow(display,root, 0, 0, 1, 1, 0,
screens[i].c[SWM_S_COLOR_UNFOCUS].color,
char conf[PATH_MAX], *cfile = NULL;
struct stat sb;
XEvent e;
- int xfd, i;
+ int xfd, i, num_screens;
fd_set rd;
struct sigaction sact;
setenv("SWM_STARTED", "YES", 1);
/* setup all bars */
- 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) {
if (winfocus == NULL)
winfocus = TAILQ_FIRST(&r->ws->winlist);
continue;
}
/* move pointer to first screen if multi screen */
- if (ScreenCount(display) > 1 || outputs > 1)
+ if (num_screens > 1 || outputs > 1)
XWarpPointer(display, None, rr->s[0].root,
0, 0, 0, 0, X(rr),
Y(rr) + (bar_enabled ? bar_height : 0));
teardown_ewmh();
bar_extra_stop();
- for (i = 0; i < ScreenCount(display); ++i)
+ for (i = 0; i < num_screens; ++i)
if (screens[i].bar_gc != NULL)
XFreeGC(display, screens[i].bar_gc);