]>
Dogcows Code - chaz/openbox/blob - otk/eventdispatcher.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
7 #include "eventdispatcher.hh"
20 EventDispatcher::EventDispatcher()
21 : _fallback(0), _master(0)
25 EventDispatcher::~EventDispatcher()
29 void EventDispatcher::clearAllHandlers(void)
34 void EventDispatcher::registerHandler(Window id
, EventHandler
*handler
)
36 _map
.insert(std::pair
<Window
, EventHandler
*>(id
, handler
));
39 void EventDispatcher::clearHandler(Window id
)
44 void EventDispatcher::dispatchEvents(void)
48 while (XPending(**display
)) {
49 XNextEvent(**display
, &e
);
52 printf("Event %d window %lx\n", e
.type
, e
.xany
.window
);
55 if (e
.type
== FocusIn
|| e
.type
== FocusOut
) {
56 // focus events are a beast all their own.. yuk, hate, etc.
64 win
= e
.xunmap
.window
;
67 win
= e
.xdestroywindow
.window
;
69 case ConfigureRequest
:
70 win
= e
.xconfigurerequest
.window
;
76 // grab the lasttime and hack up the modifiers
80 _lasttime
= e
.xbutton
.time
;
81 e
.xbutton
.state
&= ~(LockMask
| display
->numLockMask() |
82 display
->scrollLockMask());
85 e
.xkey
.state
&= ~(LockMask
| display
->numLockMask() |
86 display
->scrollLockMask());
89 _lasttime
= e
.xmotion
.time
;
90 e
.xmotion
.state
&= ~(LockMask
| display
->numLockMask() |
91 display
->scrollLockMask());
94 _lasttime
= e
.xproperty
.time
;
98 _lasttime
= e
.xcrossing
.time
;
99 if (e
.xcrossing
.mode
!= NotifyNormal
)
100 continue; // skip me!
109 void EventDispatcher::dispatchFocus(const XEvent
&e
)
111 // printf("focus %s detail %d -> 0x%lx\n",
112 // (e.xfocus.type == FocusIn ? "IN" : "OUT"),
113 // e.xfocus.detail, e.xfocus.window);
114 // ignore focus changes from grabs
115 if (e
.xfocus
.mode
== NotifyGrab
) //|| e.xfocus.mode == NotifyUngrab ||
116 // From Metacity, from WindowMaker, ignore all funky pointer root events
117 // its commented out cuz I don't think we need this at all. If problems
118 // arise we can look into it
119 //e.xfocus.detail > NotifyNonlinearVirtual)
122 if (e
.type
== FocusIn
) {
123 //printf("Got FocusIn!\n");
125 // send a FocusIn to whatever was just focused
126 dispatch(e
.xfocus
.window
, e
);
127 //printf("Sent FocusIn 0x%lx\n", e.xfocus.window);
129 } else if (e
.type
== FocusOut
) {
130 //printf("Got FocusOut!\n");
132 // FocusOut events just make us look for FocusIn events. They are ignored
135 if (XCheckTypedEvent(**display
, FocusIn
, &fi
)) {
136 //printf("Found FocusIn\n");
138 // dont unfocus the window we just focused!
139 if (fi
.xfocus
.window
== e
.xfocus
.window
)
143 dispatch(e
.xfocus
.window
, e
);
144 //printf("Sent FocusOut 0x%lx\n", e.xfocus.window);
148 void EventDispatcher::dispatch(Window win
, const XEvent
&e
)
150 EventHandler
*handler
= 0;
151 EventMap::iterator it
;
153 // master gets everything first
157 // find handler for the chosen window
160 if (it
!= _map
.end()) {
161 // if we found a handler
162 handler
= it
->second
;
163 } else if (e
.type
== ConfigureRequest
) {
164 // unhandled configure requests must be used to configure the window
168 xwc
.x
= e
.xconfigurerequest
.x
;
169 xwc
.y
= e
.xconfigurerequest
.y
;
170 xwc
.width
= e
.xconfigurerequest
.width
;
171 xwc
.height
= e
.xconfigurerequest
.height
;
172 xwc
.border_width
= e
.xconfigurerequest
.border_width
;
173 xwc
.sibling
= e
.xconfigurerequest
.above
;
174 xwc
.stack_mode
= e
.xconfigurerequest
.detail
;
177 printf("Proxying configure event for 0x%lx\n", e
.xconfigurerequest
.window
);
180 // we are not to be held responsible if someone sends us an invalid
182 display
->setIgnoreErrors(true);
183 XConfigureWindow(**display
, e
.xconfigurerequest
.window
,
184 e
.xconfigurerequest
.value_mask
, &xwc
);
185 display
->setIgnoreErrors(false);
187 // grab a falback if it exists
195 EventHandler
*EventDispatcher::findHandler(Window win
)
197 EventMap::iterator it
= _map
.find(win
);
198 if (it
!= _map
.end())
This page took 0.046691 seconds and 4 git commands to generate.