]>
Dogcows Code - chaz/openbox/blob - otk/eventdispatcher.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
5 #include "eventdispatcher.hh"
13 EventDispatcher::EventDispatcher()
14 : _fallback(0), _master(0)
18 EventDispatcher::~EventDispatcher()
22 void EventDispatcher::clearAllHandlers(void)
27 void EventDispatcher::registerHandler(Window id
, EventHandler
*handler
)
29 _map
.insert(std::pair
<Window
, EventHandler
*>(id
, handler
));
32 void EventDispatcher::clearHandler(Window id
)
37 void EventDispatcher::dispatchEvents(bool remote
)
43 There are slightly different event retrieval semantics here for local (or
44 high bandwidth) versus remote (or low bandwidth) connections to the
48 if (!XPending(**display
))
52 This XSync allows for far more compression of events, which makes
53 things like Motion events perform far far better. Since it also means
54 network traffic for every event instead of every X events (where X is
55 the number retrieved at a time), it probably should not be used for
56 setups where Openbox is running on a remote/low bandwidth
59 XSync(**display
, false);
60 if (!XEventsQueued(**display
, QueuedAlready
))
63 XNextEvent(**display
, &e
);
66 printf("Event %d window %lx\n", e
.type
, e
.xany
.window
);
69 if (e
.type
== FocusIn
|| e
.type
== FocusOut
) {
70 // focus events are a beast all their own.. yuk, hate, etc.
78 win
= e
.xunmap
.window
;
81 win
= e
.xdestroywindow
.window
;
83 case ConfigureRequest
:
84 win
= e
.xconfigurerequest
.window
;
90 // grab the lasttime and hack up the modifiers
94 _lasttime
= e
.xbutton
.time
;
95 e
.xbutton
.state
&= ~(LockMask
| display
->numLockMask() |
96 display
->scrollLockMask());
99 e
.xkey
.state
&= ~(LockMask
| display
->numLockMask() |
100 display
->scrollLockMask());
103 _lasttime
= e
.xmotion
.time
;
104 e
.xmotion
.state
&= ~(LockMask
| display
->numLockMask() |
105 display
->scrollLockMask());
108 _lasttime
= e
.xproperty
.time
;
112 _lasttime
= e
.xcrossing
.time
;
113 if (e
.xcrossing
.mode
!= NotifyNormal
)
114 continue; // skip me!
123 void EventDispatcher::dispatchFocus(const XEvent
&e
)
125 // printf("focus %s detail %d -> 0x%lx\n",
126 // (e.xfocus.type == FocusIn ? "IN" : "OUT"),
127 // e.xfocus.detail, e.xfocus.window);
128 // ignore focus changes from grabs
129 if (e
.xfocus
.mode
== NotifyGrab
) //|| e.xfocus.mode == NotifyUngrab ||
130 // From Metacity, from WindowMaker, ignore all funky pointer root events
131 // its commented out cuz I don't think we need this at all. If problems
132 // arise we can look into it
133 //e.xfocus.detail > NotifyNonlinearVirtual)
136 if (e
.type
== FocusIn
) {
137 //printf("Got FocusIn!\n");
139 // send a FocusIn to whatever was just focused
140 dispatch(e
.xfocus
.window
, e
);
141 //printf("Sent FocusIn 0x%lx\n", e.xfocus.window);
143 } else if (e
.type
== FocusOut
) {
144 //printf("Got FocusOut!\n");
146 // FocusOut events just make us look for FocusIn events. They are ignored
149 if (XCheckTypedEvent(**display
, FocusIn
, &fi
)) {
150 //printf("Found FocusIn\n");
152 // dont unfocus the window we just focused!
153 if (fi
.xfocus
.window
== e
.xfocus
.window
)
157 dispatch(e
.xfocus
.window
, e
);
158 //printf("Sent FocusOut 0x%lx\n", e.xfocus.window);
162 void EventDispatcher::dispatch(Window win
, const XEvent
&e
)
164 EventHandler
*handler
= 0;
165 EventMap::iterator it
;
167 // master gets everything first
171 // find handler for the chosen window
174 if (it
!= _map
.end()) {
175 // if we found a handler
176 handler
= it
->second
;
177 } else if (e
.type
== ConfigureRequest
) {
178 // unhandled configure requests must be used to configure the window
182 xwc
.x
= e
.xconfigurerequest
.x
;
183 xwc
.y
= e
.xconfigurerequest
.y
;
184 xwc
.width
= e
.xconfigurerequest
.width
;
185 xwc
.height
= e
.xconfigurerequest
.height
;
186 xwc
.border_width
= e
.xconfigurerequest
.border_width
;
187 xwc
.sibling
= e
.xconfigurerequest
.above
;
188 xwc
.stack_mode
= e
.xconfigurerequest
.detail
;
191 printf("Proxying configure event for 0x%lx\n", e
.xconfigurerequest
.window
);
194 // we are not to be held responsible if someone sends us an invalid
196 display
->setIgnoreErrors(true);
197 XConfigureWindow(**display
, e
.xconfigurerequest
.window
,
198 e
.xconfigurerequest
.value_mask
, &xwc
);
199 display
->setIgnoreErrors(false);
201 // grab a falback if it exists
209 EventHandler
*EventDispatcher::findHandler(Window win
)
211 EventMap::iterator it
= _map
.find(win
);
212 if (it
!= _map
.end())
This page took 0.040065 seconds and 4 git commands to generate.