]>
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"
13 OtkEventDispatcher::OtkEventDispatcher()
14 : _fallback(0), _master(0), _focus(None
)
16 _focus_e
.xfocus
.display
= OBDisplay::display
;
17 _focus_e
.xfocus
.mode
= NotifyNormal
;
18 _focus_e
.xfocus
.detail
= NotifyNonlinear
;
20 _crossing_e
.xcrossing
.display
= OBDisplay::display
;
21 _crossing_e
.xcrossing
.mode
= NotifyNormal
;
22 _crossing_e
.xcrossing
.detail
= NotifyNonlinear
;
25 OtkEventDispatcher::~OtkEventDispatcher()
29 void OtkEventDispatcher::clearAllHandlers(void)
34 void OtkEventDispatcher::registerHandler(Window id
, OtkEventHandler
*handler
)
36 _map
.insert(std::pair
<Window
, OtkEventHandler
*>(id
, handler
));
39 void OtkEventDispatcher::clearHandler(Window id
)
44 void OtkEventDispatcher::dispatchEvents(void)
47 Window focus
= None
, unfocus
= None
;
48 Window enter
= None
, leave
= None
;
49 Window enter_root
= None
, leave_root
= None
;
51 while (XPending(OBDisplay::display
)) {
52 XNextEvent(OBDisplay::display
, &e
);
55 printf("Event %d window %lx\n", e
.type
, e
.xany
.window
);
63 win
= e
.xunmap
.window
;
66 win
= e
.xdestroywindow
.window
;
68 case ConfigureRequest
:
69 win
= e
.xconfigurerequest
.window
;
75 // grab the lasttime and hack up the modifiers
79 _lasttime
= e
.xbutton
.time
;
80 e
.xbutton
.state
&= ~(LockMask
| OBDisplay::numLockMask() |
81 OBDisplay::scrollLockMask());
84 e
.xkey
.state
&= ~(LockMask
| OBDisplay::numLockMask() |
85 OBDisplay::scrollLockMask());
88 _lasttime
= e
.xmotion
.time
;
89 e
.xmotion
.state
&= ~(LockMask
| OBDisplay::numLockMask() |
90 OBDisplay::scrollLockMask());
93 _lasttime
= e
.xproperty
.time
;
97 _lasttime
= e
.xcrossing
.time
;
101 // madly compress all focus events
102 if (e
.type
== FocusIn
) {
103 // any other types are not ones we're interested in
104 if (e
.xfocus
.detail
== NotifyNonlinear
) {
105 focus
= e
.xfocus
.window
;
107 printf("FocusIn focus=%lx unfocus=%lx\n", focus
, unfocus
);
109 } else if (e
.type
== FocusOut
) {
110 // any other types are not ones we're interested in
111 if (e
.xfocus
.detail
== NotifyNonlinear
) {
112 unfocus
= e
.xfocus
.window
;
114 printf("FocusOut focus=%lx unfocus=%lx\n", focus
, unfocus
);
116 // madly compress all crossing events
117 } else if (e
.type
== EnterNotify
) {
118 // any other types are not ones we're interested in
119 if (e
.xcrossing
.mode
== NotifyNormal
) {
120 // any other types are not ones we're interested in
121 enter
= e
.xcrossing
.window
;
122 enter_root
= e
.xcrossing
.root
;
123 printf("Enter enter=%lx leave=%lx\n", enter
, leave
);
125 } else if (e
.type
== LeaveNotify
) {
126 // any other types are not ones we're interested in
127 if (e
.xcrossing
.mode
== NotifyNormal
) {
128 leave
= e
.xcrossing
.window
;
129 leave_root
= e
.xcrossing
.root
;
130 printf("Leave enter=%lx leave=%lx\n", enter
, leave
);
138 if (unfocus
!= None
) {
139 // the last focus event was an FocusOut, so where the hell is the focus at?
140 printf("UNFOCUSING: %lx\n", unfocus
);
141 _focus_e
.xfocus
.type
= FocusOut
;
142 _focus_e
.xfocus
.window
= unfocus
;
143 dispatch(_focus_e
.xfocus
.window
, _focus_e
);
146 } else if (focus
!= None
&& focus
!= _focus
) {
147 // the last focus event was a FocusIn, so unfocus what used to be focus and
148 // focus this new target
149 printf("FOCUSING: %lx\n", focus
);
150 _focus_e
.xfocus
.type
= FocusIn
;
151 _focus_e
.xfocus
.window
= focus
;
152 dispatch(_focus_e
.xfocus
.window
, _focus_e
);
154 if (_focus
!= None
) {
155 printf("UNFOCUSING: %lx\n", _focus
);
156 _focus_e
.xfocus
.type
= FocusOut
;
157 _focus_e
.xfocus
.window
= _focus
;
158 dispatch(_focus_e
.xfocus
.window
, _focus_e
);
165 _crossing_e
.xcrossing
.type
= LeaveNotify
;
166 _crossing_e
.xcrossing
.window
= leave
;
167 _crossing_e
.xcrossing
.root
= leave_root
;
168 dispatch(_crossing_e
.xcrossing
.window
, _crossing_e
);
171 _crossing_e
.xcrossing
.type
= EnterNotify
;
172 _crossing_e
.xcrossing
.window
= enter
;
173 _crossing_e
.xcrossing
.root
= enter_root
;
174 dispatch(_crossing_e
.xcrossing
.window
, _crossing_e
);
178 void OtkEventDispatcher::dispatch(Window win
, const XEvent
&e
) {
179 OtkEventHandler
*handler
= 0;
180 OtkEventMap::iterator it
;
187 if (it
!= _map
.end())
188 handler
= it
->second
;
189 // these ConfigureRequests require some special attention
190 else if (e
.type
== ConfigureRequest
) {
191 // unhandled configure requests must be used to configure the window
195 xwc
.x
= e
.xconfigurerequest
.x
;
196 xwc
.y
= e
.xconfigurerequest
.y
;
197 xwc
.width
= e
.xconfigurerequest
.width
;
198 xwc
.height
= e
.xconfigurerequest
.height
;
199 xwc
.border_width
= e
.xconfigurerequest
.border_width
;
200 xwc
.sibling
= e
.xconfigurerequest
.above
;
201 xwc
.stack_mode
= e
.xconfigurerequest
.detail
;
203 XConfigureWindow(otk::OBDisplay::display
, e
.xconfigurerequest
.window
,
204 e
.xconfigurerequest
.value_mask
, &xwc
);
212 OtkEventHandler
*OtkEventDispatcher::findHandler(Window win
)
214 OtkEventMap::iterator it
= _map
.find(win
);
215 if (it
!= _map
.end())
This page took 0.053831 seconds and 5 git commands to generate.