JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
convert a XConfigureWindow to XCB.
[spectrwm.git] / spectrwm.c
index 53aaba2..0f6b131 100644 (file)
@@ -136,7 +136,7 @@ static const char   *buildstr = SPECTRWM_VERSION;
 #define xcb_icccm_get_wm_transient_for_reply   xcb_get_wm_transient_for_reply
 #endif
 
-#define SWM_DEBUG
+/*#define SWM_DEBUG*/
 #ifdef SWM_DEBUG
 #define DPRINTF(x...)          do { if (swm_debug) fprintf(stderr, x); } while (0)
 #define DNPRINTF(n,x...)       do { if (swm_debug & n) fprintf(stderr, x); } while (0)
@@ -2044,8 +2044,9 @@ void
 drain_enter_notify(void)
 {
        int                     i = 0;
+       XEvent                  cne;
 
-       while (xcb_poll_for_event(conn))
+       while (XCheckMaskEvent(display, EnterWindowMask, &cne))
                i++;
 
        DNPRINTF(SWM_D_EVENT, "drain_enter_notify: drained: %d\n", i);
@@ -2304,7 +2305,9 @@ restart(struct swm_region *r, union arg *args)
        bar_extra_stop();
        bar_extra = 1;
        unmap_all();
-       XCloseDisplay(display);
+       xcb_flush(conn);
+       xcb_disconnect(conn);
+
        execvp(start_argv[0], start_argv);
        warn("execvp failed");
        quit(NULL, NULL);
@@ -3304,7 +3307,6 @@ adjust_font(struct ws_win *win)
 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;
@@ -3313,6 +3315,7 @@ stack_master(struct workspace *ws, struct swm_geometry *g, int rot, int flip)
        int                     split, colno, winno, mwin, msize, mscale;
        int                     remain, missing, v_slice, reconfigure;
        int                     bordered = 1;
+       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));
@@ -3475,9 +3478,14 @@ stack_master(struct workspace *ws, struct swm_geometry *g, int rot, int flip)
                        update_window(win);
                }
 
-               if (XGetWindowAttributes(display, win->id, &wa))
-                       if (wa.map_state == IsUnmapped)
+               war = xcb_get_window_attributes_reply(conn,
+                       xcb_get_window_attributes(conn, win->id),
+                       NULL);
+               if (war) {
+                       if (war->map_state == XCB_MAP_STATE_UNMAPPED)
                                map_window_raised(win->id);
+                       free(war);
+               }
 
                last_h = win_g.h;
                i++;
@@ -5521,19 +5529,36 @@ setkeymapping(char *selector, char *value, int flags)
 void
 updatenumlockmask(void)
 {
-       unsigned int            i, j;
-       XModifierKeymap         *modmap;
+       unsigned int                            i, j;
+       xcb_get_modifier_mapping_reply_t        *modmap_r;
+       xcb_keycode_t                           *modmap, kc;
+       xcb_key_symbols_t                       *syms;
 
        DNPRINTF(SWM_D_MISC, "updatenumlockmask\n");
        numlockmask = 0;
-       modmap = XGetModifierMapping(display);
-       for (i = 0; i < 8; i++)
-               for (j = 0; j < modmap->max_keypermod; j++)
-                       if (modmap->modifiermap[i * modmap->max_keypermod + j]
-                           == XKeysymToKeycode(display, XK_Num_Lock))
-                               numlockmask = (1 << i);
 
-       XFreeModifiermap(modmap);
+       syms = xcb_key_symbols_alloc(conn);
+       if (!syms)
+               return;
+       
+       modmap_r = xcb_get_modifier_mapping_reply(conn,
+               xcb_get_modifier_mapping(conn),
+               NULL);
+       if (modmap_r) {
+               modmap = xcb_get_modifier_mapping_keycodes(modmap_r);
+               for (i = 0; i < 8; i++) {
+                       for (j = 0; j < modmap_r->keycodes_per_modifier; j++) {
+                               kc = modmap[i * modmap_r->keycodes_per_modifier
+                                       + j];
+
+                               if (kc == *((xcb_keycode_t *)xcb_key_symbols_get_keycode(syms,
+                                               XK_Num_Lock))) 
+                                       numlockmask = (1 << i);
+                       }
+               }
+               free(modmap_r);
+       }
+       xcb_key_symbols_free(syms);
 }
 
 void
