]> Dogcows Code - chaz/openbox/blob - src/actions.cc
clarify an incorrect comment, and make some funcs const
[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 // kill off the Button1Mask etc, only want the modifiers
75 unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask |
76 Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
77 ButtonData *data =
78 new_button_data(otk::OBDisplay::findScreen(e.root)->screen(),
79 e.window, e.time, state, e.button, w->mcontext(),
80 MousePress);
81 Openbox::instance->bindings()->fireButton(data);
82 Py_DECREF((PyObject*)data);
83
84 if (_button) return; // won't count toward CLICK events
85
86 _button = e.button;
87 }
88
89
90 void OBActions::buttonReleaseHandler(const XButtonEvent &e)
91 {
92 OtkEventHandler::buttonReleaseHandler(e);
93 removePress(e);
94
95 OBWidget *w = dynamic_cast<OBWidget*>
96 (Openbox::instance->findHandler(e.window));
97 assert(w); // everything should be a widget
98
99 // not for the button we're watching?
100 if (_button != e.button) return;
101
102 _button = 0;
103
104 // find the area of the window
105 XWindowAttributes attr;
106 if (!XGetWindowAttributes(otk::OBDisplay::display, e.window, &attr)) return;
107
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))
111 return;
112
113 // run the CLICK python hook
114 // kill off the Button1Mask etc, only want the modifiers
115 unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask |
116 Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
117 ButtonData *data =
118 new_button_data(otk::OBDisplay::findScreen(e.root)->screen(),
119 e.window, e.time, state, e.button, w->mcontext(),
120 MouseClick);
121 Openbox::instance->bindings()->fireButton(data);
122
123
124 // XXX: dont load this every time!!@*
125 long dblclick;
126 if (!python_get_long("double_click_delay", &dblclick))
127 dblclick = 300;
128
129 if (e.time - _release.time < (unsigned)dblclick &&
130 _release.win == e.window && _release.button == e.button) {
131
132 // run the DOUBLECLICK python hook
133 data->action = MouseDoubleClick;
134 Openbox::instance->bindings()->fireButton(data);
135
136 // reset so you cant triple click for 2 doubleclicks
137 _release.win = 0;
138 _release.button = 0;
139 _release.time = 0;
140 } else {
141 // save the button release, might be part of a double click
142 _release.win = e.window;
143 _release.button = e.button;
144 _release.time = e.time;
145 }
146
147 Py_DECREF((PyObject*)data);
148 }
149
150
151 void OBActions::enterHandler(const XCrossingEvent &e)
152 {
153 OtkEventHandler::enterHandler(e);
154
155 // run the ENTER python hook
156 EventData *data =
157 new_event_data(otk::OBDisplay::findScreen(e.root)->screen(),
158 e.window, EventEnterWindow, e.state);
159 Openbox::instance->bindings()->fireEvent(data);
160 Py_DECREF((PyObject*)data);
161 }
162
163
164 void OBActions::leaveHandler(const XCrossingEvent &e)
165 {
166 OtkEventHandler::leaveHandler(e);
167
168 // run the LEAVE python hook
169 EventData *data =
170 new_event_data(otk::OBDisplay::findScreen(e.root)->screen(),
171 e.window, EventLeaveWindow, e.state);
172 Openbox::instance->bindings()->fireEvent(data);
173 Py_DECREF((PyObject*)data);
174 }
175
176
177 void OBActions::keyPressHandler(const XKeyEvent &e)
178 {
179 OtkEventHandler::keyPressHandler(e);
180
181 // kill off the Button1Mask etc, only want the modifiers
182 unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask |
183 Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
184 Openbox::instance->bindings()->
185 fireKey(otk::OBDisplay::findScreen(e.root)->screen(),
186 state, e.keycode, e.time);
187 }
188
189
190 void OBActions::motionHandler(const XMotionEvent &e)
191 {
192 OtkEventHandler::motionHandler(e);
193
194 if (!e.same_screen) return; // this just gets stupid
195
196 int x_root = e.x_root, y_root = e.y_root;
197
198 // compress changes to a window into a single change
199 XEvent ce;
200 while (XCheckTypedEvent(otk::OBDisplay::display, e.type, &ce)) {
201 if (ce.xmotion.window != e.window) {
202 XPutBackEvent(otk::OBDisplay::display, &ce);
203 break;
204 } else {
205 x_root = e.x_root;
206 y_root = e.y_root;
207 }
208 }
209
210 OBWidget *w = dynamic_cast<OBWidget*>
211 (Openbox::instance->findHandler(e.window));
212 assert(w); // everything should be a widget
213
214 // run the MOTION python hook
215 // kill off the Button1Mask etc, only want the modifiers
216 unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask |
217 Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
218 unsigned int button = _posqueue[0]->button;
219 MotionData *data =
220 new_motion_data(otk::OBDisplay::findScreen(e.root)->screen(),
221 e.window, e.time, state, button, w->mcontext(),
222 MouseMotion, x_root, y_root, _posqueue[0]->pos,
223 _posqueue[0]->clientarea);
224 Openbox::instance->bindings()->fireButton((ButtonData*)data);
225 Py_DECREF((PyObject*)data);
226 }
227
228 void OBActions::mapRequestHandler(const XMapRequestEvent &e)
229 {
230 OtkEventHandler::mapRequestHandler(e);
231 // do this in OBScreen::manageWindow
232 }
233
234 void OBActions::unmapHandler(const XUnmapEvent &e)
235 {
236 OtkEventHandler::unmapHandler(e);
237 // do this in OBScreen::unmanageWindow
238 }
239
240 void OBActions::destroyHandler(const XDestroyWindowEvent &e)
241 {
242 OtkEventHandler::destroyHandler(e);
243 // do this in OBScreen::unmanageWindow
244 }
245
246 }
This page took 0.044356 seconds and 4 git commands to generate.