]>
Dogcows Code - chaz/openbox/blob - src/actions.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
12 #include "bindings.hh"
13 #include "otk/display.hh"
19 const unsigned int OBActions::DOUBLECLICKDELAY
= 300;
20 const int OBActions::BUTTONS
;
22 OBActions::OBActions()
25 for (int i
=0; i
<BUTTONS
; ++i
)
26 _posqueue
[i
] = new ButtonPressAction();
30 OBActions::~OBActions()
32 for (int i
=0; i
<BUTTONS
; ++i
)
37 void OBActions::insertPress(const XButtonEvent
&e
)
39 ButtonPressAction
*a
= _posqueue
[BUTTONS
- 1];
40 for (int i
=BUTTONS
-1; i
>0;)
41 _posqueue
[i
] = _posqueue
[--i
];
44 a
->pos
.setPoint(e
.x_root
, e
.y_root
);
46 OBClient
*c
= Openbox::instance
->findClient(e
.window
);
47 if (c
) a
->clientarea
= c
->area();
50 void OBActions::removePress(const XButtonEvent
&e
)
52 ButtonPressAction
*a
= 0;
53 for (int i
=0; i
<BUTTONS
; ++i
) {
54 if (_posqueue
[i
]->button
== e
.button
)
56 if (a
) // found one and removed it
57 _posqueue
[i
] = _posqueue
[i
+1];
60 _posqueue
[BUTTONS
-1] = a
;
65 void OBActions::buttonPressHandler(const XButtonEvent
&e
)
67 OtkEventHandler::buttonPressHandler(e
);
70 // run the PRESS python hook
71 OBWidget
*w
= dynamic_cast<OBWidget
*>
72 (Openbox::instance
->findHandler(e
.window
));
73 assert(w
); // everything should be a widget
75 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
76 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
77 ButtonData
*data
= new_button_data(e
.window
, e
.time
, state
, e
.button
,
78 w
->mcontext(), MousePress
);
79 Openbox::instance
->bindings()->fireButton(data
);
80 Py_DECREF((PyObject
*)data
);
82 if (_button
) return; // won't count toward CLICK events
88 void OBActions::buttonReleaseHandler(const XButtonEvent
&e
)
90 OtkEventHandler::buttonReleaseHandler(e
);
93 OBWidget
*w
= dynamic_cast<OBWidget
*>
94 (Openbox::instance
->findHandler(e
.window
));
95 assert(w
); // everything should be a widget
97 // not for the button we're watching?
98 if (_button
!= e
.button
) return;
102 // find the area of the window
103 XWindowAttributes attr
;
104 if (!XGetWindowAttributes(otk::OBDisplay::display
, e
.window
, &attr
)) return;
106 // if not on the window any more, it isnt a CLICK
107 if (!(e
.same_screen
&& e
.x
>= 0 && e
.y
>= 0 &&
108 e
.x
< attr
.width
&& e
.y
< attr
.height
))
111 // run the CLICK python hook
112 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
113 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
114 ButtonData
*data
= new_button_data(e
.window
, e
.time
, state
, e
.button
,
115 w
->mcontext(), MouseClick
);
116 Openbox::instance
->bindings()->fireButton(data
);
119 if (e
.time
- _release
.time
< DOUBLECLICKDELAY
&&
120 _release
.win
== e
.window
&& _release
.button
== e
.button
) {
122 // run the DOUBLECLICK python hook
123 data
->action
= MouseDoubleClick
;
124 Openbox::instance
->bindings()->fireButton(data
);
126 // reset so you cant triple click for 2 doubleclicks
131 // save the button release, might be part of a double click
132 _release
.win
= e
.window
;
133 _release
.button
= e
.button
;
134 _release
.time
= e
.time
;
137 Py_DECREF((PyObject
*)data
);
141 void OBActions::enterHandler(const XCrossingEvent
&e
)
143 OtkEventHandler::enterHandler(e
);
145 OBWidget
*w
= dynamic_cast<OBWidget
*>
146 (Openbox::instance
->findHandler(e
.window
));
148 // run the ENTER python hook
149 doCallback(Action_EnterWindow
, e
.window
,
150 (OBWidget::WidgetType
)(w
? w
->type():-1), e
.state
, 0, 0, 0, 0);
154 void OBActions::leaveHandler(const XCrossingEvent
&e
)
156 OtkEventHandler::leaveHandler(e
);
158 OBWidget
*w
= dynamic_cast<OBWidget
*>
159 (Openbox::instance
->findHandler(e
.window
));
161 // run the LEAVE python hook
162 doCallback(Action_LeaveWindow
, e
.window
,
163 (OBWidget::WidgetType
)(w
? w
->type():-1), e
.state
, 0, 0, 0, 0);
167 void OBActions::keyPressHandler(const XKeyEvent
&e
)
169 // OBWidget *w = dynamic_cast<OBWidget*>
170 // (Openbox::instance->findHandler(e.window));
172 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
173 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
174 Openbox::instance
->bindings()->fireKey(state
, e
.keycode
, e
.time
);
178 void OBActions::motionHandler(const XMotionEvent
&e
)
180 if (!e
.same_screen
) return; // this just gets stupid
182 int x_root
= e
.x_root
, y_root
= e
.y_root
;
184 // compress changes to a window into a single change
186 while (XCheckTypedEvent(otk::OBDisplay::display
, e
.type
, &ce
)) {
187 if (ce
.xmotion
.window
!= e
.window
) {
188 XPutBackEvent(otk::OBDisplay::display
, &ce
);
196 OBWidget
*w
= dynamic_cast<OBWidget
*>
197 (Openbox::instance
->findHandler(e
.window
));
198 assert(w
); // everything should be a widget
200 // run the MOTION python hook
201 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
202 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
203 unsigned int button
= _posqueue
[0]->button
;
204 MotionData
*data
= new_motion_data(e
.window
, e
.time
, state
, button
,
205 w
->mcontext(), MouseMotion
,
206 x_root
, y_root
, _posqueue
[0]->pos
,
207 _posqueue
[0]->clientarea
);
208 Openbox::instance
->bindings()->fireButton((ButtonData
*)data
);
209 Py_DECREF((PyObject
*)data
);
212 void OBActions::mapRequestHandler(const XMapRequestEvent
&e
)
214 doCallback(Action_NewWindow
, e
.window
, (OBWidget::WidgetType
)-1,
218 void OBActions::unmapHandler(const XUnmapEvent
&e
)
221 doCallback(Action_CloseWindow
, e
.window
, (OBWidget::WidgetType
)-1,
225 void OBActions::destroyHandler(const XDestroyWindowEvent
&e
)
228 doCallback(Action_CloseWindow
, e
.window
, (OBWidget::WidgetType
)-1,
232 void OBActions::doCallback(ActionType action
, Window window
,
233 OBWidget::WidgetType type
, unsigned int state
,
234 unsigned int button
, int xroot
, int yroot
,
237 std::pair
<CallbackMap::iterator
, CallbackMap::iterator
> it_pair
=
238 _callbacks
.equal_range(action
);
240 CallbackMap::iterator it
;
241 // for (it = it_pair.first; it != it_pair.second; ++it)
242 // python_callback(it->second, action, window, type, state,
243 // button, xroot, yroot, time);
247 bool OBActions::registerCallback(ActionType action
, PyObject
*func
,
250 if (action
< 0 || action
>= OBActions::NUM_ACTIONS
) {
256 std::pair
<CallbackMap::iterator
, CallbackMap::iterator
> it_pair
=
257 _callbacks
.equal_range(action
);
259 CallbackMap::iterator it
;
260 for (it
= it_pair
.first
; it
!= it_pair
.second
; ++it
)
261 if (it
->second
== func
)
262 return true; // already in there
264 _callbacks
.insert(_callbacks
.begin(), CallbackMapPair(action
, func
));
266 _callbacks
.insert(CallbackMapPair(action
, func
));
271 bool OBActions::unregisterCallback(ActionType action
, PyObject
*func
)
273 if (action
< 0 || action
>= OBActions::NUM_ACTIONS
) {
279 std::pair
<CallbackMap::iterator
, CallbackMap::iterator
> it_pair
=
280 _callbacks
.equal_range(action
);
282 CallbackMap::iterator it
;
283 for (it
= it_pair
.first
; it
!= it_pair
.second
; ++it
)
284 if (it
->second
== func
)
286 if (it
!= it_pair
.second
) { // its been registered before
288 _callbacks
.erase(it
);
293 bool OBActions::unregisterAllCallbacks(ActionType action
)
295 if (action
< 0 || action
>= OBActions::NUM_ACTIONS
) {
299 while (!_callbacks
.empty()) {
300 CallbackMap::iterator it
= _callbacks
.begin();
301 Py_DECREF(it
->second
);
302 _callbacks
.erase(it
);
This page took 0.046606 seconds and 4 git commands to generate.