]> icculus.org git repositories - mikachu/openbox.git/blob - otk/eventdispatcher.cc
handle config req's in dispatcher properly.
[mikachu/openbox.git] / 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), _master(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 #include <stdio.h>
39 void OtkEventDispatcher::dispatchEvents(void)
40 {
41   XEvent e;
42   OtkEventHandler *handler;
43   OtkEventMap::iterator it;
44
45   while (XPending(OBDisplay::display)) {
46     XNextEvent(OBDisplay::display, &e);
47
48 #if defined(DEBUG) && 0
49     printf("Event %d window %lx\n", e.type, e.xany.window);
50 #endif
51
52     // these ConfigureRequests require some special attention
53     if (e.type == ConfigureRequest) {
54       // find the actual window! e.xany.window is the parent window
55       it = _map.find(e.xconfigurerequest.window);
56
57       if (it != _map.end())
58         it->second->handle(e);
59       else {
60         // unhandled configure requests must be used to configure the window
61         // directly
62         XWindowChanges xwc;
63
64         xwc.x = e.xconfigurerequest.x;
65         xwc.y = e.xconfigurerequest.y;
66         xwc.width = e.xconfigurerequest.width;
67         xwc.height = e.xconfigurerequest.height;
68         xwc.border_width = e.xconfigurerequest.border_width;
69         xwc.sibling = e.xconfigurerequest.above;
70         xwc.stack_mode = e.xconfigurerequest.detail;
71
72         XConfigureWindow(otk::OBDisplay::display, e.xconfigurerequest.window,
73                          e.xconfigurerequest.value_mask, &xwc);
74       }
75     } else {
76       // normal events
77       
78       it = _map.find(e.xany.window);
79
80       if (it != _map.end())
81         handler = it->second;
82       else
83         handler = _fallback;
84
85       if (handler)
86         handler->handle(e);
87     }
88
89     if (_master)
90       _master->handle(e);
91   }
92 }
93
94 }