]>
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)
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
);
63 _lasttime
= e
.xbutton
.time
; break;
65 _lasttime
= e
.xmotion
.time
; break;
67 _lasttime
= e
.xproperty
.time
; break;
70 _lasttime
= e
.xcrossing
.time
; break;
73 // these ConfigureRequests require some special attention
74 if (e
.type
== ConfigureRequest
) {
75 // find the actual window! e.xany.window is the parent window
76 it
= _map
.find(e
.xconfigurerequest
.window
);
79 it
->second
->handle(e
);
81 // unhandled configure requests must be used to configure the window
85 xwc
.x
= e
.xconfigurerequest
.x
;
86 xwc
.y
= e
.xconfigurerequest
.y
;
87 xwc
.width
= e
.xconfigurerequest
.width
;
88 xwc
.height
= e
.xconfigurerequest
.height
;
89 xwc
.border_width
= e
.xconfigurerequest
.border_width
;
90 xwc
.sibling
= e
.xconfigurerequest
.above
;
91 xwc
.stack_mode
= e
.xconfigurerequest
.detail
;
93 XConfigureWindow(otk::OBDisplay::display
, e
.xconfigurerequest
.window
,
94 e
.xconfigurerequest
.value_mask
, &xwc
);
96 // madly compress all focus events
97 } else if (e
.type
== FocusIn
) {
98 // any other types are not ones we're interested in
99 if (e
.xfocus
.detail
== NotifyNonlinear
) {
100 focus
= e
.xfocus
.window
;
102 //printf("FocusIn focus=%lx unfocus=%lx\n", focus, unfocus);
104 } else if (e
.type
== FocusOut
) {
105 // any other types are not ones we're interested in
106 if (e
.xfocus
.detail
== NotifyNonlinear
) {
107 unfocus
= e
.xfocus
.window
;
109 //printf("FocusOut focus=%lx unfocus=%lx\n", focus, unfocus);
111 // madly compress all crossing events
112 } else if (e
.type
== EnterNotify
) {
113 // any other types are not ones we're interested in
114 if (e
.xcrossing
.mode
== NotifyNormal
) {
115 // any other types are not ones we're interested in
116 enter
= e
.xcrossing
.window
;
117 enter_root
= e
.xcrossing
.root
;
118 //printf("Enter enter=%lx leave=%lx\n", enter, leave);
120 } else if (e
.type
== LeaveNotify
) {
121 // any other types are not ones we're interested in
122 if (e
.xcrossing
.mode
== NotifyNormal
) {
123 leave
= e
.xcrossing
.window
;
124 leave_root
= e
.xcrossing
.root
;
125 //printf("Leave enter=%lx leave=%lx\n", enter, leave);
133 if (unfocus
!= None
) {
134 // the last focus event was an FocusOut, so where the hell is the focus at?
135 // printf("UNFOCUSING: %lx\n", unfocus);
136 _focus_e
.xfocus
.type
= FocusOut
;
137 _focus_e
.xfocus
.window
= unfocus
;
141 } else if (focus
!= None
) {
142 // the last focus event was a FocusIn, so unfocus what used to be focus and
143 // focus this new target
144 // printf("FOCUSING: %lx\n", focus);
145 _focus_e
.xfocus
.type
= FocusIn
;
146 _focus_e
.xfocus
.window
= focus
;
149 if (_focus
!= None
) {
150 // printf("UNFOCUSING: %lx\n", _focus);
151 _focus_e
.xfocus
.type
= FocusOut
;
152 _focus_e
.xfocus
.window
= _focus
;
160 _crossing_e
.xcrossing
.type
= LeaveNotify
;
161 _crossing_e
.xcrossing
.window
= leave
;
162 _crossing_e
.xcrossing
.root
= leave_root
;
163 dispatch(_crossing_e
);
166 _crossing_e
.xcrossing
.type
= EnterNotify
;
167 _crossing_e
.xcrossing
.window
= enter
;
168 _crossing_e
.xcrossing
.root
= enter_root
;
169 dispatch(_crossing_e
);
173 void OtkEventDispatcher::dispatch(const XEvent
&e
) {
174 OtkEventHandler
*handler
;
175 OtkEventMap::iterator it
;
180 it
= _map
.find(e
.xany
.window
);
182 if (it
!= _map
.end())
183 handler
= it
->second
;
191 OtkEventHandler
*OtkEventDispatcher::findHandler(Window win
)
193 OtkEventMap::iterator it
= _map
.find(win
);
194 if (it
!= _map
.end())
This page took 0.039489 seconds and 4 git commands to generate.