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:
okan 2017-05-01 12:54:55 +00:00
parent 8bbf0afc60
commit c6ed26e240
4 changed files with 48 additions and 66 deletions

View File

@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* $OpenBSD: calmwm.h,v 1.337 2017/04/26 21:10:54 okan Exp $
* $OpenBSD: calmwm.h,v 1.338 2017/05/01 12:54:55 okan Exp $
*/
#ifndef _CALMWM_H_
@ -399,6 +399,7 @@ void client_msg(struct client_ctx *, Atom, Time);
void client_move(struct client_ctx *);
int client_inbound(struct client_ctx *, int, 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_ptrwarp(struct client_ctx *);
void client_raise(struct client_ctx *);

View File

@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* $OpenBSD: client.c,v 1.238 2017/04/26 21:10:54 okan Exp $
* $OpenBSD: client.c,v 1.239 2017/05/01 12:54:55 okan Exp $
*/
#include <sys/types.h>
@ -470,6 +470,24 @@ client_config(struct client_ctx *cc)
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
client_ptrwarp(struct client_ctx *cc)
{

View File

@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* $OpenBSD: kbfunc.c,v 1.143 2017/01/05 21:18:20 okan Exp $
* $OpenBSD: kbfunc.c,v 1.144 2017/05/01 12:54:55 okan Exp $
*/
#include <sys/types.h>
@ -38,7 +38,7 @@
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
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
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
@ -75,7 +75,7 @@ kbfunc_ptrmove(void *ctx, union arg *arg, enum xev xev)
{
struct screen_ctx *sc = ctx;
int x, y;
unsigned int mx = 0, my = 0;
int mx = 0, my = 0;
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 screen_ctx *sc = cc->sc;
struct geom area;
int x, y, px, py;
unsigned int mx = 0, my = 0;
int mx = 0, my = 0;
if (cc->flags & CLIENT_FREEZE)
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);
cc->geom.x += mx;
if (cc->geom.x + cc->geom.w < 0)
cc->geom.x = -cc->geom.w;
if (cc->geom.x > sc->view.w - 1)
cc->geom.x = sc->view.w - 1;
if (cc->geom.x < -(cc->geom.w + cc->bwidth - 1))
cc->geom.x = -(cc->geom.w + cc->bwidth - 1);
if (cc->geom.x > (sc->view.w - cc->bwidth - 1))
cc->geom.x = sc->view.w - cc->bwidth - 1;
cc->geom.y += my;
if (cc->geom.y + cc->geom.h < 0)
cc->geom.y = -cc->geom.h;
if (cc->geom.y > sc->view.h - 1)
cc->geom.y = sc->view.h - 1;
if (cc->geom.y < -(cc->geom.h + cc->bwidth - 1))
cc->geom.y = -(cc->geom.h + cc->bwidth - 1);
if (cc->geom.y > (sc->view.h - cc->bwidth - 1))
cc->geom.y = sc->view.h - cc->bwidth - 1;
area = screen_area(sc,
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 + cc->geom.h + (cc->bwidth * 2),
area.y, area.y + area.h, sc->snapdist);
client_move(cc);
xu_ptr_getpos(cc->win, &x, &y);
cc->ptr.x = x + mx;
cc->ptr.y = y + my;
client_ptrwarp(cc);
client_move(cc);
client_ptr_inbound(cc, 1);
}
void
kbfunc_client_resize(void *ctx, union arg *arg, enum xev xev)
{
struct client_ctx *cc = ctx;
unsigned int mx = 0, my = 0;
int mx = 0, my = 0;
int amt = 1;
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;
if ((cc->geom.h += my * cc->hint.inch) < cc->hint.minh)
cc->geom.h = cc->hint.minh;
if (cc->geom.x + cc->geom.w < 0)
cc->geom.x = -cc->geom.w;
if (cc->geom.y + cc->geom.h < 0)
cc->geom.y = -cc->geom.h;
client_resize(cc, 1);
if (cc->geom.x + cc->geom.w + cc->bwidth - 1 < 0)
cc->geom.x = -(cc->geom.w + cc->bwidth - 1);
if (cc->geom.y + cc->geom.h + cc->bwidth - 1 < 0)
cc->geom.y = -(cc->geom.h + cc->bwidth - 1);
/* Make sure the pointer stays within the window. */
xu_ptr_getpos(cc->win, &cc->ptr.x, &cc->ptr.y);
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);
client_resize(cc, 1);
client_ptr_inbound(cc, 1);
}
void

View File

@ -16,7 +16,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* $OpenBSD: mousefunc.c,v 1.115 2016/12/06 21:03:58 okan Exp $
* $OpenBSD: mousefunc.c,v 1.116 2017/05/01 12:54:55 okan Exp $
*/
#include <sys/types.h>
@ -79,11 +79,7 @@ mousefunc_client_resize(void *ctx, union arg *arg, enum xev xev)
XUngrabPointer(X_Dpy, CurrentTime);
/* Make sure the pointer stays within the window. */
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);
client_ptr_inbound(cc, 0);
return;
}
}
@ -98,24 +94,13 @@ mousefunc_client_move(void *ctx, union arg *arg, enum xev xev)
Time ltime = 0;
struct screen_ctx *sc = cc->sc;
struct geom area;
int px, py;
client_raise(cc);
if (cc->flags & CLIENT_FREEZE)
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);
client_ptr_inbound(cc, 1);
if (XGrabPointer(X_Dpy, cc->win, False, MOUSEMASK,
GrabModeAsync, GrabModeAsync, None, Conf.cursor[CF_MOVE],
@ -134,8 +119,8 @@ mousefunc_client_move(void *ctx, union arg *arg, enum xev xev)
continue;
ltime = ev.xmotion.time;
cc->geom.x = ev.xmotion.x_root - px - cc->bwidth;
cc->geom.y = ev.xmotion.y_root - py - cc->bwidth;
cc->geom.x = ev.xmotion.x_root - cc->ptr.x - cc->bwidth;
cc->geom.y = ev.xmotion.y_root - cc->ptr.y - cc->bwidth;
area = screen_area(sc,
cc->geom.x + cc->geom.w / 2,