mirror of
https://github.com/leahneukirchen/cwm.git
synced 2023-08-10 21:13:12 +03:00
Clean up, unify and accurately calculate edge distance with client move/resize
actions, so as to not lose windows off the edge. inspired by diffs (and feedback) from Vadim Vygonets.
This commit is contained in:
parent
4d85e2e2a6
commit
3d6ff6dabf
1
calmwm.h
1
calmwm.h
@ -399,6 +399,7 @@ void client_msg(struct client_ctx *, Atom, Time);
|
|||||||
void client_move(struct client_ctx *);
|
void client_move(struct client_ctx *);
|
||||||
int client_inbound(struct client_ctx *, int, int);
|
int client_inbound(struct client_ctx *, int, int);
|
||||||
struct client_ctx *client_init(Window, struct screen_ctx *, int);
|
struct client_ctx *client_init(Window, struct screen_ctx *, int);
|
||||||
|
void client_ptr_inbound(struct client_ctx *, int);
|
||||||
void client_ptrsave(struct client_ctx *);
|
void client_ptrsave(struct client_ctx *);
|
||||||
void client_ptrwarp(struct client_ctx *);
|
void client_ptrwarp(struct client_ctx *);
|
||||||
void client_raise(struct client_ctx *);
|
void client_raise(struct client_ctx *);
|
||||||
|
18
client.c
18
client.c
@ -470,6 +470,24 @@ client_config(struct client_ctx *cc)
|
|||||||
XSendEvent(X_Dpy, cc->win, False, StructureNotifyMask, (XEvent *)&cn);
|
XSendEvent(X_Dpy, cc->win, False, StructureNotifyMask, (XEvent *)&cn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
client_ptr_inbound(struct client_ctx *cc, int getpos)
|
||||||
|
{
|
||||||
|
if (getpos)
|
||||||
|
xu_ptr_getpos(cc->win, &cc->ptr.x, &cc->ptr.y);
|
||||||
|
|
||||||
|
if (cc->ptr.x < 0)
|
||||||
|
cc->ptr.x = 0;
|
||||||
|
else if (cc->ptr.x > cc->geom.w - 1)
|
||||||
|
cc->ptr.x = cc->geom.w - 1;
|
||||||
|
if (cc->ptr.y < 0)
|
||||||
|
cc->ptr.y = 0;
|
||||||
|
else if (cc->ptr.y > cc->geom.h - 1)
|
||||||
|
cc->ptr.y = cc->geom.h - 1;
|
||||||
|
|
||||||
|
client_ptrwarp(cc);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
client_ptrwarp(struct client_ctx *cc)
|
client_ptrwarp(struct client_ctx *cc)
|
||||||
{
|
{
|
||||||
|
64
kbfunc.c
64
kbfunc.c
@ -38,7 +38,7 @@
|
|||||||
|
|
||||||
extern sig_atomic_t cwm_status;
|
extern sig_atomic_t cwm_status;
|
||||||
|
|
||||||
static void kbfunc_amount(int, int, unsigned int *, unsigned int *);
|
static void kbfunc_amount(int, int, int *, int *);
|
||||||
|
|
||||||
void
|
void
|
||||||
kbfunc_cwm_status(void *ctx, union arg *arg, enum xev xev)
|
kbfunc_cwm_status(void *ctx, union arg *arg, enum xev xev)
|
||||||
@ -47,7 +47,7 @@ kbfunc_cwm_status(void *ctx, union arg *arg, enum xev xev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
kbfunc_amount(int flags, int amt, unsigned int *mx, unsigned int *my)
|
kbfunc_amount(int flags, int amt, int *mx, int *my)
|
||||||
{
|
{
|
||||||
#define CWM_FACTOR 10
|
#define CWM_FACTOR 10
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ kbfunc_ptrmove(void *ctx, union arg *arg, enum xev xev)
|
|||||||
{
|
{
|
||||||
struct screen_ctx *sc = ctx;
|
struct screen_ctx *sc = ctx;
|
||||||
int x, y;
|
int x, y;
|
||||||
unsigned int mx = 0, my = 0;
|
int mx = 0, my = 0;
|
||||||
|
|
||||||
kbfunc_amount(arg->i, Conf.mamount, &mx, &my);
|
kbfunc_amount(arg->i, Conf.mamount, &mx, &my);
|
||||||
|
|
||||||
@ -89,36 +89,23 @@ kbfunc_client_move(void *ctx, union arg *arg, enum xev xev)
|
|||||||
struct client_ctx *cc = ctx;
|
struct client_ctx *cc = ctx;
|
||||||
struct screen_ctx *sc = cc->sc;
|
struct screen_ctx *sc = cc->sc;
|
||||||
struct geom area;
|
struct geom area;
|
||||||
int x, y, px, py;
|
int mx = 0, my = 0;
|
||||||
unsigned int mx = 0, my = 0;
|
|
||||||
|
|
||||||
if (cc->flags & CLIENT_FREEZE)
|
if (cc->flags & CLIENT_FREEZE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
xu_ptr_getpos(cc->win, &px, &py);
|
|
||||||
if (px < 0)
|
|
||||||
px = 0;
|
|
||||||
else if (px > cc->geom.w)
|
|
||||||
px = cc->geom.w;
|
|
||||||
if (py < 0)
|
|
||||||
py = 0;
|
|
||||||
else if (py > cc->geom.h)
|
|
||||||
py = cc->geom.h;
|
|
||||||
|
|
||||||
xu_ptr_setpos(cc->win, px, py);
|
|
||||||
|
|
||||||
kbfunc_amount(arg->i, Conf.mamount, &mx, &my);
|
kbfunc_amount(arg->i, Conf.mamount, &mx, &my);
|
||||||
|
|
||||||
cc->geom.x += mx;
|
cc->geom.x += mx;
|
||||||
if (cc->geom.x + cc->geom.w < 0)
|
if (cc->geom.x < -(cc->geom.w + cc->bwidth - 1))
|
||||||
cc->geom.x = -cc->geom.w;
|
cc->geom.x = -(cc->geom.w + cc->bwidth - 1);
|
||||||
if (cc->geom.x > sc->view.w - 1)
|
if (cc->geom.x > (sc->view.w - cc->bwidth - 1))
|
||||||
cc->geom.x = sc->view.w - 1;
|
cc->geom.x = sc->view.w - cc->bwidth - 1;
|
||||||
cc->geom.y += my;
|
cc->geom.y += my;
|
||||||
if (cc->geom.y + cc->geom.h < 0)
|
if (cc->geom.y < -(cc->geom.h + cc->bwidth - 1))
|
||||||
cc->geom.y = -cc->geom.h;
|
cc->geom.y = -(cc->geom.h + cc->bwidth - 1);
|
||||||
if (cc->geom.y > sc->view.h - 1)
|
if (cc->geom.y > (sc->view.h - cc->bwidth - 1))
|
||||||
cc->geom.y = sc->view.h - 1;
|
cc->geom.y = sc->view.h - cc->bwidth - 1;
|
||||||
|
|
||||||
area = screen_area(sc,
|
area = screen_area(sc,
|
||||||
cc->geom.x + cc->geom.w / 2,
|
cc->geom.x + cc->geom.w / 2,
|
||||||
@ -129,19 +116,16 @@ kbfunc_client_move(void *ctx, union arg *arg, enum xev xev)
|
|||||||
cc->geom.y += client_snapcalc(cc->geom.y,
|
cc->geom.y += client_snapcalc(cc->geom.y,
|
||||||
cc->geom.y + cc->geom.h + (cc->bwidth * 2),
|
cc->geom.y + cc->geom.h + (cc->bwidth * 2),
|
||||||
area.y, area.y + area.h, sc->snapdist);
|
area.y, area.y + area.h, sc->snapdist);
|
||||||
client_move(cc);
|
|
||||||
|
|
||||||
xu_ptr_getpos(cc->win, &x, &y);
|
client_move(cc);
|
||||||
cc->ptr.x = x + mx;
|
client_ptr_inbound(cc, 1);
|
||||||
cc->ptr.y = y + my;
|
|
||||||
client_ptrwarp(cc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
kbfunc_client_resize(void *ctx, union arg *arg, enum xev xev)
|
kbfunc_client_resize(void *ctx, union arg *arg, enum xev xev)
|
||||||
{
|
{
|
||||||
struct client_ctx *cc = ctx;
|
struct client_ctx *cc = ctx;
|
||||||
unsigned int mx = 0, my = 0;
|
int mx = 0, my = 0;
|
||||||
int amt = 1;
|
int amt = 1;
|
||||||
|
|
||||||
if (cc->flags & CLIENT_FREEZE)
|
if (cc->flags & CLIENT_FREEZE)
|
||||||
@ -156,19 +140,13 @@ kbfunc_client_resize(void *ctx, union arg *arg, enum xev xev)
|
|||||||
cc->geom.w = cc->hint.minw;
|
cc->geom.w = cc->hint.minw;
|
||||||
if ((cc->geom.h += my * cc->hint.inch) < cc->hint.minh)
|
if ((cc->geom.h += my * cc->hint.inch) < cc->hint.minh)
|
||||||
cc->geom.h = cc->hint.minh;
|
cc->geom.h = cc->hint.minh;
|
||||||
if (cc->geom.x + cc->geom.w < 0)
|
if (cc->geom.x + cc->geom.w + cc->bwidth - 1 < 0)
|
||||||
cc->geom.x = -cc->geom.w;
|
cc->geom.x = -(cc->geom.w + cc->bwidth - 1);
|
||||||
if (cc->geom.y + cc->geom.h < 0)
|
if (cc->geom.y + cc->geom.h + cc->bwidth - 1 < 0)
|
||||||
cc->geom.y = -cc->geom.h;
|
cc->geom.y = -(cc->geom.h + cc->bwidth - 1);
|
||||||
client_resize(cc, 1);
|
|
||||||
|
|
||||||
/* Make sure the pointer stays within the window. */
|
client_resize(cc, 1);
|
||||||
xu_ptr_getpos(cc->win, &cc->ptr.x, &cc->ptr.y);
|
client_ptr_inbound(cc, 1);
|
||||||
if (cc->ptr.x > cc->geom.w)
|
|
||||||
cc->ptr.x = cc->geom.w - cc->bwidth;
|
|
||||||
if (cc->ptr.y > cc->geom.h)
|
|
||||||
cc->ptr.y = cc->geom.h - cc->bwidth;
|
|
||||||
client_ptrwarp(cc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
23
mousefunc.c
23
mousefunc.c
@ -79,11 +79,7 @@ mousefunc_client_resize(void *ctx, union arg *arg, enum xev xev)
|
|||||||
XUngrabPointer(X_Dpy, CurrentTime);
|
XUngrabPointer(X_Dpy, CurrentTime);
|
||||||
|
|
||||||
/* Make sure the pointer stays within the window. */
|
/* Make sure the pointer stays within the window. */
|
||||||
if (cc->ptr.x > cc->geom.w)
|
client_ptr_inbound(cc, 0);
|
||||||
cc->ptr.x = cc->geom.w - cc->bwidth;
|
|
||||||
if (cc->ptr.y > cc->geom.h)
|
|
||||||
cc->ptr.y = cc->geom.h - cc->bwidth;
|
|
||||||
client_ptrwarp(cc);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -98,24 +94,13 @@ mousefunc_client_move(void *ctx, union arg *arg, enum xev xev)
|
|||||||
Time ltime = 0;
|
Time ltime = 0;
|
||||||
struct screen_ctx *sc = cc->sc;
|
struct screen_ctx *sc = cc->sc;
|
||||||
struct geom area;
|
struct geom area;
|
||||||
int px, py;
|
|
||||||
|
|
||||||
client_raise(cc);
|
client_raise(cc);
|
||||||
|
|
||||||
if (cc->flags & CLIENT_FREEZE)
|
if (cc->flags & CLIENT_FREEZE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
xu_ptr_getpos(cc->win, &px, &py);
|
client_ptr_inbound(cc, 1);
|
||||||
if (px < 0)
|
|
||||||
px = 0;
|
|
||||||
else if (px > cc->geom.w)
|
|
||||||
px = cc->geom.w;
|
|
||||||
if (py < 0)
|
|
||||||
py = 0;
|
|
||||||
else if (py > cc->geom.h)
|
|
||||||
py = cc->geom.h;
|
|
||||||
|
|
||||||
xu_ptr_setpos(cc->win, px, py);
|
|
||||||
|
|
||||||
if (XGrabPointer(X_Dpy, cc->win, False, MOUSEMASK,
|
if (XGrabPointer(X_Dpy, cc->win, False, MOUSEMASK,
|
||||||
GrabModeAsync, GrabModeAsync, None, Conf.cursor[CF_MOVE],
|
GrabModeAsync, GrabModeAsync, None, Conf.cursor[CF_MOVE],
|
||||||
@ -134,8 +119,8 @@ mousefunc_client_move(void *ctx, union arg *arg, enum xev xev)
|
|||||||
continue;
|
continue;
|
||||||
ltime = ev.xmotion.time;
|
ltime = ev.xmotion.time;
|
||||||
|
|
||||||
cc->geom.x = ev.xmotion.x_root - px - cc->bwidth;
|
cc->geom.x = ev.xmotion.x_root - cc->ptr.x - cc->bwidth;
|
||||||
cc->geom.y = ev.xmotion.y_root - py - cc->bwidth;
|
cc->geom.y = ev.xmotion.y_root - cc->ptr.y - cc->bwidth;
|
||||||
|
|
||||||
area = screen_area(sc,
|
area = screen_area(sc,
|
||||||
cc->geom.x + cc->geom.w / 2,
|
cc->geom.x + cc->geom.w / 2,
|
||||||
|
Loading…
Reference in New Issue
Block a user