]> Dogcows Code - chaz/openbox/blob - src/actions.cc
put event bindings in OBBindings too
[chaz/openbox] / src / actions.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2
3 #ifdef HAVE_CONFIG_H
4 # include "../config.h"
5 #endif
6
7 #include "actions.hh"
8 #include "widget.hh"
9 #include "openbox.hh"
10 #include "client.hh"
11 #include "python.hh"
12 #include "bindings.hh"
13 #include "otk/display.hh"
14
15 #include <stdio.h>
16
17 namespace ob {
18
19 const int OBActions::BUTTONS;
20
21 OBActions::OBActions()
22 : _button(0)
23 {
24 for (int i=0; i<BUTTONS; ++i)
25 _posqueue[i] = new ButtonPressAction();
26 }
27
28
29 OBActions::~OBActions()
30 {
31 for (int i=0; i<BUTTONS; ++i)
32 delete _posqueue[i];
33 }
34
35
36 void OBActions::insertPress(const XButtonEvent &e)
37 {
38 ButtonPressAction *a = _posqueue[BUTTONS - 1];
39 for (int i=BUTTONS-1; i>0;)
40 _posqueue[i] = _posqueue[--i];
41 _posqueue[0] = a;
42 a->button = e.button;
43 a->pos.setPoint(e.x_root, e.y_root);
44
45 OBClient *c = Openbox::instance->findClient(e.window);
46 if (c) a->clientarea = c->area();
47 }
48
49 void OBActions::removePress(const XButtonEvent &e)
50 {
51 ButtonPressAction *a = 0;
52 for (int i=0; i<BUTTONS; ++i) {
53 if (_posqueue[i]->button == e.button)
54 a = _posqueue[i];
55 if (a) // found one and removed it
56 _posqueue[i] = _posqueue[i+1];
57 }
58 if (a) { // found one
59 _posqueue[BUTTONS-1] = a;
60 a->button = 0;
61 }
62 }
63
64 void OBActions::buttonPressHandler(const XButtonEvent &e)
65 {
66 OtkEventHandler::buttonPressHandler(e);
67 insertPress(e);
68
69 // run the PRESS python hook
70 OBWidget *w = dynamic_cast<OBWidget*>
71 (Openbox::instance->findHandler(e.window));
72 assert(w); // everything should be a widget
73
74 unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask |
75 Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
76 ButtonData *data = new_button_data(e.window, e.time, state, e.button,
77 w->mcontext(), MousePress);
78 Openbox::instance->bindings()->fireButton(data);
79 Py_DECREF((PyObject*)data);
80
81 if (_button) return; // won't count toward CLICK events
82
83 _button = e.button;
84 }
85
86
87 void OBActions::buttonReleaseHandler(const XButtonEvent &e)
88 {
89 OtkEventHandler::buttonReleaseHandler(e);
90 removePress(e);
91
92 OBWidget *w = dynamic_cast<OBWidget*>
93 (Openbox::instance->findHandler(e.window));
94 assert(w); // everything should be a widget
95
96 // not for the button we're watching?
97 if (_button != e.button) return;
98
99 _button = 0;
100
101 // find the area of the window
102 XWindowAttributes attr;
103 if (!XGetWindowAttributes(otk::OBDisplay::display, e.window, &attr)) return;
104
105 // if not on the window any more, it isnt a CLICK
106 if (!(e.same_screen && e.x >= 0 && e.y >= 0 &&
107 e.x < attr.width && e.y < attr.height))
108 return;
109
110 // run the CLICK python hook
111 unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask |
112 Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
113 ButtonData *data = new_button_data(e.window, e.time, state, e.button,
114 w->mcontext(), MouseClick);
115 Openbox::instance->bindings()->fireButton(data);
116
117
118 // XXX: dont load this every time!!@*
119 long dblclick;
120 if (!python_get_long("double_click_delay", &dblclick))
121 dblclick = 300;
122
123 if (e.time - _release.time < (unsigned)dblclick &&
124 _release.win == e.window && _release.button == e.button) {
125
126 // run the DOUBLECLICK python hook
127 data->action = MouseDoubleClick;
128 Openbox::instance->bindings()->fireButton(data);
129
130 // reset so you cant triple click for 2 doubleclicks
131 _release.win = 0;
132 _release.button = 0;
133 _release.time = 0;
134 } else {
135 // save the button release, might be part of a double click
136 _release.win = e.window;
137 _release.button = e.button;
138 _release.time = e.time;
139 }
140
141 Py_DECREF((PyObject*)data);
142 }
143
144
145 void OBActions::enterHandler(const XCrossingEvent &e)
146 {
147 OtkEventHandler::enterHandler(e);
148
149 // run the ENTER python hook
150 EventData *data = new_event_data(e.window, EventEnterWindow, e.state);
151 Openbox::instance->bindings()->fireEvent(data);
152 Py_DECREF((PyObject*)data);
153 }
154
155
156 void OBActions::leaveHandler(const XCrossingEvent &e)
157 {
158 OtkEventHandler::leaveHandler(e);
159
160 // run the LEAVE python hook
161 EventData *data = new_event_data(e.window, EventLeaveWindow, e.state);
162 Openbox::instance->bindings()->fireEvent(data);
163 Py_DECREF((PyObject*)data);
164 }
165
166
167 void OBActions::keyPressHandler(const XKeyEvent &e)
168 {
169 OtkEventHandler::keyPressHandler(e);
170
171 unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask |
172 Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
173 Openbox::instance->bindings()->fireKey(state, e.keycode, e.time);
174 }
175
176
177 void OBActions::motionHandler(const XMotionEvent &e)
178 {
179 OtkEventHandler::motionHandler(e);
180
181 if (!e.same_screen) return; // this just gets stupid
182
183 int x_root = e.x_root, y_root = e.y_root;
184
185 // compress changes to a window into a single change
186 XEvent ce;
187 while (XCheckTypedEvent(otk::OBDisplay::display, e.type, &ce)) {
188 if (ce.xmotion.window != e.window) {
189 XPutBackEvent(otk::OBDisplay::display, &ce);
190 break;
191 } else {
192 x_root = e.x_root;
193 y_root = e.y_root;
194 }
195 }
196
197 OBWidget *w = dynamic_cast<OBWidget*>
198 (Openbox::instance->findHandler(e.window));
199 assert(w); // everything should be a widget
200
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 MotionData *data = new_motion_data(e.window, e.time, state, button,
206 w->mcontext(), MouseMotion,
207 x_root, y_root, _posqueue[0]->pos,
208 _posqueue[0]->clientarea);
209 Openbox::instance->bindings()->fireButton((ButtonData*)data);
210 Py_DECREF((PyObject*)data);
211 }
212
213 void OBActions::mapRequestHandler(const XMapRequestEvent &e)
214 {
215 OtkEventHandler::mapRequestHandler(e);
216
217 EventData *data = new_event_data(e.window, EventNewWindow, 0);
218 Openbox::instance->bindings()->fireEvent(data);
219 Py_DECREF((PyObject*)data);
220 }
221
222 void OBActions::unmapHandler(const XUnmapEvent &e)
223 {
224 OtkEventHandler::unmapHandler(e);
225
226 EventData *data = new_event_data(e.window, EventCloseWindow, 0);
227 Openbox::instance->bindings()->fireEvent(data);
228 Py_DECREF((PyObject*)data);
229 }
230
231 void OBActions::destroyHandler(const XDestroyWindowEvent &e)
232 {
233 OtkEventHandler::destroyHandler(e);
234
235 EventData *data = new_event_data(e.window, EventCloseWindow, 0);
236 Openbox::instance->bindings()->fireEvent(data);
237 Py_DECREF((PyObject*)data);
238 }
239
240 }
This page took 0.045428 seconds and 5 git commands to generate.