]>
Dogcows Code - chaz/openbox/blob - src/actions.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
12 #include "bindings.hh"
13 #include "otk/display.hh"
19 const unsigned int OBActions::DOUBLECLICKDELAY
= 300;
21 OBActions::OBActions()
24 // XXX: load a configuration out of somewhere
29 OBActions::~OBActions()
34 void OBActions::buttonPressHandler(const XButtonEvent
&e
)
36 OtkEventHandler::buttonPressHandler(e
);
38 // run the PRESS guile hook
39 OBWidget
*w
= dynamic_cast<OBWidget
*>
40 (Openbox::instance
->findHandler(e
.window
));
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 if (w
&& w
->type() == OBWidget::Type_Frame
) // a binding
46 Openbox::instance
->bindings()->fire(Action_ButtonPress
, e
.window
,
47 e
.state
, e
.button
, e
.time
);
49 if (_button
) return; // won't count toward CLICK events
55 void OBActions::buttonReleaseHandler(const XButtonEvent
&e
)
57 OtkEventHandler::buttonReleaseHandler(e
);
59 OBWidget
*w
= dynamic_cast<OBWidget
*>
60 (Openbox::instance
->findHandler(e
.window
));
62 // run the RELEASE guile hook
63 python_callback(Action_ButtonRelease
, e
.window
,
64 (OBWidget::WidgetType
)(w
? w
->type():-1),
65 e
.state
, e
.button
, e
.x_root
, e
.y_root
, e
.time
);
66 if (w
&& w
->type() == OBWidget::Type_Frame
) // a binding
67 Openbox::instance
->bindings()->fire(Action_ButtonRelease
, e
.window
,
68 e
.state
, e
.button
, e
.time
);
70 // not for the button we're watching?
71 if (_button
!= e
.button
) return;
75 // find the area of the window
76 XWindowAttributes attr
;
77 if (!XGetWindowAttributes(otk::OBDisplay::display
, e
.window
, &attr
)) return;
79 // if not on the window any more, it isnt a CLICK
80 if (!(e
.same_screen
&& e
.x
>= 0 && e
.y
>= 0 &&
81 e
.x
< attr
.width
&& e
.y
< attr
.height
))
84 // run the CLICK guile hook
85 python_callback(Action_Click
, e
.window
,
86 (OBWidget::WidgetType
)(w
? w
->type():-1),
87 e
.state
, e
.button
, e
.time
);
88 if (w
&& w
->type() == OBWidget::Type_Frame
) // a binding
89 Openbox::instance
->bindings()->fire(Action_Click
, e
.window
,
90 e
.state
, e
.button
, e
.time
);
92 if (e
.time
- _release
.time
< DOUBLECLICKDELAY
&&
93 _release
.win
== e
.window
&& _release
.button
== e
.button
) {
95 // run the DOUBLECLICK guile hook
96 python_callback(Action_DoubleClick
, e
.window
,
97 (OBWidget::WidgetType
)(w
? w
->type():-1),
98 e
.state
, e
.button
, e
.time
);
99 if (w
&& w
->type() == OBWidget::Type_Frame
) // a binding
100 Openbox::instance
->bindings()->fire(Action_DoubleClick
, e
.window
,
101 e
.state
, e
.button
, e
.time
);
103 // reset so you cant triple click for 2 doubleclicks
108 // save the button release, might be part of a double click
109 _release
.win
= e
.window
;
110 _release
.button
= e
.button
;
111 _release
.time
= e
.time
;
116 void OBActions::enterHandler(const XCrossingEvent
&e
)
118 OtkEventHandler::enterHandler(e
);
120 OBWidget
*w
= dynamic_cast<OBWidget
*>
121 (Openbox::instance
->findHandler(e
.window
));
123 // run the ENTER guile hook
124 python_callback(Action_EnterWindow
, e
.window
,
125 (OBWidget::WidgetType
)(w
? w
->type():-1), e
.state
);
129 void OBActions::leaveHandler(const XCrossingEvent
&e
)
131 OtkEventHandler::leaveHandler(e
);
133 OBWidget
*w
= dynamic_cast<OBWidget
*>
134 (Openbox::instance
->findHandler(e
.window
));
136 // run the LEAVE guile hook
137 python_callback(Action_LeaveWindow
, e
.window
,
138 (OBWidget::WidgetType
)(w
? w
->type():-1), e
.state
);
142 void OBActions::keyPressHandler(const XKeyEvent
&e
)
144 // OBWidget *w = dynamic_cast<OBWidget*>
145 // (Openbox::instance->findHandler(e.window));
147 Openbox::instance
->bindings()->fire(Action_KeyPress
, e
.window
,
148 e
.state
, e
.keycode
, e
.time
);
152 void OBActions::motionHandler(const XMotionEvent
&e
)
154 if (!e
.same_screen
) return; // this just gets stupid
156 int x_root
= e
.x_root
, y_root
= e
.y_root
;
158 // compress changes to a window into a single change
160 while (XCheckTypedEvent(otk::OBDisplay::display
, e
.type
, &ce
)) {
161 if (ce
.xmotion
.window
!= e
.window
) {
162 XPutBackEvent(otk::OBDisplay::display
, &ce
);
171 OBWidget
*w
= dynamic_cast<OBWidget
*>
172 (Openbox::instance
->findHandler(e
.window
));
174 // XXX: i can envision all sorts of crazy shit with this.. gestures, etc
175 // maybe that should all be done via python tho..
176 // run the simple MOTION guile hook for now...
177 python_callback(Action_MouseMotion
, e
.window
,
178 (OBWidget::WidgetType
)(w
? w
->type():-1),
179 e
.state
, e
.x_root
, e
.y_root
, e
.time
);
This page took 0.041083 seconds and 4 git commands to generate.