2007-04-27 11:58:48 -06:00
|
|
|
/*
|
|
|
|
* calmwm - the calm window manager
|
|
|
|
*
|
|
|
|
* Copyright (c) 2004 Marius Aamodt Eriksen <marius@monkey.org>
|
|
|
|
*
|
2008-01-11 09:06:44 -07: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.
|
|
|
|
*
|
2009-05-01 11:50:20 -06:00
|
|
|
* $Id: xevents.c,v 1.40 2009/05/01 17:50:20 okan Exp $
|
2007-04-27 11:58:48 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NOTE:
|
|
|
|
* It is the responsibility of the caller to deal with memory
|
|
|
|
* management of the xevent's.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "headers.h"
|
|
|
|
#include "calmwm.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NOTE: in reality, many of these should move to client.c now that
|
|
|
|
* we've got this nice event layer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
xev_handle_maprequest(struct xevent *xev, XEvent *ee)
|
|
|
|
{
|
2008-07-11 08:21:28 -06:00
|
|
|
XMapRequestEvent *e = &ee->xmaprequest;
|
|
|
|
struct client_ctx *cc = NULL, *old_cc;
|
2009-01-17 11:41:50 -07:00
|
|
|
XWindowAttributes xattr;
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2008-07-11 08:21:28 -06:00
|
|
|
if ((old_cc = client_current()) != NULL)
|
2007-04-27 11:58:48 -06:00
|
|
|
client_ptrsave(old_cc);
|
|
|
|
|
2008-04-15 14:24:41 -06:00
|
|
|
if ((cc = client_find(e->window)) == NULL) {
|
2007-05-28 12:34:27 -06:00
|
|
|
XGetWindowAttributes(X_Dpy, e->window, &xattr);
|
2007-04-27 11:58:48 -06:00
|
|
|
cc = client_new(e->window, screen_fromroot(xattr.root), 1);
|
2008-12-04 16:55:04 -07:00
|
|
|
}
|
2007-04-27 11:58:48 -06:00
|
|
|
|
|
|
|
client_ptrwarp(cc);
|
|
|
|
xev_register(xev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xev_handle_unmapnotify(struct xevent *xev, XEvent *ee)
|
|
|
|
{
|
2008-07-11 08:21:28 -06:00
|
|
|
XUnmapEvent *e = &ee->xunmap;
|
2009-01-17 11:41:50 -07:00
|
|
|
XEvent ev;
|
2008-07-11 08:21:28 -06:00
|
|
|
struct client_ctx *cc;
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2009-01-17 11:41:50 -07:00
|
|
|
/* XXX, we need a recursive locking wrapper around grab server */
|
|
|
|
XGrabServer(X_Dpy);
|
|
|
|
if ((cc = client_find(e->window)) != NULL) {
|
|
|
|
/*
|
|
|
|
* If it's going to die anyway, nuke it.
|
|
|
|
*
|
|
|
|
* Else, if it's a synthetic event delete state, since they
|
|
|
|
* want it to be withdrawn. ICCM recommends you withdraw on
|
|
|
|
* this even if we haven't alredy been told to iconify, to
|
|
|
|
* deal with legacy clients.
|
|
|
|
*/
|
|
|
|
if (XCheckTypedWindowEvent(X_Dpy, cc->win,
|
|
|
|
DestroyNotify, &ev) || e->send_event != 0) {
|
|
|
|
client_delete(cc);
|
|
|
|
} else
|
|
|
|
client_hide(cc);
|
|
|
|
}
|
|
|
|
XUngrabServer(X_Dpy);
|
2007-04-27 11:58:48 -06:00
|
|
|
|
|
|
|
xev_register(xev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xev_handle_destroynotify(struct xevent *xev, XEvent *ee)
|
|
|
|
{
|
2008-07-11 08:21:28 -06:00
|
|
|
XDestroyWindowEvent *e = &ee->xdestroywindow;
|
|
|
|
struct client_ctx *cc;
|
2007-04-27 11:58:48 -06:00
|
|
|
|
|
|
|
if ((cc = client_find(e->window)) != NULL)
|
2009-01-17 11:41:50 -07:00
|
|
|
client_delete(cc);
|
2007-04-27 11:58:48 -06:00
|
|
|
|
|
|
|
xev_register(xev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xev_handle_configurerequest(struct xevent *xev, XEvent *ee)
|
|
|
|
{
|
2008-07-11 08:21:28 -06:00
|
|
|
XConfigureRequestEvent *e = &ee->xconfigurerequest;
|
|
|
|
struct client_ctx *cc;
|
|
|
|
struct screen_ctx *sc;
|
|
|
|
XWindowChanges wc;
|
2007-04-27 11:58:48 -06:00
|
|
|
|
|
|
|
if ((cc = client_find(e->window)) != NULL) {
|
|
|
|
sc = CCTOSC(cc);
|
|
|
|
|
|
|
|
if (e->value_mask & CWWidth)
|
|
|
|
cc->geom.width = e->width;
|
|
|
|
if (e->value_mask & CWHeight)
|
|
|
|
cc->geom.height = e->height;
|
|
|
|
if (e->value_mask & CWX)
|
|
|
|
cc->geom.x = e->x;
|
|
|
|
if (e->value_mask & CWY)
|
|
|
|
cc->geom.y = e->y;
|
2009-01-22 12:01:56 -07:00
|
|
|
if (e->value_mask & CWBorderWidth)
|
|
|
|
wc.border_width = e->border_width;
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2009-01-22 12:01:56 -07:00
|
|
|
if (cc->geom.x == 0 && cc->geom.width >= sc->xmax)
|
2007-04-27 11:58:48 -06:00
|
|
|
cc->geom.x -= cc->bwidth;
|
|
|
|
|
2009-01-22 12:01:56 -07:00
|
|
|
if (cc->geom.y == 0 && cc->geom.height >= sc->ymax)
|
2008-04-15 14:24:41 -06:00
|
|
|
cc->geom.y -= cc->bwidth;
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2009-01-22 12:01:56 -07:00
|
|
|
wc.x = cc->geom.x;
|
|
|
|
wc.y = cc->geom.y;
|
|
|
|
wc.width = cc->geom.width;
|
|
|
|
wc.height = cc->geom.height;
|
2009-01-16 08:24:14 -07:00
|
|
|
wc.border_width = cc->bwidth;
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2009-01-16 08:24:14 -07:00
|
|
|
XConfigureWindow(X_Dpy, cc->win, e->value_mask, &wc);
|
2007-04-27 11:58:48 -06:00
|
|
|
xev_reconfig(cc);
|
2009-01-16 08:24:14 -07:00
|
|
|
} else {
|
|
|
|
/* let it do what it wants, it'll be ours when we map it. */
|
|
|
|
wc.x = e->x;
|
|
|
|
wc.y = e->y;
|
|
|
|
wc.width = e->width;
|
|
|
|
wc.height = e->height;
|
2009-01-22 12:01:56 -07:00
|
|
|
wc.border_width = e->border_width;
|
2009-01-16 08:24:14 -07:00
|
|
|
wc.stack_mode = Above;
|
|
|
|
e->value_mask &= ~CWStackMode;
|
|
|
|
|
|
|
|
XConfigureWindow(X_Dpy, e->window, e->value_mask, &wc);
|
2007-04-27 11:58:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
xev_register(xev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xev_handle_propertynotify(struct xevent *xev, XEvent *ee)
|
|
|
|
{
|
2008-07-11 08:21:28 -06:00
|
|
|
XPropertyEvent *e = &ee->xproperty;
|
|
|
|
struct client_ctx *cc;
|
|
|
|
long tmp;
|
2007-04-27 11:58:48 -06:00
|
|
|
|
|
|
|
if ((cc = client_find(e->window)) != NULL) {
|
2008-04-15 14:24:41 -06:00
|
|
|
switch (e->atom) {
|
2007-04-27 11:58:48 -06:00
|
|
|
case XA_WM_NORMAL_HINTS:
|
2007-05-28 12:34:27 -06:00
|
|
|
XGetWMNormalHints(X_Dpy, cc->win, cc->size, &tmp);
|
2007-04-27 11:58:48 -06:00
|
|
|
break;
|
|
|
|
case XA_WM_NAME:
|
|
|
|
client_setname(cc);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* do nothing */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
xev_register(xev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xev_reconfig(struct client_ctx *cc)
|
|
|
|
{
|
2008-07-11 08:21:28 -06:00
|
|
|
XConfigureEvent ce;
|
2007-04-27 11:58:48 -06:00
|
|
|
|
|
|
|
ce.type = ConfigureNotify;
|
|
|
|
ce.event = cc->win;
|
|
|
|
ce.window = cc->win;
|
|
|
|
ce.x = cc->geom.x;
|
|
|
|
ce.y = cc->geom.y;
|
|
|
|
ce.width = cc->geom.width;
|
|
|
|
ce.height = cc->geom.height;
|
2009-01-16 08:24:14 -07:00
|
|
|
ce.border_width = cc->bwidth;
|
2007-04-27 11:58:48 -06:00
|
|
|
ce.above = None;
|
|
|
|
ce.override_redirect = 0;
|
|
|
|
|
2007-05-28 12:34:27 -06:00
|
|
|
XSendEvent(X_Dpy, cc->win, False, StructureNotifyMask, (XEvent *)&ce);
|
2007-04-27 11:58:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xev_handle_enternotify(struct xevent *xev, XEvent *ee)
|
|
|
|
{
|
2008-07-11 08:21:28 -06:00
|
|
|
XCrossingEvent *e = &ee->xcrossing;
|
|
|
|
struct client_ctx *cc;
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2009-01-17 13:39:24 -07:00
|
|
|
if ((cc = client_find(e->window)) != NULL)
|
2007-04-27 11:58:48 -06:00
|
|
|
client_setactive(cc, 1);
|
|
|
|
|
|
|
|
xev_register(xev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xev_handle_leavenotify(struct xevent *xev, XEvent *ee)
|
|
|
|
{
|
|
|
|
client_leave(NULL);
|
|
|
|
|
|
|
|
xev_register(xev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We can split this into two event handlers. */
|
|
|
|
void
|
|
|
|
xev_handle_buttonpress(struct xevent *xev, XEvent *ee)
|
|
|
|
{
|
2008-06-17 14:21:17 -06:00
|
|
|
XButtonEvent *e = &ee->xbutton;
|
|
|
|
struct client_ctx *cc;
|
2008-07-11 08:21:28 -06:00
|
|
|
struct screen_ctx *sc;
|
2008-06-17 14:21:17 -06:00
|
|
|
struct mousebinding *mb;
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2008-07-11 08:21:28 -06:00
|
|
|
sc = screen_fromroot(e->root);
|
2007-04-27 11:58:48 -06:00
|
|
|
cc = client_find(e->window);
|
|
|
|
|
2008-06-17 17:40:33 -06:00
|
|
|
/* Ignore caps lock and numlock */
|
|
|
|
e->state &= ~(Mod2Mask | LockMask);
|
|
|
|
|
2008-06-17 14:55:48 -06:00
|
|
|
TAILQ_FOREACH(mb, &Conf.mousebindingq, entry) {
|
|
|
|
if (e->button == mb->button && e->state == mb->modmask)
|
|
|
|
break;
|
2008-06-17 14:21:17 -06:00
|
|
|
}
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2008-06-17 14:55:48 -06:00
|
|
|
if (mb == NULL)
|
2007-04-27 11:58:48 -06:00
|
|
|
goto out;
|
|
|
|
|
2008-06-17 14:55:48 -06:00
|
|
|
if (mb->context == MOUSEBIND_CTX_ROOT) {
|
|
|
|
if (e->window != sc->rootwin)
|
|
|
|
goto out;
|
|
|
|
} else if (mb->context == MOUSEBIND_CTX_WIN) {
|
|
|
|
cc = client_find(e->window);
|
|
|
|
if (cc == NULL)
|
|
|
|
goto out;
|
2007-04-27 11:58:48 -06:00
|
|
|
}
|
2008-06-17 14:55:48 -06:00
|
|
|
|
|
|
|
(*mb->callback)(cc, e);
|
2008-05-15 16:18:00 -06:00
|
|
|
out:
|
2007-04-27 11:58:48 -06:00
|
|
|
xev_register(xev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xev_handle_buttonrelease(struct xevent *xev, XEvent *ee)
|
|
|
|
{
|
2008-07-11 08:21:28 -06:00
|
|
|
struct client_ctx *cc;
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2008-07-11 08:21:28 -06:00
|
|
|
if ((cc = client_current()) != NULL)
|
2007-04-27 11:58:48 -06:00
|
|
|
group_sticky_toggle_exit(cc);
|
|
|
|
|
|
|
|
xev_register(xev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xev_handle_keypress(struct xevent *xev, XEvent *ee)
|
|
|
|
{
|
2008-07-11 08:21:28 -06:00
|
|
|
XKeyEvent *e = &ee->xkey;
|
|
|
|
struct client_ctx *cc = NULL;
|
|
|
|
struct keybinding *kb;
|
|
|
|
KeySym keysym, skeysym;
|
|
|
|
int modshift;
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2007-05-28 12:34:27 -06:00
|
|
|
keysym = XKeycodeToKeysym(X_Dpy, e->keycode, 0);
|
|
|
|
skeysym = XKeycodeToKeysym(X_Dpy, e->keycode, 1);
|
2008-04-15 14:24:41 -06:00
|
|
|
|
2008-06-17 17:40:33 -06:00
|
|
|
/* we don't care about caps lock and numlock here */
|
|
|
|
e->state &= ~(LockMask | Mod2Mask);
|
|
|
|
|
2008-04-15 14:24:41 -06:00
|
|
|
TAILQ_FOREACH(kb, &Conf.keybindingq, entry) {
|
2007-04-27 11:58:48 -06:00
|
|
|
if (keysym != kb->keysym && skeysym == kb->keysym)
|
|
|
|
modshift = ShiftMask;
|
|
|
|
else
|
|
|
|
modshift = 0;
|
|
|
|
|
|
|
|
if ((kb->modmask | modshift) != e->state)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((kb->keycode != 0 && kb->keysym == NoSymbol &&
|
2008-04-15 14:24:41 -06:00
|
|
|
kb->keycode == e->keycode) || kb->keysym ==
|
|
|
|
(modshift == 0 ? keysym : skeysym))
|
2007-04-27 11:58:48 -06:00
|
|
|
break;
|
2008-04-15 14:24:41 -06:00
|
|
|
}
|
2007-04-27 11:58:48 -06:00
|
|
|
|
|
|
|
if (kb == NULL)
|
|
|
|
goto out;
|
|
|
|
|
2008-04-15 14:24:41 -06:00
|
|
|
if ((kb->flags & (KBFLAG_NEEDCLIENT)) &&
|
2007-04-27 11:58:48 -06:00
|
|
|
(cc = client_find(e->window)) == NULL &&
|
|
|
|
(cc = client_current()) == NULL)
|
|
|
|
if (kb->flags & KBFLAG_NEEDCLIENT)
|
|
|
|
goto out;
|
|
|
|
|
2009-01-23 11:58:40 -07:00
|
|
|
(*kb->callback)(cc, &kb->argument);
|
2007-04-27 11:58:48 -06:00
|
|
|
|
|
|
|
out:
|
|
|
|
xev_register(xev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-02-20 05:56:10 -07:00
|
|
|
* This is only used for the alt suppression detection.
|
2007-04-27 11:58:48 -06:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
xev_handle_keyrelease(struct xevent *xev, XEvent *ee)
|
|
|
|
{
|
2008-07-11 08:21:28 -06:00
|
|
|
XKeyEvent *e = &ee->xkey;
|
|
|
|
struct screen_ctx *sc;
|
|
|
|
struct client_ctx *cc;
|
|
|
|
int keysym;
|
|
|
|
|
|
|
|
sc = screen_fromroot(e->root);
|
|
|
|
cc = client_current();
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2007-05-28 12:34:27 -06:00
|
|
|
keysym = XKeycodeToKeysym(X_Dpy, e->keycode, 0);
|
2007-04-27 11:58:48 -06:00
|
|
|
if (keysym != XK_Alt_L && keysym != XK_Alt_R)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
sc->altpersist = 0;
|
2008-04-15 14:24:41 -06:00
|
|
|
|
2007-04-27 11:58:48 -06:00
|
|
|
/*
|
|
|
|
* XXX - better interface... xevents should not know about
|
|
|
|
* how/when to mtf.
|
|
|
|
*/
|
|
|
|
client_mtf(NULL);
|
|
|
|
|
2008-05-19 06:56:58 -06:00
|
|
|
if (cc != NULL) {
|
|
|
|
group_sticky_toggle_exit(cc);
|
|
|
|
XUngrabKeyboard(X_Dpy, CurrentTime);
|
|
|
|
}
|
|
|
|
|
2008-05-15 16:18:00 -06:00
|
|
|
out:
|
2007-04-27 11:58:48 -06:00
|
|
|
xev_register(xev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xev_handle_clientmessage(struct xevent *xev, XEvent *ee)
|
|
|
|
{
|
2008-07-11 08:21:28 -06:00
|
|
|
XClientMessageEvent *e = &ee->xclient;
|
|
|
|
Atom xa_wm_change_state;
|
|
|
|
struct client_ctx *cc;
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2008-07-11 08:21:28 -06:00
|
|
|
xa_wm_change_state = XInternAtom(X_Dpy, "WM_CHANGE_STATE", False);
|
|
|
|
|
|
|
|
if ((cc = client_find(e->window)) == NULL)
|
2007-04-27 11:58:48 -06:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (e->message_type == xa_wm_change_state && e->format == 32 &&
|
|
|
|
e->data.l[0] == IconicState)
|
|
|
|
client_hide(cc);
|
|
|
|
out:
|
|
|
|
xev_register(xev);
|
|
|
|
}
|
|
|
|
|
2008-09-29 17:16:46 -06:00
|
|
|
void
|
|
|
|
xev_handle_randr(struct xevent *xev, XEvent *ee)
|
|
|
|
{
|
|
|
|
XRRScreenChangeNotifyEvent *rev = (XRRScreenChangeNotifyEvent *)ee;
|
|
|
|
struct screen_ctx *sc;
|
2009-05-01 11:50:20 -06:00
|
|
|
int i;
|
|
|
|
|
|
|
|
i = XRRRootToScreen(X_Dpy, rev->root);
|
|
|
|
TAILQ_FOREACH(sc, &Screenq, entry) {
|
|
|
|
if (sc->which == (u_int)i) {
|
|
|
|
XRRUpdateConfiguration(ee);
|
|
|
|
sc->xmax = rev->width;
|
|
|
|
sc->ymax = rev->height;
|
|
|
|
screen_init_xinerama(sc);
|
|
|
|
}
|
2008-09-29 17:16:46 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-22 15:01:54 -06:00
|
|
|
/*
|
|
|
|
* Called when the keymap has changed.
|
|
|
|
* Ungrab all keys, reload keymap and then regrab
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
xev_handle_mapping(struct xevent *xev, XEvent *ee)
|
|
|
|
{
|
|
|
|
XMappingEvent *e = &ee->xmapping;
|
|
|
|
struct keybinding *kb;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(kb, &Conf.keybindingq, entry)
|
|
|
|
conf_ungrab(&Conf, kb);
|
|
|
|
|
|
|
|
XRefreshKeyboardMapping(e);
|
|
|
|
|
|
|
|
TAILQ_FOREACH(kb, &Conf.keybindingq, entry)
|
|
|
|
conf_grab(&Conf, kb);
|
|
|
|
|
|
|
|
xev_register(xev);
|
|
|
|
}
|
|
|
|
|
2007-04-27 11:58:48 -06:00
|
|
|
/*
|
|
|
|
* X Event handling
|
|
|
|
*/
|
|
|
|
|
2008-04-15 14:24:41 -06:00
|
|
|
static struct xevent_q _xevq, _xevq_putaway;
|
|
|
|
static short _xev_q_lock = 0;
|
|
|
|
volatile sig_atomic_t _xev_quit = 0;
|
2007-04-27 11:58:48 -06:00
|
|
|
|
|
|
|
void
|
|
|
|
xev_init(void)
|
|
|
|
{
|
|
|
|
TAILQ_INIT(&_xevq);
|
|
|
|
TAILQ_INIT(&_xevq_putaway);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct xevent *
|
|
|
|
xev_new(Window *win, Window *root,
|
|
|
|
int type, void (*cb)(struct xevent *, XEvent *), void *arg)
|
|
|
|
{
|
2008-07-11 08:21:28 -06:00
|
|
|
struct xevent *xev;
|
2007-04-27 11:58:48 -06:00
|
|
|
|
|
|
|
XMALLOC(xev, struct xevent);
|
|
|
|
xev->xev_win = win;
|
|
|
|
xev->xev_root = root;
|
|
|
|
xev->xev_type = type;
|
|
|
|
xev->xev_cb = cb;
|
|
|
|
xev->xev_arg = arg;
|
|
|
|
|
|
|
|
return (xev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xev_register(struct xevent *xev)
|
|
|
|
{
|
2008-07-11 08:21:28 -06:00
|
|
|
struct xevent_q *xq;
|
2007-04-27 11:58:48 -06:00
|
|
|
|
|
|
|
xq = _xev_q_lock ? &_xevq_putaway : &_xevq;
|
|
|
|
TAILQ_INSERT_TAIL(xq, xev, entry);
|
|
|
|
}
|
|
|
|
|
2009-03-28 10:38:54 -06:00
|
|
|
static void
|
2007-04-27 11:58:48 -06:00
|
|
|
_xev_reincorporate(void)
|
|
|
|
{
|
2008-07-11 08:21:28 -06:00
|
|
|
struct xevent *xev;
|
2007-04-27 11:58:48 -06:00
|
|
|
|
|
|
|
while ((xev = TAILQ_FIRST(&_xevq_putaway)) != NULL) {
|
|
|
|
TAILQ_REMOVE(&_xevq_putaway, xev, entry);
|
|
|
|
TAILQ_INSERT_TAIL(&_xevq, xev, entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xev_handle_expose(struct xevent *xev, XEvent *ee)
|
|
|
|
{
|
2008-07-11 08:21:28 -06:00
|
|
|
XExposeEvent *e = &ee->xexpose;
|
|
|
|
struct client_ctx *cc;
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2009-01-16 08:24:14 -07:00
|
|
|
if ((cc = client_find(e->window)) != NULL && e->count == 0)
|
2007-04-27 11:58:48 -06:00
|
|
|
client_draw_border(cc);
|
|
|
|
|
|
|
|
xev_register(xev);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ASSIGN(xtype) do { \
|
|
|
|
root = e. xtype .root; \
|
|
|
|
win = e. xtype .window; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define ASSIGN1(xtype) do { \
|
|
|
|
win = e. xtype .window; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
void
|
|
|
|
xev_loop(void)
|
|
|
|
{
|
2008-07-11 08:21:28 -06:00
|
|
|
Window win, root;
|
|
|
|
XEvent e;
|
|
|
|
struct xevent *xev = NULL, *nextxev;
|
2007-04-27 11:58:48 -06:00
|
|
|
int type;
|
|
|
|
|
2008-04-07 17:47:09 -06:00
|
|
|
while (_xev_quit == 0) {
|
2007-04-27 11:58:48 -06:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (TAILQ_EMPTY(&_xevq))
|
|
|
|
errx(1, "X event queue empty");
|
2008-04-15 14:24:41 -06:00
|
|
|
#endif
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2007-05-28 12:34:27 -06:00
|
|
|
XNextEvent(X_Dpy, &e);
|
2007-04-27 11:58:48 -06:00
|
|
|
type = e.type;
|
|
|
|
|
|
|
|
win = root = 0;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case MapRequest:
|
|
|
|
ASSIGN1(xmaprequest);
|
|
|
|
break;
|
|
|
|
case UnmapNotify:
|
|
|
|
ASSIGN1(xunmap);
|
|
|
|
break;
|
|
|
|
case ConfigureRequest:
|
|
|
|
ASSIGN1(xconfigurerequest);
|
|
|
|
break;
|
|
|
|
case PropertyNotify:
|
|
|
|
ASSIGN1(xproperty);
|
|
|
|
break;
|
|
|
|
case EnterNotify:
|
|
|
|
case LeaveNotify:
|
|
|
|
ASSIGN(xcrossing);
|
|
|
|
break;
|
|
|
|
case ButtonPress:
|
|
|
|
ASSIGN(xbutton);
|
|
|
|
break;
|
|
|
|
case ButtonRelease:
|
|
|
|
ASSIGN(xbutton);
|
|
|
|
break;
|
|
|
|
case KeyPress:
|
|
|
|
case KeyRelease:
|
|
|
|
ASSIGN(xkey);
|
|
|
|
break;
|
|
|
|
case DestroyNotify:
|
|
|
|
ASSIGN1(xdestroywindow);
|
|
|
|
break;
|
|
|
|
case ClientMessage:
|
|
|
|
ASSIGN1(xclient);
|
|
|
|
break;
|
2008-06-14 16:04:11 -06:00
|
|
|
default:
|
2009-01-16 08:24:14 -07:00
|
|
|
if (e.type == Randr_ev)
|
2008-09-29 17:16:46 -06:00
|
|
|
xev_handle_randr(xev, &e);
|
2007-04-27 11:58:48 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now, search for matches, and call each of them.
|
|
|
|
*/
|
|
|
|
_xev_q_lock = 1;
|
|
|
|
for (xev = TAILQ_FIRST(&_xevq); xev != NULL; xev = nextxev) {
|
|
|
|
nextxev = TAILQ_NEXT(xev, entry);
|
|
|
|
|
|
|
|
if ((type != xev->xev_type && xev->xev_type != 0) ||
|
|
|
|
(xev->xev_win != NULL && win != *xev->xev_win) ||
|
|
|
|
(xev->xev_root != NULL && root != *xev->xev_root))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
TAILQ_REMOVE(&_xevq, xev, entry);
|
|
|
|
|
|
|
|
(*xev->xev_cb)(xev, &e);
|
|
|
|
}
|
|
|
|
_xev_q_lock = 0;
|
|
|
|
_xev_reincorporate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef ASSIGN
|
|
|
|
#undef ASSIGN1
|