1 // -*- mode: C++; indent-tabs-mode: nil; -*-
4 # include "../config.h"
10 #include "otk/display.hh"
16 const unsigned int OBActions::DOUBLECLICKDELAY = 300;
17 const int OBActions::BUTTONS;
19 OBActions::OBActions()
22 for (int i=0; i<BUTTONS; ++i)
23 _posqueue[i] = new ButtonPressAction();
25 // XXX: load a configuration out of somewhere
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, e.y);
47 void OBActions::removePress(const XButtonEvent &e)
49 ButtonPressAction *a = 0;
50 for (int i=0; i<BUTTONS; ++i) {
51 if (_posqueue[i]->button == e.button)
53 if (a) // found one and removed it
54 _posqueue[i] = _posqueue[i+1];
57 _posqueue[BUTTONS-1] = a;
62 void OBActions::buttonPressHandler(const XButtonEvent &e)
64 OtkEventHandler::buttonPressHandler(e);
67 // XXX: run the PRESS guile hook
68 OBWidget *w = dynamic_cast<OBWidget*>
69 (Openbox::instance->findHandler(e.window));
71 printf("GUILE: PRESS: win %lx type %d modifiers %u button %u time %lx\n",
72 (long)e.window, (w ? w->type():-1), e.state, e.button, e.time);
74 if (_button) return; // won't count toward CLICK events
80 void OBActions::buttonReleaseHandler(const XButtonEvent &e)
82 OtkEventHandler::buttonReleaseHandler(e);
85 // XXX: run the RELEASE guile hook
86 OBWidget *w = dynamic_cast<OBWidget*>
87 (Openbox::instance->findHandler(e.window));
89 printf("GUILE: RELEASE: win %lx type %d, modifiers %u button %u time %lx\n",
90 (long)e.window, (w ? w->type():-1), e.state, e.button, e.time);
92 // not for the button we're watching?
93 if (_button != e.button) return;
97 // find the area of the window
98 XWindowAttributes attr;
99 if (!XGetWindowAttributes(otk::OBDisplay::display, e.window, &attr)) return;
101 // if not on the window any more, it isnt a CLICK
102 if (!(e.same_screen && e.x >= 0 && e.y >= 0 &&
103 e.x < attr.width && e.y < attr.height))
106 // XXX: run the CLICK guile hook
107 printf("GUILE: CLICK: win %lx type %d modifiers %u button %u time %lx\n",
108 (long)e.window, (w ? w->type():-1), e.state, e.button, e.time);
110 if (e.time - _release.time < DOUBLECLICKDELAY &&
111 _release.win == e.window && _release.button == e.button) {
113 // XXX: run the DOUBLECLICK guile hook
114 printf("GUILE: DOUBLECLICK: win %lx type %d modifiers %u button %u time %lx\n",
115 (long)e.window, (w ? w->type():-1), e.state, e.button, e.time);
117 // reset so you cant triple click for 2 doubleclicks
122 // save the button release, might be part of a double click
123 _release.win = e.window;
124 _release.button = e.button;
125 _release.time = e.time;
130 void OBActions::enterHandler(const XCrossingEvent &e)
132 OtkEventHandler::enterHandler(e);
134 // XXX: run the ENTER guile hook
135 OBWidget *w = dynamic_cast<OBWidget*>
136 (Openbox::instance->findHandler(e.window));
138 printf("GUILE: ENTER: win %lx type %d modifiers %u\n",
139 (long)e.window, (w ? w->type():-1), e.state);
143 void OBActions::leaveHandler(const XCrossingEvent &e)
145 OtkEventHandler::leaveHandler(e);
147 // XXX: run the LEAVE guile hook
148 OBWidget *w = dynamic_cast<OBWidget*>
149 (Openbox::instance->findHandler(e.window));
151 printf("GUILE: LEAVE: win %lx type %d modifiers %u\n",
152 (long)e.window, (w ? w->type():-1), e.state);
156 void OBActions::keyPressHandler(const XKeyEvent &e)
158 // XXX: run the KEY guile hook
159 OBWidget *w = dynamic_cast<OBWidget*>
160 (Openbox::instance->findHandler(e.window));
162 printf("GUILE: KEY: win %lx type %d modifiers %u keycode %u\n",
163 (long)e.window, (w ? w->type():-1), e.state, e.keycode);
167 void OBActions::motionHandler(const XMotionEvent &e)
169 if (!e.same_screen) return; // this just gets stupid
171 OBWidget *w = dynamic_cast<OBWidget*>
172 (Openbox::instance->findHandler(e.window));
174 _dx = e.x - _posqueue[0]->pos.x();
175 _dy = e.y - _posqueue[0]->pos.y();
177 // XXX: i can envision all sorts of crazy shit with this.. gestures, etc
178 printf("GUILE: MOTION: win %lx type %d modifiers %u x %d y %d\n",
179 (long)e.window, (w ? w->type():-1), e.state, _dx, _dy);