2008-06-15 01:48:54 +04:00
|
|
|
/*
|
2011-05-11 17:53:51 +04:00
|
|
|
* calmwm - the calm window manager
|
2008-06-15 01:48:54 +04:00
|
|
|
*
|
2011-05-11 17:53:51 +04:00
|
|
|
* Copyright (c) 2004 Marius Aamodt Eriksen <marius@monkey.org>
|
|
|
|
* Copyright (c) 2008 rivo nurges <rix@estpak.ee>
|
2008-06-15 01:48:54 +04:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
2011-05-11 17:53:51 +04:00
|
|
|
* $OpenBSD$
|
2008-06-15 01:48:54 +04:00
|
|
|
*/
|
|
|
|
|
2015-01-19 17:54:16 +03:00
|
|
|
#include <sys/types.h>
|
2009-12-15 07:10:42 +03:00
|
|
|
#include <sys/queue.h>
|
|
|
|
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
2015-01-19 17:54:16 +03:00
|
|
|
#include <limits.h>
|
2012-11-09 07:52:02 +04:00
|
|
|
#include <stdio.h>
|
2009-12-15 07:10:42 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2008-06-15 01:48:54 +04:00
|
|
|
#include "calmwm.h"
|
|
|
|
|
|
|
|
void
|
2016-10-18 20:03:30 +03:00
|
|
|
mousefunc_client_resize(void *ctx, union arg *arg, enum xev xev)
|
2008-06-15 01:48:54 +04:00
|
|
|
{
|
2016-10-18 20:03:30 +03:00
|
|
|
struct client_ctx *cc = ctx;
|
2009-01-11 21:34:46 +03:00
|
|
|
XEvent ev;
|
2011-10-17 22:18:38 +04:00
|
|
|
Time ltime = 0;
|
2009-08-27 05:38:08 +04:00
|
|
|
struct screen_ctx *sc = cc->sc;
|
2009-01-11 21:34:46 +03:00
|
|
|
|
2015-08-21 19:14:39 +03:00
|
|
|
if (cc->flags & CLIENT_FREEZE)
|
2011-05-07 21:15:37 +04:00
|
|
|
return;
|
|
|
|
|
2009-01-11 21:34:46 +03:00
|
|
|
client_raise(cc);
|
|
|
|
client_ptrsave(cc);
|
|
|
|
|
2016-10-03 16:52:17 +03:00
|
|
|
xu_ptr_setpos(cc->win, cc->geom.w, cc->geom.h);
|
|
|
|
|
2016-09-30 21:28:06 +03:00
|
|
|
if (XGrabPointer(X_Dpy, cc->win, False, MOUSEMASK,
|
|
|
|
GrabModeAsync, GrabModeAsync, None, Conf.cursor[CF_RESIZE],
|
|
|
|
CurrentTime) != GrabSuccess)
|
2009-01-11 21:34:46 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
for (;;) {
|
2016-09-30 18:05:02 +03:00
|
|
|
XWindowEvent(X_Dpy, cc->win, MOUSEMASK, &ev);
|
2009-01-11 21:34:46 +03:00
|
|
|
|
|
|
|
switch (ev.type) {
|
|
|
|
case MotionNotify:
|
2014-09-18 17:56:58 +04:00
|
|
|
/* not more than 60 times / second */
|
|
|
|
if ((ev.xmotion.time - ltime) <= (1000 / 60))
|
|
|
|
continue;
|
|
|
|
ltime = ev.xmotion.time;
|
|
|
|
|
2016-09-13 16:42:28 +03:00
|
|
|
cc->geom.w = ev.xmotion.x;
|
|
|
|
cc->geom.h = ev.xmotion.y;
|
2015-11-17 17:31:28 +03:00
|
|
|
client_applysizehints(cc);
|
2014-09-18 17:56:58 +04:00
|
|
|
client_resize(cc, 1);
|
2016-09-30 18:12:19 +03:00
|
|
|
menu_windraw(sc, cc->win,
|
|
|
|
"%4d x %-4d", cc->dim.w, cc->dim.h);
|
2009-01-11 21:34:46 +03:00
|
|
|
break;
|
|
|
|
case ButtonRelease:
|
2014-09-18 17:56:58 +04:00
|
|
|
client_resize(cc, 1);
|
2016-09-29 03:21:55 +03:00
|
|
|
XUnmapWindow(X_Dpy, sc->menu.win);
|
|
|
|
XReparentWindow(X_Dpy, sc->menu.win, sc->rootwin, 0, 0);
|
2016-09-30 21:28:06 +03:00
|
|
|
XUngrabPointer(X_Dpy, CurrentTime);
|
2009-01-11 21:34:46 +03:00
|
|
|
|
|
|
|
/* Make sure the pointer stays within the window. */
|
2012-07-13 21:01:04 +04:00
|
|
|
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;
|
2009-01-11 21:34:46 +03:00
|
|
|
client_ptrwarp(cc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* NOTREACHED */
|
2008-06-15 01:48:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-10-18 20:03:30 +03:00
|
|
|
mousefunc_client_move(void *ctx, union arg *arg, enum xev xev)
|
2008-06-15 01:48:54 +04:00
|
|
|
{
|
2016-10-18 20:03:30 +03:00
|
|
|
struct client_ctx *cc = ctx;
|
2009-01-11 21:34:46 +03:00
|
|
|
XEvent ev;
|
2011-10-17 22:18:38 +04:00
|
|
|
Time ltime = 0;
|
2012-07-05 03:42:03 +04:00
|
|
|
struct screen_ctx *sc = cc->sc;
|
2015-11-11 17:22:01 +03:00
|
|
|
struct geom area;
|
2009-06-17 16:45:01 +04:00
|
|
|
int px, py;
|
2009-01-11 21:34:46 +03:00
|
|
|
|
|
|
|
client_raise(cc);
|
|
|
|
|
2015-08-21 19:14:39 +03:00
|
|
|
if (cc->flags & CLIENT_FREEZE)
|
2011-05-07 21:15:37 +04:00
|
|
|
return;
|
|
|
|
|
2016-10-03 16:52:17 +03:00
|
|
|
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);
|
|
|
|
|
2016-09-30 21:28:06 +03:00
|
|
|
if (XGrabPointer(X_Dpy, cc->win, False, MOUSEMASK,
|
|
|
|
GrabModeAsync, GrabModeAsync, None, Conf.cursor[CF_MOVE],
|
|
|
|
CurrentTime) != GrabSuccess)
|
2009-01-11 21:34:46 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
for (;;) {
|
2016-09-30 18:05:02 +03:00
|
|
|
XWindowEvent(X_Dpy, cc->win, MOUSEMASK, &ev);
|
2009-01-11 21:34:46 +03:00
|
|
|
|
|
|
|
switch (ev.type) {
|
|
|
|
case MotionNotify:
|
2014-09-18 17:56:58 +04:00
|
|
|
/* not more than 60 times / second */
|
|
|
|
if ((ev.xmotion.time - ltime) <= (1000 / 60))
|
|
|
|
continue;
|
|
|
|
ltime = ev.xmotion.time;
|
|
|
|
|
2010-12-14 14:08:47 +03:00
|
|
|
cc->geom.x = ev.xmotion.x_root - px - cc->bwidth;
|
|
|
|
cc->geom.y = ev.xmotion.y_root - py - cc->bwidth;
|
2009-04-15 18:10:07 +04:00
|
|
|
|
2015-11-11 17:22:01 +03:00
|
|
|
area = screen_area(sc,
|
|
|
|
cc->geom.x + cc->geom.w / 2,
|
|
|
|
cc->geom.y + cc->geom.h / 2, CWM_GAP);
|
2011-06-24 10:06:24 +04:00
|
|
|
cc->geom.x += client_snapcalc(cc->geom.x,
|
2013-01-03 01:37:21 +04:00
|
|
|
cc->geom.x + cc->geom.w + (cc->bwidth * 2),
|
2015-11-11 17:22:01 +03:00
|
|
|
area.x, area.x + area.w, sc->snapdist);
|
2011-06-24 10:06:24 +04:00
|
|
|
cc->geom.y += client_snapcalc(cc->geom.y,
|
2013-01-03 01:37:21 +04:00
|
|
|
cc->geom.y + cc->geom.h + (cc->bwidth * 2),
|
2015-11-11 17:22:01 +03:00
|
|
|
area.y, area.y + area.h, sc->snapdist);
|
2014-09-18 17:56:58 +04:00
|
|
|
client_move(cc);
|
2016-09-30 18:12:19 +03:00
|
|
|
menu_windraw(sc, cc->win,
|
|
|
|
"%4d, %-4d", cc->geom.x, cc->geom.y);
|
2009-01-11 21:34:46 +03:00
|
|
|
break;
|
|
|
|
case ButtonRelease:
|
2014-09-18 17:56:58 +04:00
|
|
|
client_move(cc);
|
2016-09-30 18:12:19 +03:00
|
|
|
XUnmapWindow(X_Dpy, sc->menu.win);
|
|
|
|
XReparentWindow(X_Dpy, sc->menu.win, sc->rootwin, 0, 0);
|
2016-09-30 21:28:06 +03:00
|
|
|
XUngrabPointer(X_Dpy, CurrentTime);
|
2009-01-11 21:34:46 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* NOTREACHED */
|
2008-06-15 01:48:54 +04:00
|
|
|
}
|