]> icculus.org git repositories - dana/openbox.git/blob - src/actions.cc
add click_raise global var
[dana/openbox.git] / src / actions.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2
3 #ifdef HAVE_CONFIG_H
4 # include "../config.h"
5 #endif
6
7 #include "actions.hh"
8 #include "widget.hh"
9 #include "openbox.hh"
10 #include "client.hh"
11 #include "python.hh"
12 #include "bindings.hh"
13 #include "otk/display.hh"
14
15 #include <stdio.h>
16
17 namespace ob {
18
19 const unsigned int OBActions::DOUBLECLICKDELAY = 300;
20
21 OBActions::OBActions()
22   : _button(0)
23 {
24   // XXX: load a configuration out of somewhere
25
26 }
27
28
29 OBActions::~OBActions()
30 {
31 }
32
33
34 void OBActions::buttonPressHandler(const XButtonEvent &e)
35 {
36   OtkEventHandler::buttonPressHandler(e);
37   
38   // run the PRESS python hook
39   OBWidget *w = dynamic_cast<OBWidget*>
40     (Openbox::instance->findHandler(e.window));
41
42   python_callback(Action_ButtonPress, e.window,
43                   (OBWidget::WidgetType)(w ? w->type():-1),
44                   e.state, e.button, e.x_root, e.y_root, e.time);
45     
46   if (_button) return; // won't count toward CLICK events
47
48   _button = e.button;
49 }
50   
51
52 void OBActions::buttonReleaseHandler(const XButtonEvent &e)
53 {
54   OtkEventHandler::buttonReleaseHandler(e);
55   
56   OBWidget *w = dynamic_cast<OBWidget*>
57     (Openbox::instance->findHandler(e.window));
58
59   // run the RELEASE python hook
60   python_callback(Action_ButtonRelease, e.window,
61                   (OBWidget::WidgetType)(w ? w->type():-1),
62                   e.state, e.button, e.x_root, e.y_root, e.time);
63
64   // not for the button we're watching?
65   if (_button != e.button) return;
66
67   _button = 0;
68
69   // find the area of the window
70   XWindowAttributes attr;
71   if (!XGetWindowAttributes(otk::OBDisplay::display, e.window, &attr)) return;
72
73   // if not on the window any more, it isnt a CLICK
74   if (!(e.same_screen && e.x >= 0 && e.y >= 0 &&
75         e.x < attr.width && e.y < attr.height))
76     return;
77
78   // run the CLICK python hook
79   python_callback(Action_Click, e.window,
80                   (OBWidget::WidgetType)(w ? w->type():-1),
81                   e.state, e.button, e.time);
82
83   if (e.time - _release.time < DOUBLECLICKDELAY &&
84       _release.win == e.window && _release.button == e.button) {
85
86     // run the DOUBLECLICK python hook
87     python_callback(Action_DoubleClick, e.window,
88                   (OBWidget::WidgetType)(w ? w->type():-1),
89                   e.state, e.button, e.time);
90     
91     // reset so you cant triple click for 2 doubleclicks
92     _release.win = 0;
93     _release.button = 0;
94     _release.time = 0;
95   } else {
96     // save the button release, might be part of a double click
97     _release.win = e.window;
98     _release.button = e.button;
99     _release.time = e.time;
100   }
101 }
102
103
104 void OBActions::enterHandler(const XCrossingEvent &e)
105 {
106   OtkEventHandler::enterHandler(e);
107   
108   OBWidget *w = dynamic_cast<OBWidget*>
109     (Openbox::instance->findHandler(e.window));
110
111   // run the ENTER python hook
112   python_callback(Action_EnterWindow, e.window,
113                   (OBWidget::WidgetType)(w ? w->type():-1), e.state);
114 }
115
116
117 void OBActions::leaveHandler(const XCrossingEvent &e)
118 {
119   OtkEventHandler::leaveHandler(e);
120
121   OBWidget *w = dynamic_cast<OBWidget*>
122     (Openbox::instance->findHandler(e.window));
123
124   // run the LEAVE python hook
125   python_callback(Action_LeaveWindow, e.window,
126                   (OBWidget::WidgetType)(w ? w->type():-1), e.state);
127 }
128
129
130 void OBActions::keyPressHandler(const XKeyEvent &e)
131 {
132 //  OBWidget *w = dynamic_cast<OBWidget*>
133 //    (Openbox::instance->findHandler(e.window));
134
135   Openbox::instance->bindings()->fire(e.window, e.state, e.keycode, e.time);
136 }
137
138
139 void OBActions::motionHandler(const XMotionEvent &e)
140 {
141   if (!e.same_screen) return; // this just gets stupid
142
143   int x_root = e.x_root, y_root = e.y_root;
144   
145   // compress changes to a window into a single change
146   XEvent ce;
147   while (XCheckTypedEvent(otk::OBDisplay::display, e.type, &ce)) {
148     if (ce.xmotion.window != e.window) {
149       XPutBackEvent(otk::OBDisplay::display, &ce);
150       break;
151     } else {
152       x_root = e.x_root;
153       y_root = e.y_root;
154     }
155   }
156
157
158   OBWidget *w = dynamic_cast<OBWidget*>
159     (Openbox::instance->findHandler(e.window));
160
161   // XXX: i can envision all sorts of crazy shit with this.. gestures, etc
162   //      maybe that should all be done via python tho.. (or radial menus!)
163   // run the simple MOTION python hook for now...
164   python_callback(Action_MouseMotion, e.window,
165                   (OBWidget::WidgetType)(w ? w->type():-1),
166                   e.state, e.x_root, e.y_root, e.time);
167 }
168
169 void OBActions::mapRequestHandler(const XMapRequestEvent &e)
170 {
171 }
172
173 void OBActions::unmapHandler(const XUnmapEvent &e)
174 {
175 }
176
177 void OBActions::destroyHandler(const XDestroyWindowEvent &e)
178 {
179 }
180
181 }