2007-04-27 21:58:48 +04:00
|
|
|
/*
|
|
|
|
* calmwm - the calm window manager
|
|
|
|
*
|
|
|
|
* Copyright (c) 2004 Marius Aamodt Eriksen <marius@monkey.org>
|
2008-01-11 19:06:44 +03: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.
|
2007-04-27 21:58:48 +04:00
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "headers.h"
|
|
|
|
#include "calmwm.h"
|
|
|
|
|
2008-01-14 18:21:10 +03:00
|
|
|
static int _sweepcalc(struct client_ctx *, int, int, int, int);
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
#define ADJUST_HEIGHT(cc, dy) ((cc->geom.height - cc->geom.min_dy)/ dy)
|
|
|
|
#define ADJUST_WIDTH(cc, dx) ((cc->geom.width - cc->geom.min_dx)/ dx)
|
|
|
|
|
|
|
|
void
|
|
|
|
grab_sweep_draw(struct client_ctx *cc, int dx, int dy)
|
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
struct screen_ctx *sc = CCTOSC(cc);
|
|
|
|
char asize[10]; /* fits "nnnnxnnnn\0" */
|
|
|
|
int wide, height, wide_size, wide_name;
|
|
|
|
int x = cc->geom.x, y = cc->geom.y;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
snprintf(asize, sizeof(asize), "%dx%d",
|
|
|
|
ADJUST_WIDTH(cc, dx), ADJUST_HEIGHT(cc, dy));
|
2008-06-15 06:47:46 +04:00
|
|
|
wide_size = font_width(asize, strlen(asize)) + 4;
|
|
|
|
wide_name = font_width(cc->name, strlen(cc->name)) + 4;
|
2007-04-27 21:58:48 +04:00
|
|
|
wide = MAX(wide_size, wide_name);
|
2008-06-15 06:47:46 +04:00
|
|
|
height = font_ascent() + font_descent() + 1;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2008-07-11 18:21:28 +04:00
|
|
|
XMoveResizeWindow(X_Dpy, sc->menuwin, x, y, wide, height * 2);
|
2007-05-28 22:34:27 +04:00
|
|
|
XMapWindow(X_Dpy, sc->menuwin);
|
|
|
|
XReparentWindow(X_Dpy, sc->menuwin, cc->win, 0, 0);
|
|
|
|
XClearWindow(X_Dpy, sc->menuwin);
|
2008-06-15 06:47:46 +04:00
|
|
|
font_draw(sc, cc->name, strlen(cc->name), sc->menuwin,
|
|
|
|
2, font_ascent() + 1);
|
|
|
|
font_draw(sc, asize, strlen(asize), sc->menuwin,
|
2008-07-11 18:21:28 +04:00
|
|
|
wide / 2 - wide_size / 2, height + font_ascent() + 1);
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
2008-01-16 14:39:20 +03:00
|
|
|
void
|
2007-04-27 21:58:48 +04:00
|
|
|
grab_sweep(struct client_ctx *cc)
|
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
XEvent ev;
|
|
|
|
struct screen_ctx *sc = CCTOSC(cc);
|
|
|
|
int x = cc->geom.x, y = cc->geom.y, dx, dy;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
dx = MAX(1, cc->size->width_inc);
|
|
|
|
dy = MAX(1, cc->size->height_inc);
|
|
|
|
|
|
|
|
client_raise(cc);
|
|
|
|
client_ptrsave(cc);
|
|
|
|
|
2007-05-28 22:34:27 +04:00
|
|
|
if (xu_ptr_grab(sc->rootwin, MouseMask, Cursor_resize) < 0)
|
2008-01-16 14:39:20 +03:00
|
|
|
return;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
xu_ptr_setpos(cc->win, cc->geom.width, cc->geom.height);
|
|
|
|
grab_sweep_draw(cc, dx, dy);
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
/* Look for changes in ptr position. */
|
2007-06-05 22:57:03 +04:00
|
|
|
XMaskEvent(X_Dpy, MouseMask|ExposureMask, &ev);
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
switch (ev.type) {
|
2007-06-05 22:57:03 +04:00
|
|
|
case Expose:
|
|
|
|
client_draw_border(cc);
|
|
|
|
break;
|
2007-04-27 21:58:48 +04:00
|
|
|
case MotionNotify:
|
2008-07-11 18:21:28 +04:00
|
|
|
if (_sweepcalc(cc, x, y, ev.xmotion.x, ev.xmotion.y))
|
2008-04-16 00:24:41 +04:00
|
|
|
/* Recompute window output */
|
2007-04-27 21:58:48 +04:00
|
|
|
grab_sweep_draw(cc, dx, dy);
|
|
|
|
|
2007-05-28 22:34:27 +04:00
|
|
|
XMoveResizeWindow(X_Dpy, cc->pwin,
|
2007-04-27 21:58:48 +04:00
|
|
|
cc->geom.x - cc->bwidth,
|
|
|
|
cc->geom.y - cc->bwidth,
|
|
|
|
cc->geom.width + cc->bwidth*2,
|
|
|
|
cc->geom.height + cc->bwidth*2);
|
2007-05-28 22:34:27 +04:00
|
|
|
XMoveResizeWindow(X_Dpy, cc->win,
|
2007-04-27 21:58:48 +04:00
|
|
|
cc->bwidth, cc->bwidth,
|
|
|
|
cc->geom.width, cc->geom.height);
|
|
|
|
|
2008-06-15 02:04:11 +04:00
|
|
|
client_do_shape(cc);
|
2007-04-27 21:58:48 +04:00
|
|
|
break;
|
|
|
|
case ButtonRelease:
|
2007-05-28 22:34:27 +04:00
|
|
|
XUnmapWindow(X_Dpy, sc->menuwin);
|
|
|
|
XReparentWindow(X_Dpy, sc->menuwin, sc->rootwin, 0, 0);
|
2007-04-27 21:58:48 +04:00
|
|
|
xu_ptr_ungrab();
|
2008-06-12 22:32:06 +04:00
|
|
|
|
|
|
|
/* Make sure the pointer stays within the window. */
|
|
|
|
if (cc->ptr.x > cc->geom.width)
|
|
|
|
cc->ptr.x = cc->geom.width - cc->bwidth;
|
|
|
|
if (cc->ptr.y > cc->geom.height)
|
|
|
|
cc->ptr.y = cc->geom.height - cc->bwidth;
|
2007-04-27 21:58:48 +04:00
|
|
|
client_ptrwarp(cc);
|
2008-06-12 22:32:06 +04:00
|
|
|
|
2008-01-16 14:39:20 +03:00
|
|
|
return;
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
2008-01-16 14:39:20 +03:00
|
|
|
void
|
2007-04-27 21:58:48 +04:00
|
|
|
grab_drag(struct client_ctx *cc)
|
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
XEvent ev;
|
|
|
|
struct screen_ctx *sc = CCTOSC(cc);
|
|
|
|
int x = cc->geom.x, y = cc->geom.y, xm, ym;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
client_raise(cc);
|
|
|
|
|
2007-05-28 22:34:27 +04:00
|
|
|
if (xu_ptr_grab(sc->rootwin, MouseMask, Cursor_move) < 0)
|
2008-01-16 14:39:20 +03:00
|
|
|
return;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
xu_ptr_getpos(sc->rootwin, &xm, &ym);
|
|
|
|
|
|
|
|
for (;;) {
|
2007-06-05 22:57:03 +04:00
|
|
|
XMaskEvent(X_Dpy, MouseMask|ExposureMask, &ev);
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
switch (ev.type) {
|
2007-06-05 22:57:03 +04:00
|
|
|
case Expose:
|
|
|
|
client_draw_border(cc);
|
|
|
|
break;
|
2007-04-27 21:58:48 +04:00
|
|
|
case MotionNotify:
|
2008-07-11 18:21:28 +04:00
|
|
|
cc->geom.x = x + (ev.xmotion.x - xm);
|
|
|
|
cc->geom.y = y + (ev.xmotion.y - ym);
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2007-05-28 22:34:27 +04:00
|
|
|
XMoveWindow(X_Dpy, cc->pwin,
|
2007-04-27 21:58:48 +04:00
|
|
|
cc->geom.x - cc->bwidth, cc->geom.y - cc->bwidth);
|
|
|
|
|
|
|
|
break;
|
|
|
|
case ButtonRelease:
|
|
|
|
xu_ptr_ungrab();
|
2008-01-16 14:39:20 +03:00
|
|
|
return;
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
2008-01-14 18:21:10 +03:00
|
|
|
static int
|
2008-07-11 18:21:28 +04:00
|
|
|
_sweepcalc(struct client_ctx *cc, int x, int y, int motionx, int motiony)
|
2007-04-27 21:58:48 +04:00
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
int width, height;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
width = cc->geom.width;
|
|
|
|
height = cc->geom.height;
|
|
|
|
|
2008-07-11 18:21:28 +04:00
|
|
|
cc->geom.width = abs(x - motionx);
|
|
|
|
cc->geom.height = abs(y - motiony);
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
if (cc->size->flags & PResizeInc) {
|
|
|
|
cc->geom.width -=
|
|
|
|
(cc->geom.width - cc->geom.min_dx) % cc->size->width_inc;
|
|
|
|
cc->geom.height -=
|
|
|
|
(cc->geom.height - cc->geom.min_dy) % cc->size->height_inc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cc->size->flags & PMinSize) {
|
|
|
|
cc->geom.width = MAX(cc->geom.width, cc->size->min_width);
|
|
|
|
cc->geom.height = MAX(cc->geom.height, cc->size->min_height);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cc->size->flags & PMaxSize) {
|
|
|
|
cc->geom.width = MIN(cc->geom.width, cc->size->max_width);
|
|
|
|
cc->geom.height = MIN(cc->geom.height, cc->size->max_height);
|
|
|
|
}
|
|
|
|
|
2008-07-11 18:21:28 +04:00
|
|
|
cc->geom.x = x <= motionx ? x : x - cc->geom.width;
|
|
|
|
cc->geom.y = y <= motiony ? y : y - cc->geom.height;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
return (width != cc->geom.width || height != cc->geom.height);
|
|
|
|
}
|