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