]>
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();
48 printf("press %d x:%d y:%d winx:%d winy:%d\n", e
.button
, e
.x_root
, e
.y_root
, c
->area().x(), c
->area().y());
51 void OBActions::removePress(const XButtonEvent
&e
)
53 ButtonPressAction
*a
= 0;
54 for (int i
=0; i
<BUTTONS
; ++i
) {
55 if (_posqueue
[i
]->button
== e
.button
)
57 if (a
) // found one and removed it
58 _posqueue
[i
] = _posqueue
[i
+1];
61 _posqueue
[BUTTONS
-1] = a
;
66 void OBActions::buttonPressHandler(const XButtonEvent
&e
)
68 OtkEventHandler::buttonPressHandler(e
);
71 // run the PRESS python hook
72 OBWidget
*w
= dynamic_cast<OBWidget
*>
73 (Openbox::instance
->findHandler(e
.window
));
74 assert(w
); // everything should be a widget
76 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
77 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
78 ButtonData
*data
= new_button_data(e
.window
, e
.time
, state
, e
.button
,
79 w
->mcontext(), MousePress
);
80 Openbox::instance
->bindings()->fire(data
);
81 Py_DECREF((PyObject
*)data
);
83 if (_button
) return; // won't count toward CLICK events
89 void OBActions::buttonReleaseHandler(const XButtonEvent
&e
)
91 OtkEventHandler::buttonReleaseHandler(e
);
94 OBWidget
*w
= dynamic_cast<OBWidget
*>
95 (Openbox::instance
->findHandler(e
.window
));
96 assert(w
); // everything should be a widget
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 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
114 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
115 ButtonData
*data
= new_button_data(e
.window
, e
.time
, state
, e
.button
,
116 w
->mcontext(), MouseClick
);
117 Openbox::instance
->bindings()->fire(data
);
120 if (e
.time
- _release
.time
< DOUBLECLICKDELAY
&&
121 _release
.win
== e
.window
&& _release
.button
== e
.button
) {
123 // run the DOUBLECLICK python hook
124 data
->action
= MouseDoubleClick
;
125 Openbox::instance
->bindings()->fire(data
);
127 // reset so you cant triple click for 2 doubleclicks
132 // save the button release, might be part of a double click
133 _release
.win
= e
.window
;
134 _release
.button
= e
.button
;
135 _release
.time
= e
.time
;
138 Py_DECREF((PyObject
*)data
);
142 void OBActions::enterHandler(const XCrossingEvent
&e
)
144 OtkEventHandler::enterHandler(e
);
146 OBWidget
*w
= dynamic_cast<OBWidget
*>
147 (Openbox::instance
->findHandler(e
.window
));
149 // run the ENTER python hook
150 doCallback(Action_EnterWindow
, e
.window
,
151 (OBWidget::WidgetType
)(w
? w
->type():-1), e
.state
, 0, 0, 0, 0);
155 void OBActions::leaveHandler(const XCrossingEvent
&e
)
157 OtkEventHandler::leaveHandler(e
);
159 OBWidget
*w
= dynamic_cast<OBWidget
*>
160 (Openbox::instance
->findHandler(e
.window
));
162 // run the LEAVE python hook
163 doCallback(Action_LeaveWindow
, e
.window
,
164 (OBWidget::WidgetType
)(w
? w
->type():-1), e
.state
, 0, 0, 0, 0);
168 void OBActions::keyPressHandler(const XKeyEvent
&e
)
170 // OBWidget *w = dynamic_cast<OBWidget*>
171 // (Openbox::instance->findHandler(e.window));
173 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
174 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
175 Openbox::instance
->bindings()->fire(state
, e
.keycode
, e
.time
);
179 void OBActions::motionHandler(const XMotionEvent
&e
)
181 if (!e
.same_screen
) return; // this just gets stupid
183 int x_root
= e
.x_root
, y_root
= e
.y_root
;
185 // compress changes to a window into a single change
187 while (XCheckTypedEvent(otk::OBDisplay::display
, e
.type
, &ce
)) {
188 if (ce
.xmotion
.window
!= e
.window
) {
189 XPutBackEvent(otk::OBDisplay::display
, &ce
);
197 OBWidget
*w
= dynamic_cast<OBWidget
*>
198 (Openbox::instance
->findHandler(e
.window
));
199 assert(w
); // everything should be a widget
201 // run the MOTION python hook
202 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
203 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
204 unsigned int button
= _posqueue
[0]->button
;
205 printf("motion %d x:%d y:%d winx:%d winy:%d\n", button
, x_root
, y_root
,
206 _posqueue
[0]->clientarea
.x(), _posqueue
[0]->clientarea
.y());
207 MotionData
*data
= new_motion_data(e
.window
, e
.time
, state
, button
,
208 w
->mcontext(), MouseMotion
,
209 x_root
, y_root
, _posqueue
[0]->pos
,
210 _posqueue
[0]->clientarea
);
211 Openbox::instance
->bindings()->fire((ButtonData
*)data
);
212 Py_DECREF((PyObject
*)data
);
215 void OBActions::mapRequestHandler(const XMapRequestEvent
&e
)
217 doCallback(Action_NewWindow
, e
.window
, (OBWidget::WidgetType
)-1,
221 void OBActions::unmapHandler(const XUnmapEvent
&e
)
224 doCallback(Action_CloseWindow
, e
.window
, (OBWidget::WidgetType
)-1,
228 void OBActions::destroyHandler(const XDestroyWindowEvent
&e
)
231 doCallback(Action_CloseWindow
, e
.window
, (OBWidget::WidgetType
)-1,
235 void OBActions::doCallback(ActionType action
, Window window
,
236 OBWidget::WidgetType type
, unsigned int state
,
237 unsigned int button
, int xroot
, int yroot
,
240 std::pair
<CallbackMap::iterator
, CallbackMap::iterator
> it_pair
=
241 _callbacks
.equal_range(action
);
243 CallbackMap::iterator it
;
244 // for (it = it_pair.first; it != it_pair.second; ++it)
245 // python_callback(it->second, action, window, type, state,
246 // button, xroot, yroot, time);
250 bool OBActions::registerCallback(ActionType action
, PyObject
*func
,
253 if (action
< 0 || action
>= OBActions::NUM_ACTIONS
) {
259 std::pair
<CallbackMap::iterator
, CallbackMap::iterator
> it_pair
=
260 _callbacks
.equal_range(action
);
262 CallbackMap::iterator it
;
263 for (it
= it_pair
.first
; it
!= it_pair
.second
; ++it
)
264 if (it
->second
== func
)
265 return true; // already in there
267 _callbacks
.insert(_callbacks
.begin(), CallbackMapPair(action
, func
));
269 _callbacks
.insert(CallbackMapPair(action
, func
));
274 bool OBActions::unregisterCallback(ActionType action
, PyObject
*func
)
276 if (action
< 0 || action
>= OBActions::NUM_ACTIONS
) {
282 std::pair
<CallbackMap::iterator
, CallbackMap::iterator
> it_pair
=
283 _callbacks
.equal_range(action
);
285 CallbackMap::iterator it
;
286 for (it
= it_pair
.first
; it
!= it_pair
.second
; ++it
)
287 if (it
->second
== func
)
289 if (it
!= it_pair
.second
) { // its been registered before
291 _callbacks
.erase(it
);
296 bool OBActions::unregisterAllCallbacks(ActionType action
)
298 if (action
< 0 || action
>= OBActions::NUM_ACTIONS
) {
302 while (!_callbacks
.empty()) {
303 CallbackMap::iterator it
= _callbacks
.begin();
304 Py_DECREF(it
->second
);
305 _callbacks
.erase(it
);
This page took 0.050583 seconds and 4 git commands to generate.