]>
Dogcows Code - chaz/openbox/blob - src/actions.cc
c04457da726a93fb4590f3609db3db93e2c91724
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
));
74 /* doCallback(Action_ButtonPress, e.window,
75 (OBWidget::WidgetType)(w ? w->type():-1),
76 e.state, e.button, e.x_root, e.y_root, e.time);*/
78 Openbox::instance
->bindings()->fire(MousePress
, w
->type(), e
.window
,
80 e
.x_root
, e
.y_root
, e
.time
);
82 assert(false); // why isnt there a type?
84 if (_button
) return; // won't count toward CLICK events
90 void OBActions::buttonReleaseHandler(const XButtonEvent
&e
)
92 OtkEventHandler::buttonReleaseHandler(e
);
95 OBWidget
*w
= dynamic_cast<OBWidget
*>
96 (Openbox::instance
->findHandler(e
.window
));
98 // not for the button we're watching?
99 if (_button
!= e
.button
) return;
103 // find the area of the window
104 XWindowAttributes attr
;
105 if (!XGetWindowAttributes(otk::OBDisplay::display
, e
.window
, &attr
)) return;
107 // if not on the window any more, it isnt a CLICK
108 if (!(e
.same_screen
&& e
.x
>= 0 && e
.y
>= 0 &&
109 e
.x
< attr
.width
&& e
.y
< attr
.height
))
112 // run the CLICK python hook
113 /* doCallback(Action_Click, e.window,
114 (OBWidget::WidgetType)(w ? w->type():-1),
115 e.state, e.button, e.x_root, e.y_root, e.time);*/
117 Openbox::instance
->bindings()->fire(MouseClick
, w
->type(), e
.window
,
119 e
.x_root
, e
.y_root
, e
.time
);
121 assert(false); // why isnt there a type?
123 if (e
.time
- _release
.time
< DOUBLECLICKDELAY
&&
124 _release
.win
== e
.window
&& _release
.button
== e
.button
) {
126 // run the DOUBLECLICK python hook
127 /* doCallback(Action_DoubleClick, e.window,
128 (OBWidget::WidgetType)(w ? w->type():-1),
129 e.state, e.button, e.x_root, e.y_root, e.time);*/
131 Openbox::instance
->bindings()->fire(MouseDoubleClick
, w
->type(),
132 e
.window
, e
.state
, e
.button
,
133 e
.x_root
, e
.y_root
, e
.time
);
135 assert(false); // why isnt there a type?
137 // reset so you cant triple click for 2 doubleclicks
142 // save the button release, might be part of a double click
143 _release
.win
= e
.window
;
144 _release
.button
= e
.button
;
145 _release
.time
= e
.time
;
150 void OBActions::enterHandler(const XCrossingEvent
&e
)
152 OtkEventHandler::enterHandler(e
);
154 OBWidget
*w
= dynamic_cast<OBWidget
*>
155 (Openbox::instance
->findHandler(e
.window
));
157 // run the ENTER python hook
158 doCallback(Action_EnterWindow
, e
.window
,
159 (OBWidget::WidgetType
)(w
? w
->type():-1), e
.state
, 0, 0, 0, 0);
163 void OBActions::leaveHandler(const XCrossingEvent
&e
)
165 OtkEventHandler::leaveHandler(e
);
167 OBWidget
*w
= dynamic_cast<OBWidget
*>
168 (Openbox::instance
->findHandler(e
.window
));
170 // run the LEAVE python hook
171 doCallback(Action_LeaveWindow
, e
.window
,
172 (OBWidget::WidgetType
)(w
? w
->type():-1), e
.state
, 0, 0, 0, 0);
176 void OBActions::keyPressHandler(const XKeyEvent
&e
)
178 // OBWidget *w = dynamic_cast<OBWidget*>
179 // (Openbox::instance->findHandler(e.window));
181 Openbox::instance
->bindings()->fire(e
.state
, e
.keycode
, e
.time
);
185 void OBActions::motionHandler(const XMotionEvent
&e
)
187 if (!e
.same_screen
) return; // this just gets stupid
189 int x_root
= e
.x_root
, y_root
= e
.y_root
;
191 // compress changes to a window into a single change
193 while (XCheckTypedEvent(otk::OBDisplay::display
, e
.type
, &ce
)) {
194 if (ce
.xmotion
.window
!= e
.window
) {
195 XPutBackEvent(otk::OBDisplay::display
, &ce
);
203 _dx
= x_root
- _posqueue
[0]->pos
.x(); _posqueue
[0]->pos
.setX(x_root
);
204 _dy
= y_root
- _posqueue
[0]->pos
.y(); _posqueue
[0]->pos
.setY(y_root
);
206 OBWidget
*w
= dynamic_cast<OBWidget
*>
207 (Openbox::instance
->findHandler(e
.window
));
209 // XXX: i can envision all sorts of crazy shit with this.. gestures, etc
210 // maybe that should all be done via python tho.. (or radial menus!)
211 // run the simple MOTION python hook for now...
212 /* doCallback(Action_MouseMotion, e.window,
213 (OBWidget::WidgetType)(w ? w->type():-1),
214 e.state, (unsigned)-1, x_root, y_root, e.time);*/
216 Openbox::instance
->bindings()->fire(MouseMotion
, w
->type(), e
.window
,
217 e
.state
, _posqueue
[0]->button
,
220 assert(false); // why isnt there a type?
223 void OBActions::mapRequestHandler(const XMapRequestEvent
&e
)
225 doCallback(Action_NewWindow
, e
.window
, (OBWidget::WidgetType
)-1,
229 void OBActions::unmapHandler(const XUnmapEvent
&e
)
232 doCallback(Action_CloseWindow
, e
.window
, (OBWidget::WidgetType
)-1,
236 void OBActions::destroyHandler(const XDestroyWindowEvent
&e
)
239 doCallback(Action_CloseWindow
, e
.window
, (OBWidget::WidgetType
)-1,
243 void OBActions::doCallback(ActionType action
, Window window
,
244 OBWidget::WidgetType type
, unsigned int state
,
245 unsigned int button
, int xroot
, int yroot
,
248 std::pair
<CallbackMap::iterator
, CallbackMap::iterator
> it_pair
=
249 _callbacks
.equal_range(action
);
251 CallbackMap::iterator it
;
252 // for (it = it_pair.first; it != it_pair.second; ++it)
253 // python_callback(it->second, action, window, type, state,
254 // button, xroot, yroot, time);
258 bool OBActions::registerCallback(ActionType action
, PyObject
*func
,
261 if (action
< 0 || action
>= OBActions::NUM_ACTIONS
) {
267 std::pair
<CallbackMap::iterator
, CallbackMap::iterator
> it_pair
=
268 _callbacks
.equal_range(action
);
270 CallbackMap::iterator it
;
271 for (it
= it_pair
.first
; it
!= it_pair
.second
; ++it
)
272 if (it
->second
== func
)
273 return true; // already in there
275 _callbacks
.insert(_callbacks
.begin(), CallbackMapPair(action
, func
));
277 _callbacks
.insert(CallbackMapPair(action
, func
));
282 bool OBActions::unregisterCallback(ActionType action
, PyObject
*func
)
284 if (action
< 0 || action
>= OBActions::NUM_ACTIONS
) {
290 std::pair
<CallbackMap::iterator
, CallbackMap::iterator
> it_pair
=
291 _callbacks
.equal_range(action
);
293 CallbackMap::iterator it
;
294 for (it
= it_pair
.first
; it
!= it_pair
.second
; ++it
)
295 if (it
->second
== func
)
297 if (it
!= it_pair
.second
) { // its been registered before
299 _callbacks
.erase(it
);
304 bool OBActions::unregisterAllCallbacks(ActionType action
)
306 if (action
< 0 || action
>= OBActions::NUM_ACTIONS
) {
310 while (!_callbacks
.empty()) {
311 CallbackMap::iterator it
= _callbacks
.begin();
312 Py_DECREF(it
->second
);
313 _callbacks
.erase(it
);
This page took 0.045261 seconds and 4 git commands to generate.