@@ -6450,7 +6475,6 @@ manage_window(xcb_window_t id)
 
        /* Get all the window data in one shot */
        ws_idx_atom = get_atom_from_string("_SWM_WS");
-       fprintf(stderr, "ws_idx_atom: %d\n", ws_idx_atom);
        if (ws_idx_atom) {
                gpr = xcb_get_property_reply(conn,
                        xcb_get_property(conn, False, id, ws_idx_atom,
@@ -6811,28 +6835,49 @@ configurerequest(XEvent *e)
 {
        XConfigureRequestEvent  *ev = &e->xconfigurerequest;
        struct ws_win           *win;
-       int                     new = 0;
-       XWindowChanges          wc;
+       int                     new = 0, i = 0;
+       uint16_t                mask = 0;       
+       uint32_t                wc[7];
 
        if ((win = find_window(ev->window)) == NULL)
                if ((win = find_unmanaged_window(ev->window)) == NULL)
                        new = 1;
 
        if (new) {
-               bzero(&wc, sizeof wc);
-               wc.x = ev->x;
-               wc.y = ev->y;
-               wc.width = ev->width;
-               wc.height = ev->height;
-               wc.border_width = ev->border_width;
-               wc.sibling = ev->above;
-               wc.stack_mode = ev->detail;
+               if (ev->value_mask & XCB_CONFIG_WINDOW_X) {
+                       mask |= XCB_CONFIG_WINDOW_X;
+                       wc[i++] = ev->x;
+               }
+               if (ev->value_mask & XCB_CONFIG_WINDOW_Y) {
+                       mask |= XCB_CONFIG_WINDOW_Y;
+                       wc[i++] = ev->y;
+               }
+               if (ev->value_mask & XCB_CONFIG_WINDOW_WIDTH) {
+                       mask |= XCB_CONFIG_WINDOW_WIDTH;
+                       wc[i++] = ev->width;
+               }
+               if (ev->value_mask & XCB_CONFIG_WINDOW_HEIGHT) {
+                       mask |= XCB_CONFIG_WINDOW_HEIGHT;
+                       wc[i++] = ev->height;
+               }
+               if (ev->value_mask & XCB_CONFIG_WINDOW_BORDER_WIDTH) {
+                       mask |= XCB_CONFIG_WINDOW_BORDER_WIDTH;
+                       wc[i++] = ev->border_width;
+               }
+               if (ev->value_mask & XCB_CONFIG_WINDOW_SIBLING) {
+                       mask |= XCB_CONFIG_WINDOW_SIBLING;
+                       wc[i++] = ev->above;
+               }
+               if (ev->value_mask & XCB_CONFIG_WINDOW_STACK_MODE) {
+                       mask |= XCB_CONFIG_WINDOW_STACK_MODE;
+                       wc[i++] = ev->detail;
+               }
 
                DNPRINTF(SWM_D_EVENT, "configurerequest: new window: 0x%lx, "
                    "new: %s, (x,y) w x h: (%d,%d) %d x %d\n", ev->window,
                    YESNO(new), wc.x, wc.y, wc.width, wc.height);
 
-               XConfigureWindow(display, ev->window, ev->value_mask, &wc);
+               xcb_configure_window(conn, ev->window, mask, wc);
        } else if ((!win->manual || win->quirks & SWM_Q_ANYWHERE) &&
            !(win->ewmh_flags & EWMH_F_FULLSCREEN)) {
                win->g_float.x = ev->x - X(win->ws->r);
@@ -7187,8 +7232,8 @@ propertynotify(XEvent *e)
                XMoveResizeWindow(display, win->id,
                    X(win), Y(win), WIDTH(win), HEIGHT(win));
 #endif
-       case XA_WM_CLASS:
-       case XA_WM_NAME:
+       case XCB_ATOM_WM_CLASS:
+       case XCB_ATOM_WM_NAME:
                bar_update();
                break;
        default:
@@ -7225,7 +7270,7 @@ unmapnotify(XEvent *e)
                    SubstructureNotifyMask, &cne))
                        ;
                /* resend unmap because we ated it */
-               XUnmapWindow(display, e->xunmap.window);
+               xcb_unmap_window(conn, e->xunmap.window);
        }
 
        if (focus_mode == SWM_FOCUS_DEFAULT)
@@ -7945,7 +7990,6 @@ done:
                        xcb_free_gc(conn, screens[i].bar_gc);
        XFreeFontSet(display, bar_fs);
        xcb_disconnect(conn);
-       XCloseDisplay(display);
 
        return (0);
 }