porting tinywm to c++

http://incise.org/tinywm.html
tinywm shows a basic event-handling situation.
I was thinking to create a union of all eventtypes, and initialize the right one.
anyone done something similar? any other ideas how to lift the concept of events to c++ objects?

the task: write a class XEventpp that registers button-notification and receives events returning a pointer to the class which is capable of handling the event. use -std=c++11 to make the code short. preferably there should be no use of the heap or c++ libs. i.e. make it tiny. sourcecode can be big, but memory usage and program-size not. of course it must be easy to extend, unlike tinywm...
yes, that's the old way, fit for actually handling multiple windows.
however, a windowmanager knows only 2 kinds of windows: root and subwindows.
so I wrote something like this:
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
#include <X11/Xlb.h>
#include <new>

    union eventtypes
    {
        struct _
        {
            XEvent* ep;
            _(XEvent& e) : ep(&e) {}
        };
        struct k : _
        {
            k(XEvent& e) : _(e) {}
        }key;
        struct b : _
        {
            b(XEvent& e) : _(e) {}
        }button;
        struct m : _
        {
            m(XEvent& e) : _(e) {}
        }mptr;
        struct __ : _
        {
             __(XEvent& e) : _(e) {}
        } i;
        eventtypes(XEvent& ev)
        {
            switch(ev.type)
            {
                case KeyPress: new(&key) k(ev); break;
                case ButtonPress: new(&button) b(ev); break;
                case MotionNotify: new(&mptr) m(ev); break;
                default: new(&i) __(ev); break;
            }
        }
        void handle();
    };


any thoughts?
Last edited on
Topic archived. No new replies allowed.