JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
convert dumpwins() to XCB
[spectrwm.git] / spectrwm.c
index f7ed89b..ef20ce0 100644 (file)
@@ -637,6 +637,7 @@ map_window_raised(xcb_window_t win)
                XCB_CONFIG_WINDOW_STACK_MODE, &val);
 
        xcb_map_window(conn, win);      
+       xcb_flush(conn);
 }
 
 xcb_atom_t
@@ -1122,9 +1123,10 @@ xrandr_geteventname(XEvent *e)
 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");
@@ -1132,26 +1134,33 @@ dumpwins(struct swm_region *r, union arg *args)
        }
 
        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("=================================");
@@ -1502,10 +1511,11 @@ int             urgent[SWM_WS_MAX];
 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;
@@ -1514,13 +1524,12 @@ bar_urgent(char *s, size_t sz)
        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++) {
@@ -2724,7 +2733,8 @@ cyclescr(struct swm_region *r, union arg *args)
        /* move mouse to region */
        x = X(rr) + 1;
        y = Y(rr) + 1 + (bar_enabled ? bar_height : 0);
-       XWarpPointer(display, None, rr->s[i].root, 0, 0, 0, 0, x, y);
+       xcb_warp_pointer(conn, XCB_WINDOW_NONE, rr->s[i].root, 0, 0, 0, 0,
+               x, y);
 
        a.id = SWM_ARG_ID_FOCUSCUR;
        focus(rr, &a);
@@ -2733,7 +2743,8 @@ cyclescr(struct swm_region *r, union arg *args)
                /* move to focus window */
                x = X(rr->ws->focus) + 1;
                y = Y(rr->ws->focus) + 1;
-               XWarpPointer(display, None, rr->s[i].root, 0, 0, 0, 0, x, y);
+               xcb_warp_pointer(conn, XCB_WINDOW_NONE, rr->s[i].root, 0, 0, 0,
+                       0, x, y);
        }
 }
 
@@ -6285,7 +6296,8 @@ manage_window(xcb_window_t id)
        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 */
 
@@ -6504,9 +6516,12 @@ manage_window(xcb_window_t id)
                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);
@@ -7419,10 +7434,9 @@ void
 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;
 
@@ -7433,18 +7447,16 @@ setup_screens(void)
                    "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++) {
@@ -7549,7 +7561,6 @@ main(int argc, char *argv[])
        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);
@@ -7671,7 +7682,7 @@ noconfig:
 
        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;
@@ -7709,9 +7720,9 @@ noconfig:
                        }
                        /* move pointer to first screen if multi screen */
                        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));
+                               xcb_warp_pointer(conn, XCB_WINDOW_NONE,
+                                       rr->s[0].root, 0, 0, 0, 0, X(rr),
+                                       Y(rr) + (bar_enabled ? bar_height : 0));
 
                        a.id = SWM_ARG_ID_FOCUSCUR;
                        focus(rr, &a);