diff options
author | okan | 2009-01-11 18:34:46 +0000 |
---|---|---|
committer | okan | 2009-01-11 18:34:46 +0000 |
commit | 0e2bd8a93af8740bb1f20f83b0563e53b581eec7 (patch) | |
tree | 2367671321b9fb93a8c28907aace0135aeaf593f | |
parent | 86647d3a5625ccd784cf46d4e4f14abaf0599af5 (diff) | |
download | cwm-0e2bd8a93af8740bb1f20f83b0563e53b581eec7.tar.gz |
- merge grab_sweep() into mousefunc_window_resize().
- merge grab_drag() into mousefunc_window_move().
- properly name, proto and static private functions.
- since we already do XMoveResizeWindow() and XMoveWindow() in (now)
mousefunc_window_resize() and mousefunc_window_move() respectively,
client_resize() and client_move() calls are unnecessary.
ok oga@
Diffstat (limited to '')
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | calmwm.h | 5 | ||||
-rw-r--r-- | grab.c | 184 | ||||
-rw-r--r-- | mousefunc.c | 159 |
4 files changed, 157 insertions, 195 deletions
@@ -1,10 +1,10 @@ -# $OpenBSD: Makefile,v 1.12 2008/09/29 23:16:46 oga Exp $ +# $OpenBSD: Makefile,v 1.13 2009/01/11 18:34:46 okan Exp $ .include <bsd.xconf.mk> PROG= cwm -SRCS= calmwm.c screen.c xmalloc.c client.c grab.c menu.c \ +SRCS= calmwm.c screen.c xmalloc.c client.c menu.c \ search.c util.c xutil.c conf.c input.c xevents.c group.c \ kbfunc.c mousefunc.c font.c parse.y @@ -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. * - * $Id: calmwm.h,v 1.69 2008/12/04 23:55:04 oga Exp $ + * $Id: calmwm.h,v 1.70 2009/01/11 18:34:46 okan Exp $ */ #ifndef _CALMWM_H_ @@ -405,9 +405,6 @@ int xu_getstate(struct client_ctx *, int *); int u_spawn(char *); void u_exec(char *); -void grab_sweep(struct client_ctx *); -void grab_drag(struct client_ctx *); - void xfree(void *); void *xmalloc(size_t); void *xcalloc(size_t, size_t); @@ -1,184 +0,0 @@ -/* - * calmwm - the calm window manager - * - * Copyright (c) 2004 Marius Aamodt Eriksen <marius@monkey.org> - * - * 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. - * - * $Id: grab.c,v 1.20 2008/07/11 14:21:28 okan Exp $ - */ - -#include "headers.h" -#include "calmwm.h" - -static int _sweepcalc(struct client_ctx *, int, int, int, int); - -#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) -{ - 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; - - snprintf(asize, sizeof(asize), "%dx%d", - ADJUST_WIDTH(cc, dx), ADJUST_HEIGHT(cc, dy)); - wide_size = font_width(asize, strlen(asize)) + 4; - wide_name = font_width(cc->name, strlen(cc->name)) + 4; - wide = MAX(wide_size, wide_name); - height = font_ascent() + font_descent() + 1; - - XMoveResizeWindow(X_Dpy, sc->menuwin, x, y, wide, height * 2); - XMapWindow(X_Dpy, sc->menuwin); - XReparentWindow(X_Dpy, sc->menuwin, cc->win, 0, 0); - XClearWindow(X_Dpy, sc->menuwin); - font_draw(sc, cc->name, strlen(cc->name), sc->menuwin, - 2, font_ascent() + 1); - font_draw(sc, asize, strlen(asize), sc->menuwin, - wide / 2 - wide_size / 2, height + font_ascent() + 1); -} - -void -grab_sweep(struct client_ctx *cc) -{ - XEvent ev; - struct screen_ctx *sc = CCTOSC(cc); - int x = cc->geom.x, y = cc->geom.y, dx, dy; - - dx = MAX(1, cc->size->width_inc); - dy = MAX(1, cc->size->height_inc); - - client_raise(cc); - client_ptrsave(cc); - - if (xu_ptr_grab(sc->rootwin, MouseMask, Cursor_resize) < 0) - return; - - xu_ptr_setpos(cc->win, cc->geom.width, cc->geom.height); - grab_sweep_draw(cc, dx, dy); - - for (;;) { - /* Look for changes in ptr position. */ - XMaskEvent(X_Dpy, MouseMask|ExposureMask, &ev); - - switch (ev.type) { - case Expose: - client_draw_border(cc); - break; - case MotionNotify: - if (_sweepcalc(cc, x, y, ev.xmotion.x, ev.xmotion.y)) - /* Recompute window output */ - grab_sweep_draw(cc, dx, dy); - - XMoveResizeWindow(X_Dpy, cc->pwin, - cc->geom.x - cc->bwidth, - cc->geom.y - cc->bwidth, - cc->geom.width + cc->bwidth*2, - cc->geom.height + cc->bwidth*2); - XMoveResizeWindow(X_Dpy, cc->win, - cc->bwidth, cc->bwidth, - cc->geom.width, cc->geom.height); - - client_do_shape(cc); - break; - case ButtonRelease: - XUnmapWindow(X_Dpy, sc->menuwin); - XReparentWindow(X_Dpy, sc->menuwin, sc->rootwin, 0, 0); - xu_ptr_ungrab(); - - /* 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; - client_ptrwarp(cc); - - return; - } - } - /* NOTREACHED */ -} - -void -grab_drag(struct client_ctx *cc) -{ - XEvent ev; - struct screen_ctx *sc = CCTOSC(cc); - int x = cc->geom.x, y = cc->geom.y, xm, ym; - - client_raise(cc); - - if (xu_ptr_grab(sc->rootwin, MouseMask, Cursor_move) < 0) - return; - - xu_ptr_getpos(sc->rootwin, &xm, &ym); - - for (;;) { - XMaskEvent(X_Dpy, MouseMask|ExposureMask, &ev); - - switch (ev.type) { - case Expose: - client_draw_border(cc); - break; - case MotionNotify: - cc->geom.x = x + (ev.xmotion.x - xm); - cc->geom.y = y + (ev.xmotion.y - ym); - - XMoveWindow(X_Dpy, cc->pwin, - cc->geom.x - cc->bwidth, cc->geom.y - cc->bwidth); - - break; - case ButtonRelease: - xu_ptr_ungrab(); - return; - } - } - /* NOTREACHED */ -} - -static int -_sweepcalc(struct client_ctx *cc, int x, int y, int motionx, int motiony) -{ - int width, height; - - width = cc->geom.width; - height = cc->geom.height; - - cc->geom.width = abs(x - motionx); - cc->geom.height = abs(y - motiony); - - 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); - } - - cc->geom.x = x <= motionx ? x : x - cc->geom.width; - cc->geom.y = y <= motiony ? y : y - cc->geom.height; - - return (width != cc->geom.width || height != cc->geom.height); -} diff --git a/mousefunc.c b/mousefunc.c index a38fdd7..4e6897f 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -1,6 +1,7 @@ /* * calmwm - the calm window manager * + * Copyright (c) 2004 Marius Aamodt Eriksen <marius@monkey.org> * Copyright (c) 2008 rivo nurges <rix@estpak.ee> * * Permission to use, copy, modify, and distribute this software for any @@ -15,24 +16,172 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * $Id: mousefunc.c,v 1.4 2008/07/11 15:18:29 okan Exp $ + * $Id: mousefunc.c,v 1.5 2009/01/11 18:34:46 okan Exp $ */ #include "headers.h" #include "calmwm.h" +static int _mousefunc_sweep_calc(struct client_ctx *, int, int, int, int); +static void _mousefunc_sweep_draw(struct client_ctx *, int, int); + +#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) + +static int +_mousefunc_sweep_calc(struct client_ctx *cc, int x, int y, int mx, int my) +{ + int width = cc->geom.width, height = cc->geom.height; + + cc->geom.width = abs(x - mx); + cc->geom.height = abs(y - my); + + 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); + } + + cc->geom.x = x <= mx ? x : x - cc->geom.width; + cc->geom.y = y <= my ? y : y - cc->geom.height; + + return (width != cc->geom.width || height != cc->geom.height); +} + +static void +_mousefunc_sweep_draw(struct client_ctx *cc, int dx, int dy) +{ + 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; + + snprintf(asize, sizeof(asize), "%dx%d", + ADJUST_WIDTH(cc, dx), ADJUST_HEIGHT(cc, dy)); + wide_size = font_width(asize, strlen(asize)) + 4; + wide_name = font_width(cc->name, strlen(cc->name)) + 4; + wide = MAX(wide_size, wide_name); + height = font_ascent() + font_descent() + 1; + + XMoveResizeWindow(X_Dpy, sc->menuwin, x, y, wide, height * 2); + XMapWindow(X_Dpy, sc->menuwin); + XReparentWindow(X_Dpy, sc->menuwin, cc->win, 0, 0); + XClearWindow(X_Dpy, sc->menuwin); + font_draw(sc, cc->name, strlen(cc->name), sc->menuwin, + 2, font_ascent() + 1); + font_draw(sc, asize, strlen(asize), sc->menuwin, + wide / 2 - wide_size / 2, height + font_ascent() + 1); +} + void mousefunc_window_resize(struct client_ctx *cc, void *arg) { - grab_sweep(cc); - client_resize(cc); + XEvent ev; + struct screen_ctx *sc = CCTOSC(cc); + int dx, dy; + int x = cc->geom.x, y = cc->geom.y; + + dx = MAX(1, cc->size->width_inc); + dy = MAX(1, cc->size->height_inc); + + client_raise(cc); + client_ptrsave(cc); + + if (xu_ptr_grab(sc->rootwin, MouseMask, Cursor_resize) < 0) + return; + + xu_ptr_setpos(cc->win, cc->geom.width, cc->geom.height); + _mousefunc_sweep_draw(cc, dx, dy); + + for (;;) { + XMaskEvent(X_Dpy, MouseMask|ExposureMask, &ev); + + switch (ev.type) { + case Expose: + client_draw_border(cc); + break; + case MotionNotify: + if (_mousefunc_sweep_calc(cc, x, y, + ev.xmotion.x, ev.xmotion.y)) + /* Recompute window output */ + _mousefunc_sweep_draw(cc, dx, dy); + + XMoveResizeWindow(X_Dpy, cc->pwin, + cc->geom.x - cc->bwidth, + cc->geom.y - cc->bwidth, + cc->geom.width + cc->bwidth * 2, + cc->geom.height + cc->bwidth * 2); + XMoveResizeWindow(X_Dpy, cc->win, + cc->bwidth, cc->bwidth, + cc->geom.width, cc->geom.height); + + client_do_shape(cc); + break; + case ButtonRelease: + XUnmapWindow(X_Dpy, sc->menuwin); + XReparentWindow(X_Dpy, sc->menuwin, sc->rootwin, 0, 0); + xu_ptr_ungrab(); + + /* 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; + client_ptrwarp(cc); + + return; + } + } + /* NOTREACHED */ } void mousefunc_window_move(struct client_ctx *cc, void *arg) { - grab_drag(cc); - client_move(cc); + XEvent ev; + struct screen_ctx *sc = CCTOSC(cc); + int mx, my; + int x = cc->geom.x, y = cc->geom.y; + + client_raise(cc); + + if (xu_ptr_grab(sc->rootwin, MouseMask, Cursor_move) < 0) + return; + + xu_ptr_getpos(sc->rootwin, &mx, &my); + + for (;;) { + XMaskEvent(X_Dpy, MouseMask|ExposureMask, &ev); + + switch (ev.type) { + case Expose: + client_draw_border(cc); + break; + case MotionNotify: + cc->geom.x = x + (ev.xmotion.x - mx); + cc->geom.y = y + (ev.xmotion.y - my); + + XMoveWindow(X_Dpy, cc->pwin, + cc->geom.x - cc->bwidth, cc->geom.y - cc->bwidth); + + break; + case ButtonRelease: + xu_ptr_ungrab(); + return; + } + } + /* NOTREACHED */ } void |