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 int OBActions::BUTTONS;
21 OBActions::OBActions()
24 for (int i=0; i<BUTTONS; ++i)
25 _posqueue[i] = new ButtonPressAction();
27 for (int i = 0; i < NUM_EVENTS; ++i)
32 OBActions::~OBActions()
34 for (int i=0; i<BUTTONS; ++i)
39 void OBActions::insertPress(const XButtonEvent &e)
41 ButtonPressAction *a = _posqueue[BUTTONS - 1];
42 for (int i=BUTTONS-1; i>0;)
43 _posqueue[i] = _posqueue[--i];
46 a->pos.setPoint(e.x_root, e.y_root);
48 OBClient *c = Openbox::instance->findClient(e.window);
49 if (c) a->clientarea = c->area();
52 void OBActions::removePress(const XButtonEvent &e)
54 ButtonPressAction *a = 0;
55 for (int i=0; i<BUTTONS; ++i) {
56 if (_posqueue[i]->button == e.button)
58 if (a) // found one and removed it
59 _posqueue[i] = _posqueue[i+1];
62 _posqueue[BUTTONS-1] = a;
67 void OBActions::buttonPressHandler(const XButtonEvent &e)
69 OtkEventHandler::buttonPressHandler(e);
72 // run the PRESS python hook
73 OBWidget *w = dynamic_cast<OBWidget*>
74 (Openbox::instance->findHandler(e.window));
75 assert(w); // everything should be a widget
77 unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask |
78 Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
79 ButtonData *data = new_button_data(e.window, e.time, state, e.button,
80 w->mcontext(), MousePress);
81 Openbox::instance->bindings()->fireButton(data);
82 Py_DECREF((PyObject*)data);
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));
97 assert(w); // everything should be a widget
99 // not for the button we're watching?
100 if (_button != e.button) return;
104 // find the area of the window
105 XWindowAttributes attr;
106 if (!XGetWindowAttributes(otk::OBDisplay::display, e.window, &attr)) return;
108 // if not on the window any more, it isnt a CLICK
109 if (!(e.same_screen && e.x >= 0 && e.y >= 0 &&
110 e.x < attr.width && e.y < attr.height))
113 // run the CLICK python hook
114 unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask |
115 Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
116 ButtonData *data = new_button_data(e.window, e.time, state, e.button,
117 w->mcontext(), MouseClick);
118 Openbox::instance->bindings()->fireButton(data);
121 // XXX: dont load this every time!!@*
123 if (!python_get_long("double_click_delay", &dblclick))
126 if (e.time - _release.time < (unsigned)dblclick &&
127 _release.win == e.window && _release.button == e.button) {
129 // run the DOUBLECLICK python hook
130 data->action = MouseDoubleClick;
131 Openbox::instance->bindings()->fireButton(data);
133 // reset so you cant triple click for 2 doubleclicks
138 // save the button release, might be part of a double click
139 _release.win = e.window;
140 _release.button = e.button;
141 _release.time = e.time;
144 Py_DECREF((PyObject*)data);
148 void OBActions::enterHandler(const XCrossingEvent &e)
150 OtkEventHandler::enterHandler(e);
152 // run the ENTER python hook
153 if (_callback[EventEnterWindow]) {
154 EventData *data = new_event_data(e.window, EventEnterWindow, e.state);
155 python_callback(_callback[EventEnterWindow], (PyObject*)data);
156 Py_DECREF((PyObject*)data);
161 void OBActions::leaveHandler(const XCrossingEvent &e)
163 OtkEventHandler::leaveHandler(e);
165 // run the LEAVE python hook
166 if (_callback[EventLeaveWindow]) {
167 EventData *data = new_event_data(e.window, EventLeaveWindow, e.state);
168 python_callback(_callback[EventLeaveWindow], (PyObject*)data);
169 Py_DECREF((PyObject*)data);
174 void OBActions::keyPressHandler(const XKeyEvent &e)
176 OtkEventHandler::keyPressHandler(e);
178 unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask |
179 Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
180 Openbox::instance->bindings()->fireKey(state, e.keycode, e.time);
184 void OBActions::motionHandler(const XMotionEvent &e)
186 OtkEventHandler::motionHandler(e);
188 if (!e.same_screen) return; // this just gets stupid
190 int x_root = e.x_root, y_root = e.y_root;
192 // compress changes to a window into a single change
194 while (XCheckTypedEvent(otk::OBDisplay::display, e.type, &ce)) {
195 if (ce.xmotion.window != e.window) {
196 XPutBackEvent(otk::OBDisplay::display, &ce);
204 OBWidget *w = dynamic_cast<OBWidget*>
205 (Openbox::instance->findHandler(e.window));
206 assert(w); // everything should be a widget
208 // run the MOTION python hook
209 unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask |
210 Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
211 unsigned int button = _posqueue[0]->button;
212 MotionData *data = new_motion_data(e.window, e.time, state, button,
213 w->mcontext(), MouseMotion,
214 x_root, y_root, _posqueue[0]->pos,
215 _posqueue[0]->clientarea);
216 Openbox::instance->bindings()->fireButton((ButtonData*)data);
217 Py_DECREF((PyObject*)data);
220 void OBActions::mapRequestHandler(const XMapRequestEvent &e)
222 OtkEventHandler::mapRequestHandler(e);
224 if (_callback[EventNewWindow]) {
225 EventData *data = new_event_data(e.window, EventNewWindow, 0);
226 python_callback(_callback[EventNewWindow], (PyObject*)data);
227 Py_DECREF((PyObject*)data);
231 void OBActions::unmapHandler(const XUnmapEvent &e)
233 OtkEventHandler::unmapHandler(e);
235 if (_callback[EventCloseWindow]) {
236 EventData *data = new_event_data(e.window, EventCloseWindow, 0);
237 python_callback(_callback[EventCloseWindow], (PyObject*)data);
238 Py_DECREF((PyObject*)data);
242 void OBActions::destroyHandler(const XDestroyWindowEvent &e)
244 OtkEventHandler::destroyHandler(e);
246 if (_callback[EventCloseWindow]) {
247 EventData *data = new_event_data(e.window, EventCloseWindow, 0);
248 python_callback(_callback[EventCloseWindow], (PyObject*)data);
249 Py_DECREF((PyObject*)data);
253 bool OBActions::bind(EventAction action, PyObject *func)
255 if (action < 0 || action >= NUM_EVENTS) {
259 Py_XDECREF(_callback[action]);
260 _callback[action] = func;
265 bool OBActions::unbind(EventAction action)
267 if (action < 0 || action >= NUM_EVENTS) {
271 Py_XDECREF(_callback[action]);
272 _callback[action] = 0;
276 void OBActions::unbindAll()
278 for (int i = 0; i < NUM_EVENTS; ++i) {
279 Py_XDECREF(_callback[i]);