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 // if it's not defined, they should have clicked on the root window, so this
49 // area would be meaningless anyways
50 if (c) a->clientarea = c->area();
53 void OBActions::removePress(const XButtonEvent &e)
55 ButtonPressAction *a = 0;
56 for (int i=0; i<BUTTONS; ++i) {
57 if (_posqueue[i]->button == e.button)
59 if (a) // found one and removed it
60 _posqueue[i] = _posqueue[i+1];
63 _posqueue[BUTTONS-1] = a;
68 void OBActions::buttonPressHandler(const XButtonEvent &e)
70 OtkEventHandler::buttonPressHandler(e);
73 // XXX: run the PRESS guile hook
74 OBWidget *w = dynamic_cast<OBWidget*>
75 (Openbox::instance->findHandler(e.window));
77 printf("GUILE: PRESS: win %lx type %d modifiers %u button %u time %lx\n",
78 (long)e.window, (w ? w->type():-1), e.state, e.button, e.time);
80 if (_button) return; // won't count toward CLICK events
86 void OBActions::buttonReleaseHandler(const XButtonEvent &e)
88 OtkEventHandler::buttonReleaseHandler(e);
91 // XXX: run the RELEASE guile hook
92 OBWidget *w = dynamic_cast<OBWidget*>
93 (Openbox::instance->findHandler(e.window));
95 printf("GUILE: RELEASE: win %lx type %d, modifiers %u button %u time %lx\n",
96 (long)e.window, (w ? w->type():-1), e.state, e.button, e.time);
98 // not for the button we're watching?
99 if (_button != e.button) return;
103 // find the area of the window
104 XWindowAttributes attr;
105 if (!XGetWindowAttributes(otk::OBDisplay::display, e.window, &attr)) return;
107 // if not on the window any more, it isnt a CLICK
108 if (!(e.same_screen && e.x >= 0 && e.y >= 0 &&
109 e.x < attr.width && e.y < attr.height))
112 // XXX: run the CLICK guile hook
113 printf("GUILE: CLICK: win %lx type %d modifiers %u button %u time %lx\n",
114 (long)e.window, (w ? w->type():-1), e.state, e.button, e.time);
116 if (e.time - _release.time < DOUBLECLICKDELAY &&
117 _release.win == e.window && _release.button == e.button) {
119 // XXX: run the DOUBLECLICK guile hook
120 printf("GUILE: DOUBLECLICK: win %lx type %d modifiers %u button %u time %lx\n",
121 (long)e.window, (w ? w->type():-1), e.state, e.button, e.time);
123 // reset so you cant triple click for 2 doubleclicks
128 // save the button release, might be part of a double click
129 _release.win = e.window;
130 _release.button = e.button;
131 _release.time = e.time;
136 void OBActions::enterHandler(const XCrossingEvent &e)
138 OtkEventHandler::enterHandler(e);
140 // XXX: run the ENTER guile hook
141 OBWidget *w = dynamic_cast<OBWidget*>
142 (Openbox::instance->findHandler(e.window));
144 printf("GUILE: ENTER: win %lx type %d modifiers %u\n",
145 (long)e.window, (w ? w->type():-1), e.state);
149 void OBActions::leaveHandler(const XCrossingEvent &e)
151 OtkEventHandler::leaveHandler(e);
153 // XXX: run the LEAVE guile hook
154 OBWidget *w = dynamic_cast<OBWidget*>
155 (Openbox::instance->findHandler(e.window));
157 printf("GUILE: LEAVE: win %lx type %d modifiers %u\n",
158 (long)e.window, (w ? w->type():-1), e.state);
162 void OBActions::keyPressHandler(const XKeyEvent &e)
164 // XXX: run the KEY guile hook
165 OBWidget *w = dynamic_cast<OBWidget*>
166 (Openbox::instance->findHandler(e.window));
168 printf("GUILE: KEY: win %lx type %d modifiers %u keycode %u\n",
169 (long)e.window, (w ? w->type():-1), e.state, e.keycode);
173 void OBActions::motionHandler(const XMotionEvent &e)
175 if (!e.same_screen) return; // this just gets stupid
177 int x_root = e.x_root, y_root = e.y_root;
179 // compress changes to a window into a single change
181 while (XCheckTypedEvent(otk::OBDisplay::display, e.type, &ce)) {
182 if (ce.xmotion.window != e.window) {
183 XPutBackEvent(otk::OBDisplay::display, &ce);
192 OBWidget *w = dynamic_cast<OBWidget*>
193 (Openbox::instance->findHandler(e.window));
195 _dx = x_root - _posqueue[0]->pos.x();
196 _dy = y_root - _posqueue[0]->pos.y();
198 // XXX: i can envision all sorts of crazy shit with this.. gestures, etc
199 printf("GUILE: MOTION: win %lx type %d modifiers %u x %d y %d\n",
200 (long)e.window, (w ? w->type():-1), e.state, _dx, _dy);
202 OBClient *c = Openbox::instance->findClient(e.window);
205 case OBWidget::Type_Titlebar:
206 case OBWidget::Type_Label:
207 c->move(_posqueue[0]->clientarea.x() + _dx,
208 _posqueue[0]->clientarea.y() + _dy);
210 case OBWidget::Type_LeftGrip:
211 c->resize(OBClient::TopRight,
212 _posqueue[0]->clientarea.width() - _dx,
213 _posqueue[0]->clientarea.height() + _dy);
215 case OBWidget::Type_RightGrip:
216 c->resize(OBClient::TopLeft,
217 _posqueue[0]->clientarea.width() + _dx,
218 _posqueue[0]->clientarea.height() + _dy);