]>
Dogcows Code - chaz/openbox/blob - actions.cc
bb5088e92447e23d9b1da283e90e1f835247a51a
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
13 #include "bindings.hh"
14 #include "otk/display.hh"
21 const int Actions::BUTTONS
;
27 for (int i
=0; i
<BUTTONS
; ++i
)
28 _posqueue
[i
] = new ButtonPressAction();
34 for (int i
=0; i
<BUTTONS
; ++i
)
39 void Actions::insertPress(const XButtonEvent
&e
)
41 ButtonPressAction
*a
= _posqueue
[BUTTONS
- 1];
42 // rm'd the last one, shift them all down one
43 for (int i
= BUTTONS
-1; i
> 0; --i
) {
44 _posqueue
[i
] = _posqueue
[i
-1];
48 a
->pos
= otk::Point(e
.x_root
, e
.y_root
);
50 Client
*c
= openbox
->findClient(e
.window
);
51 if (c
) a
->clientarea
= c
->area();
54 void Actions::removePress(const XButtonEvent
&e
)
57 ButtonPressAction
*a
= 0;
58 for (i
=0; i
<BUTTONS
-1; ++i
)
59 if (_posqueue
[i
]->button
== e
.button
) {
63 if (a
) { // found one, remove it and shift the rest up one
64 for (; i
< BUTTONS
-1; ++i
)
65 _posqueue
[i
] = _posqueue
[i
+1];
66 _posqueue
[BUTTONS
-1] = a
;
68 _posqueue
[BUTTONS
-1]->button
= 0;
71 void Actions::buttonPressHandler(const XButtonEvent
&e
)
73 otk::EventHandler::buttonPressHandler(e
);
76 MouseContext::MC context
;
77 EventHandler
*h
= openbox
->findHandler(e
.window
);
78 Frame
*f
= dynamic_cast<Frame
*>(h
);
80 context
= f
->mouseContext(e
.window
);
81 else if (dynamic_cast<Client
*>(h
))
82 context
= MouseContext::Window
;
83 else if (dynamic_cast<Screen
*>(h
))
84 context
= MouseContext::Root
;
86 return; // not a valid mouse context
88 // run the PRESS python hook
89 // kill off the Button1Mask etc, only want the modifiers
90 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
91 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
93 Client
*c
= openbox
->findClient(e
.window
);
97 screen
= otk::display
->findScreen(e
.root
)->screen();
98 MouseData
data(screen
, c
, e
.time
, state
, e
.button
, context
,
100 openbox
->bindings()->fireButton(&data
);
102 if (_button
) return; // won't count toward CLICK events
106 if (context
== MouseContext::Window
) {
108 Because of how events are grabbed on the client window, we can't get
109 ButtonRelease events, so instead we simply manufacture them here, so that
110 clicks/doubleclicks etc still work.
112 //XButtonEvent ev = e;
113 //ev.type = ButtonRelease;
114 buttonReleaseHandler(e
);
119 void Actions::buttonReleaseHandler(const XButtonEvent
&e
)
121 otk::EventHandler::buttonReleaseHandler(e
);
124 MouseContext::MC context
;
125 EventHandler
*h
= openbox
->findHandler(e
.window
);
126 Frame
*f
= dynamic_cast<Frame
*>(h
);
128 context
= f
->mouseContext(e
.window
);
129 else if (dynamic_cast<Client
*>(h
))
130 context
= MouseContext::Window
;
131 else if (dynamic_cast<Screen
*>(h
))
132 context
= MouseContext::Root
;
134 return; // not a valid mouse context
136 // run the RELEASE python hook
137 // kill off the Button1Mask etc, only want the modifiers
138 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
139 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
141 Client
*c
= openbox
->findClient(e
.window
);
143 screen
= c
->screen();
145 screen
= otk::display
->findScreen(e
.root
)->screen();
146 MouseData
data(screen
, c
, e
.time
, state
, e
.button
, context
,
147 MouseAction::Release
);
148 openbox
->bindings()->fireButton(&data
);
150 // not for the button we're watching?
151 if (_button
!= e
.button
) return;
156 // find the area of the window
157 XWindowAttributes attr
;
158 if (!XGetWindowAttributes(**otk::display
, e
.window
, &attr
)) return;
160 // if not on the window any more, it isnt a CLICK
161 if (!(e
.same_screen
&& e
.x
>= 0 && e
.y
>= 0 &&
162 e
.x
< attr
.width
&& e
.y
< attr
.height
))
165 // run the CLICK python hook
166 data
.action
= MouseAction::Click
;
167 openbox
->bindings()->fireButton(&data
);
170 // XXX: dont load this every time!!@*
172 if (!python_get_long("DOUBLE_CLICK_DELAY", &dblclick
))
175 if (e
.time
- _release
.time
< (unsigned)dblclick
&&
176 _release
.win
== e
.window
&& _release
.button
== e
.button
) {
178 // run the DOUBLECLICK python hook
179 data
.action
= MouseAction::DoubleClick
;
180 openbox
->bindings()->fireButton(&data
);
182 // reset so you cant triple click for 2 doubleclicks
187 // save the button release, might be part of a double click
188 _release
.win
= e
.window
;
189 _release
.button
= e
.button
;
190 _release
.time
= e
.time
;
195 void Actions::enterHandler(const XCrossingEvent
&e
)
197 otk::EventHandler::enterHandler(e
);
199 // run the ENTER python hook
201 Client
*c
= openbox
->findClient(e
.window
);
203 screen
= c
->screen();
205 screen
= otk::display
->findScreen(e
.root
)->screen();
206 EventData
data(screen
, c
, EventAction::EnterWindow
, e
.state
);
207 openbox
->bindings()->fireEvent(&data
);
211 void Actions::leaveHandler(const XCrossingEvent
&e
)
213 otk::EventHandler::leaveHandler(e
);
215 // run the LEAVE python hook
217 Client
*c
= openbox
->findClient(e
.window
);
219 screen
= c
->screen();
221 screen
= otk::display
->findScreen(e
.root
)->screen();
222 EventData
data(screen
, c
, EventAction::LeaveWindow
, e
.state
);
223 openbox
->bindings()->fireEvent(&data
);
227 void Actions::keyPressHandler(const XKeyEvent
&e
)
229 otk::EventHandler::keyPressHandler(e
);
231 // kill off the Button1Mask etc, only want the modifiers
232 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
233 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
234 openbox
->bindings()->
235 fireKey(otk::display
->findScreen(e
.root
)->screen(),
236 state
, e
.keycode
, e
.time
, KeyAction::Press
);
240 void Actions::keyReleaseHandler(const XKeyEvent
&e
)
242 otk::EventHandler::keyReleaseHandler(e
);
244 // kill off the Button1Mask etc, only want the modifiers
245 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
246 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
248 // remove from the state the mask of the modifier being released, if it is
249 // a modifier key being released (this is a little ugly..)
250 const XModifierKeymap
*map
= otk::display
->modifierMap();
251 const int mask_table
[] = {
252 ShiftMask
, LockMask
, ControlMask
, Mod1Mask
,
253 Mod2Mask
, Mod3Mask
, Mod4Mask
, Mod5Mask
255 KeyCode
*kp
= map
->modifiermap
;
256 for (int i
= 0, n
= sizeof(mask_table
)/sizeof(mask_table
[0]); i
< n
; ++i
) {
257 for (int k
= 0; k
< map
->max_keypermod
; ++k
) {
258 if (*kp
== e
.keycode
) { // found the keycode
259 state
&= ~mask_table
[i
]; // remove the mask for it
260 i
= n
; // cause the first loop to break;
261 break; // get outta here!
267 openbox
->bindings()->
268 fireKey(otk::display
->findScreen(e
.root
)->screen(),
269 state
, e
.keycode
, e
.time
, KeyAction::Release
);
273 void Actions::motionHandler(const XMotionEvent
&e
)
275 otk::EventHandler::motionHandler(e
);
277 if (!e
.same_screen
) return; // this just gets stupid
279 MouseContext::MC context
;
280 EventHandler
*h
= openbox
->findHandler(e
.window
);
281 Frame
*f
= dynamic_cast<Frame
*>(h
);
283 context
= f
->mouseContext(e
.window
);
284 else if (dynamic_cast<Client
*>(h
))
285 context
= MouseContext::Window
;
286 else if (dynamic_cast<Screen
*>(h
))
287 context
= MouseContext::Root
;
289 return; // not a valid mouse context
291 int x_root
= e
.x_root
, y_root
= e
.y_root
;
293 // compress changes to a window into a single change
295 while (XCheckTypedWindowEvent(**otk::display
, e
.window
, e
.type
, &ce
)) {
302 int dx
= x_root
- _posqueue
[0]->pos
.x();
303 int dy
= y_root
- _posqueue
[0]->pos
.y();
304 // XXX: dont get this from python every time!
305 if (!python_get_long("DRAG_THRESHOLD", &threshold
))
307 if (!(std::abs(dx
) >= threshold
|| std::abs(dy
) >= threshold
))
308 return; // not at the threshold yet
310 _dragging
= true; // in a drag now
312 // check if the movement is more than the threshold
314 // run the MOTION python hook
315 // kill off the Button1Mask etc, only want the modifiers
316 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
317 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
318 unsigned int button
= _posqueue
[0]->button
;
320 Client
*c
= openbox
->findClient(e
.window
);
322 screen
= c
->screen();
324 screen
= otk::display
->findScreen(e
.root
)->screen();
325 MouseData
data(screen
, c
, e
.time
, state
, button
, context
,
326 MouseAction::Motion
, x_root
, y_root
,
327 _posqueue
[0]->pos
, _posqueue
[0]->clientarea
);
328 openbox
->bindings()->fireButton(&data
);
332 void Actions::xkbHandler(const XkbEvent
&e
)
337 otk::EventHandler::xkbHandler(e
);
339 switch (((XkbAnyEvent
*)&e
)->xkb_type
) {
341 w
= ((XkbBellNotifyEvent
*)&e
)->window
;
342 Client
*c
= openbox
->findClient(w
);
344 screen
= c
->screen();
346 screen
= openbox
->focusedScreen()->number();
347 EventData
data(screen
, c
, EventAction::Bell
, 0);
348 openbox
->bindings()->fireEvent(&data
);
This page took 0.053403 seconds and 3 git commands to generate.