1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
8 #include "widgetbase.hh"
13 #include "bindings.hh"
14 #include "otk/display.hh"
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 // rm'd the last one, shift them all down one
41 for (int i = BUTTONS-1; i > 0; --i) {
42 _posqueue[i] = _posqueue[i-1];
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)
55 ButtonPressAction *a = 0;
56 for (i=0; i<BUTTONS-1; ++i)
57 if (_posqueue[i]->button == e.button) {
61 if (a) { // found one, remove it and shift the rest up one
62 for (; i < BUTTONS-1; ++i)
63 _posqueue[i] = _posqueue[i+1];
64 _posqueue[BUTTONS-1] = a;
66 _posqueue[BUTTONS-1]->button = 0;
69 void OBActions::buttonPressHandler(const XButtonEvent &e)
71 OtkEventHandler::buttonPressHandler(e);
74 // run the PRESS python hook
75 OBWidget *w = dynamic_cast<OBWidget*>
76 (Openbox::instance->findHandler(e.window));
77 assert(w); // everything should be a widget
79 // kill off the Button1Mask etc, only want the modifiers
80 unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask |
81 Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
83 OBClient *c = Openbox::instance->findClient(e.window);
87 screen = otk::OBDisplay::findScreen(e.root)->screen();
88 MouseData data(screen, c, e.time, state, e.button, w->mcontext(),
90 Openbox::instance->bindings()->fireButton(&data);
92 if (_button) return; // won't count toward CLICK events
96 if (w->mcontext() == MC_Window) {
98 Because of how events are grabbed on the client window, we can't get
99 ButtonRelease events, so instead we simply manufacture them here, so that
100 clicks/doubleclicks etc still work.
102 //XButtonEvent ev = e;
103 //ev.type = ButtonRelease;
104 buttonReleaseHandler(e);
109 void OBActions::buttonReleaseHandler(const XButtonEvent &e)
111 OtkEventHandler::buttonReleaseHandler(e);
114 OBWidget *w = dynamic_cast<OBWidget*>
115 (Openbox::instance->findHandler(e.window));
116 assert(w); // everything should be a widget
118 // not for the button we're watching?
119 if (_button != e.button) return;
123 // find the area of the window
124 XWindowAttributes attr;
125 if (!XGetWindowAttributes(otk::OBDisplay::display, e.window, &attr)) return;
127 // if not on the window any more, it isnt a CLICK
128 if (!(e.same_screen && e.x >= 0 && e.y >= 0 &&
129 e.x < attr.width && e.y < attr.height))
132 // run the CLICK python hook
133 // kill off the Button1Mask etc, only want the modifiers
134 unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask |
135 Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
137 OBClient *c = Openbox::instance->findClient(e.window);
139 screen = c->screen();
141 screen = otk::OBDisplay::findScreen(e.root)->screen();
142 MouseData data(screen, c, e.time, state, e.button, w->mcontext(),
144 Openbox::instance->bindings()->fireButton(&data);
147 // XXX: dont load this every time!!@*
149 if (!python_get_long("double_click_delay", &dblclick))
152 if (e.time - _release.time < (unsigned)dblclick &&
153 _release.win == e.window && _release.button == e.button) {
155 // run the DOUBLECLICK python hook
156 data.action = MouseDoubleClick;
157 Openbox::instance->bindings()->fireButton(&data);
159 // reset so you cant triple click for 2 doubleclicks
164 // save the button release, might be part of a double click
165 _release.win = e.window;
166 _release.button = e.button;
167 _release.time = e.time;
172 void OBActions::enterHandler(const XCrossingEvent &e)
174 OtkEventHandler::enterHandler(e);
176 // run the ENTER python hook
178 OBClient *c = Openbox::instance->findClient(e.window);
180 screen = c->screen();
182 screen = otk::OBDisplay::findScreen(e.root)->screen();
183 EventData data(screen, c, EventEnterWindow, e.state);
184 Openbox::instance->bindings()->fireEvent(&data);
188 void OBActions::leaveHandler(const XCrossingEvent &e)
190 OtkEventHandler::leaveHandler(e);
192 // run the LEAVE python hook
194 OBClient *c = Openbox::instance->findClient(e.window);
196 screen = c->screen();
198 screen = otk::OBDisplay::findScreen(e.root)->screen();
199 EventData data(screen, c, EventLeaveWindow, e.state);
200 Openbox::instance->bindings()->fireEvent(&data);
204 void OBActions::keyPressHandler(const XKeyEvent &e)
206 OtkEventHandler::keyPressHandler(e);
208 // kill off the Button1Mask etc, only want the modifiers
209 unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask |
210 Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
211 Openbox::instance->bindings()->
212 fireKey(otk::OBDisplay::findScreen(e.root)->screen(),
213 state, e.keycode, e.time);
217 void OBActions::motionHandler(const XMotionEvent &e)
219 OtkEventHandler::motionHandler(e);
221 if (!e.same_screen) return; // this just gets stupid
223 int x_root = e.x_root, y_root = e.y_root;
225 // compress changes to a window into a single change
227 while (XCheckTypedEvent(otk::OBDisplay::display, e.type, &ce)) {
228 if (ce.xmotion.window != e.window) {
229 XPutBackEvent(otk::OBDisplay::display, &ce);
237 OBWidget *w = dynamic_cast<OBWidget*>
238 (Openbox::instance->findHandler(e.window));
239 assert(w); // everything should be a widget
241 // run the MOTION python hook
242 // kill off the Button1Mask etc, only want the modifiers
243 unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask |
244 Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
245 unsigned int button = _posqueue[0]->button;
247 OBClient *c = Openbox::instance->findClient(e.window);
249 screen = c->screen();
251 screen = otk::OBDisplay::findScreen(e.root)->screen();
252 MouseData data(screen, c, e.time, state, button, w->mcontext(), MouseMotion,
253 x_root, y_root, _posqueue[0]->pos, _posqueue[0]->clientarea);
254 Openbox::instance->bindings()->fireButton(&data);
257 void OBActions::mapRequestHandler(const XMapRequestEvent &e)
259 OtkEventHandler::mapRequestHandler(e);
260 // do this in OBScreen::manageWindow
263 void OBActions::unmapHandler(const XUnmapEvent &e)
265 OtkEventHandler::unmapHandler(e);
266 // do this in OBScreen::unmanageWindow
269 void OBActions::destroyHandler(const XDestroyWindowEvent &e)
271 OtkEventHandler::destroyHandler(e);
272 // do this in OBScreen::unmanageWindow
276 void OBActions::xkbHandler(const XkbEvent &e)
281 OtkEventHandler::xkbHandler(e);
283 switch (((XkbAnyEvent*)&e)->xkb_type) {
285 w = ((XkbBellNotifyEvent*)&e)->window;
286 OBClient *c = Openbox::instance->findClient(w);
288 screen = c->screen();
290 screen = Openbox::instance->focusedScreen()->number();
291 EventData data(screen, c, EventBell, 0);
292 Openbox::instance->bindings()->fireEvent(&data);