#include <X11/Xlib-xcb.h>
#include <xcb/randr.h>
#include <xcb/xcb_icccm.h>
+#include <xcb/xcb_keysyms.h>
#include <X11/Xproto.h>
#include <X11/Xutil.h>
#include <X11/extensions/Xrandr.h>
XCB_CONFIG_WINDOW_STACK_MODE, &val);
xcb_map_window(conn, win);
+ xcb_flush(conn);
}
xcb_atom_t
void
dumpwins(struct swm_region *r, union arg *args)
{
- struct ws_win *win;
- uint16_t state;
- XWindowAttributes wa;
+ struct ws_win *win;
+ uint16_t state;
+ xcb_get_window_attributes_cookie_t c;
+ xcb_get_window_attributes_reply_t *r;
if (r->ws == NULL) {
warnx("dumpwins: invalid workspace");
}
warnx("=== managed window list ws %02d ===", r->ws->idx);
-
TAILQ_FOREACH(win, &r->ws->winlist, entry) {
state = getstate(win->id);
- if (!XGetWindowAttributes(display, win->id, &wa))
- warnx("window: 0x%lx, failed XGetWindowAttributes",
+ c = xcb_get_window_attributes(conn, win->id);
+ r = xcb_get_window_attributes_reply(conn, c, NULL);
+ if (r) {
+ warnx("window: 0x%x, map_state: %d, state: %u, "
+ "transient: 0x%x", win->id, wa.map_state,
+ state, win->transient);
+ free(r);
+ } else
+ warnx("window: 0x%x, failed xcb_get_window_attributes",
win->id);
- warnx("window: 0x%lx, map_state: %d, state: %u, "
- "transient: 0x%lx", win->id, wa.map_state, state,
- win->transient);
}
warnx("===== unmanaged window list =====");
TAILQ_FOREACH(win, &r->ws->unmanagedlist, entry) {
state = getstate(win->id);
- if (!XGetWindowAttributes(display, win->id, &wa))
+ c = xcb_get_window_attributes(conn, win->id);
+ r xcb_get_window_attributes_reply(conn, c, NULL);
+ if (r) {
+ warnx("window: 0x%lx, map_state: %d, state: %u, "
+ "transient: 0x%lx", win->id, wa.map_state,
+ state, win->transient);
+ free(r);
+ } else
warnx("window: 0x%lx, failed XGetWindowAttributes",
win->id);
- warnx("window: 0x%lx, map_state: %d, state: %u, "
- "transient: 0x%lx", win->id, wa.map_state, state,
- win->transient);
}
warnx("=================================");
void
bar_urgent(char *s, size_t sz)
{
- XWMHints *wmh = NULL;
struct ws_win *win;
int i, j, num_screens;
char b[8];
+ xcb_get_property_cookie_t c;
+ xcb_wm_hints_t hints;
for (i = 0; i < workspace_limit; i++)
urgent[i] = 0;
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);
- if (wmh == NULL)
+ c = xcb_get_wm_hints(conn, win->id);
+ if (xcb_get_wm_hints_reply(conn, c,
+ &hints, NULL) == 0)
continue;
-
- if (wmh->flags & XUrgencyHint)
+ if (hints.flags & XCB_WM_HINT_X_URGENCY)
urgent[j] = 1;
- XFree(wmh);
}
for (i = 0; i < workspace_limit; i++) {
xcb_send_event(conn, False, win->id,
XCB_EVENT_MASK_NO_EVENT, (const char *)&ev);
+ xcb_flush(conn);
}
/* synthetic response to a ConfigureRequest when not making a change */
void
config_win(struct ws_win *win, XConfigureRequestEvent *ev)
{
- XConfigureEvent ce;
+ xcb_configure_notify_event_t ce;
if (win == NULL)
return;
/* send notification of unchanged state. */
- ce.type = ConfigureNotify;
+ bzero(&ce, sizeof(ce));
+ ce.response_type = XCB_CONFIGURE_NOTIFY;
ce.x = X(win);
ce.y = Y(win);
ce.width = WIDTH(win);
if (ev == NULL) {
/* EWMH */
- ce.display = display;
ce.event = win->id;
ce.window = win->id;
ce.border_width = BORDER(win);
- ce.above = None;
+ ce.above_sibling = XCB_WINDOW_NONE;
} else {
/* normal */
- ce.display = ev->display;
ce.event = ev->window;
ce.window = ev->window;
/* make response appear more WM_SIZE_HINTS-compliant */
if (win->sh_mask)
- DNPRINTF(SWM_D_MISC, "config_win: hints: window: 0x%lx,"
+ DNPRINTF(SWM_D_MISC, "config_win: hints: window: 0x%x,"
" sh_mask: %ld, min: %d x %d, max: %d x %d, inc: "
"%d x %d\n", win->id, win->sh_mask, SH_MIN_W(win),
SH_MIN_H(win), SH_MAX_W(win), SH_MAX_H(win),
ce.x += BORDER(win) - ev->border_width;
ce.y += BORDER(win) - ev->border_width;
ce.border_width = ev->border_width;
- ce.above = ev->above;
+ ce.above_sibling = ev->above;
}
- DNPRINTF(SWM_D_MISC, "config_win: ewmh: %s, window: 0x%lx, (x,y) w x h: "
+ DNPRINTF(SWM_D_MISC, "config_win: ewmh: %s, window: 0x%x, (x,y) w x h: "
"(%d,%d) %d x %d, border: %d\n", YESNO(ev == NULL), win->id, ce.x,
ce.y, ce.width, ce.height, ce.border_width);
- XSendEvent(display, win->id, False, StructureNotifyMask, (XEvent *)&ce);
+ xcb_send_event(conn, False, win->id, XCB_EVENT_MASK_STRUCTURE_NOTIFY,
+ (char *)&ce);
+ xcb_flush(conn);
}
int
}
void
-fake_keypress(struct ws_win *win, int keysym, int modifiers)
+fake_keypress(struct ws_win *win, xcb_keysym_t keysym, uint16_t modifiers)
{
- XKeyEvent event;
+ xcb_key_press_event_t event;
+ xcb_key_symbols_t *syms;
+ xcb_keycode_t *keycode;
if (win == NULL)
return;
-
- event.display = display; /* Ignored, but what the hell */
- event.window = win->id;
+
+ syms = xcb_key_symbols_alloc(conn);
+ keycode = xcb_key_symbols_get_keycode(syms, keysym);
+
+ event.event = win->id;
event.root = win->s->root;
- event.subwindow = None;
- event.time = CurrentTime;
- event.x = X(win);
- event.y = Y(win);
- event.x_root = 1;
- event.y_root = 1;
+ event.child = XCB_WINDOW_NONE;
+ event.time = XCB_CURRENT_TIME;
+ event.event_x = X(win);
+ event.event_y = Y(win);
+ event.root_x = 1;
+ event.root_y = 1;
event.same_screen = True;
- event.keycode = XKeysymToKeycode(display, keysym);
+ event.detail = *keycode;
event.state = modifiers;
- event.type = KeyPress;
- XSendEvent(event.display, event.window, True,
- KeyPressMask, (XEvent *)&event);
-
- event.type = KeyRelease;
- XSendEvent(event.display, event.window, True,
- KeyPressMask, (XEvent *)&event);
+ event.response_type = XCB_KEY_PRESS;
+ xcb_send_event(conn, win->id, True,
+ XCB_EVENT_MASK_KEY_PRESS, (char *)&event);
+ event.response_type = XCB_KEY_RELEASE;
+ xcb_send_event(conn, win->id, True,
+ XCB_EVENT_MASK_KEY_RELEASE, (char *)&event);
+ xcb_flush(conn);
+
+ xcb_key_symbols_free(syms);
}
void
void
stack_master(struct workspace *ws, struct swm_geometry *g, int rot, int flip)
{
+ XWindowAttributes wa;
struct swm_geometry win_g, r_g = *g;
struct ws_win *win, *fs_win = NULL;
int i, j, s, stacks;
int split, colno, winno, mwin, msize, mscale;
int remain, missing, v_slice, reconfigure;
int bordered = 1;
- xcb_get_window_attributes_cookie_t wac;
- xcb_get_window_attributes_reply_t *war;
DNPRINTF(SWM_D_STACK, "stack_master: workspace: %d, rot: %s, "
"flip: %s\n", ws->idx, YESNO(rot), YESNO(flip));
update_window(win);
}
- wac = xcb_get_window_attributes(conn, win->id);
- war = xcb_get_window_attributes_reply(conn, wac, NULL);
- if (war) {
- if (war->map_state == XCB_MAP_STATE_UNMAPPED)
+ if (XGetWindowAttributes(display, win->id, &wa))
+ if (wa.map_state == IsUnmapped)
map_window_raised(win->id);
- free(war);
- }
+
last_h = win_g.h;
i++;
j++;
const char *errstr;
struct pid_e *p;
struct quirk *qp;
-
+ uint32_t event_mask;
+
if ((win = find_window(id)) != NULL)
return (win); /* already being managed */
update_window(win);
}
- XSelectInput(display, id, EnterWindowMask | FocusChangeMask |
- PropertyChangeMask | StructureNotifyMask);
+ event_mask = XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_FOCUS_CHANGE |
+ XCB_EVENT_MASK_PROPERTY_CHANGE |
+ XCB_EVENT_MASK_STRUCTURE_NOTIFY;
+ xcb_change_window_attributes(conn, id, XCB_CW_EVENT_MASK, &event_mask);
+
/* floaters need to be mapped if they are in the current workspace */
if ((win->floating || win->transient) && (ws->idx == r->ws->idx))
map_window_raised(win->id);
setup_screens(void)
{
int i, j, k, num_screens;
- int errorbase;
struct workspace *ws;
XGCValues gcv;
-
+ const xcb_query_extension_reply_t *qep;
xcb_randr_query_version_cookie_t c;
xcb_randr_query_version_reply_t *r;
"screens");
/* initial Xrandr setup */
- xrandr_support = XRRQueryExtension(display,
- &xrandr_eventbase, &errorbase);
- if (xrandr_support) {
- c = xcb_randr_query_version(conn, True, False);
- r = xcb_randr_query_version_reply(conn, c, NULL);
- if (r) {
- if (r->major_version < 1)
- xrandr_support = 0;
- free(r);
- } else
- xrandr_support = 0;
+ xrandr_support = False;
+ c = xcb_randr_query_version(conn, True, True);
+ r = xcb_randr_query_version_reply(conn, c, NULL);
+ if (r) {
+ if (r->major_version >= 1)
+ xrandr_support = True;
+ free(r);
}
+ qep = xcb_get_extension_data(conn, &xcb_randr_id);
+ xrandr_eventbase = qep->first_event;
/* map physical screens */
for (i = 0; i < num_screens; i++) {
int xfd, i, num_screens;
fd_set rd;
struct sigaction sact;
- xcb_generic_event_t *evt;
start_argv = argv;
warnx("Welcome to spectrwm V%s Build: %s", SPECTRWM_VERSION, buildstr);
xfd = xcb_get_file_descriptor(conn);
while (running) {
- while ((evt = xcb_poll_for_event(conn)) == 0) {
+ while (XPending(display)) {
XNextEvent(display, &e);
if (running == 0)
goto done;
xrandr_geteventname(&e), e.type);
switch (e.type - xrandr_eventbase) {
- case RRScreenChangeNotify:
+ case XCB_RANDR_SCREEN_CHANGE_NOTIFY:
screenchange(&e);
break;
default: