This repository has been archived by the owner on Jan 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
tilemovemouse.c
70 lines (63 loc) · 1.55 KB
/
tilemovemouse.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH))
void
insertbefore(Client *a, Client *b) { /* insert a before b in the client list */
Monitor *m = a->mon;
Client **x = &m->clients;
while(*x != b && *x)
x = & (*x)->next;
*x = a;
a->next = b;
}
void
insertafter(Client *a, Client *b) { /* insert a after b in the client list */
a->next = b->next;
b->next = a;
}
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);
}