summaryrefslogtreecommitdiffstats
path: root/tools/aewm-drakx/events.c
blob: 4a6ba53a431fc1470b6ea6864eb32d121d1c10fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* aewm - a minimalistic X11 window manager. ------- vim:sw=4:et
 * Copyright (c) 1998-2001 Decklin Foster <decklin@red-bean.com>
 * Free software! Please see README for details and license.  */

#include "aewm.h"


static void handle_configure_request(XConfigureRequestEvent *e)
{
    XWindowChanges wc;

    wc.x = e->x;
    wc.y = e->y;
    wc.width = e->width;
    wc.height = e->height;
    wc.sibling = e->above;
    wc.stack_mode = e->detail;
    XConfigureWindow(dpy, e->window, e->value_mask, &wc);
}

static void handle_map_request(XMapRequestEvent *e)
{
    Client *c = find_client(e->window);

    if (c) {
        XMapWindow(dpy, c->window);
        set_wm_state(c, NormalState);
    } else {
        make_new_client(e->window);
    }
}

static void handle_destroy_event(XDestroyWindowEvent *e)
{
    Client *c = find_client(e->window);

    if (c) remove_client(c);
}


#ifdef DEBUG
#define SHOW_EV(name, memb) \
    case name: s = #name; w = e.memb.window; break;
#define SHOW(name) \
    case name: return #name;

void show_event(XEvent e)
{
    char *s = 0, buf[20];
    char *dd = 0;
    Window w = 0;
    Client *c;

    switch (e.type) {
        SHOW_EV(ButtonPress, xbutton)
        SHOW_EV(ButtonRelease, xbutton)
        SHOW_EV(ClientMessage, xclient)
        SHOW_EV(ColormapNotify, xcolormap)
        SHOW_EV(ConfigureNotify, xconfigure)
        SHOW_EV(ConfigureRequest, xconfigurerequest)
        SHOW_EV(CreateNotify, xcreatewindow)
        SHOW_EV(DestroyNotify, xdestroywindow)
        SHOW_EV(EnterNotify, xcrossing)
        SHOW_EV(Expose, xexpose)
        SHOW_EV(MapNotify, xmap)
        SHOW_EV(MapRequest, xmaprequest)
        SHOW_EV(MappingNotify, xmapping)
        SHOW_EV(MotionNotify, xmotion)
        SHOW_EV(PropertyNotify, xproperty)
        SHOW_EV(ReparentNotify, xreparent)
        SHOW_EV(ResizeRequest, xresizerequest)
        SHOW_EV(UnmapNotify, xunmap)
        default:
            break;
    }

    c = find_client(w);

    if (c) XFetchName(dpy, c->window, &dd);

    snprintf(buf, sizeof buf, dd ? dd : "");
    err("%#-10lx: %-20s: %s", w, buf, s);
}
#endif


void do_event_loop(void)
{
    XEvent ev;

    for (;;) {
        XNextEvent(dpy, &ev);
#ifdef DEBUG
	show_event(ev);
#endif
        switch (ev.type) {
            case ConfigureRequest:
                handle_configure_request(&ev.xconfigurerequest); break;
            case MapRequest:
                handle_map_request(&ev.xmaprequest); break;
            case DestroyNotify:
                handle_destroy_event(&ev.xdestroywindow); break;
        }
    }
}