]>
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 int OBActions::BUTTONS
;
21 OBActions::OBActions()
24 for (int i
=0; i
<BUTTONS
; ++i
)
25 _posqueue
[i
] = new ButtonPressAction();
29 OBActions::~OBActions()
31 for (int i
=0; i
<BUTTONS
; ++i
)
36 void OBActions::insertPress(const XButtonEvent
&e
)
38 ButtonPressAction
*a
= _posqueue
[BUTTONS
- 1];
39 for (int i
=BUTTONS
-1; i
>0;)
40 _posqueue
[i
] = _posqueue
[--i
];
43 a
->pos
.setPoint(e
.x_root
, e
.y_root
);
45 OBClient
*c
= Openbox::instance
->findClient(e
.window
);
46 if (c
) a
->clientarea
= c
->area();
49 void OBActions::removePress(const XButtonEvent
&e
)
51 ButtonPressAction
*a
= 0;
52 for (int i
=0; i
<BUTTONS
; ++i
) {
53 if (_posqueue
[i
]->button
== e
.button
)
55 if (a
) // found one and removed it
56 _posqueue
[i
] = _posqueue
[i
+1];
59 _posqueue
[BUTTONS
-1] = a
;
64 void OBActions::buttonPressHandler(const XButtonEvent
&e
)
66 OtkEventHandler::buttonPressHandler(e
);
69 // run the PRESS python hook
70 OBWidget
*w
= dynamic_cast<OBWidget
*>
71 (Openbox::instance
->findHandler(e
.window
));
72 assert(w
); // everything should be a widget
74 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
75 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
76 ButtonData
*data
= new_button_data(e
.window
, e
.time
, state
, e
.button
,
77 w
->mcontext(), MousePress
);
78 Openbox::instance
->bindings()->fireButton(data
);
79 Py_DECREF((PyObject
*)data
);
81 if (_button
) return; // won't count toward CLICK events
87 void OBActions::buttonReleaseHandler(const XButtonEvent
&e
)
89 OtkEventHandler::buttonReleaseHandler(e
);
92 OBWidget
*w
= dynamic_cast<OBWidget
*>
93 (Openbox::instance
->findHandler(e
.window
));
94 assert(w
); // everything should be a widget
96 // not for the button we're watching?
97 if (_button
!= e
.button
) return;
101 // find the area of the window
102 XWindowAttributes attr
;
103 if (!XGetWindowAttributes(otk::OBDisplay::display
, e
.window
, &attr
)) return;
105 // if not on the window any more, it isnt a CLICK
106 if (!(e
.same_screen
&& e
.x
>= 0 && e
.y
>= 0 &&
107 e
.x
< attr
.width
&& e
.y
< attr
.height
))
110 // run the CLICK python hook
111 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
112 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
113 ButtonData
*data
= new_button_data(e
.window
, e
.time
, state
, e
.button
,
114 w
->mcontext(), MouseClick
);
115 Openbox::instance
->bindings()->fireButton(data
);
118 // XXX: dont load this every time!!@*
120 if (!python_get_long("double_click_delay", &dblclick
))
123 if (e
.time
- _release
.time
< (unsigned)dblclick
&&
124 _release
.win
== e
.window
&& _release
.button
== e
.button
) {
126 // run the DOUBLECLICK python hook
127 data
->action
= MouseDoubleClick
;
128 Openbox::instance
->bindings()->fireButton(data
);
130 // reset so you cant triple click for 2 doubleclicks
135 // save the button release, might be part of a double click
136 _release
.win
= e
.window
;
137 _release
.button
= e
.button
;
138 _release
.time
= e
.time
;
141 Py_DECREF((PyObject
*)data
);
145 void OBActions::enterHandler(const XCrossingEvent
&e
)
147 OtkEventHandler::enterHandler(e
);
149 // run the ENTER python hook
150 EventData
*data
= new_event_data(e
.window
, EventEnterWindow
, e
.state
);
151 Openbox::instance
->bindings()->fireEvent(data
);
152 Py_DECREF((PyObject
*)data
);
156 void OBActions::leaveHandler(const XCrossingEvent
&e
)
158 OtkEventHandler::leaveHandler(e
);
160 // run the LEAVE python hook
161 EventData
*data
= new_event_data(e
.window
, EventLeaveWindow
, e
.state
);
162 Openbox::instance
->bindings()->fireEvent(data
);
163 Py_DECREF((PyObject
*)data
);
167 void OBActions::keyPressHandler(const XKeyEvent
&e
)
169 OtkEventHandler::keyPressHandler(e
);
171 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
172 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
173 Openbox::instance
->bindings()->fireKey(state
, e
.keycode
, e
.time
);
177 void OBActions::motionHandler(const XMotionEvent
&e
)
179 OtkEventHandler::motionHandler(e
);
181 if (!e
.same_screen
) return; // this just gets stupid
183 int x_root
= e
.x_root
, y_root
= e
.y_root
;
185 // compress changes to a window into a single change
187 while (XCheckTypedEvent(otk::OBDisplay::display
, e
.type
, &ce
)) {
188 if (ce
.xmotion
.window
!= e
.window
) {
189 XPutBackEvent(otk::OBDisplay::display
, &ce
);
197 OBWidget
*w
= dynamic_cast<OBWidget
*>
198 (Openbox::instance
->findHandler(e
.window
));
199 assert(w
); // everything should be a widget
201 // run the MOTION python hook
202 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
203 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
204 unsigned int button
= _posqueue
[0]->button
;
205 MotionData
*data
= new_motion_data(e
.window
, e
.time
, state
, button
,
206 w
->mcontext(), MouseMotion
,
207 x_root
, y_root
, _posqueue
[0]->pos
,
208 _posqueue
[0]->clientarea
);
209 Openbox::instance
->bindings()->fireButton((ButtonData
*)data
);
210 Py_DECREF((PyObject
*)data
);
213 void OBActions::mapRequestHandler(const XMapRequestEvent
&e
)
215 OtkEventHandler::mapRequestHandler(e
);
217 EventData
*data
= new_event_data(e
.window
, EventNewWindow
, 0);
218 Openbox::instance
->bindings()->fireEvent(data
);
219 Py_DECREF((PyObject
*)data
);
222 void OBActions::unmapHandler(const XUnmapEvent
&e
)
224 OtkEventHandler::unmapHandler(e
);
226 EventData
*data
= new_event_data(e
.window
, EventCloseWindow
, 0);
227 Openbox::instance
->bindings()->fireEvent(data
);
228 Py_DECREF((PyObject
*)data
);
231 void OBActions::destroyHandler(const XDestroyWindowEvent
&e
)
233 OtkEventHandler::destroyHandler(e
);
235 EventData
*data
= new_event_data(e
.window
, EventCloseWindow
, 0);
236 Openbox::instance
->bindings()->fireEvent(data
);
237 Py_DECREF((PyObject
*)data
);
This page took 0.045645 seconds and 4 git commands to generate.