2008-06-14 15:48:54 -06:00
|
|
|
/*
|
2011-05-11 07:53:51 -06:00
|
|
|
* calmwm - the calm window manager
|
2008-06-14 15:48:54 -06:00
|
|
|
*
|
2011-05-11 07:53:51 -06:00
|
|
|
* Copyright (c) 2004 Marius Aamodt Eriksen <marius@monkey.org>
|
|
|
|
* Copyright (c) 2008 rivo nurges <rix@estpak.ee>
|
2008-06-14 15:48:54 -06: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.
|
|
|
|
*
|
2013-07-08 12:39:20 -06:00
|
|
|
* $OpenBSD: mousefunc.c,v 1.55 2013/07/08 18:39:20 okan Exp $
|
2008-06-14 15:48:54 -06:00
|
|
|
*/
|
|
|
|
|
2009-12-14 21:10:42 -07:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
2012-11-08 20:52:02 -07:00
|
|
|
#include <stdio.h>
|
2009-12-14 21:10:42 -07:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2008-06-14 15:48:54 -06:00
|
|
|
#include "calmwm.h"
|
|
|
|
|
2013-05-02 13:30:10 -06:00
|
|
|
static void mousefunc_sweep_calc(struct client_ctx *, int, int, int, int);
|
2009-06-17 06:45:01 -06:00
|
|
|
static void mousefunc_sweep_draw(struct client_ctx *);
|
2009-01-11 11:34:46 -07:00
|
|
|
|
2013-05-02 13:30:10 -06:00
|
|
|
static void
|
2009-05-17 18:23:35 -06:00
|
|
|
mousefunc_sweep_calc(struct client_ctx *cc, int x, int y, int mx, int my)
|
2009-01-11 11:34:46 -07:00
|
|
|
{
|
2012-07-13 11:01:04 -06:00
|
|
|
cc->geom.w = abs(x - mx) - cc->bwidth;
|
|
|
|
cc->geom.h = abs(y - my) - cc->bwidth;
|
2009-01-11 11:34:46 -07:00
|
|
|
|
2009-08-24 17:49:04 -06:00
|
|
|
client_applysizehints(cc);
|
2009-01-11 11:34:46 -07:00
|
|
|
|
2012-07-13 11:01:04 -06:00
|
|
|
cc->geom.x = x <= mx ? x : x - cc->geom.w;
|
|
|
|
cc->geom.y = y <= my ? y : y - cc->geom.h;
|
2009-01-11 11:34:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-06-17 06:45:01 -06:00
|
|
|
mousefunc_sweep_draw(struct client_ctx *cc)
|
2009-01-11 11:34:46 -07:00
|
|
|
{
|
2009-08-26 19:38:08 -06:00
|
|
|
struct screen_ctx *sc = cc->sc;
|
2013-05-02 13:33:17 -06:00
|
|
|
char asize[14]; /* fits " nnnn x nnnn \0" */
|
2009-01-11 11:34:46 -07:00
|
|
|
|
2013-05-02 13:33:17 -06:00
|
|
|
(void)snprintf(asize, sizeof(asize), " %4d x %-4d ",
|
2012-07-13 11:01:04 -06:00
|
|
|
(cc->geom.w - cc->hint.basew) / cc->hint.incw,
|
|
|
|
(cc->geom.h - cc->hint.baseh) / cc->hint.inch);
|
2009-01-11 11:34:46 -07:00
|
|
|
|
|
|
|
XReparentWindow(X_Dpy, sc->menuwin, cc->win, 0, 0);
|
2013-05-02 13:33:17 -06:00
|
|
|
XMoveResizeWindow(X_Dpy, sc->menuwin, 0, 0,
|
2013-05-19 17:38:20 -06:00
|
|
|
xu_xft_width(sc->xftfont, asize, strlen(asize)),
|
|
|
|
sc->xftfont->height);
|
2011-06-23 23:51:25 -06:00
|
|
|
XMapWindow(X_Dpy, sc->menuwin);
|
2009-01-11 11:34:46 -07:00
|
|
|
XClearWindow(X_Dpy, sc->menuwin);
|
2013-05-02 13:33:17 -06:00
|
|
|
|
2013-05-20 14:21:04 -06:00
|
|
|
xu_xft_draw(sc, asize, CWM_COLOR_MENU_FONT,
|
2013-05-14 06:35:56 -06:00
|
|
|
0, sc->xftfont->ascent + 1);
|
2009-01-11 11:34:46 -07:00
|
|
|
}
|
|
|
|
|
2008-06-14 15:48:54 -06:00
|
|
|
void
|
2013-07-08 12:19:22 -06:00
|
|
|
mousefunc_client_resize(struct client_ctx *cc, void *arg)
|
2008-06-14 15:48:54 -06:00
|
|
|
{
|
2009-01-11 11:34:46 -07:00
|
|
|
XEvent ev;
|
2011-10-17 12:18:38 -06:00
|
|
|
Time ltime = 0;
|
2009-08-26 19:38:08 -06:00
|
|
|
struct screen_ctx *sc = cc->sc;
|
2009-01-11 11:34:46 -07:00
|
|
|
int x = cc->geom.x, y = cc->geom.y;
|
|
|
|
|
2011-05-07 11:15:37 -06:00
|
|
|
if (cc->flags & CLIENT_FREEZE)
|
|
|
|
return;
|
|
|
|
|
2009-01-11 11:34:46 -07:00
|
|
|
client_raise(cc);
|
|
|
|
client_ptrsave(cc);
|
|
|
|
|
2013-06-17 11:11:10 -06:00
|
|
|
if (xu_ptr_grab(cc->win, MOUSEMASK, Conf.cursor[CF_RESIZE]) < 0)
|
2009-01-11 11:34:46 -07:00
|
|
|
return;
|
|
|
|
|
2012-07-13 11:01:04 -06:00
|
|
|
xu_ptr_setpos(cc->win, cc->geom.w, cc->geom.h);
|
2009-06-17 06:45:01 -06:00
|
|
|
mousefunc_sweep_draw(cc);
|
2009-01-11 11:34:46 -07:00
|
|
|
|
|
|
|
for (;;) {
|
2011-07-23 07:09:11 -06:00
|
|
|
XMaskEvent(X_Dpy, MOUSEMASK|ExposureMask, &ev);
|
2009-01-11 11:34:46 -07:00
|
|
|
|
|
|
|
switch (ev.type) {
|
|
|
|
case Expose:
|
|
|
|
client_draw_border(cc);
|
|
|
|
break;
|
|
|
|
case MotionNotify:
|
2013-05-02 13:30:10 -06:00
|
|
|
mousefunc_sweep_calc(cc, x, y,
|
|
|
|
ev.xmotion.x_root, ev.xmotion.y_root);
|
2009-04-15 08:10:07 -06:00
|
|
|
|
2011-05-05 13:52:52 -06:00
|
|
|
/* don't resize more than 60 times / second */
|
2011-10-17 12:18:38 -06:00
|
|
|
if ((ev.xmotion.time - ltime) > (1000 / 60)) {
|
|
|
|
ltime = ev.xmotion.time;
|
2012-09-09 13:47:47 -06:00
|
|
|
client_resize(cc, 1);
|
2013-05-02 13:30:10 -06:00
|
|
|
mousefunc_sweep_draw(cc);
|
2009-04-15 08:10:07 -06:00
|
|
|
}
|
2009-01-11 11:34:46 -07:00
|
|
|
break;
|
|
|
|
case ButtonRelease:
|
2011-10-17 12:18:38 -06:00
|
|
|
if (ltime)
|
2012-09-09 13:47:47 -06:00
|
|
|
client_resize(cc, 1);
|
2009-01-11 11:34:46 -07: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 11:01:04 -06: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 11:34:46 -07:00
|
|
|
client_ptrwarp(cc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* NOTREACHED */
|
2008-06-14 15:48:54 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-07-08 12:19:22 -06:00
|
|
|
mousefunc_client_move(struct client_ctx *cc, void *arg)
|
2008-06-14 15:48:54 -06:00
|
|
|
{
|
2009-01-11 11:34:46 -07:00
|
|
|
XEvent ev;
|
2011-10-17 12:18:38 -06:00
|
|
|
Time ltime = 0;
|
2012-07-04 17:42:03 -06:00
|
|
|
struct screen_ctx *sc = cc->sc;
|
2009-06-17 06:45:01 -06:00
|
|
|
int px, py;
|
2009-01-11 11:34:46 -07:00
|
|
|
|
|
|
|
client_raise(cc);
|
|
|
|
|
2011-05-07 11:15:37 -06:00
|
|
|
if (cc->flags & CLIENT_FREEZE)
|
|
|
|
return;
|
|
|
|
|
2013-06-17 11:11:10 -06:00
|
|
|
if (xu_ptr_grab(cc->win, MOUSEMASK, Conf.cursor[CF_MOVE]) < 0)
|
2009-01-11 11:34:46 -07:00
|
|
|
return;
|
|
|
|
|
2009-06-17 06:45:01 -06:00
|
|
|
xu_ptr_getpos(cc->win, &px, &py);
|
2009-01-11 11:34:46 -07:00
|
|
|
|
|
|
|
for (;;) {
|
2011-07-23 07:09:11 -06:00
|
|
|
XMaskEvent(X_Dpy, MOUSEMASK|ExposureMask, &ev);
|
2009-01-11 11:34:46 -07:00
|
|
|
|
|
|
|
switch (ev.type) {
|
|
|
|
case Expose:
|
|
|
|
client_draw_border(cc);
|
|
|
|
break;
|
|
|
|
case MotionNotify:
|
2010-12-14 04:08:47 -07:00
|
|
|
cc->geom.x = ev.xmotion.x_root - px - cc->bwidth;
|
|
|
|
cc->geom.y = ev.xmotion.y_root - py - cc->bwidth;
|
2009-04-15 08:10:07 -06:00
|
|
|
|
2011-06-24 00:06:24 -06:00
|
|
|
cc->geom.x += client_snapcalc(cc->geom.x,
|
2013-01-02 14:37:21 -07:00
|
|
|
cc->geom.x + cc->geom.w + (cc->bwidth * 2),
|
2013-01-02 14:41:14 -07:00
|
|
|
sc->work.x, sc->work.w, Conf.snapdist);
|
2011-06-24 00:06:24 -06:00
|
|
|
cc->geom.y += client_snapcalc(cc->geom.y,
|
2013-01-02 14:37:21 -07:00
|
|
|
cc->geom.y + cc->geom.h + (cc->bwidth * 2),
|
2013-01-02 14:41:14 -07:00
|
|
|
sc->work.y, sc->work.h, Conf.snapdist);
|
2011-06-24 00:06:24 -06:00
|
|
|
|
2011-05-05 13:52:52 -06:00
|
|
|
/* don't move more than 60 times / second */
|
2011-10-17 12:18:38 -06:00
|
|
|
if ((ev.xmotion.time - ltime) > (1000 / 60)) {
|
|
|
|
ltime = ev.xmotion.time;
|
2009-04-15 08:10:07 -06:00
|
|
|
client_move(cc);
|
|
|
|
}
|
2009-01-11 11:34:46 -07:00
|
|
|
break;
|
|
|
|
case ButtonRelease:
|
2011-10-17 12:18:38 -06:00
|
|
|
if (ltime)
|
2009-04-15 08:10:07 -06:00
|
|
|
client_move(cc);
|
2009-01-11 11:34:46 -07:00
|
|
|
xu_ptr_ungrab();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* NOTREACHED */
|
2008-06-14 15:48:54 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-07-08 12:19:22 -06:00
|
|
|
mousefunc_client_grouptoggle(struct client_ctx *cc, void *arg)
|
2008-06-14 15:48:54 -06:00
|
|
|
{
|
|
|
|
group_sticky_toggle_enter(cc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-07-08 12:19:22 -06:00
|
|
|
mousefunc_client_lower(struct client_ctx *cc, void *arg)
|
2008-06-14 15:48:54 -06:00
|
|
|
{
|
|
|
|
client_ptrsave(cc);
|
|
|
|
client_lower(cc);
|
|
|
|
}
|
|
|
|
|
2011-06-24 00:09:26 -06:00
|
|
|
void
|
2013-07-08 12:19:22 -06:00
|
|
|
mousefunc_client_raise(struct client_ctx *cc, void *arg)
|
2011-06-24 00:09:26 -06:00
|
|
|
{
|
|
|
|
client_raise(cc);
|
|
|
|
}
|
|
|
|
|
2008-06-25 16:44:42 -06:00
|
|
|
void
|
2013-07-08 12:19:22 -06:00
|
|
|
mousefunc_client_hide(struct client_ctx *cc, void *arg)
|
2008-06-25 16:44:42 -06:00
|
|
|
{
|
|
|
|
client_hide(cc);
|
|
|
|
}
|
|
|
|
|
2013-07-08 12:39:20 -06:00
|
|
|
void
|
|
|
|
mousefunc_client_cyclegroup(struct client_ctx *cc, void *arg)
|
|
|
|
{
|
|
|
|
group_cycle(cc->sc, CWM_CYCLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mousefunc_client_rcyclegroup(struct client_ctx *cc, void *arg)
|
|
|
|
{
|
|
|
|
group_cycle(cc->sc, CWM_RCYCLE);
|
|
|
|
}
|
|
|
|
|
2008-06-14 15:48:54 -06:00
|
|
|
void
|
|
|
|
mousefunc_menu_group(struct client_ctx *cc, void *arg)
|
|
|
|
{
|
|
|
|
group_menu(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mousefunc_menu_unhide(struct client_ctx *cc, void *arg)
|
|
|
|
{
|
2012-07-04 17:42:03 -06:00
|
|
|
struct screen_ctx *sc = cc->sc;
|
2008-07-11 08:21:28 -06:00
|
|
|
struct client_ctx *old_cc;
|
|
|
|
struct menu *mi;
|
|
|
|
struct menu_q menuq;
|
|
|
|
char *wname;
|
|
|
|
|
|
|
|
old_cc = client_current();
|
2008-06-14 15:48:54 -06:00
|
|
|
|
|
|
|
TAILQ_INIT(&menuq);
|
2013-04-08 07:02:31 -06:00
|
|
|
|
2008-06-14 15:48:54 -06:00
|
|
|
TAILQ_FOREACH(cc, &Clientq, entry)
|
|
|
|
if (cc->flags & CLIENT_HIDDEN) {
|
2009-06-19 18:55:41 -06:00
|
|
|
wname = (cc->label) ? cc->label : cc->name;
|
2008-06-14 15:48:54 -06:00
|
|
|
if (wname == NULL)
|
|
|
|
continue;
|
|
|
|
|
2009-06-19 18:22:39 -06:00
|
|
|
mi = xcalloc(1, sizeof(*mi));
|
2011-07-25 09:10:24 -06:00
|
|
|
(void)strlcpy(mi->text, wname, sizeof(mi->text));
|
2008-06-14 15:48:54 -06:00
|
|
|
mi->ctx = cc;
|
|
|
|
TAILQ_INSERT_TAIL(&menuq, mi, entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TAILQ_EMPTY(&menuq))
|
|
|
|
return;
|
|
|
|
|
2009-12-10 10:16:51 -07:00
|
|
|
mi = menu_filter(sc, &menuq, NULL, NULL, 0, NULL, NULL);
|
2008-06-14 15:48:54 -06:00
|
|
|
if (mi != NULL) {
|
|
|
|
cc = (struct client_ctx *)mi->ctx;
|
|
|
|
client_unhide(cc);
|
|
|
|
|
|
|
|
if (old_cc != NULL)
|
|
|
|
client_ptrsave(old_cc);
|
|
|
|
client_ptrwarp(cc);
|
2013-04-08 09:43:04 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
menuq_clear(&menuq);
|
2008-06-14 15:48:54 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mousefunc_menu_cmd(struct client_ctx *cc, void *arg)
|
|
|
|
{
|
2012-07-04 17:42:03 -06:00
|
|
|
struct screen_ctx *sc = cc->sc;
|
2009-12-10 10:16:51 -07:00
|
|
|
struct menu *mi;
|
|
|
|
struct menu_q menuq;
|
|
|
|
struct cmd *cmd;
|
|
|
|
|
2008-06-14 15:48:54 -06:00
|
|
|
TAILQ_INIT(&menuq);
|
2013-04-08 07:02:31 -06:00
|
|
|
|
2008-06-14 15:48:54 -06:00
|
|
|
TAILQ_FOREACH(cmd, &Conf.cmdq, entry) {
|
2009-06-19 18:22:39 -06:00
|
|
|
mi = xcalloc(1, sizeof(*mi));
|
2011-07-25 09:10:24 -06:00
|
|
|
(void)strlcpy(mi->text, cmd->label, sizeof(mi->text));
|
2008-06-14 15:48:54 -06:00
|
|
|
mi->ctx = cmd;
|
|
|
|
TAILQ_INSERT_TAIL(&menuq, mi, entry);
|
|
|
|
}
|
|
|
|
if (TAILQ_EMPTY(&menuq))
|
|
|
|
return;
|
|
|
|
|
2009-12-10 10:16:51 -07:00
|
|
|
mi = menu_filter(sc, &menuq, NULL, NULL, 0, NULL, NULL);
|
2008-06-14 15:48:54 -06:00
|
|
|
if (mi != NULL)
|
|
|
|
u_spawn(((struct cmd *)mi->ctx)->image);
|
2013-04-08 09:43:04 -06:00
|
|
|
|
|
|
|
menuq_clear(&menuq);
|
2008-06-14 15:48:54 -06:00
|
|
|
}
|