]>
Dogcows Code - chaz/openbox/blob - eventdispatcher.cc
760f86a4435f51599d1bb5075af9f82cba263aa5
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)
46 OtkEventMap::iterator it
;
48 Window focus
= None
, unfocus
= None
;
49 Window enter
= None
, leave
= None
;
50 Window enter_root
= None
, leave_root
= None
;
52 while (XPending(OBDisplay::display
)) {
53 XNextEvent(OBDisplay::display
, &e
);
56 printf("Event %d window %lx\n", e
.type
, e
.xany
.window
);
59 // grab the lasttime and hack up the modifiers
63 _lasttime
= e
.xbutton
.time
;
64 e
.xbutton
.state
&= ~(LockMask
| OBDisplay::numLockMask() |
65 OBDisplay::scrollLockMask());
68 e
.xkey
.state
&= ~(LockMask
| OBDisplay::numLockMask() |
69 OBDisplay::scrollLockMask());
72 _lasttime
= e
.xmotion
.time
;
73 e
.xmotion
.state
&= ~(LockMask
| OBDisplay::numLockMask() |
74 OBDisplay::scrollLockMask());
77 _lasttime
= e
.xproperty
.time
; break;
80 _lasttime
= e
.xcrossing
.time
; break;
83 // these ConfigureRequests require some special attention
84 if (e
.type
== ConfigureRequest
) {
85 // find the actual window! e.xany.window is the parent window
86 it
= _map
.find(e
.xconfigurerequest
.window
);
89 it
->second
->handle(e
);
91 // unhandled configure requests must be used to configure the window
95 xwc
.x
= e
.xconfigurerequest
.x
;
96 xwc
.y
= e
.xconfigurerequest
.y
;
97 xwc
.width
= e
.xconfigurerequest
.width
;
98 xwc
.height
= e
.xconfigurerequest
.height
;
99 xwc
.border_width
= e
.xconfigurerequest
.border_width
;
100 xwc
.sibling
= e
.xconfigurerequest
.above
;
101 xwc
.stack_mode
= e
.xconfigurerequest
.detail
;
103 XConfigureWindow(otk::OBDisplay::display
, e
.xconfigurerequest
.window
,
104 e
.xconfigurerequest
.value_mask
, &xwc
);
106 // madly compress all focus events
107 } else if (e
.type
== FocusIn
) {
108 // any other types are not ones we're interested in
109 if (e
.xfocus
.detail
== NotifyNonlinear
) {
110 focus
= e
.xfocus
.window
;
112 //printf("FocusIn focus=%lx unfocus=%lx\n", focus, unfocus);
114 } else if (e
.type
== FocusOut
) {
115 // any other types are not ones we're interested in
116 if (e
.xfocus
.detail
== NotifyNonlinear
) {
117 unfocus
= e
.xfocus
.window
;
119 //printf("FocusOut focus=%lx unfocus=%lx\n", focus, unfocus);
121 // madly compress all crossing events
122 } else if (e
.type
== EnterNotify
) {
123 // any other types are not ones we're interested in
124 if (e
.xcrossing
.mode
== NotifyNormal
) {
125 // any other types are not ones we're interested in
126 enter
= e
.xcrossing
.window
;
127 enter_root
= e
.xcrossing
.root
;
128 //printf("Enter enter=%lx leave=%lx\n", enter, leave);
130 } else if (e
.type
== LeaveNotify
) {
131 // any other types are not ones we're interested in
132 if (e
.xcrossing
.mode
== NotifyNormal
) {
133 leave
= e
.xcrossing
.window
;
134 leave_root
= e
.xcrossing
.root
;
135 //printf("Leave enter=%lx leave=%lx\n", enter, leave);
143 if (unfocus
!= None
) {
144 // the last focus event was an FocusOut, so where the hell is the focus at?
145 //printf("UNFOCUSING: %lx\n", unfocus);
146 _focus_e
.xfocus
.type
= FocusOut
;
147 _focus_e
.xfocus
.window
= unfocus
;
151 } else if (focus
!= None
&& focus
!= _focus
) {
152 // the last focus event was a FocusIn, so unfocus what used to be focus and
153 // focus this new target
154 //printf("FOCUSING: %lx\n", focus);
155 _focus_e
.xfocus
.type
= FocusIn
;
156 _focus_e
.xfocus
.window
= focus
;
159 if (_focus
!= None
) {
160 //printf("UNFOCUSING: %lx\n", _focus);
161 _focus_e
.xfocus
.type
= FocusOut
;
162 _focus_e
.xfocus
.window
= _focus
;
170 _crossing_e
.xcrossing
.type
= LeaveNotify
;
171 _crossing_e
.xcrossing
.window
= leave
;
172 _crossing_e
.xcrossing
.root
= leave_root
;
173 dispatch(_crossing_e
);
176 _crossing_e
.xcrossing
.type
= EnterNotify
;
177 _crossing_e
.xcrossing
.window
= enter
;
178 _crossing_e
.xcrossing
.root
= enter_root
;
179 dispatch(_crossing_e
);
183 void OtkEventDispatcher::dispatch(const XEvent
&e
) {
184 OtkEventHandler
*handler
;
185 OtkEventMap::iterator it
;
190 it
= _map
.find(e
.xany
.window
);
192 if (it
!= _map
.end())
193 handler
= it
->second
;
201 OtkEventHandler
*OtkEventDispatcher::findHandler(Window win
)
203 OtkEventMap::iterator it
= _map
.find(win
);
204 if (it
!= _map
.end())
This page took 0.043597 seconds and 3 git commands to generate.