]> icculus.org git repositories - mikachu/openbox.git/blob - otk/eventdispatcher.cc
event handling classes
[mikachu/openbox.git] / otk / eventdispatcher.cc
1 #include "eventdispatcher.hh"
2 #include "display.hh"
3
4 namespace otk {
5
6 OtkEventDispatcher::OtkEventDispatcher()
7 {
8 }
9
10 OtkEventDispatcher::~OtkEventDispatcher()
11 {
12 }
13
14 void OtkEventDispatcher::clearAllHandlers(void)
15 {
16   _map.clear();
17 }
18
19 void OtkEventDispatcher::registerHandler(Window id, OtkEventHandler *handler)
20 {
21   _map.insert(std::pair<Window, OtkEventHandler*>(id, handler));
22 }
23
24 void OtkEventDispatcher::clearHandler(Window id)
25 {
26   _map.erase(id);
27 }
28
29 void OtkEventDispatcher::dispatchEvents(void)
30 {
31   XEvent e;
32   OtkEventHandler *handler;
33   OtkEventMap::iterator it;
34
35   while (XPending(OBDisplay::display)) {
36     XNextEvent(OBDisplay::display, &e);
37     it = _map.find(e.xany.window);
38
39     if (it == _map.end())
40       handler = _fallback;
41     else
42       handler = it->second;
43
44     if (handler)
45       handler->handle(e);
46   }
47 }
48
49 }