コード例 #1
0
void
tilemovemouse(const Arg *arg) {
	/* Could EnterNotify events be used instead? */
	Client *c, *d;
	Monitor *m;
	XEvent ev;
	int x, y;
	Bool after;

	if(!(c = selmon->sel))
		return;

	if((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) {
		sendmon(c, m);
		selmon = m;
		focus(NULL);
	}

	if(c->isfloating || !selmon->lt[selmon->sellt]->arrange){
		movemouse(NULL);
		return;
	}
	if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
		None, cursor[CurMove], CurrentTime) != GrabSuccess)
		return;
	do {
		XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
		switch (ev.type) {
		case ConfigureRequest:
		case Expose:
		case MapRequest:
			handler[ev.type](&ev);
			break;
		case MotionNotify:
			x = ev.xmotion.x;
			y = ev.xmotion.y;
			after = False;
			for(d = nexttiled(m->clients); d; d = nexttiled(d->next)){
				if(d == c)
					after = True;
				else if(INRECT(x, y, d->x, d->y, d->w+2*borderpx, d->h+2*borderpx)){
					detach(c);
					after ? insertafter(c, d) : insertbefore(c,d);
					arrange(c->mon);
					break;
				}
			}
		}
	} while(ev.type != ButtonRelease);
	XUngrabPointer(dpy, CurrentTime);
}
コード例 #2
0
ファイル: event.c プロジェクト: DrItanium/2wmr
static void
buttonpress(XEvent *e) {
	Client *c;
	XButtonPressedEvent *ev = &e->xbutton;

	if((c = getclient(ev->window))) {
		focus(c);
		if(CLEANMASK(ev->state) != MODKEY)
			return;
		if(ev->button == Button1 && c->isfloat) {
			restack();
			movemouse(c);
		}
		else if(ev->button == Button2)
			zoom(NULL);
		else if(ev->button == Button3 && c->isfloat && !c->isfixed) {
			restack();
			resizemouse(c);
		}
	}
}
コード例 #3
0
ファイル: xs.c プロジェクト: npe9/harvey
int
play(void)
{
    int i;
    Mouse om;
    int s;
    Rune r;
    Alt alts[NALT+1];

    alts[TIMER].c = timerc;
    alts[TIMER].v = nil;
    alts[TIMER].op = CHANRCV;
    alts[MOUSE].c = mousec;
    alts[MOUSE].v = &mouse;
    alts[MOUSE].op = CHANRCV;
    alts[SUSPEND].c = suspc;
    alts[SUSPEND].v = &s;
    alts[SUSPEND].op = CHANRCV;
    alts[RESHAPE].c = mousectl->resizec;
    alts[RESHAPE].v = nil;
    alts[RESHAPE].op = CHANRCV;
    alts[KBD].c = kbdc;
    alts[KBD].v = &r;
    alts[KBD].op = CHANRCV;
    alts[NALT].op = CHANEND;

    dt = 64;
    lastmx = -1;
    lastmx = movemouse();
    choosepiece();
    lastmx = warp(mouse.xy, lastmx);
    for(;;)
        switch(alt(alts)) {
        case MOUSE:
            if(suspended) {
                om = mouse;
                break;
            }
            if(lastmx < 0)
                lastmx = mouse.xy.x;
            if(mouse.xy.x > lastmx+DMOUSE) {
                mright();
                lastmx = mouse.xy.x;
            }
            if(mouse.xy.x < lastmx-DMOUSE) {
                mleft();
                lastmx = mouse.xy.x;
            }
            if(mouse.buttons&1 && !(om.buttons&1))
                rleft();
            if(mouse.buttons&2 && !(om.buttons&2))
                if(drop(1))
                    return 1;
            if(mouse.buttons&4 && !(om.buttons&4))
                rright();
            om = mouse;
            break;
        case SUSPEND:
            if (!suspended && s)
                suspend(1);
            else if (suspended && !s) {
                suspend(0);
                lastmx = warp(mouse.xy, lastmx);
            }
            break;
        case RESHAPE:
            redraw(1);
            break;
        case KBD:
            if(suspended)
                break;
            switch(r) {
            case 'f':
            case ';':
                mright();
                break;
            case 'a':
            case 'j':
                mleft();
                break;
            case 'd':
            case 'l':
                rright();
                break;
            case 's':
            case 'k':
                rleft();
                break;
            case ' ':
                if(drop(1))
                    return 1;
                break;
            }
            break;
        case TIMER:
            if(suspended)
                break;
            dt -= tsleep;
            if(dt < 0) {
                i = 1;
                dt = 16 * (points+nrand(10000)-5000) / 10000;
                if(dt >= 32) {
                    i += (dt-32)/16;
                    dt = 32;
                }
                dt = 52-dt;
                while(i-- > 0)
                    if(movepiece()==0 && ++fusst==40) {
                        if(drop(0))
                            return 1;
                        break;
                    }
            }
            break;
        }
}