#include "dat.h"
#include "fns.h"

int
grab(Box * box, Window w, int mask, Cursor curs, int t)
{
    int status;

    if (t == 0)
        t = CurrentTime;
    status = XGrabPointer(box->dpy, w, False, mask,
        GrabModeAsync, GrabModeAsync, None, curs, t);
    return status;
}


void
ungrab(Box * box, XButtonEvent * e)
{
    XEvent ev;

    if (!nobuttons(e))
        for (;;) {
            XMaskEvent(box->dpy, ButtonMask | ButtonMotionMask, &ev);
            if (ev.type == MotionNotify)
                continue;
            e = &ev.xbutton;
            if (nobuttons(e))
                break;
        }
    XUngrabPointer(box->dpy, e->time);
    box->curtime = e->time;
}
