]>
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];
47 a
->pos
= otk::Point(e
.x_root
, e
.y_root
);
49 Client
*c
= openbox
->findClient(e
.window
);
50 if (c
) a
->clientarea
= c
->area();
53 void Actions::removePress(const XButtonEvent
&e
)
56 ButtonPressAction
*a
= 0;
57 for (i
=0; i
<BUTTONS
-1; ++i
)
58 if (_posqueue
[i
]->button
== e
.button
) {
62 if (a
) { // found one, remove it and shift the rest up one
63 for (; i
< BUTTONS
-1; ++i
)
64 _posqueue
[i
] = _posqueue
[i
+1];
65 _posqueue
[BUTTONS
-1] = a
;
67 _posqueue
[BUTTONS
-1]->button
= 0;
70 void Actions::buttonPressHandler(const XButtonEvent
&e
)
72 otk::EventHandler::buttonPressHandler(e
);
75 MouseContext::MC context
;
76 EventHandler
*h
= openbox
->findHandler(e
.window
);
77 Frame
*f
= dynamic_cast<Frame
*>(h
);
79 context
= f
->mouseContext(e
.window
);
80 else if (dynamic_cast<Client
*>(h
))
81 context
= MouseContext::Window
;
82 else if (dynamic_cast<Screen
*>(h
))
83 context
= MouseContext::Root
;
85 return; // not a valid mouse context
87 // run the PRESS python hook
88 // kill off the Button1Mask etc, only want the modifiers
89 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
90 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
92 Client
*c
= openbox
->findClient(e
.window
);
96 screen
= otk::display
->findScreen(e
.root
)->screen();
97 MouseData
data(screen
, c
, e
.time
, state
, e
.button
, context
,
99 openbox
->bindings()->fireButton(&data
);
101 if (_button
) return; // won't count toward CLICK events
105 if (context
== MouseContext::Window
) {
107 Because of how events are grabbed on the client window, we can't get
108 ButtonRelease events, so instead we simply manufacture them here, so that
109 clicks/doubleclicks etc still work.
111 //XButtonEvent ev = e;
112 //ev.type = ButtonRelease;
113 buttonReleaseHandler(e
);
118 void Actions::buttonReleaseHandler(const XButtonEvent
&e
)
120 otk::EventHandler::buttonReleaseHandler(e
);
123 MouseContext::MC context
;
124 EventHandler
*h
= openbox
->findHandler(e
.window
);
125 Frame
*f
= dynamic_cast<Frame
*>(h
);
127 context
= f
->mouseContext(e
.window
);
128 else if (dynamic_cast<Client
*>(h
))
129 context
= MouseContext::Window
;
130 else if (dynamic_cast<Screen
*>(h
))
131 context
= MouseContext::Root
;
133 return; // not a valid mouse context
135 // run the RELEASE 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
, context
,
146 MouseAction::Release
);
147 openbox
->bindings()->fireButton(&data
);
149 // not for the button we're watching?
150 if (_button
!= e
.button
) return;
155 // find the area of the window
156 XWindowAttributes attr
;
157 if (!XGetWindowAttributes(**otk::display
, e
.window
, &attr
)) return;
159 // if not on the window any more, it isnt a CLICK
160 if (!(e
.same_screen
&& e
.x
>= 0 && e
.y
>= 0 &&
161 e
.x
< attr
.width
&& e
.y
< attr
.height
))
164 // run the CLICK python hook
165 data
.action
= MouseAction::Click
;
166 openbox
->bindings()->fireButton(&data
);
169 // XXX: dont load this every time!!@*
171 if (!python_get_long("DOUBLE_CLICK_DELAY", &dblclick
))
174 if (e
.time
- _release
.time
< (unsigned)dblclick
&&
175 _release
.win
== e
.window
&& _release
.button
== e
.button
) {
177 // run the DOUBLECLICK python hook
178 data
.action
= MouseAction::DoubleClick
;
179 openbox
->bindings()->fireButton(&data
);
181 // reset so you cant triple click for 2 doubleclicks
186 // save the button release, might be part of a double click
187 _release
.win
= e
.window
;
188 _release
.button
= e
.button
;
189 _release
.time
= e
.time
;
194 void Actions::enterHandler(const XCrossingEvent
&e
)
196 otk::EventHandler::enterHandler(e
);
198 // run the ENTER python hook
200 Client
*c
= openbox
->findClient(e
.window
);
202 screen
= c
->screen();
204 screen
= otk::display
->findScreen(e
.root
)->screen();
205 EventData
data(screen
, c
, EventAction::EnterWindow
, e
.state
);
206 openbox
->bindings()->fireEvent(&data
);
210 void Actions::leaveHandler(const XCrossingEvent
&e
)
212 otk::EventHandler::leaveHandler(e
);
214 // run the LEAVE python hook
216 Client
*c
= openbox
->findClient(e
.window
);
218 screen
= c
->screen();
220 screen
= otk::display
->findScreen(e
.root
)->screen();
221 EventData
data(screen
, c
, EventAction::LeaveWindow
, e
.state
);
222 openbox
->bindings()->fireEvent(&data
);
226 void Actions::keyPressHandler(const XKeyEvent
&e
)
228 otk::EventHandler::keyPressHandler(e
);
230 // kill off the Button1Mask etc, only want the modifiers
231 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
232 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
233 openbox
->bindings()->
234 fireKey(otk::display
->findScreen(e
.root
)->screen(),
235 state
, e
.keycode
, e
.time
, KeyAction::Press
);
239 void Actions::keyReleaseHandler(const XKeyEvent
&e
)
241 otk::EventHandler::keyReleaseHandler(e
);
243 // kill off the Button1Mask etc, only want the modifiers
244 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
245 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
247 // remove from the state the mask of the modifier being released, if it is
248 // a modifier key being released (this is a little ugly..)
249 const XModifierKeymap
*map
= otk::display
->modifierMap();
250 const int mask_table
[] = {
251 ShiftMask
, LockMask
, ControlMask
, Mod1Mask
,
252 Mod2Mask
, Mod3Mask
, Mod4Mask
, Mod5Mask
254 KeyCode
*kp
= map
->modifiermap
;
255 for (int i
= 0, n
= sizeof(mask_table
)/sizeof(mask_table
[0]); i
< n
; ++i
) {
256 for (int k
= 0; k
< map
->max_keypermod
; ++k
) {
257 if (*kp
== e
.keycode
) { // found the keycode
258 state
&= ~mask_table
[i
]; // remove the mask for it
259 i
= n
; // cause the first loop to break;
260 break; // get outta here!
266 openbox
->bindings()->
267 fireKey(otk::display
->findScreen(e
.root
)->screen(),
268 state
, e
.keycode
, e
.time
, KeyAction::Release
);
272 void Actions::motionHandler(const XMotionEvent
&e
)
274 otk::EventHandler::motionHandler(e
);
276 if (!e
.same_screen
) return; // this just gets stupid
278 if (e
.window
!= _posqueue
[0]->win
) return;
280 MouseContext::MC context
;
281 EventHandler
*h
= openbox
->findHandler(e
.window
);
282 Frame
*f
= dynamic_cast<Frame
*>(h
);
284 context
= f
->mouseContext(e
.window
);
285 else if (dynamic_cast<Client
*>(h
))
286 context
= MouseContext::Window
;
287 else if (dynamic_cast<Screen
*>(h
))
288 context
= MouseContext::Root
;
290 return; // not a valid mouse context
292 int x_root
= e
.x_root
, y_root
= e
.y_root
;
294 // compress changes to a window into a single change
296 while (XCheckTypedWindowEvent(**otk::display
, e
.window
, e
.type
, &ce
)) {
303 int dx
= x_root
- _posqueue
[0]->pos
.x();
304 int dy
= y_root
- _posqueue
[0]->pos
.y();
305 // XXX: dont get this from python every time!
306 if (!python_get_long("DRAG_THRESHOLD", &threshold
))
308 if (!(std::abs(dx
) >= threshold
|| std::abs(dy
) >= threshold
))
309 return; // not at the threshold yet
311 _dragging
= true; // in a drag now
313 // check if the movement is more than the threshold
315 // run the MOTION python hook
316 // kill off the Button1Mask etc, only want the modifiers
317 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
318 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
319 unsigned int button
= _posqueue
[0]->button
;
321 Client
*c
= openbox
->findClient(e
.window
);
323 screen
= c
->screen();
325 screen
= otk::display
->findScreen(e
.root
)->screen();
326 MouseData
data(screen
, c
, e
.time
, state
, button
, context
,
327 MouseAction::Motion
, x_root
, y_root
,
328 _posqueue
[0]->pos
, _posqueue
[0]->clientarea
);
329 openbox
->bindings()->fireButton(&data
);
333 void Actions::xkbHandler(const XkbEvent
&e
)
338 otk::EventHandler::xkbHandler(e
);
340 switch (((XkbAnyEvent
*)&e
)->xkb_type
) {
342 w
= ((XkbBellNotifyEvent
*)&e
)->window
;
343 Client
*c
= openbox
->findClient(w
);
345 screen
= c
->screen();
347 screen
= openbox
->focusedScreen()->number();
348 EventData
data(screen
, c
, EventAction::Bell
, 0);
349 openbox
->bindings()->fireEvent(&data
);
This page took 0.04873 seconds and 4 git commands to generate.