2008-06-14 15:48:54 -06:00
|
|
|
/*
|
|
|
|
* calmwm - the calm window manager
|
|
|
|
*
|
2009-01-11 11:34:46 -07:00
|
|
|
* Copyright (c) 2004 Marius Aamodt Eriksen <marius@monkey.org>
|
2008-06-14 15:48:54 -06:00
|
|
|
* Copyright (c) 2008 rivo nurges <rix@estpak.ee>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2010-12-14 04:08:47 -07:00
|
|
|
* $Id: mousefunc.c,v 1.20 2010/12/14 11:08:47 martynas 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>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2008-06-14 15:48:54 -06:00
|
|
|
#include "calmwm.h"
|
|
|
|
|
2009-05-17 18:23:35 -06:00
|
|
|
static int 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
|
|
|
|
|
|
|
static int
|
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
|
|
|
{
|
|
|
|
int width = cc->geom.width, height = cc->geom.height;
|
|
|
|
|
2009-01-22 12:01:56 -07:00
|
|
|
cc->geom.width = abs(x - mx) - cc->bwidth;
|
|
|
|
cc->geom.height = 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
|
|
|
|
|
|
|
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
|
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;
|
2009-01-11 11:34:46 -07:00
|
|
|
char asize[10]; /* fits "nnnnxnnnn\0" */
|
2009-06-17 06:45:01 -06:00
|
|
|
int width, height, width_size, width_name;
|
2009-01-11 11:34:46 -07:00
|
|
|
|
|
|
|
snprintf(asize, sizeof(asize), "%dx%d",
|
2009-08-24 19:32:40 -06:00
|
|
|
(cc->geom.width - cc->geom.basew) / cc->geom.incw,
|
|
|
|
(cc->geom.height - cc->geom.baseh) / cc->geom.inch);
|
2009-12-08 09:52:17 -07:00
|
|
|
width_size = font_width(sc, asize, strlen(asize)) + 4;
|
|
|
|
width_name = font_width(sc, cc->name, strlen(cc->name)) + 4;
|
2009-06-17 06:45:01 -06:00
|
|
|
width = MAX(width_size, width_name);
|
2009-12-08 09:52:17 -07:00
|
|
|
height = font_ascent(sc) + font_descent(sc) + 1;
|
2009-01-11 11:34:46 -07:00
|
|
|
|
2009-06-17 06:45:01 -06:00
|
|
|
XMoveResizeWindow(X_Dpy, sc->menuwin, cc->geom.x, cc->geom.y,
|
|
|
|
width, height * 2);
|
2009-01-11 11:34:46 -07:00
|
|
|
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,
|
2009-12-08 09:52:17 -07:00
|
|
|
2, font_ascent(sc) + 1);
|
2009-01-11 11:34:46 -07:00
|
|
|
font_draw(sc, asize, strlen(asize), sc->menuwin,
|
2009-12-08 09:52:17 -07:00
|
|
|
width / 2 - width_size / 2, height + font_ascent(sc) + 1);
|
2009-01-11 11:34:46 -07:00
|
|
|
}
|
|
|
|
|
2008-06-14 15:48:54 -06:00
|
|
|
void
|
|
|
|
mousefunc_window_resize(struct client_ctx *cc, void *arg)
|
|
|
|
{
|
2009-01-11 11:34:46 -07:00
|
|
|
XEvent ev;
|
2009-04-15 08:10:07 -06:00
|
|
|
Time time = 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;
|
|
|
|
|
|
|
|
client_raise(cc);
|
|
|
|
client_ptrsave(cc);
|
|
|
|
|
2009-06-17 06:45:01 -06:00
|
|
|
if (xu_ptr_grab(cc->win, MouseMask, Cursor_resize) < 0)
|
2009-01-11 11:34:46 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
xu_ptr_setpos(cc->win, cc->geom.width, cc->geom.height);
|
2009-06-17 06:45:01 -06:00
|
|
|
mousefunc_sweep_draw(cc);
|
2009-01-11 11:34:46 -07:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
XMaskEvent(X_Dpy, MouseMask|ExposureMask, &ev);
|
|
|
|
|
|
|
|
switch (ev.type) {
|
|
|
|
case Expose:
|
|
|
|
client_draw_border(cc);
|
|
|
|
break;
|
|
|
|
case MotionNotify:
|
2009-05-17 18:23:35 -06:00
|
|
|
if (mousefunc_sweep_calc(cc, x, y,
|
2009-06-17 06:45:01 -06:00
|
|
|
ev.xmotion.x_root, ev.xmotion.y_root))
|
2009-01-11 11:34:46 -07:00
|
|
|
/* Recompute window output */
|
2009-06-17 06:45:01 -06:00
|
|
|
mousefunc_sweep_draw(cc);
|
2009-04-15 08:10:07 -06:00
|
|
|
|
|
|
|
/* don't sync more than 60 times / second */
|
2009-06-17 06:45:01 -06:00
|
|
|
if ((ev.xmotion.time - time) > (1000 / 60)) {
|
2009-04-15 08:10:07 -06:00
|
|
|
time = ev.xmotion.time;
|
|
|
|
XSync(X_Dpy, False);
|
|
|
|
client_resize(cc);
|
|
|
|
}
|
2009-01-11 11:34:46 -07:00
|
|
|
break;
|
|
|
|
case ButtonRelease:
|
2009-04-15 08:10:07 -06:00
|
|
|
if (time) {
|
|
|
|
XSync(X_Dpy, False);
|
|
|
|
client_resize(cc);
|
|
|
|
}
|
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. */
|
|
|
|
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 */
|
2008-06-14 15:48:54 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mousefunc_window_move(struct client_ctx *cc, void *arg)
|
|
|
|
{
|
2009-01-11 11:34:46 -07:00
|
|
|
XEvent ev;
|
2009-04-15 08:10:07 -06:00
|
|
|
Time time = 0;
|
2009-06-17 06:45:01 -06:00
|
|
|
int px, py;
|
2009-01-11 11:34:46 -07:00
|
|
|
|
|
|
|
client_raise(cc);
|
|
|
|
|
2009-06-17 06:45:01 -06:00
|
|
|
if (xu_ptr_grab(cc->win, MouseMask, Cursor_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 (;;) {
|
|
|
|
XMaskEvent(X_Dpy, MouseMask|ExposureMask, &ev);
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
/* don't sync more than 60 times / second */
|
2009-06-17 06:45:01 -06:00
|
|
|
if ((ev.xmotion.time - time) > (1000 / 60)) {
|
2009-04-15 08:10:07 -06:00
|
|
|
time = ev.xmotion.time;
|
|
|
|
XSync(X_Dpy, False);
|
|
|
|
client_move(cc);
|
|
|
|
}
|
2009-01-11 11:34:46 -07:00
|
|
|
break;
|
|
|
|
case ButtonRelease:
|
2009-04-15 08:10:07 -06:00
|
|
|
if (time) {
|
|
|
|
XSync(X_Dpy, False);
|
|
|
|
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
|
|
|
|
mousefunc_window_grouptoggle(struct client_ctx *cc, void *arg)
|
|
|
|
{
|
|
|
|
group_sticky_toggle_enter(cc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mousefunc_window_lower(struct client_ctx *cc, void *arg)
|
|
|
|
{
|
|
|
|
client_ptrsave(cc);
|
|
|
|
client_lower(cc);
|
|
|
|
}
|
|
|
|
|
2008-06-25 16:44:42 -06:00
|
|
|
void
|
|
|
|
mousefunc_window_hide(struct client_ctx *cc, void *arg)
|
|
|
|
{
|
|
|
|
client_hide(cc);
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2009-12-10 10:16:51 -07:00
|
|
|
struct screen_ctx *sc;
|
2008-07-11 08:21:28 -06:00
|
|
|
struct client_ctx *old_cc;
|
|
|
|
struct menu *mi;
|
|
|
|
struct menu_q menuq;
|
|
|
|
char *wname;
|
|
|
|
|
2009-12-10 10:16:51 -07:00
|
|
|
sc = cc->sc;
|
2008-07-11 08:21:28 -06:00
|
|
|
old_cc = client_current();
|
2008-06-14 15:48:54 -06:00
|
|
|
|
|
|
|
TAILQ_INIT(&menuq);
|
|
|
|
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));
|
2008-06-14 15:48:54 -06:00
|
|
|
strlcpy(mi->text, wname, sizeof(mi->text));
|
|
|
|
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);
|
2008-07-11 08:21:28 -06:00
|
|
|
} else {
|
2008-06-14 15:48:54 -06:00
|
|
|
while ((mi = TAILQ_FIRST(&menuq)) != NULL) {
|
|
|
|
TAILQ_REMOVE(&menuq, mi, entry);
|
|
|
|
xfree(mi);
|
|
|
|
}
|
2008-07-11 08:21:28 -06:00
|
|
|
}
|
2008-06-14 15:48:54 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mousefunc_menu_cmd(struct client_ctx *cc, void *arg)
|
|
|
|
{
|
2009-12-10 10:16:51 -07:00
|
|
|
struct screen_ctx *sc;
|
|
|
|
struct menu *mi;
|
|
|
|
struct menu_q menuq;
|
|
|
|
struct cmd *cmd;
|
|
|
|
|
|
|
|
sc = cc->sc;
|
2008-07-11 08:21:28 -06:00
|
|
|
|
2008-06-14 15:48:54 -06:00
|
|
|
TAILQ_INIT(&menuq);
|
|
|
|
TAILQ_FOREACH(cmd, &Conf.cmdq, entry) {
|
2009-06-19 18:22:39 -06:00
|
|
|
mi = xcalloc(1, sizeof(*mi));
|
2008-06-14 15:48:54 -06:00
|
|
|
strlcpy(mi->text, cmd->label, sizeof(mi->text));
|
|
|
|
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);
|
|
|
|
else
|
|
|
|
while ((mi = TAILQ_FIRST(&menuq)) != NULL) {
|
|
|
|
TAILQ_REMOVE(&menuq, mi, entry);
|
|
|
|
xfree(mi);
|
|
|
|
}
|
|
|
|
}
|