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"
|
|
|
|
|
2013-05-02 23:30:10 +04:00
|
|
|
static void mousefunc_sweep_calc(struct client_ctx *, int, int, int, int);
|
2009-06-17 16:45:01 +04:00
|
|
|
static void mousefunc_sweep_draw(struct client_ctx *);
|
2009-01-11 21:34:46 +03:00
|
|
|
|
2013-05-02 23:30:10 +04:00
|
|
|
static void
|
2009-05-18 04:23:35 +04:00
|
|
|
mousefunc_sweep_calc(struct client_ctx *cc, int x, int y, int mx, int my)
|
2009-01-11 21:34:46 +03:00
|
|
|
{
|
2012-07-13 21:01:04 +04:00
|
|
|
cc->geom.w = abs(x - mx) - cc->bwidth;
|
|
|
|
cc->geom.h = abs(y - my) - cc->bwidth;
|
2009-01-11 21:34:46 +03:00
|
|
|
|
2009-08-25 03:49:04 +04:00
|
|
|
client_applysizehints(cc);
|
2009-01-11 21:34:46 +03:00
|
|
|
|
2015-07-01 17:36:42 +03:00
|
|
|
cc->geom.x = (x <= mx) ? x : x - cc->geom.w;
|
|
|
|
cc->geom.y = (y <= my) ? y : y - cc->geom.h;
|
2009-01-11 21:34:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-06-17 16:45:01 +04:00
|
|
|
mousefunc_sweep_draw(struct client_ctx *cc)
|
2009-01-11 21:34:46 +03:00
|
|
|
{
|
2009-08-27 05:38:08 +04:00
|
|
|
struct screen_ctx *sc = cc->sc;
|
2013-11-27 18:20:32 +04:00
|
|
|
char s[14]; /* fits " nnnn x nnnn \0" */
|
2009-01-11 21:34:46 +03:00
|
|
|
|
2015-06-08 18:11:29 +03:00
|
|
|
(void)snprintf(s, sizeof(s), " %4d x %-4d ", cc->dim.w, cc->dim.h);
|
2009-01-11 21:34:46 +03:00
|
|
|
|
|
|
|
XReparentWindow(X_Dpy, sc->menuwin, cc->win, 0, 0);
|
2013-05-02 23:33:17 +04:00
|
|
|
XMoveResizeWindow(X_Dpy, sc->menuwin, 0, 0,
|
2013-11-27 18:20:32 +04:00
|
|
|
xu_xft_width(sc->xftfont, s, strlen(s)), sc->xftfont->height);
|
2011-06-24 09:51:25 +04:00
|
|
|
XMapWindow(X_Dpy, sc->menuwin);
|
2009-01-11 21:34:46 +03:00
|
|
|
XClearWindow(X_Dpy, sc->menuwin);
|
2013-05-02 23:33:17 +04:00
|
|
|
|
2013-11-27 18:20:32 +04:00
|
|
|
xu_xft_draw(sc, s, CWM_COLOR_MENU_FONT, 0, sc->xftfont->ascent + 1);
|
2009-01-11 21:34:46 +03:00
|
|
|
}
|
|
|
|
|
2008-06-15 01:48:54 +04:00
|
|
|
void
|
2014-01-03 01:30:20 +04:00
|
|
|
mousefunc_client_resize(struct client_ctx *cc, union arg *arg)
|
2008-06-15 01:48:54 +04:00
|
|
|
{
|
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
|
|
|
int x = cc->geom.x, y = cc->geom.y;
|
|
|
|
|
2014-09-17 22:09:30 +04:00
|
|
|
if (cc->flags & (CLIENT_FREEZE|CLIENT_STICKY))
|
2011-05-07 21:15:37 +04:00
|
|
|
return;
|
|
|
|
|
2009-01-11 21:34:46 +03:00
|
|
|
client_raise(cc);
|
|
|
|
client_ptrsave(cc);
|
|
|
|
|
2013-06-17 21:11:10 +04:00
|
|
|
if (xu_ptr_grab(cc->win, MOUSEMASK, Conf.cursor[CF_RESIZE]) < 0)
|
2009-01-11 21:34:46 +03:00
|
|
|
return;
|
|
|
|
|
2012-07-13 21:01:04 +04:00
|
|
|
xu_ptr_setpos(cc->win, cc->geom.w, cc->geom.h);
|
2009-06-17 16:45:01 +04:00
|
|
|
mousefunc_sweep_draw(cc);
|
2009-01-11 21:34:46 +03:00
|
|
|
|
|
|
|
for (;;) {
|
2013-10-19 22:59:22 +04:00
|
|
|
XMaskEvent(X_Dpy, 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;
|
|
|
|
|
2013-05-02 23:30:10 +04:00
|
|
|
mousefunc_sweep_calc(cc, x, y,
|
|
|
|
ev.xmotion.x_root, ev.xmotion.y_root);
|
2014-09-18 17:56:58 +04:00
|
|
|
client_resize(cc, 1);
|
|
|
|
mousefunc_sweep_draw(cc);
|
2009-01-11 21:34:46 +03:00
|
|
|
break;
|
|
|
|
case ButtonRelease:
|
2014-09-18 17:56:58 +04:00
|
|
|
client_resize(cc, 1);
|
2009-01-11 21:34:46 +03:00
|
|
|
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. */
|
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
|
2014-01-03 01:30:20 +04:00
|
|
|
mousefunc_client_move(struct client_ctx *cc, union arg *arg)
|
2008-06-15 01:48:54 +04:00
|
|
|
{
|
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-06-26 20:17:46 +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);
|
|
|
|
|
2014-09-17 22:09:30 +04:00
|
|
|
if (cc->flags & (CLIENT_FREEZE|CLIENT_STICKY))
|
2011-05-07 21:15:37 +04:00
|
|
|
return;
|
|
|
|
|
2013-06-17 21:11:10 +04:00
|
|
|
if (xu_ptr_grab(cc->win, MOUSEMASK, Conf.cursor[CF_MOVE]) < 0)
|
2009-01-11 21:34:46 +03:00
|
|
|
return;
|
|
|
|
|
2009-06-17 16:45:01 +04:00
|
|
|
xu_ptr_getpos(cc->win, &px, &py);
|
2009-01-11 21:34:46 +03:00
|
|
|
|
|
|
|
for (;;) {
|
2013-10-19 22:59:22 +04:00
|
|
|
XMaskEvent(X_Dpy, 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-06-26 20:17:46 +03:00
|
|
|
area = screen_area(sc,
|
2013-12-14 01:51:56 +04:00
|
|
|
cc->geom.x + cc->geom.w / 2,
|
2013-12-14 02:39:13 +04:00
|
|
|
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-06-26 20:17:46 +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-06-26 20:17:46 +03:00
|
|
|
area.y, area.y + area.h, sc->snapdist);
|
2011-06-24 10:06:24 +04:00
|
|
|
|
2014-09-18 17:56:58 +04:00
|
|
|
client_move(cc);
|
2009-01-11 21:34:46 +03:00
|
|
|
break;
|
|
|
|
case ButtonRelease:
|
2014-09-18 17:56:58 +04:00
|
|
|
client_move(cc);
|
2009-01-11 21:34:46 +03:00
|
|
|
xu_ptr_ungrab();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* NOTREACHED */
|
2008-06-15 01:48:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-03 01:30:20 +04:00
|
|
|
mousefunc_menu_group(struct client_ctx *cc, union arg *arg)
|
2008-06-15 01:48:54 +04:00
|
|
|
{
|
2014-09-01 22:04:58 +04:00
|
|
|
struct screen_ctx *sc = cc->sc;
|
|
|
|
struct group_ctx *gc;
|
|
|
|
struct menu *mi;
|
|
|
|
struct menu_q menuq;
|
|
|
|
|
|
|
|
TAILQ_INIT(&menuq);
|
|
|
|
TAILQ_FOREACH(gc, &sc->groupq, entry) {
|
2014-09-17 18:31:37 +04:00
|
|
|
if (group_holds_only_sticky(gc))
|
2014-09-01 22:04:58 +04:00
|
|
|
continue;
|
2015-07-12 17:31:47 +03:00
|
|
|
menuq_add(&menuq, gc, "%d %s", gc->num, gc->name);
|
2014-09-01 22:04:58 +04:00
|
|
|
}
|
|
|
|
|
2015-06-05 18:01:51 +03:00
|
|
|
if ((mi = menu_filter(sc, &menuq, NULL, NULL, CWM_MENU_LIST,
|
2015-07-12 17:31:47 +03:00
|
|
|
NULL, search_print_group)) != NULL) {
|
2014-09-01 22:04:58 +04:00
|
|
|
gc = (struct group_ctx *)mi->ctx;
|
2014-09-17 20:32:53 +04:00
|
|
|
(group_holds_only_hidden(gc)) ?
|
2014-09-08 17:51:29 +04:00
|
|
|
group_show(gc) : group_hide(gc);
|
2014-09-01 22:04:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
menuq_clear(&menuq);
|
2008-06-15 01:48:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-03 01:30:20 +04:00
|
|
|
mousefunc_menu_unhide(struct client_ctx *cc, union arg *arg)
|
2008-06-15 01:48:54 +04:00
|
|
|
{
|
2012-07-05 03:42:03 +04:00
|
|
|
struct screen_ctx *sc = cc->sc;
|
2008-07-11 18:21:28 +04:00
|
|
|
struct client_ctx *old_cc;
|
|
|
|
struct menu *mi;
|
|
|
|
struct menu_q menuq;
|
|
|
|
|
|
|
|
old_cc = client_current();
|
2008-06-15 01:48:54 +04:00
|
|
|
|
|
|
|
TAILQ_INIT(&menuq);
|
2014-09-09 00:11:22 +04:00
|
|
|
TAILQ_FOREACH(cc, &sc->clientq, entry) {
|
2008-06-15 01:48:54 +04:00
|
|
|
if (cc->flags & CLIENT_HIDDEN) {
|
2015-06-08 18:41:27 +03:00
|
|
|
menuq_add(&menuq, cc, NULL);
|
2008-06-15 01:48:54 +04:00
|
|
|
}
|
2014-09-01 22:17:32 +04:00
|
|
|
}
|
2008-06-15 01:48:54 +04:00
|
|
|
|
2015-06-05 18:01:51 +03:00
|
|
|
if ((mi = menu_filter(sc, &menuq, NULL, NULL, CWM_MENU_LIST,
|
2015-06-08 18:41:27 +03:00
|
|
|
NULL, search_print_client)) != NULL) {
|
2008-06-15 01:48:54 +04:00
|
|
|
cc = (struct client_ctx *)mi->ctx;
|
|
|
|
client_unhide(cc);
|
|
|
|
if (old_cc != NULL)
|
|
|
|
client_ptrsave(old_cc);
|
|
|
|
client_ptrwarp(cc);
|
2013-04-08 19:43:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
menuq_clear(&menuq);
|
2008-06-15 01:48:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-03 01:30:20 +04:00
|
|
|
mousefunc_menu_cmd(struct client_ctx *cc, union arg *arg)
|
2008-06-15 01:48:54 +04:00
|
|
|
{
|
2012-07-05 03:42:03 +04:00
|
|
|
struct screen_ctx *sc = cc->sc;
|
2014-01-30 02:30:00 +04:00
|
|
|
struct cmd *cmd;
|
2009-12-10 20:16:51 +03:00
|
|
|
struct menu *mi;
|
|
|
|
struct menu_q menuq;
|
|
|
|
|
2008-06-15 01:48:54 +04:00
|
|
|
TAILQ_INIT(&menuq);
|
2014-01-20 22:58:03 +04:00
|
|
|
TAILQ_FOREACH(cmd, &Conf.cmdq, entry)
|
2015-06-30 22:02:24 +03:00
|
|
|
menuq_add(&menuq, cmd, NULL);
|
2008-06-15 01:48:54 +04:00
|
|
|
|
2015-06-05 18:01:51 +03:00
|
|
|
if ((mi = menu_filter(sc, &menuq, NULL, NULL, CWM_MENU_LIST,
|
2015-06-30 21:54:12 +03:00
|
|
|
NULL, search_print_cmd)) != NULL)
|
2014-01-21 01:34:32 +04:00
|
|
|
u_spawn(((struct cmd *)mi->ctx)->path);
|
2013-04-08 19:43:04 +04:00
|
|
|
|
|
|
|
menuq_clear(&menuq);
|
2008-06-15 01:48:54 +04:00
|
|
|
}
|