]>
Dogcows Code - chaz/openbox/blob - src/actions.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
11 #include "bindings.hh"
12 #include "otk/display.hh"
19 const int Actions::BUTTONS
;
25 for (int i
=0; i
<BUTTONS
; ++i
)
26 _posqueue
[i
] = new ButtonPressAction();
32 for (int i
=0; i
<BUTTONS
; ++i
)
37 void Actions::insertPress(const XButtonEvent
&e
)
39 ButtonPressAction
*a
= _posqueue
[BUTTONS
- 1];
40 // rm'd the last one, shift them all down one
41 for (int i
= BUTTONS
-1; i
> 0; --i
) {
42 _posqueue
[i
] = _posqueue
[i
-1];
46 a
->pos
= otk::Point(e
.x_root
, e
.y_root
);
48 Client
*c
= openbox
->findClient(e
.window
);
49 if (c
) a
->clientarea
= c
->area();
52 void Actions::removePress(const XButtonEvent
&e
)
55 ButtonPressAction
*a
= 0;
56 for (i
=0; i
<BUTTONS
-1; ++i
)
57 if (_posqueue
[i
]->button
== e
.button
) {
61 if (a
) { // found one, remove it and shift the rest up one
62 for (; i
< BUTTONS
-1; ++i
)
63 _posqueue
[i
] = _posqueue
[i
+1];
64 _posqueue
[BUTTONS
-1] = a
;
66 _posqueue
[BUTTONS
-1]->button
= 0;
69 void Actions::buttonPressHandler(const XButtonEvent
&e
)
71 otk::EventHandler::buttonPressHandler(e
);
74 MouseContext::MC context
;
75 EventHandler
*h
= openbox
->findHandler(e
.window
);
76 Frame
*f
= dynamic_cast<Frame
*>(h
);
78 context
= f
->mouseContext(e
.window
);
79 else if (dynamic_cast<Client
*>(h
))
80 context
= MouseContext::Window
;
81 else if (dynamic_cast<Screen
*>(h
))
82 context
= MouseContext::Root
;
84 return; // not a valid mouse context
86 // run the PRESS python hook
87 // kill off the Button1Mask etc, only want the modifiers
88 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
89 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
91 Client
*c
= openbox
->findClient(e
.window
);
95 screen
= otk::display
->findScreen(e
.root
)->screen();
96 MouseData
data(screen
, c
, e
.time
, state
, e
.button
, context
,
98 openbox
->bindings()->fireButton(&data
);
100 if (_button
) return; // won't count toward CLICK events
104 if (context
== MouseContext::Window
) {
106 Because of how events are grabbed on the client window, we can't get
107 ButtonRelease events, so instead we simply manufacture them here, so that
108 clicks/doubleclicks etc still work.
110 //XButtonEvent ev = e;
111 //ev.type = ButtonRelease;
112 buttonReleaseHandler(e
);
117 void Actions::buttonReleaseHandler(const XButtonEvent
&e
)
119 otk::EventHandler::buttonReleaseHandler(e
);
122 MouseContext::MC context
;
123 EventHandler
*h
= openbox
->findHandler(e
.window
);
124 Frame
*f
= dynamic_cast<Frame
*>(h
);
126 context
= f
->mouseContext(e
.window
);
127 else if (dynamic_cast<Client
*>(h
))
128 context
= MouseContext::Window
;
129 else if (dynamic_cast<Screen
*>(h
))
130 context
= MouseContext::Root
;
132 return; // not a valid mouse context
134 // run the RELEASE python hook
135 // kill off the Button1Mask etc, only want the modifiers
136 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
137 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
139 Client
*c
= openbox
->findClient(e
.window
);
141 screen
= c
->screen();
143 screen
= otk::display
->findScreen(e
.root
)->screen();
144 MouseData
data(screen
, c
, e
.time
, state
, e
.button
, context
,
145 MouseAction::Release
);
146 openbox
->bindings()->fireButton(&data
);
148 // not for the button we're watching?
149 if (_button
!= e
.button
) return;
154 // find the area of the window
155 XWindowAttributes attr
;
156 if (!XGetWindowAttributes(**otk::display
, e
.window
, &attr
)) return;
158 // if not on the window any more, it isnt a CLICK
159 if (!(e
.same_screen
&& e
.x
>= 0 && e
.y
>= 0 &&
160 e
.x
< attr
.width
&& e
.y
< attr
.height
))
163 // run the CLICK python hook
164 data
.action
= MouseAction::Click
;
165 openbox
->bindings()->fireButton(&data
);
168 // XXX: dont load this every time!!@*
170 if (!python_get_long("DOUBLE_CLICK_DELAY", &dblclick
))
173 if (e
.time
- _release
.time
< (unsigned)dblclick
&&
174 _release
.win
== e
.window
&& _release
.button
== e
.button
) {
176 // run the DOUBLECLICK python hook
177 data
.action
= MouseAction::DoubleClick
;
178 openbox
->bindings()->fireButton(&data
);
180 // reset so you cant triple click for 2 doubleclicks
185 // save the button release, might be part of a double click
186 _release
.win
= e
.window
;
187 _release
.button
= e
.button
;
188 _release
.time
= e
.time
;
193 void Actions::enterHandler(const XCrossingEvent
&e
)
195 otk::EventHandler::enterHandler(e
);
197 // run the ENTER python hook
199 Client
*c
= openbox
->findClient(e
.window
);
201 screen
= c
->screen();
203 screen
= otk::display
->findScreen(e
.root
)->screen();
204 EventData
data(screen
, c
, EventAction::EnterWindow
, e
.state
);
205 openbox
->bindings()->fireEvent(&data
);
209 void Actions::leaveHandler(const XCrossingEvent
&e
)
211 otk::EventHandler::leaveHandler(e
);
213 // run the LEAVE python hook
215 Client
*c
= openbox
->findClient(e
.window
);
217 screen
= c
->screen();
219 screen
= otk::display
->findScreen(e
.root
)->screen();
220 EventData
data(screen
, c
, EventAction::LeaveWindow
, e
.state
);
221 openbox
->bindings()->fireEvent(&data
);
225 void Actions::keyPressHandler(const XKeyEvent
&e
)
227 otk::EventHandler::keyPressHandler(e
);
229 // kill off the Button1Mask etc, only want the modifiers
230 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
231 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
232 openbox
->bindings()->
233 fireKey(otk::display
->findScreen(e
.root
)->screen(),
234 state
, e
.keycode
, e
.time
, KeyAction::Press
);
238 void Actions::keyReleaseHandler(const XKeyEvent
&e
)
240 otk::EventHandler::keyReleaseHandler(e
);
242 // kill off the Button1Mask etc, only want the modifiers
243 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
244 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
246 // remove from the state the mask of the modifier being released, if it is
247 // a modifier key being released (this is a little ugly..)
248 const XModifierKeymap
*map
= otk::display
->modifierMap();
249 const int mask_table
[] = {
250 ShiftMask
, LockMask
, ControlMask
, Mod1Mask
,
251 Mod2Mask
, Mod3Mask
, Mod4Mask
, Mod5Mask
253 KeyCode
*kp
= map
->modifiermap
;
254 for (int i
= 0, n
= sizeof(mask_table
)/sizeof(mask_table
[0]); i
< n
; ++i
) {
255 for (int k
= 0; k
< map
->max_keypermod
; ++k
) {
256 if (*kp
== e
.keycode
) { // found the keycode
257 state
&= ~mask_table
[i
]; // remove the mask for it
258 i
= n
; // cause the first loop to break;
259 break; // get outta here!
265 openbox
->bindings()->
266 fireKey(otk::display
->findScreen(e
.root
)->screen(),
267 state
, e
.keycode
, e
.time
, KeyAction::Release
);
271 void Actions::motionHandler(const XMotionEvent
&e
)
273 otk::EventHandler::motionHandler(e
);
275 if (!e
.same_screen
) return; // this just gets stupid
277 MouseContext::MC context
;
278 EventHandler
*h
= openbox
->findHandler(e
.window
);
279 Frame
*f
= dynamic_cast<Frame
*>(h
);
281 context
= f
->mouseContext(e
.window
);
282 else if (dynamic_cast<Client
*>(h
))
283 context
= MouseContext::Window
;
284 else if (dynamic_cast<Screen
*>(h
))
285 context
= MouseContext::Root
;
287 return; // not a valid mouse context
289 int x_root
= e
.x_root
, y_root
= e
.y_root
;
291 // compress changes to a window into a single change
293 while (XCheckTypedWindowEvent(**otk::display
, e
.window
, e
.type
, &ce
)) {
300 int dx
= x_root
- _posqueue
[0]->pos
.x();
301 int dy
= y_root
- _posqueue
[0]->pos
.y();
302 // XXX: dont get this from python every time!
303 if (!python_get_long("DRAG_THRESHOLD", &threshold
))
305 if (!(std::abs(dx
) >= threshold
|| std::abs(dy
) >= threshold
))
306 return; // not at the threshold yet
308 _dragging
= true; // in a drag now
310 // check if the movement is more than the threshold
312 // run the MOTION python hook
313 // kill off the Button1Mask etc, only want the modifiers
314 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
315 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
316 unsigned int button
= _posqueue
[0]->button
;
318 Client
*c
= openbox
->findClient(e
.window
);
320 screen
= c
->screen();
322 screen
= otk::display
->findScreen(e
.root
)->screen();
323 MouseData
data(screen
, c
, e
.time
, state
, button
, context
,
324 MouseAction::Motion
, x_root
, y_root
,
325 _posqueue
[0]->pos
, _posqueue
[0]->clientarea
);
326 openbox
->bindings()->fireButton(&data
);
330 void Actions::xkbHandler(const XkbEvent
&e
)
335 otk::EventHandler::xkbHandler(e
);
337 switch (((XkbAnyEvent
*)&e
)->xkb_type
) {
339 w
= ((XkbBellNotifyEvent
*)&e
)->window
;
340 Client
*c
= openbox
->findClient(w
);
342 screen
= c
->screen();
344 screen
= openbox
->focusedScreen()->number();
345 EventData
data(screen
, c
, EventAction::Bell
, 0);
346 openbox
->bindings()->fireEvent(&data
);
This page took 0.052083 seconds and 4 git commands to generate.