]>
Dogcows Code - chaz/openbox/blob - src/actions.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
8 #include "widgetbase.hh"
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
.setPoint(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 // run the PRESS python hook
77 WidgetBase
*w
= dynamic_cast<WidgetBase
*>
78 (openbox
->findHandler(e
.window
));
81 // kill off the Button1Mask etc, only want the modifiers
82 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
83 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
85 Client
*c
= openbox
->findClient(e
.window
);
89 screen
= otk::display
->findScreen(e
.root
)->screen();
90 MouseData
data(screen
, c
, e
.time
, state
, e
.button
, w
->mcontext(),
92 openbox
->bindings()->fireButton(&data
);
94 if (_button
) return; // won't count toward CLICK events
98 if (w
->mcontext() == MouseContext::Window
) {
100 Because of how events are grabbed on the client window, we can't get
101 ButtonRelease events, so instead we simply manufacture them here, so that
102 clicks/doubleclicks etc still work.
104 //XButtonEvent ev = e;
105 //ev.type = ButtonRelease;
106 buttonReleaseHandler(e
);
111 void Actions::buttonReleaseHandler(const XButtonEvent
&e
)
113 otk::EventHandler::buttonReleaseHandler(e
);
116 WidgetBase
*w
= dynamic_cast<WidgetBase
*>
117 (openbox
->findHandler(e
.window
));
120 // not for the button we're watching?
121 if (_button
!= e
.button
) return;
126 // find the area of the window
127 XWindowAttributes attr
;
128 if (!XGetWindowAttributes(**otk::display
, e
.window
, &attr
)) return;
130 // if not on the window any more, it isnt a CLICK
131 if (!(e
.same_screen
&& e
.x
>= 0 && e
.y
>= 0 &&
132 e
.x
< attr
.width
&& e
.y
< attr
.height
))
135 // run the CLICK python hook
136 // kill off the Button1Mask etc, only want the modifiers
137 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
138 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
140 Client
*c
= openbox
->findClient(e
.window
);
142 screen
= c
->screen();
144 screen
= otk::display
->findScreen(e
.root
)->screen();
145 MouseData
data(screen
, c
, e
.time
, state
, e
.button
, w
->mcontext(),
147 openbox
->bindings()->fireButton(&data
);
150 // XXX: dont load this every time!!@*
152 if (!python_get_long("double_click_delay", &dblclick
))
155 if (e
.time
- _release
.time
< (unsigned)dblclick
&&
156 _release
.win
== e
.window
&& _release
.button
== e
.button
) {
158 // run the DOUBLECLICK python hook
159 data
.action
= MouseAction::DoubleClick
;
160 openbox
->bindings()->fireButton(&data
);
162 // reset so you cant triple click for 2 doubleclicks
167 // save the button release, might be part of a double click
168 _release
.win
= e
.window
;
169 _release
.button
= e
.button
;
170 _release
.time
= e
.time
;
175 void Actions::enterHandler(const XCrossingEvent
&e
)
177 otk::EventHandler::enterHandler(e
);
179 // run the ENTER python hook
181 Client
*c
= openbox
->findClient(e
.window
);
183 screen
= c
->screen();
185 screen
= otk::display
->findScreen(e
.root
)->screen();
186 EventData
data(screen
, c
, EventAction::EnterWindow
, e
.state
);
187 openbox
->bindings()->fireEvent(&data
);
191 void Actions::leaveHandler(const XCrossingEvent
&e
)
193 otk::EventHandler::leaveHandler(e
);
195 // run the LEAVE python hook
197 Client
*c
= openbox
->findClient(e
.window
);
199 screen
= c
->screen();
201 screen
= otk::display
->findScreen(e
.root
)->screen();
202 EventData
data(screen
, c
, EventAction::LeaveWindow
, e
.state
);
203 openbox
->bindings()->fireEvent(&data
);
207 void Actions::keyPressHandler(const XKeyEvent
&e
)
209 otk::EventHandler::keyPressHandler(e
);
211 // kill off the Button1Mask etc, only want the modifiers
212 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
213 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
214 openbox
->bindings()->
215 fireKey(otk::display
->findScreen(e
.root
)->screen(),
216 state
, e
.keycode
, e
.time
, KeyAction::Press
);
220 void Actions::keyReleaseHandler(const XKeyEvent
&e
)
222 otk::EventHandler::keyReleaseHandler(e
);
224 // kill off the Button1Mask etc, only want the modifiers
225 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
226 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
228 // remove from the state the mask of the modifier being released, if it is
229 // a modifier key being released (XXX this is a little ugly..)
230 const XModifierKeymap
*map
= otk::display
->modifierMap();
231 const int mask_table
[] = {
232 ShiftMask
, LockMask
, ControlMask
, Mod1Mask
,
233 Mod2Mask
, Mod3Mask
, Mod4Mask
, Mod5Mask
235 KeyCode
*kp
= map
->modifiermap
;
236 for (int i
= 0, n
= sizeof(mask_table
)/sizeof(mask_table
[0]); i
< n
; ++i
) {
237 for (int k
= 0; k
< map
->max_keypermod
; ++k
) {
238 if (*kp
== e
.keycode
) { // found the keycode
239 state
&= ~mask_table
[i
]; // remove the mask for it
240 i
= n
; // cause the first loop to break;
241 break; // get outta here!
247 openbox
->bindings()->
248 fireKey(otk::display
->findScreen(e
.root
)->screen(),
249 state
, e
.keycode
, e
.time
, KeyAction::Release
);
253 void Actions::motionHandler(const XMotionEvent
&e
)
255 otk::EventHandler::motionHandler(e
);
257 if (!e
.same_screen
) return; // this just gets stupid
259 int x_root
= e
.x_root
, y_root
= e
.y_root
;
261 // compress changes to a window into a single change
263 while (XCheckTypedEvent(**otk::display
, e
.type
, &ce
)) {
264 if (ce
.xmotion
.window
!= e
.window
) {
265 XPutBackEvent(**otk::display
, &ce
);
273 WidgetBase
*w
= dynamic_cast<WidgetBase
*>
274 (openbox
->findHandler(e
.window
));
279 int dx
= x_root
- _posqueue
[0]->pos
.x();
280 int dy
= y_root
- _posqueue
[0]->pos
.y();
281 // XXX: dont get this from python every time!
282 if (!python_get_long("drag_threshold", &threshold
))
284 if (!(std::abs(dx
) >= threshold
|| std::abs(dy
) >= threshold
))
285 return; // not at the threshold yet
287 _dragging
= true; // in a drag now
289 // check if the movement is more than the threshold
291 // run the MOTION python hook
292 // kill off the Button1Mask etc, only want the modifiers
293 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
294 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
295 unsigned int button
= _posqueue
[0]->button
;
297 Client
*c
= openbox
->findClient(e
.window
);
299 screen
= c
->screen();
301 screen
= otk::display
->findScreen(e
.root
)->screen();
302 MouseData
data(screen
, c
, e
.time
, state
, button
, w
->mcontext(),
303 MouseAction::Motion
, x_root
, y_root
,
304 _posqueue
[0]->pos
, _posqueue
[0]->clientarea
);
305 openbox
->bindings()->fireButton(&data
);
309 void Actions::xkbHandler(const XkbEvent
&e
)
314 otk::EventHandler::xkbHandler(e
);
316 switch (((XkbAnyEvent
*)&e
)->xkb_type
) {
318 w
= ((XkbBellNotifyEvent
*)&e
)->window
;
319 Client
*c
= openbox
->findClient(w
);
321 screen
= c
->screen();
323 screen
= openbox
->focusedScreen()->number();
324 EventData
data(screen
, c
, EventAction::Bell
, 0);
325 openbox
->bindings()->fireEvent(&data
);
This page took 0.047651 seconds and 4 git commands to generate.