]> Dogcows Code - chaz/openbox/blob - otk/eventdispatcher.cc
add a skeletal OBActions class for user actions
[chaz/openbox] / otk / eventdispatcher.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2
3 #ifdef HAVE_CONFIG_H
4 # include "../config.h"
5 #endif
6
7 #include "eventdispatcher.hh"
8 #include "display.hh"
9 #include <iostream>
10
11 namespace otk {
12
13 OtkEventDispatcher::OtkEventDispatcher()
14 : _fallback(0)
15 {
16 }
17
18 OtkEventDispatcher::~OtkEventDispatcher()
19 {
20 }
21
22 void OtkEventDispatcher::clearAllHandlers(void)
23 {
24 _map.clear();
25 }
26
27 void OtkEventDispatcher::registerHandler(Window id, OtkEventHandler *handler)
28 {
29 _map.insert(std::pair<Window, OtkEventHandler*>(id, handler));
30 }
31
32 void OtkEventDispatcher::clearHandler(Window id)
33 {
34 _map.erase(id);
35 }
36
37 #include <stdio.h>
38 void OtkEventDispatcher::dispatchEvents(void)
39 {
40 XEvent e;
41 OtkEventHandler *handler;
42 OtkEventMap::iterator it;
43
44 while (XPending(OBDisplay::display)) {
45 XNextEvent(OBDisplay::display, &e);
46
47 #ifdef DEBUG
48 printf("Event %d window %lx\n", e.type, e.xany.window);
49 #endif
50
51 it = _map.find(e.xany.window);
52
53 if (it != _map.end())
54 handler = it->second;
55 else
56 handler = _fallback;
57
58 if (handler)
59 handler->handle(e);
60 }
61 }
62
63 }
This page took 0.036085 seconds and 4 git commands to generate.