Xinqi Bao's Git
projects
/
dwm.git
/ blobdiff
summary
|
log
|
commit
|
diff
|
tree
raw
|
inline
| side by side
added screen-border snapping in floating mode, feels quite well
[dwm.git]
/
event.c
diff --git
a/event.c
b/event.c
index
50c59a0
..
d0f446f
100644
(file)
--- a/
event.c
+++ b/
event.c
@@
-1,6
+1,4
@@
-#include <stdio.h>
-/*
- * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
+/* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
* See LICENSE file for license details.
*/
#include "dwm.h"
* See LICENSE file for license details.
*/
#include "dwm.h"
@@
-20,6
+18,7
@@
typedef struct {
KEYS
#define CLEANMASK(mask) (mask & ~(numlockmask | LockMask))
KEYS
#define CLEANMASK(mask) (mask & ~(numlockmask | LockMask))
+#define MOUSEMASK (BUTTONMASK | PointerMotionMask)
static void
movemouse(Client *c) {
static void
movemouse(Client *c) {
@@
-49,6
+48,14
@@
movemouse(Client *c) {
XSync(dpy, False);
c->x = ocx + (ev.xmotion.x - x1);
c->y = ocy + (ev.xmotion.y - y1);
XSync(dpy, False);
c->x = ocx + (ev.xmotion.x - x1);
c->y = ocy + (ev.xmotion.y - y1);
+ if(abs(c->x) < sx + SNAP)
+ c->x = sx;
+ if(abs(c->y) < sy + bh + SNAP)
+ c->y = sy + bh;
+ if(abs(c->x + c->w) > sx + sw - SNAP)
+ c->x = sw - c->w - 2 * BORDERPX;
+ if(abs(c->y + c->h) > sy + sh - SNAP)
+ c->y = sh - c->h - 2 * BORDERPX;
resize(c, False, TopLeft);
break;
}
resize(c, False, TopLeft);
break;
}
@@
-65,7
+72,7
@@
resizemouse(Client *c) {
ocx = c->x;
ocy = c->y;
if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
ocx = c->x;
ocy = c->y;
if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
-
None, cursor[CurResize], CurrentTime) != GrabSuccess)
+ None, cursor[CurResize], CurrentTime) != GrabSuccess)
return;
c->ismax = False;
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
return;
c->ismax = False;
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
@@
-124,10
+131,8
@@
buttonpress(XEvent *e) {
return;
}
}
return;
}
}
- if(ev->x < x + bmw) {
- if(ev->button == Button1)
- togglemode(NULL);
- }
+ if((ev->x < x + bmw) && (ev->button == Button1))
+ togglemode(NULL);
}
else if((c = getclient(ev->window))) {
focus(c);
}
else if((c = getclient(ev->window))) {
focus(c);
@@
-139,7
+144,8
@@
buttonpress(XEvent *e) {
}
else if(ev->button == Button2)
zoom(NULL);
}
else if(ev->button == Button2)
zoom(NULL);
- else if(ev->button == Button3 && (arrange == dofloat || c->isfloat)) {
+ else if(ev->button == Button3 && (arrange == dofloat || c->isfloat) &&
+ !c->isfixed) {
restack();
resizemouse(c);
}
restack();
resizemouse(c);
}
@@
-151,10
+157,8
@@
configurerequest(XEvent *e) {
unsigned long newmask;
Client *c;
XConfigureRequestEvent *ev = &e->xconfigurerequest;
unsigned long newmask;
Client *c;
XConfigureRequestEvent *ev = &e->xconfigurerequest;
- XEvent synev;
XWindowChanges wc;
XWindowChanges wc;
- fputs("configurerequest\n", stderr);
if((c = getclient(ev->window))) {
c->ismax = False;
gravitate(c, True);
if((c = getclient(ev->window))) {
c->ismax = False;
gravitate(c, True);
@@
-179,10
+183,13
@@
configurerequest(XEvent *e) {
else
configure(c);
XSync(dpy, False);
else
configure(c);
XSync(dpy, False);
- if(c->isfloat)
+ if(c->isfloat)
{
resize(c, False, TopLeft);
resize(c, False, TopLeft);
+ if(!isvisible(c))
+ ban(c);
+ }
else
else
- arrange(
NULL
);
+ arrange();
}
else {
wc.x = ev->x;
}
else {
wc.x = ev->x;
@@
-211,10
+218,8
@@
enternotify(XEvent *e) {
Client *c;
XCrossingEvent *ev = &e->xcrossing;
Client *c;
XCrossingEvent *ev = &e->xcrossing;
- fputs("enternotify\n", stderr);
if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
return;
if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
return;
-
if(((c = getclient(ev->window)) || (c = getctitle(ev->window))) && isvisible(c))
focus(c);
else if(ev->window == root) {
if(((c = getclient(ev->window)) || (c = getctitle(ev->window))) && isvisible(c))
focus(c);
else if(ev->window == root) {
@@
-282,13
+287,11
@@
maprequest(XEvent *e) {
if(!XGetWindowAttributes(dpy, ev->window, &wa))
return;
if(!XGetWindowAttributes(dpy, ev->window, &wa))
return;
-
if(wa.override_redirect) {
XSelectInput(dpy, ev->window,
(StructureNotifyMask | PropertyChangeMask));
return;
}
if(wa.override_redirect) {
XSelectInput(dpy, ev->window,
(StructureNotifyMask | PropertyChangeMask));
return;
}
-
if(!getclient(ev->window))
manage(ev->window, &wa);
}
if(!getclient(ev->window))
manage(ev->window, &wa);
}
@@
-299,10
+302,8
@@
propertynotify(XEvent *e) {
Window trans;
XPropertyEvent *ev = &e->xproperty;
Window trans;
XPropertyEvent *ev = &e->xproperty;
- fputs("propertynotify\n", stderr);
if(ev->state == PropertyDelete)
return; /* ignore */
if(ev->state == PropertyDelete)
return; /* ignore */
-
if((c = getclient(ev->window))) {
if(ev->atom == wmatom[WMProtocols]) {
c->proto = getproto(c->win);
if((c = getclient(ev->window))) {
if(ev->atom == wmatom[WMProtocols]) {
c->proto = getproto(c->win);
@@
-313,7
+314,7
@@
propertynotify(XEvent *e) {
case XA_WM_TRANSIENT_FOR:
XGetTransientForHint(dpy, c->win, &trans);
if(!c->isfloat && (c->isfloat = (trans != 0)))
case XA_WM_TRANSIENT_FOR:
XGetTransientForHint(dpy, c->win, &trans);
if(!c->isfloat && (c->isfloat = (trans != 0)))
- arrange(
NULL
);
+ arrange();
break;
case XA_WM_NORMAL_HINTS:
updatesize(c);
break;
case XA_WM_NORMAL_HINTS:
updatesize(c);
@@
-321,6
+322,7
@@
propertynotify(XEvent *e) {
}
if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
updatetitle(c);
}
if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
updatetitle(c);
+ resizetitle(c);
drawtitle(c);
}
}
drawtitle(c);
}
}