]>
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);
117 // madly compress all crossing events
118 } else if (e.type == EnterNotify) {
119 // any other types are not ones we're interested in
120 if (e.xcrossing.mode == NotifyNormal) {
121 // any other types are not ones we're interested in
122 enter = e.xcrossing.window;
123 enter_root = e.xcrossing.root;
124 //printf("Enter enter=%lx leave=%lx\n", enter, leave);
126 } else if (e.type == LeaveNotify) {
127 // any other types are not ones we're interested in
128 if (e.xcrossing.mode == NotifyNormal) {
129 leave = e.xcrossing.window;
130 leave_root = e.xcrossing.root;
131 //printf("Leave enter=%lx leave=%lx\n", enter, leave);
140 if (unfocus
!= None
) {
141 // the last focus event was an FocusOut, so where the hell is the focus at?
142 //printf("UNFOCUSING: %lx\n", unfocus);
143 _focus_e
.xfocus
.type
= FocusOut
;
144 _focus_e
.xfocus
.window
= unfocus
;
145 dispatch(_focus_e
.xfocus
.window
, _focus_e
);
148 } else if (focus
!= None
&& focus
!= _focus
) {
149 // the last focus event was a FocusIn, so unfocus what used to be focus and
150 // focus this new target
151 //printf("FOCUSING: %lx\n", focus);
152 _focus_e
.xfocus
.type
= FocusIn
;
153 _focus_e
.xfocus
.window
= focus
;
154 dispatch(_focus_e
.xfocus
.window
, _focus_e
);
156 if (_focus
!= None
) {
157 //printf("UNFOCUSING: %lx\n", _focus);
158 _focus_e
.xfocus
.type
= FocusOut
;
159 _focus_e
.xfocus
.window
= _focus
;
160 dispatch(_focus_e
.xfocus
.window
, _focus_e
);
167 _crossing_e.xcrossing.type = LeaveNotify;
168 _crossing_e.xcrossing.window = leave;
169 _crossing_e.xcrossing.root = leave_root;
170 dispatch(_crossing_e.xcrossing.window, _crossing_e);
173 _crossing_e.xcrossing.type = EnterNotify;
174 _crossing_e.xcrossing.window = enter;
175 _crossing_e.xcrossing.root = enter_root;
176 dispatch(_crossing_e.xcrossing.window, _crossing_e);
180 void OtkEventDispatcher::dispatch(Window win
, const XEvent
&e
) {
181 OtkEventHandler
*handler
= 0;
182 OtkEventMap::iterator it
;
189 if (it
!= _map
.end())
190 handler
= it
->second
;
191 // these ConfigureRequests require some special attention
192 else if (e
.type
== ConfigureRequest
) {
193 // unhandled configure requests must be used to configure the window
197 xwc
.x
= e
.xconfigurerequest
.x
;
198 xwc
.y
= e
.xconfigurerequest
.y
;
199 xwc
.width
= e
.xconfigurerequest
.width
;
200 xwc
.height
= e
.xconfigurerequest
.height
;
201 xwc
.border_width
= e
.xconfigurerequest
.border_width
;
202 xwc
.sibling
= e
.xconfigurerequest
.above
;
203 xwc
.stack_mode
= e
.xconfigurerequest
.detail
;
205 XConfigureWindow(otk::OBDisplay::display
, e
.xconfigurerequest
.window
,
206 e
.xconfigurerequest
.value_mask
, &xwc
);
214 OtkEventHandler
*OtkEventDispatcher::findHandler(Window win
)
216 OtkEventMap::iterator it
= _map
.find(win
);
217 if (it
!= _map
.end())
This page took 0.05079 seconds and 5 git commands to generate.