]>
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;
21 OBActions::OBActions()
24 // XXX: load a configuration out of somewhere
29 OBActions::~OBActions()
34 void OBActions::buttonPressHandler(const XButtonEvent
&e
)
36 OtkEventHandler::buttonPressHandler(e
);
38 // run the PRESS python hook
39 OBWidget
*w
= dynamic_cast<OBWidget
*>
40 (Openbox::instance
->findHandler(e
.window
));
42 doCallback(Action_ButtonPress
, e
.window
,
43 (OBWidget::WidgetType
)(w
? w
->type():-1),
44 e
.state
, e
.button
, e
.x_root
, e
.y_root
, e
.time
);
46 if (_button
) return; // won't count toward CLICK events
52 void OBActions::buttonReleaseHandler(const XButtonEvent
&e
)
54 OtkEventHandler::buttonReleaseHandler(e
);
56 OBWidget
*w
= dynamic_cast<OBWidget
*>
57 (Openbox::instance
->findHandler(e
.window
));
59 // not for the button we're watching?
60 if (_button
!= e
.button
) return;
64 // find the area of the window
65 XWindowAttributes attr
;
66 if (!XGetWindowAttributes(otk::OBDisplay::display
, e
.window
, &attr
)) return;
68 // if not on the window any more, it isnt a CLICK
69 if (!(e
.same_screen
&& e
.x
>= 0 && e
.y
>= 0 &&
70 e
.x
< attr
.width
&& e
.y
< attr
.height
))
73 // run the CLICK python hook
74 doCallback(Action_Click
, e
.window
,
75 (OBWidget::WidgetType
)(w
? w
->type():-1),
76 e
.state
, e
.button
, e
.x_root
, e
.y_root
, e
.time
);
78 if (e
.time
- _release
.time
< DOUBLECLICKDELAY
&&
79 _release
.win
== e
.window
&& _release
.button
== e
.button
) {
81 // run the DOUBLECLICK python hook
82 doCallback(Action_DoubleClick
, e
.window
,
83 (OBWidget::WidgetType
)(w
? w
->type():-1),
84 e
.state
, e
.button
, e
.x_root
, e
.y_root
, e
.time
);
86 // reset so you cant triple click for 2 doubleclicks
91 // save the button release, might be part of a double click
92 _release
.win
= e
.window
;
93 _release
.button
= e
.button
;
94 _release
.time
= e
.time
;
99 void OBActions::enterHandler(const XCrossingEvent
&e
)
101 OtkEventHandler::enterHandler(e
);
103 OBWidget
*w
= dynamic_cast<OBWidget
*>
104 (Openbox::instance
->findHandler(e
.window
));
106 // run the ENTER python hook
107 doCallback(Action_EnterWindow
, e
.window
,
108 (OBWidget::WidgetType
)(w
? w
->type():-1), e
.state
, 0, 0, 0, 0);
112 void OBActions::leaveHandler(const XCrossingEvent
&e
)
114 OtkEventHandler::leaveHandler(e
);
116 OBWidget
*w
= dynamic_cast<OBWidget
*>
117 (Openbox::instance
->findHandler(e
.window
));
119 // run the LEAVE python hook
120 doCallback(Action_LeaveWindow
, e
.window
,
121 (OBWidget::WidgetType
)(w
? w
->type():-1), e
.state
, 0, 0, 0, 0);
125 void OBActions::keyPressHandler(const XKeyEvent
&e
)
127 // OBWidget *w = dynamic_cast<OBWidget*>
128 // (Openbox::instance->findHandler(e.window));
130 Openbox::instance
->bindings()->fire(e
.state
, e
.keycode
, e
.time
);
134 void OBActions::motionHandler(const XMotionEvent
&e
)
136 if (!e
.same_screen
) return; // this just gets stupid
138 int x_root
= e
.x_root
, y_root
= e
.y_root
;
140 // compress changes to a window into a single change
142 while (XCheckTypedEvent(otk::OBDisplay::display
, e
.type
, &ce
)) {
143 if (ce
.xmotion
.window
!= e
.window
) {
144 XPutBackEvent(otk::OBDisplay::display
, &ce
);
153 OBWidget
*w
= dynamic_cast<OBWidget
*>
154 (Openbox::instance
->findHandler(e
.window
));
156 // XXX: i can envision all sorts of crazy shit with this.. gestures, etc
157 // maybe that should all be done via python tho.. (or radial menus!)
158 // run the simple MOTION python hook for now...
159 doCallback(Action_MouseMotion
, e
.window
,
160 (OBWidget::WidgetType
)(w
? w
->type():-1),
161 e
.state
, (unsigned)-1, x_root
, y_root
, e
.time
);
164 void OBActions::mapRequestHandler(const XMapRequestEvent
&e
)
166 doCallback(Action_NewWindow
, e
.window
, (OBWidget::WidgetType
)-1,
170 void OBActions::unmapHandler(const XUnmapEvent
&e
)
173 doCallback(Action_CloseWindow
, e
.window
, (OBWidget::WidgetType
)-1,
177 void OBActions::destroyHandler(const XDestroyWindowEvent
&e
)
180 doCallback(Action_CloseWindow
, e
.window
, (OBWidget::WidgetType
)-1,
184 void OBActions::doCallback(ActionType action
, Window window
,
185 OBWidget::WidgetType type
, unsigned int state
,
186 unsigned int button
, int xroot
, int yroot
,
189 std::pair
<CallbackMap::iterator
, CallbackMap::iterator
> it_pair
=
190 _callbacks
.equal_range(action
);
192 CallbackMap::iterator it
;
193 for (it
= it_pair
.first
; it
!= it_pair
.second
; ++it
)
194 python_callback(it
->second
, action
, window
, type
, state
,
195 button
, xroot
, yroot
, time
);
198 bool OBActions::registerCallback(ActionType action
, PyObject
*func
,
201 if (action
< 0 || action
>= OBActions::NUM_ACTIONS
||
202 action
== OBActions::Action_KeyPress
) {
208 std::pair
<CallbackMap::iterator
, CallbackMap::iterator
> it_pair
=
209 _callbacks
.equal_range(action
);
211 CallbackMap::iterator it
;
212 for (it
= it_pair
.first
; it
!= it_pair
.second
; ++it
)
213 if (it
->second
== func
)
214 return true; // already in there
216 _callbacks
.insert(_callbacks
.begin(), CallbackMapPair(action
, func
));
218 _callbacks
.insert(CallbackMapPair(action
, func
));
223 bool OBActions::unregisterCallback(ActionType action
, PyObject
*func
)
225 if (action
< 0 || action
>= OBActions::NUM_ACTIONS
||
226 action
== OBActions::Action_KeyPress
) {
232 std::pair
<CallbackMap::iterator
, CallbackMap::iterator
> it_pair
=
233 _callbacks
.equal_range(action
);
235 CallbackMap::iterator it
;
236 for (it
= it_pair
.first
; it
!= it_pair
.second
; ++it
)
237 if (it
->second
== func
)
239 if (it
!= it_pair
.second
) { // its been registered before
241 _callbacks
.erase(it
);
246 bool OBActions::unregisterAllCallbacks(ActionType action
)
248 if (action
< 0 || action
>= OBActions::NUM_ACTIONS
||
249 action
== OBActions::Action_KeyPress
) {
253 while (!_callbacks
.empty()) {
254 CallbackMap::iterator it
= _callbacks
.begin();
255 Py_DECREF(it
->second
);
256 _callbacks
.erase(it
);
This page took 0.045361 seconds and 4 git commands to generate.