2007-04-27 21:58:48 +04:00
|
|
|
/*
|
|
|
|
* calmwm - the calm window manager
|
|
|
|
*
|
|
|
|
* Copyright (c) 2004 Marius Aamodt Eriksen <marius@monkey.org>
|
2008-01-11 19:06:44 +03: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.
|
2007-04-27 21:58:48 +04:00
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NOTE:
|
|
|
|
* It is the responsibility of the caller to deal with memory
|
|
|
|
* management of the xevent's.
|
|
|
|
*/
|
|
|
|
|
2009-12-15 07:10:42 +03: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>
|
|
|
|
|
2007-04-27 21:58:48 +04:00
|
|
|
#include "calmwm.h"
|
|
|
|
|
2009-05-18 04:14:19 +04:00
|
|
|
static void xev_handle_maprequest(XEvent *);
|
|
|
|
static void xev_handle_unmapnotify(XEvent *);
|
|
|
|
static void xev_handle_destroynotify(XEvent *);
|
|
|
|
static void xev_handle_configurerequest(XEvent *);
|
|
|
|
static void xev_handle_propertynotify(XEvent *);
|
|
|
|
static void xev_handle_enternotify(XEvent *);
|
|
|
|
static void xev_handle_leavenotify(XEvent *);
|
|
|
|
static void xev_handle_buttonpress(XEvent *);
|
|
|
|
static void xev_handle_buttonrelease(XEvent *);
|
|
|
|
static void xev_handle_keypress(XEvent *);
|
|
|
|
static void xev_handle_keyrelease(XEvent *);
|
|
|
|
static void xev_handle_expose(XEvent *);
|
|
|
|
static void xev_handle_clientmessage(XEvent *);
|
|
|
|
static void xev_handle_randr(XEvent *);
|
|
|
|
static void xev_handle_mappingnotify(XEvent *);
|
|
|
|
|
|
|
|
|
|
|
|
void (*xev_handlers[LASTEvent])(XEvent *) = {
|
|
|
|
[MapRequest] = xev_handle_maprequest,
|
|
|
|
[UnmapNotify] = xev_handle_unmapnotify,
|
|
|
|
[ConfigureRequest] = xev_handle_configurerequest,
|
|
|
|
[PropertyNotify] = xev_handle_propertynotify,
|
|
|
|
[EnterNotify] = xev_handle_enternotify,
|
|
|
|
[LeaveNotify] = xev_handle_leavenotify,
|
|
|
|
[ButtonPress] = xev_handle_buttonpress,
|
|
|
|
[ButtonRelease] = xev_handle_buttonrelease,
|
|
|
|
[KeyPress] = xev_handle_keypress,
|
|
|
|
[KeyRelease] = xev_handle_keyrelease,
|
|
|
|
[Expose] = xev_handle_expose,
|
|
|
|
[DestroyNotify] = xev_handle_destroynotify,
|
|
|
|
[ClientMessage] = xev_handle_clientmessage,
|
|
|
|
[MappingNotify] = xev_handle_mappingnotify,
|
|
|
|
};
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2009-05-18 04:14:19 +04:00
|
|
|
static void
|
|
|
|
xev_handle_maprequest(XEvent *ee)
|
2007-04-27 21:58:48 +04:00
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
XMapRequestEvent *e = &ee->xmaprequest;
|
|
|
|
struct client_ctx *cc = NULL, *old_cc;
|
2009-01-17 21:41:50 +03:00
|
|
|
XWindowAttributes xattr;
|
2010-09-26 00:04:55 +04:00
|
|
|
struct winmatch *wm;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2008-07-11 18:21:28 +04:00
|
|
|
if ((old_cc = client_current()) != NULL)
|
2007-04-27 21:58:48 +04:00
|
|
|
client_ptrsave(old_cc);
|
|
|
|
|
2008-04-16 00:24:41 +04:00
|
|
|
if ((cc = client_find(e->window)) == NULL) {
|
2007-05-28 22:34:27 +04:00
|
|
|
XGetWindowAttributes(X_Dpy, e->window, &xattr);
|
2007-04-27 21:58:48 +04:00
|
|
|
cc = client_new(e->window, screen_fromroot(xattr.root), 1);
|
2008-12-05 02:55:04 +03:00
|
|
|
}
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2010-09-26 00:04:55 +04:00
|
|
|
TAILQ_FOREACH(wm, &Conf.ignoreq, entry) {
|
|
|
|
if (strncasecmp(wm->title, cc->name, strlen(wm->title)) == 0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-04-27 21:58:48 +04:00
|
|
|
client_ptrwarp(cc);
|
|
|
|
}
|
|
|
|
|
2009-05-18 04:14:19 +04:00
|
|
|
static void
|
|
|
|
xev_handle_unmapnotify(XEvent *ee)
|
2007-04-27 21:58:48 +04:00
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
XUnmapEvent *e = &ee->xunmap;
|
2009-01-17 21:41:50 +03:00
|
|
|
XEvent ev;
|
2008-07-11 18:21:28 +04:00
|
|
|
struct client_ctx *cc;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2009-01-17 21:41:50 +03: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 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
2009-05-18 04:14:19 +04:00
|
|
|
static void
|
|
|
|
xev_handle_destroynotify(XEvent *ee)
|
2007-04-27 21:58:48 +04:00
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
XDestroyWindowEvent *e = &ee->xdestroywindow;
|
|
|
|
struct client_ctx *cc;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
if ((cc = client_find(e->window)) != NULL)
|
2009-01-17 21:41:50 +03:00
|
|
|
client_delete(cc);
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
2009-05-18 04:14:19 +04:00
|
|
|
static void
|
|
|
|
xev_handle_configurerequest(XEvent *ee)
|
2007-04-27 21:58:48 +04:00
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
XConfigureRequestEvent *e = &ee->xconfigurerequest;
|
|
|
|
struct client_ctx *cc;
|
|
|
|
struct screen_ctx *sc;
|
|
|
|
XWindowChanges wc;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
if ((cc = client_find(e->window)) != NULL) {
|
2009-08-27 05:38:08 +04:00
|
|
|
sc = cc->sc;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
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 22:01:56 +03:00
|
|
|
if (e->value_mask & CWBorderWidth)
|
|
|
|
wc.border_width = e->border_width;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2009-01-22 22:01:56 +03:00
|
|
|
if (cc->geom.x == 0 && cc->geom.width >= sc->xmax)
|
2007-04-27 21:58:48 +04:00
|
|
|
cc->geom.x -= cc->bwidth;
|
|
|
|
|
2009-01-22 22:01:56 +03:00
|
|
|
if (cc->geom.y == 0 && cc->geom.height >= sc->ymax)
|
2008-04-16 00:24:41 +04:00
|
|
|
cc->geom.y -= cc->bwidth;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2009-01-22 22:01:56 +03:00
|
|
|
wc.x = cc->geom.x;
|
|
|
|
wc.y = cc->geom.y;
|
|
|
|
wc.width = cc->geom.width;
|
|
|
|
wc.height = cc->geom.height;
|
2009-01-16 18:24:14 +03:00
|
|
|
wc.border_width = cc->bwidth;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2009-01-16 18:24:14 +03:00
|
|
|
XConfigureWindow(X_Dpy, cc->win, e->value_mask, &wc);
|
2007-04-27 21:58:48 +04:00
|
|
|
xev_reconfig(cc);
|
2009-01-16 18:24:14 +03: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 22:01:56 +03:00
|
|
|
wc.border_width = e->border_width;
|
2009-01-16 18:24:14 +03:00
|
|
|
wc.stack_mode = Above;
|
|
|
|
e->value_mask &= ~CWStackMode;
|
|
|
|
|
|
|
|
XConfigureWindow(X_Dpy, e->window, e->value_mask, &wc);
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-18 04:14:19 +04:00
|
|
|
static void
|
|
|
|
xev_handle_propertynotify(XEvent *ee)
|
2007-04-27 21:58:48 +04:00
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
XPropertyEvent *e = &ee->xproperty;
|
2009-12-11 20:51:42 +03:00
|
|
|
struct screen_ctx *sc;
|
2008-07-11 18:21:28 +04:00
|
|
|
struct client_ctx *cc;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
if ((cc = client_find(e->window)) != NULL) {
|
2008-04-16 00:24:41 +04:00
|
|
|
switch (e->atom) {
|
2007-04-27 21:58:48 +04:00
|
|
|
case XA_WM_NORMAL_HINTS:
|
2009-08-25 03:49:04 +04:00
|
|
|
client_getsizehints(cc);
|
2007-04-27 21:58:48 +04:00
|
|
|
break;
|
|
|
|
case XA_WM_NAME:
|
|
|
|
client_setname(cc);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* do nothing */
|
|
|
|
break;
|
|
|
|
}
|
2009-12-11 20:51:42 +03:00
|
|
|
} else {
|
|
|
|
TAILQ_FOREACH(sc, &Screenq, entry)
|
|
|
|
if (sc->rootwin == e->window)
|
|
|
|
goto test;
|
|
|
|
return;
|
|
|
|
|
|
|
|
test:
|
|
|
|
if (e->atom == _NET_DESKTOP_NAMES)
|
|
|
|
group_update_names(sc);
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
2009-12-11 20:51:42 +03:00
|
|
|
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xev_reconfig(struct client_ctx *cc)
|
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
XConfigureEvent ce;
|
2007-04-27 21:58:48 +04: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 18:24:14 +03:00
|
|
|
ce.border_width = cc->bwidth;
|
2007-04-27 21:58:48 +04:00
|
|
|
ce.above = None;
|
|
|
|
ce.override_redirect = 0;
|
|
|
|
|
2007-05-28 22:34:27 +04:00
|
|
|
XSendEvent(X_Dpy, cc->win, False, StructureNotifyMask, (XEvent *)&ce);
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
2009-05-18 04:14:19 +04:00
|
|
|
static void
|
|
|
|
xev_handle_enternotify(XEvent *ee)
|
2007-04-27 21:58:48 +04:00
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
XCrossingEvent *e = &ee->xcrossing;
|
|
|
|
struct client_ctx *cc;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2009-01-17 23:39:24 +03:00
|
|
|
if ((cc = client_find(e->window)) != NULL)
|
2007-04-27 21:58:48 +04:00
|
|
|
client_setactive(cc, 1);
|
|
|
|
}
|
|
|
|
|
2009-05-18 04:14:19 +04:00
|
|
|
static void
|
|
|
|
xev_handle_leavenotify(XEvent *ee)
|
2007-04-27 21:58:48 +04:00
|
|
|
{
|
|
|
|
client_leave(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We can split this into two event handlers. */
|
2009-05-18 04:14:19 +04:00
|
|
|
static void
|
|
|
|
xev_handle_buttonpress(XEvent *ee)
|
2007-04-27 21:58:48 +04:00
|
|
|
{
|
2008-06-18 00:21:17 +04:00
|
|
|
XButtonEvent *e = &ee->xbutton;
|
2009-12-10 20:16:51 +03:00
|
|
|
struct client_ctx *cc, fakecc;
|
2008-07-11 18:21:28 +04:00
|
|
|
struct screen_ctx *sc;
|
2008-06-18 00:21:17 +04:00
|
|
|
struct mousebinding *mb;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2008-07-11 18:21:28 +04:00
|
|
|
sc = screen_fromroot(e->root);
|
2007-04-27 21:58:48 +04:00
|
|
|
cc = client_find(e->window);
|
|
|
|
|
2008-06-18 03:40:33 +04:00
|
|
|
/* Ignore caps lock and numlock */
|
|
|
|
e->state &= ~(Mod2Mask | LockMask);
|
|
|
|
|
2008-06-18 00:55:48 +04:00
|
|
|
TAILQ_FOREACH(mb, &Conf.mousebindingq, entry) {
|
|
|
|
if (e->button == mb->button && e->state == mb->modmask)
|
|
|
|
break;
|
2008-06-18 00:21:17 +04:00
|
|
|
}
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2008-06-18 00:55:48 +04:00
|
|
|
if (mb == NULL)
|
2009-05-18 04:14:19 +04:00
|
|
|
return;
|
2008-06-18 00:55:48 +04:00
|
|
|
if (mb->context == MOUSEBIND_CTX_ROOT) {
|
|
|
|
if (e->window != sc->rootwin)
|
2009-05-18 04:14:19 +04:00
|
|
|
return;
|
2009-12-10 20:16:51 +03:00
|
|
|
cc = &fakecc;
|
|
|
|
cc->sc = screen_fromroot(e->window);
|
|
|
|
} else if (cc == NULL) /* (mb->context == MOUSEBIND_CTX_WIN */
|
|
|
|
return;
|
2008-06-18 00:55:48 +04:00
|
|
|
|
|
|
|
(*mb->callback)(cc, e);
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
2009-05-18 04:14:19 +04:00
|
|
|
static void
|
|
|
|
xev_handle_buttonrelease(XEvent *ee)
|
2007-04-27 21:58:48 +04:00
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
struct client_ctx *cc;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2008-07-11 18:21:28 +04:00
|
|
|
if ((cc = client_current()) != NULL)
|
2007-04-27 21:58:48 +04:00
|
|
|
group_sticky_toggle_exit(cc);
|
|
|
|
}
|
|
|
|
|
2009-05-18 04:14:19 +04:00
|
|
|
static void
|
|
|
|
xev_handle_keypress(XEvent *ee)
|
2007-04-27 21:58:48 +04:00
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
XKeyEvent *e = &ee->xkey;
|
2009-12-10 20:16:51 +03:00
|
|
|
struct client_ctx *cc = NULL, fakecc;
|
2008-07-11 18:21:28 +04:00
|
|
|
struct keybinding *kb;
|
|
|
|
KeySym keysym, skeysym;
|
|
|
|
int modshift;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2007-05-28 22:34:27 +04:00
|
|
|
keysym = XKeycodeToKeysym(X_Dpy, e->keycode, 0);
|
|
|
|
skeysym = XKeycodeToKeysym(X_Dpy, e->keycode, 1);
|
2008-04-16 00:24:41 +04:00
|
|
|
|
2008-06-18 03:40:33 +04:00
|
|
|
/* we don't care about caps lock and numlock here */
|
|
|
|
e->state &= ~(LockMask | Mod2Mask);
|
|
|
|
|
2008-04-16 00:24:41 +04:00
|
|
|
TAILQ_FOREACH(kb, &Conf.keybindingq, entry) {
|
2007-04-27 21:58:48 +04: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-16 00:24:41 +04:00
|
|
|
kb->keycode == e->keycode) || kb->keysym ==
|
|
|
|
(modshift == 0 ? keysym : skeysym))
|
2007-04-27 21:58:48 +04:00
|
|
|
break;
|
2008-04-16 00:24:41 +04:00
|
|
|
}
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
if (kb == NULL)
|
2009-05-18 04:14:19 +04:00
|
|
|
return;
|
2009-12-10 20:16:51 +03:00
|
|
|
if (kb->flags & KBFLAG_NEEDCLIENT) {
|
|
|
|
if (((cc = client_find(e->window)) == NULL) &&
|
|
|
|
(cc = client_current()) == NULL)
|
2009-05-18 04:14:19 +04:00
|
|
|
return;
|
2009-12-10 20:16:51 +03:00
|
|
|
} else {
|
|
|
|
cc = &fakecc;
|
|
|
|
cc->sc = screen_fromroot(e->window);
|
|
|
|
}
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2009-01-23 21:58:40 +03:00
|
|
|
(*kb->callback)(cc, &kb->argument);
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-02-20 15:56:10 +03:00
|
|
|
* This is only used for the alt suppression detection.
|
2007-04-27 21:58:48 +04:00
|
|
|
*/
|
2009-05-18 04:14:19 +04:00
|
|
|
static void
|
|
|
|
xev_handle_keyrelease(XEvent *ee)
|
2007-04-27 21:58:48 +04:00
|
|
|
{
|
2008-07-11 18:21:28 +04: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 21:58:48 +04:00
|
|
|
|
2007-05-28 22:34:27 +04:00
|
|
|
keysym = XKeycodeToKeysym(X_Dpy, e->keycode, 0);
|
2007-04-27 21:58:48 +04:00
|
|
|
if (keysym != XK_Alt_L && keysym != XK_Alt_R)
|
2009-05-18 04:14:19 +04:00
|
|
|
return;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
sc->altpersist = 0;
|
2008-04-16 00:24:41 +04:00
|
|
|
|
2007-04-27 21:58:48 +04:00
|
|
|
/*
|
|
|
|
* XXX - better interface... xevents should not know about
|
|
|
|
* how/when to mtf.
|
|
|
|
*/
|
|
|
|
client_mtf(NULL);
|
|
|
|
|
2008-05-19 16:56:58 +04:00
|
|
|
if (cc != NULL) {
|
|
|
|
group_sticky_toggle_exit(cc);
|
|
|
|
XUngrabKeyboard(X_Dpy, CurrentTime);
|
|
|
|
}
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
2009-05-18 04:14:19 +04:00
|
|
|
static void
|
|
|
|
xev_handle_clientmessage(XEvent *ee)
|
2007-04-27 21:58:48 +04:00
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
XClientMessageEvent *e = &ee->xclient;
|
|
|
|
Atom xa_wm_change_state;
|
|
|
|
struct client_ctx *cc;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2008-07-11 18:21:28 +04:00
|
|
|
xa_wm_change_state = XInternAtom(X_Dpy, "WM_CHANGE_STATE", False);
|
|
|
|
|
|
|
|
if ((cc = client_find(e->window)) == NULL)
|
2009-05-18 04:14:19 +04:00
|
|
|
return;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
if (e->message_type == xa_wm_change_state && e->format == 32 &&
|
|
|
|
e->data.l[0] == IconicState)
|
|
|
|
client_hide(cc);
|
|
|
|
}
|
|
|
|
|
2009-05-18 04:14:19 +04:00
|
|
|
static void
|
|
|
|
xev_handle_randr(XEvent *ee)
|
2008-09-30 03:16:46 +04:00
|
|
|
{
|
|
|
|
XRRScreenChangeNotifyEvent *rev = (XRRScreenChangeNotifyEvent *)ee;
|
|
|
|
struct screen_ctx *sc;
|
2009-05-01 21:50:20 +04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
i = XRRRootToScreen(X_Dpy, rev->root);
|
|
|
|
TAILQ_FOREACH(sc, &Screenq, entry) {
|
|
|
|
if (sc->which == (u_int)i) {
|
|
|
|
XRRUpdateConfiguration(ee);
|
2009-12-11 02:14:58 +03:00
|
|
|
screen_update_geometry(sc, rev->width, rev->height);
|
2009-05-01 21:50:20 +04:00
|
|
|
screen_init_xinerama(sc);
|
|
|
|
}
|
2008-09-30 03:16:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-28 20:52:12 +03:00
|
|
|
/*
|
2008-07-23 01:01:54 +04:00
|
|
|
* Called when the keymap has changed.
|
|
|
|
* Ungrab all keys, reload keymap and then regrab
|
|
|
|
*/
|
2009-05-18 04:14:19 +04:00
|
|
|
static void
|
|
|
|
xev_handle_mappingnotify(XEvent *ee)
|
2008-07-23 01:01:54 +04:00
|
|
|
{
|
|
|
|
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);
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
2009-03-28 19:38:54 +03:00
|
|
|
static void
|
2009-05-18 04:14:19 +04:00
|
|
|
xev_handle_expose(XEvent *ee)
|
2007-04-27 21:58:48 +04:00
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
XExposeEvent *e = &ee->xexpose;
|
|
|
|
struct client_ctx *cc;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2009-01-16 18:24:14 +03:00
|
|
|
if ((cc = client_find(e->window)) != NULL && e->count == 0)
|
2007-04-27 21:58:48 +04:00
|
|
|
client_draw_border(cc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-18 04:14:19 +04:00
|
|
|
volatile sig_atomic_t _xev_quit = 0;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
xev_loop(void)
|
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
XEvent e;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2008-04-08 03:47:09 +04:00
|
|
|
while (_xev_quit == 0) {
|
2007-05-28 22:34:27 +04:00
|
|
|
XNextEvent(X_Dpy, &e);
|
2009-05-18 04:14:19 +04:00
|
|
|
if (e.type - Randr_ev == RRScreenChangeNotify)
|
|
|
|
xev_handle_randr(&e);
|
|
|
|
else if (e.type < LASTEvent && xev_handlers[e.type] != NULL)
|
|
|
|
(*xev_handlers[e.type])(&e);
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
}
|