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 for (int i=BUTTONS-1; i>0;)
41 _posqueue[i] = _posqueue[--i];
44 a->pos.setPoint(e.x_root, e.y_root);
46 OBClient *c = Openbox::instance->findClient(e.window);
47 if (c) a->clientarea = c->area();
50 void OBActions::removePress(const XButtonEvent &e)
52 ButtonPressAction *a = 0;
53 for (int i=0; i<BUTTONS; ++i) {
54 if (_posqueue[i]->button == e.button)
56 if (a) // found one and removed it
57 _posqueue[i] = _posqueue[i+1];
60 _posqueue[BUTTONS-1] = a;
65 void OBActions::buttonPressHandler(const XButtonEvent &e)
67 OtkEventHandler::buttonPressHandler(e);
70 // run the PRESS python hook
71 OBWidget *w = dynamic_cast<OBWidget*>
72 (Openbox::instance->findHandler(e.window));
73 assert(w); // everything should be a widget
75 // kill off the Button1Mask etc, only want the modifiers
76 unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask |
77 Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
79 OBClient *c = Openbox::instance->findClient(e.window);
83 screen = otk::OBDisplay::findScreen(e.root)->screen();
84 MouseData data(screen, c, e.time, state, e.button, w->mcontext(),
86 Openbox::instance->bindings()->fireButton(&data);
88 if (_button) return; // won't count toward CLICK events
92 if (w->mcontext() == MC_Window) {
94 Because of how events are grabbed on the client window, we can't get
95 ButtonRelease events, so instead we simply manufacture them here, so that
96 clicks/doubleclicks etc still work.
98 //XButtonEvent ev = e;
99 //ev.type = ButtonRelease;
100 buttonReleaseHandler(e);
105 void OBActions::buttonReleaseHandler(const XButtonEvent &e)
107 OtkEventHandler::buttonReleaseHandler(e);
110 OBWidget *w = dynamic_cast<OBWidget*>
111 (Openbox::instance->findHandler(e.window));
112 assert(w); // everything should be a widget
114 // not for the button we're watching?
115 if (_button != e.button) return;
119 // find the area of the window
120 XWindowAttributes attr;
121 if (!XGetWindowAttributes(otk::OBDisplay::display, e.window, &attr)) return;
123 // if not on the window any more, it isnt a CLICK
124 if (!(e.same_screen && e.x >= 0 && e.y >= 0 &&
125 e.x < attr.width && e.y < attr.height))
128 // run the CLICK python hook
129 // kill off the Button1Mask etc, only want the modifiers
130 unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask |
131 Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
133 OBClient *c = Openbox::instance->findClient(e.window);
135 screen = c->screen();
137 screen = otk::OBDisplay::findScreen(e.root)->screen();
138 MouseData data(screen, c, e.time, state, e.button, w->mcontext(),
140 Openbox::instance->bindings()->fireButton(&data);
143 // XXX: dont load this every time!!@*
145 if (!python_get_long("double_click_delay", &dblclick))
148 if (e.time - _release.time < (unsigned)dblclick &&
149 _release.win == e.window && _release.button == e.button) {
151 // run the DOUBLECLICK python hook
152 data.action = MouseDoubleClick;
153 Openbox::instance->bindings()->fireButton(&data);
155 // reset so you cant triple click for 2 doubleclicks
160 // save the button release, might be part of a double click
161 _release.win = e.window;
162 _release.button = e.button;
163 _release.time = e.time;
168 void OBActions::enterHandler(const XCrossingEvent &e)
170 OtkEventHandler::enterHandler(e);
172 // run the ENTER python hook
174 OBClient *c = Openbox::instance->findClient(e.window);
176 screen = c->screen();
178 screen = otk::OBDisplay::findScreen(e.root)->screen();
179 EventData data(screen, c, EventEnterWindow, e.state);
180 Openbox::instance->bindings()->fireEvent(&data);
184 void OBActions::leaveHandler(const XCrossingEvent &e)
186 OtkEventHandler::leaveHandler(e);
188 // run the LEAVE python hook
190 OBClient *c = Openbox::instance->findClient(e.window);
192 screen = c->screen();
194 screen = otk::OBDisplay::findScreen(e.root)->screen();
195 EventData data(screen, c, EventLeaveWindow, e.state);
196 Openbox::instance->bindings()->fireEvent(&data);
200 void OBActions::keyPressHandler(const XKeyEvent &e)
202 OtkEventHandler::keyPressHandler(e);
204 // kill off the Button1Mask etc, only want the modifiers
205 unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask |
206 Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
207 Openbox::instance->bindings()->
208 fireKey(otk::OBDisplay::findScreen(e.root)->screen(),
209 state, e.keycode, e.time);
213 void OBActions::motionHandler(const XMotionEvent &e)
215 OtkEventHandler::motionHandler(e);
217 if (!e.same_screen) return; // this just gets stupid
219 int x_root = e.x_root, y_root = e.y_root;
221 // compress changes to a window into a single change
223 while (XCheckTypedEvent(otk::OBDisplay::display, e.type, &ce)) {
224 if (ce.xmotion.window != e.window) {
225 XPutBackEvent(otk::OBDisplay::display, &ce);
233 OBWidget *w = dynamic_cast<OBWidget*>
234 (Openbox::instance->findHandler(e.window));
235 assert(w); // everything should be a widget
237 // run the MOTION python hook
238 // kill off the Button1Mask etc, only want the modifiers
239 unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask |
240 Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
241 unsigned int button = _posqueue[0]->button;
243 OBClient *c = Openbox::instance->findClient(e.window);
245 screen = c->screen();
247 screen = otk::OBDisplay::findScreen(e.root)->screen();
248 MouseData data(screen, c, e.time, state, button, w->mcontext(), MouseMotion,
249 x_root, y_root, _posqueue[0]->pos, _posqueue[0]->clientarea);
250 Openbox::instance->bindings()->fireButton(&data);
253 void OBActions::mapRequestHandler(const XMapRequestEvent &e)
255 OtkEventHandler::mapRequestHandler(e);
256 // do this in OBScreen::manageWindow
259 void OBActions::unmapHandler(const XUnmapEvent &e)
261 OtkEventHandler::unmapHandler(e);
262 // do this in OBScreen::unmanageWindow
265 void OBActions::destroyHandler(const XDestroyWindowEvent &e)
267 OtkEventHandler::destroyHandler(e);
268 // do this in OBScreen::unmanageWindow
272 void OBActions::xkbHandler(const XkbEvent &e)
277 OtkEventHandler::xkbHandler(e);
279 switch (((XkbAnyEvent*)&e)->xkb_type) {
281 w = ((XkbBellNotifyEvent*)&e)->window;
282 OBClient *c = Openbox::instance->findClient(w);
284 screen = c->screen();
286 screen = Openbox::instance->focusedScreen()->number();
287 EventData data(screen, c, EventBell, 0);
288 Openbox::instance->bindings()->fireEvent(&data);