]> code.delx.au - spectrwm/blobdiff - spectrwm.c
convert a XGetWindowAttributes
[spectrwm] / spectrwm.c
index 605ba368cd43315ad8195e67df1787e38abbe790..3367c2a79b1ab11d37884d23eca1cba4a32d93e2 100644 (file)
@@ -486,7 +486,7 @@ struct swm_screen {
 
        /* colors */
        struct {
-               unsigned long   color;
+               uint32_t        color;
                char            *name;
        } c[SWM_S_COLOR_MAX];
 
@@ -2162,8 +2162,8 @@ unmap_window(struct ws_win *win)
        set_win_state(win, XCB_WM_STATE_ICONIC);
 
        xcb_unmap_window(conn, win->id);
-       XSetWindowBorder(display, win->id,
-           win->s->c[SWM_S_COLOR_UNFOCUS].color);
+       xcb_change_window_attributes(conn, win->id,
+               XCB_CW_BORDER_PIXEL, &win->s->c[SWM_S_COLOR_UNFOCUS].color);
 }
 
 void
@@ -2229,29 +2229,32 @@ restart(struct swm_region *r, union arg *args)
 }
 
 struct swm_region *
-root_to_region(Window root)
+root_to_region(xcb_window_t root)
 {
        struct swm_region       *r = NULL;
-       Window                  rr, cr;
-       int                     i, x, y, wx, wy, num_screens;
-       unsigned int            mask;
+       int                     i, num_screens;
+       xcb_query_pointer_cookie_t      qpc;
+       xcb_query_pointer_reply_t       *qpr;
 
-       DNPRINTF(SWM_D_MISC, "root_to_region: window: 0x%lx\n", root);
+       DNPRINTF(SWM_D_MISC, "root_to_region: window: 0x%x\n", root);
 
        num_screens = xcb_setup_roots_length(xcb_get_setup(conn));
        for (i = 0; i < num_screens; i++)
                if (screens[i].root == root)
                        break;
 
-       if (XQueryPointer(display, screens[i].root,
-           &rr, &cr, &x, &y, &wx, &wy, &mask) != False) {
+       qpc = xcb_query_pointer(conn, screens[i].root);
+       qpr = xcb_query_pointer_reply(conn, qpc, NULL);
+
+       if (qpr) {
                DNPRINTF(SWM_D_MISC, "root_to_region: pointer: (%d,%d)\n",
-                   x, y);
+                   qpr->root_x, qpr->root_y);
                /* choose a region based on pointer location */
                TAILQ_FOREACH(r, &screens[i].rl, entry)
-                       if (X(r) <= x && x < MAX_X(r) &&
-                           Y(r) <= y && y < MAX_Y(r))
+                       if (X(r) <= qpr->root_x && qpr->root_x < MAX_X(r) &&
+                           Y(r) <= qpr->root_y && qpr->root_y < MAX_Y(r))
                                break;
+               free(qpr);
        }
 
        if (r == NULL)
@@ -2476,9 +2479,8 @@ unfocus_win(struct ws_win *win)
                ;
 
        grabbuttons(win, 0);
-       XSetWindowBorder(display, win->id,
-           win->ws->r->s->c[SWM_S_COLOR_UNFOCUS].color);
-
+       xcb_change_window_attributes(conn, win->id, XCB_CW_BORDER_PIXEL,
+               &win->ws->r->s->c[SWM_S_COLOR_UNFOCUS].color);
        xcb_change_property(conn, XCB_PROP_MODE_REPLACE, win->s->root,
                ewmh[_NET_ACTIVE_WINDOW].atom, XCB_ATOM_WINDOW, 32, 1,
                &none);
@@ -2540,8 +2542,9 @@ focus_win(struct ws_win *win)
                /* use larger hammer since the window was killed somehow */
                TAILQ_FOREACH(cfw, &win->ws->winlist, entry)
                        if (cfw->ws && cfw->ws->r && cfw->ws->r->s)
-                               XSetWindowBorder(display, cfw->id,
-                                   cfw->ws->r->s->c[SWM_S_COLOR_UNFOCUS].color);
+                               xcb_change_window_attributes(conn, cfw->id,
+                                       XCB_CW_BORDER_PIXEL,
+                                       &cfw->ws->r->s->c[SWM_S_COLOR_UNFOCUS].color);
        }
 
        win->ws->focus = win;
@@ -2555,8 +2558,9 @@ focus_win(struct ws_win *win)
                        xcb_set_input_focus(conn, XCB_INPUT_FOCUS_PARENT,
                                win->id, XCB_CURRENT_TIME);
                grabbuttons(win, 1);
-               XSetWindowBorder(display, win->id,
-                   win->ws->r->s->c[SWM_S_COLOR_FOCUS].color);
+               xcb_change_window_attributes(conn, win->id,
+                       XCB_CW_BORDER_PIXEL,
+                       &win->ws->r->s->c[SWM_S_COLOR_FOCUS].color);
                if (win->ws->cur_layout->flags & SWM_L_MAPONFOCUS ||
                    win->ws->always_raise)
                        map_window_raised(win->id);
@@ -2720,7 +2724,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);
@@ -2729,7 +2734,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);
        }
 }
 
@@ -3217,7 +3223,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;
@@ -3226,6 +3231,8 @@ 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_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));
@@ -3388,10 +3395,13 @@ 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)
+               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)
                                map_window_raised(win->id);
-
+                       free(war);
+               }
                last_h = win_g.h;
                i++;
                j++;
@@ -6540,6 +6550,7 @@ void
 unmanage_window(struct ws_win *win)
 {
        struct ws_win           *parent;
+       xcb_screen_t            *screen;
 
        if (win == NULL)
                return;
@@ -6553,8 +6564,10 @@ unmanage_window(struct ws_win *win)
        }
 
        /* focus on root just in case */
-       XSetInputFocus(display, PointerRoot, PointerRoot, CurrentTime);
-
+       screen = xcb_setup_roots_iterator(xcb_get_setup(conn)).data;
+       xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT,
+               screen->root, XCB_CURRENT_TIME); 
+       
        focus_prev(win);
 
        if (win->hints) {
@@ -7702,9 +7715,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);