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_root, e.y_root);
47 OBClient *c = Openbox::instance->findClient(e.window);
48 a->clientarea = c->area();
51 void OBActions::removePress(const XButtonEvent &e)
53 ButtonPressAction *a = 0;
54 for (int i=0; i<BUTTONS; ++i) {
55 if (_posqueue[i]->button == e.button)
57 if (a) // found one and removed it
58 _posqueue[i] = _posqueue[i+1];
61 _posqueue[BUTTONS-1] = a;
66 void OBActions::buttonPressHandler(const XButtonEvent &e)
68 OtkEventHandler::buttonPressHandler(e);
71 // XXX: run the PRESS guile hook
72 OBWidget *w = dynamic_cast<OBWidget*>
73 (Openbox::instance->findHandler(e.window));
75 printf("GUILE: PRESS: win %lx type %d modifiers %u button %u time %lx\n",
76 (long)e.window, (w ? w->type():-1), e.state, e.button, e.time);
78 if (_button) return; // won't count toward CLICK events
84 void OBActions::buttonReleaseHandler(const XButtonEvent &e)
86 OtkEventHandler::buttonReleaseHandler(e);
89 // XXX: run the RELEASE guile hook
90 OBWidget *w = dynamic_cast<OBWidget*>
91 (Openbox::instance->findHandler(e.window));
93 printf("GUILE: RELEASE: win %lx type %d, modifiers %u button %u time %lx\n",
94 (long)e.window, (w ? w->type():-1), e.state, e.button, e.time);
96 // not for the button we're watching?
97 if (_button != e.button) return;
101 // find the area of the window
102 XWindowAttributes attr;
103 if (!XGetWindowAttributes(otk::OBDisplay::display, e.window, &attr)) return;
105 // if not on the window any more, it isnt a CLICK
106 if (!(e.same_screen && e.x >= 0 && e.y >= 0 &&
107 e.x < attr.width && e.y < attr.height))
110 // XXX: run the CLICK guile hook
111 printf("GUILE: CLICK: win %lx type %d modifiers %u button %u time %lx\n",
112 (long)e.window, (w ? w->type():-1), e.state, e.button, e.time);
114 if (e.time - _release.time < DOUBLECLICKDELAY &&
115 _release.win == e.window && _release.button == e.button) {
117 // XXX: run the DOUBLECLICK guile hook
118 printf("GUILE: DOUBLECLICK: win %lx type %d modifiers %u button %u time %lx\n",
119 (long)e.window, (w ? w->type():-1), e.state, e.button, e.time);
121 // reset so you cant triple click for 2 doubleclicks
126 // save the button release, might be part of a double click
127 _release.win = e.window;
128 _release.button = e.button;
129 _release.time = e.time;
134 void OBActions::enterHandler(const XCrossingEvent &e)
136 OtkEventHandler::enterHandler(e);
138 // XXX: run the ENTER guile hook
139 OBWidget *w = dynamic_cast<OBWidget*>
140 (Openbox::instance->findHandler(e.window));
142 printf("GUILE: ENTER: win %lx type %d modifiers %u\n",
143 (long)e.window, (w ? w->type():-1), e.state);
147 void OBActions::leaveHandler(const XCrossingEvent &e)
149 OtkEventHandler::leaveHandler(e);
151 // XXX: run the LEAVE guile hook
152 OBWidget *w = dynamic_cast<OBWidget*>
153 (Openbox::instance->findHandler(e.window));
155 printf("GUILE: LEAVE: win %lx type %d modifiers %u\n",
156 (long)e.window, (w ? w->type():-1), e.state);
160 void OBActions::keyPressHandler(const XKeyEvent &e)
162 // XXX: run the KEY guile hook
163 OBWidget *w = dynamic_cast<OBWidget*>
164 (Openbox::instance->findHandler(e.window));
166 printf("GUILE: KEY: win %lx type %d modifiers %u keycode %u\n",
167 (long)e.window, (w ? w->type():-1), e.state, e.keycode);
171 void OBActions::motionHandler(const XMotionEvent &e)
173 if (!e.same_screen) return; // this just gets stupid
175 int x_root = e.x_root, y_root = e.y_root;
177 // compress changes to a window into a single change
179 while (XCheckTypedEvent(otk::OBDisplay::display, e.type, &ce)) {
180 if (ce.xmotion.window != e.window) {
181 XPutBackEvent(otk::OBDisplay::display, &ce);
190 OBWidget *w = dynamic_cast<OBWidget*>
191 (Openbox::instance->findHandler(e.window));
193 _dx = x_root - _posqueue[0]->pos.x();
194 _dy = y_root - _posqueue[0]->pos.y();
196 // XXX: i can envision all sorts of crazy shit with this.. gestures, etc
197 printf("GUILE: MOTION: win %lx type %d modifiers %u x %d y %d\n",
198 (long)e.window, (w ? w->type():-1), e.state, _dx, _dy);
200 OBClient *c = Openbox::instance->findClient(e.window);
203 case OBWidget::Type_Titlebar:
204 case OBWidget::Type_Label:
205 c->move(_posqueue[0]->clientarea.x() + _dx,
206 _posqueue[0]->clientarea.y() + _dy);
208 case OBWidget::Type_LeftGrip:
209 c->resize(OBClient::TopRight,
210 _posqueue[0]->clientarea.width() - _dx,
211 _posqueue[0]->clientarea.height() + _dy);
213 case OBWidget::Type_RightGrip:
214 c->resize(OBClient::TopLeft,
215 _posqueue[0]->clientarea.width() + _dx,
216 _posqueue[0]->clientarea.height() + _dy);