1 // -*- mode: C++; indent-tabs-mode: nil; -*-
4 # include "../config.h"
12 #include "otk/display.hh"
18 const unsigned int OBActions::DOUBLECLICKDELAY = 300;
20 OBActions::OBActions()
23 // XXX: load a configuration out of somewhere
28 OBActions::~OBActions()
33 void OBActions::buttonPressHandler(const XButtonEvent &e)
35 OtkEventHandler::buttonPressHandler(e);
37 // run the PRESS guile hook
38 OBWidget *w = dynamic_cast<OBWidget*>
39 (Openbox::instance->findHandler(e.window));
41 python_callback(Action_ButtonPress, e.window,
42 (OBWidget::WidgetType)(w ? w->type():-1),
43 e.state, e.button, e.x_root, e.y_root, e.time);
45 if (_button) return; // won't count toward CLICK events
51 void OBActions::buttonReleaseHandler(const XButtonEvent &e)
53 OtkEventHandler::buttonReleaseHandler(e);
55 OBWidget *w = dynamic_cast<OBWidget*>
56 (Openbox::instance->findHandler(e.window));
58 // run the RELEASE guile hook
59 python_callback(Action_ButtonRelease, e.window,
60 (OBWidget::WidgetType)(w ? w->type():-1),
61 e.state, e.button, e.x_root, e.y_root, e.time);
63 // not for the button we're watching?
64 if (_button != e.button) return;
68 // find the area of the window
69 XWindowAttributes attr;
70 if (!XGetWindowAttributes(otk::OBDisplay::display, e.window, &attr)) return;
72 // if not on the window any more, it isnt a CLICK
73 if (!(e.same_screen && e.x >= 0 && e.y >= 0 &&
74 e.x < attr.width && e.y < attr.height))
77 // run the CLICK guile hook
78 python_callback(Action_Click, e.window,
79 (OBWidget::WidgetType)(w ? w->type():-1),
80 e.state, e.button, e.time);
82 if (e.time - _release.time < DOUBLECLICKDELAY &&
83 _release.win == e.window && _release.button == e.button) {
85 // run the DOUBLECLICK guile hook
86 python_callback(Action_DoubleClick, e.window,
87 (OBWidget::WidgetType)(w ? w->type():-1),
88 e.state, e.button, e.time);
90 // reset so you cant triple click for 2 doubleclicks
95 // save the button release, might be part of a double click
96 _release.win = e.window;
97 _release.button = e.button;
98 _release.time = e.time;
103 void OBActions::enterHandler(const XCrossingEvent &e)
105 OtkEventHandler::enterHandler(e);
107 OBWidget *w = dynamic_cast<OBWidget*>
108 (Openbox::instance->findHandler(e.window));
110 // run the ENTER guile hook
111 python_callback(Action_EnterWindow, e.window,
112 (OBWidget::WidgetType)(w ? w->type():-1), e.state);
116 void OBActions::leaveHandler(const XCrossingEvent &e)
118 OtkEventHandler::leaveHandler(e);
120 OBWidget *w = dynamic_cast<OBWidget*>
121 (Openbox::instance->findHandler(e.window));
123 // run the LEAVE guile hook
124 python_callback(Action_LeaveWindow, e.window,
125 (OBWidget::WidgetType)(w ? w->type():-1), e.state);
129 void OBActions::keyPressHandler(const XKeyEvent &e)
131 OBWidget *w = dynamic_cast<OBWidget*>
132 (Openbox::instance->findHandler(e.window));
134 // run the KEY guile hook
135 python_callback(Action_KeyPress, e.window,
136 (OBWidget::WidgetType)(w ? w->type():-1),
141 void OBActions::motionHandler(const XMotionEvent &e)
143 if (!e.same_screen) return; // this just gets stupid
145 int x_root = e.x_root, y_root = e.y_root;
147 // compress changes to a window into a single change
149 while (XCheckTypedEvent(otk::OBDisplay::display, e.type, &ce)) {
150 if (ce.xmotion.window != e.window) {
151 XPutBackEvent(otk::OBDisplay::display, &ce);
160 OBWidget *w = dynamic_cast<OBWidget*>
161 (Openbox::instance->findHandler(e.window));
163 // XXX: i can envision all sorts of crazy shit with this.. gestures, etc
164 // maybe that should all be done via python tho..
165 // run the simple MOTION guile hook for now...
166 python_callback(Action_MouseMotion, e.window,
167 (OBWidget::WidgetType)(w ? w->type():-1),
168 e.state, e.x_root, e.y_root, e.time);