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