1 // -*- mode: C++; indent-tabs-mode: nil; -*-
4 # include "../config.h"
11 #include "otk/display.hh"
17 const unsigned int OBActions::DOUBLECLICKDELAY = 300;
18 const int OBActions::BUTTONS;
20 OBActions::OBActions()
23 for (int i=0; i<BUTTONS; ++i)
24 _posqueue[i] = new ButtonPressAction();
26 // XXX: load a configuration out of somewhere
31 OBActions::~OBActions()
33 for (int i=0; i<BUTTONS; ++i)
38 void OBActions::insertPress(const XButtonEvent &e)
40 ButtonPressAction *a = _posqueue[BUTTONS - 1];
41 for (int i=BUTTONS-1; i>0;)
42 _posqueue[i] = _posqueue[--i];
45 a->pos.setPoint(e.x, e.y);
48 void OBActions::removePress(const XButtonEvent &e)
50 ButtonPressAction *a = 0;
51 for (int i=0; i<BUTTONS; ++i) {
52 if (_posqueue[i]->button == e.button)
54 if (a) // found one and removed it
55 _posqueue[i] = _posqueue[i+1];
58 _posqueue[BUTTONS-1] = a;
63 void OBActions::buttonPressHandler(const XButtonEvent &e)
65 OtkEventHandler::buttonPressHandler(e);
68 // XXX: run the PRESS guile hook
69 OBWidget *w = dynamic_cast<OBWidget*>
70 (Openbox::instance->findHandler(e.window));
72 printf("GUILE: PRESS: win %lx type %d modifiers %u button %u time %lx\n",
73 (long)e.window, (w ? w->type():-1), e.state, e.button, e.time);
75 if (_button) return; // won't count toward CLICK events
81 void OBActions::buttonReleaseHandler(const XButtonEvent &e)
83 OtkEventHandler::buttonReleaseHandler(e);
86 // XXX: run the RELEASE guile hook
87 OBWidget *w = dynamic_cast<OBWidget*>
88 (Openbox::instance->findHandler(e.window));
90 printf("GUILE: RELEASE: win %lx type %d, modifiers %u button %u time %lx\n",
91 (long)e.window, (w ? w->type():-1), e.state, e.button, e.time);
93 // not for the button we're watching?
94 if (_button != e.button) return;
98 // find the area of the window
99 XWindowAttributes attr;
100 if (!XGetWindowAttributes(otk::OBDisplay::display, e.window, &attr)) return;
102 // if not on the window any more, it isnt a CLICK
103 if (!(e.same_screen && e.x >= 0 && e.y >= 0 &&
104 e.x < attr.width && e.y < attr.height))
107 // XXX: run the CLICK guile hook
108 printf("GUILE: CLICK: win %lx type %d modifiers %u button %u time %lx\n",
109 (long)e.window, (w ? w->type():-1), e.state, e.button, e.time);
111 if (e.time - _release.time < DOUBLECLICKDELAY &&
112 _release.win == e.window && _release.button == e.button) {
114 // XXX: run the DOUBLECLICK guile hook
115 printf("GUILE: DOUBLECLICK: win %lx type %d modifiers %u button %u time %lx\n",
116 (long)e.window, (w ? w->type():-1), e.state, e.button, e.time);
118 // reset so you cant triple click for 2 doubleclicks
123 // save the button release, might be part of a double click
124 _release.win = e.window;
125 _release.button = e.button;
126 _release.time = e.time;
131 void OBActions::enterHandler(const XCrossingEvent &e)
133 OtkEventHandler::enterHandler(e);
135 // XXX: run the ENTER guile hook
136 OBWidget *w = dynamic_cast<OBWidget*>
137 (Openbox::instance->findHandler(e.window));
139 printf("GUILE: ENTER: win %lx type %d modifiers %u\n",
140 (long)e.window, (w ? w->type():-1), e.state);
144 void OBActions::leaveHandler(const XCrossingEvent &e)
146 OtkEventHandler::leaveHandler(e);
148 // XXX: run the LEAVE guile hook
149 OBWidget *w = dynamic_cast<OBWidget*>
150 (Openbox::instance->findHandler(e.window));
152 printf("GUILE: LEAVE: win %lx type %d modifiers %u\n",
153 (long)e.window, (w ? w->type():-1), e.state);
157 void OBActions::keyPressHandler(const XKeyEvent &e)
159 // XXX: run the KEY guile hook
160 OBWidget *w = dynamic_cast<OBWidget*>
161 (Openbox::instance->findHandler(e.window));
163 printf("GUILE: KEY: win %lx type %d modifiers %u keycode %u\n",
164 (long)e.window, (w ? w->type():-1), e.state, e.keycode);
168 void OBActions::motionHandler(const XMotionEvent &e)
170 if (!e.same_screen) return; // this just gets stupid
172 OBWidget *w = dynamic_cast<OBWidget*>
173 (Openbox::instance->findHandler(e.window));
175 _dx = e.x - _posqueue[0]->pos.x();
176 _dy = e.y - _posqueue[0]->pos.y();
178 // XXX: i can envision all sorts of crazy shit with this.. gestures, etc
179 printf("GUILE: MOTION: win %lx type %d modifiers %u x %d y %d\n",
180 (long)e.window, (w ? w->type():-1), e.state, _dx, _dy);
182 if (w && (w->type() == OBWidget::Type_Titlebar ||
183 w->type() == OBWidget::Type_Label)) {
184 OBClient *c = Openbox::instance->findClient(e.window);
185 if (c) c->move(c->area().x() + _dx, c->area().y() + _dy);