]> Dogcows Code - chaz/openbox/blob - otk/eventdispatcher.cc
rm old debug printfs
[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), _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 void OtkEventDispatcher::dispatchEvents(void)
38 {
39 XEvent e;
40
41 while (XPending(OBDisplay::display)) {
42 XNextEvent(OBDisplay::display, &e);
43
44 #if 0//defined(DEBUG)
45 printf("Event %d window %lx\n", e.type, e.xany.window);
46 #endif
47
48 Window win;
49
50 // pick a window
51 switch (e.type) {
52 case UnmapNotify:
53 win = e.xunmap.window;
54 break;
55 case DestroyNotify:
56 win = e.xdestroywindow.window;
57 break;
58 case ConfigureRequest:
59 win = e.xconfigurerequest.window;
60 break;
61 default:
62 win = e.xany.window;
63 }
64
65 // grab the lasttime and hack up the modifiers
66 switch (e.type) {
67 case ButtonPress:
68 case ButtonRelease:
69 _lasttime = e.xbutton.time;
70 e.xbutton.state &= ~(LockMask | OBDisplay::numLockMask() |
71 OBDisplay::scrollLockMask());
72 break;
73 case KeyPress:
74 e.xkey.state &= ~(LockMask | OBDisplay::numLockMask() |
75 OBDisplay::scrollLockMask());
76 break;
77 case MotionNotify:
78 _lasttime = e.xmotion.time;
79 e.xmotion.state &= ~(LockMask | OBDisplay::numLockMask() |
80 OBDisplay::scrollLockMask());
81 break;
82 case PropertyNotify:
83 _lasttime = e.xproperty.time;
84 break;
85 case EnterNotify:
86 case LeaveNotify:
87 _lasttime = e.xcrossing.time;
88 break;
89 }
90
91 if (e.type == FocusIn || e.type == FocusOut)
92 // any other types are not ones we're interested in
93 if (e.xfocus.detail != NotifyNonlinear)
94 continue;
95
96 if (e.type == FocusOut) {
97 XEvent fi;
98 // send a FocusIn first if one exists
99 while (XCheckTypedEvent(OBDisplay::display, FocusIn, &fi)) {
100 // any other types are not ones we're interested in
101 if (fi.xfocus.detail == NotifyNonlinear) {
102 dispatch(fi.xfocus.window, fi);
103 break;
104 }
105 }
106 }
107
108 dispatch(win, e);
109 }
110 }
111
112 void OtkEventDispatcher::dispatch(Window win, const XEvent &e)
113 {
114 OtkEventHandler *handler = 0;
115 OtkEventMap::iterator it;
116
117 // master gets everything first
118 if (_master)
119 _master->handle(e);
120
121 // find handler for the chosen window
122 it = _map.find(win);
123
124 if (it != _map.end()) {
125 // if we found a handler
126 handler = it->second;
127 } else if (e.type == ConfigureRequest) {
128 // unhandled configure requests must be used to configure the window
129 // directly
130 XWindowChanges xwc;
131
132 xwc.x = e.xconfigurerequest.x;
133 xwc.y = e.xconfigurerequest.y;
134 xwc.width = e.xconfigurerequest.width;
135 xwc.height = e.xconfigurerequest.height;
136 xwc.border_width = e.xconfigurerequest.border_width;
137 xwc.sibling = e.xconfigurerequest.above;
138 xwc.stack_mode = e.xconfigurerequest.detail;
139
140 XConfigureWindow(otk::OBDisplay::display, e.xconfigurerequest.window,
141 e.xconfigurerequest.value_mask, &xwc);
142 } else {
143 // grab a falback if it exists
144 handler = _fallback;
145 }
146
147 if (handler)
148 handler->handle(e);
149 }
150
151 OtkEventHandler *OtkEventDispatcher::findHandler(Window win)
152 {
153 OtkEventMap::iterator it = _map.find(win);
154 if (it != _map.end())
155 return it->second;
156 return 0;
157 }
158
159 }
This page took 0.041341 seconds and 5 git commands to generate.