]>
Dogcows Code - chaz/openbox/blob - src/actions.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
8 #include "widgetbase.hh"
13 #include "bindings.hh"
14 #include "otk/display.hh"
20 const int OBActions::BUTTONS
;
22 OBActions::OBActions()
25 for (int i
=0; i
<BUTTONS
; ++i
)
26 _posqueue
[i
] = new ButtonPressAction();
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_root
, e
.y_root
);
46 OBClient
*c
= Openbox::instance
->findClient(e
.window
);
47 if (c
) a
->clientarea
= c
->area();
50 void OBActions::removePress(const XButtonEvent
&e
)
52 ButtonPressAction
*a
= 0;
53 for (int i
=0; i
<BUTTONS
; ++i
) {
54 if (_posqueue
[i
]->button
== e
.button
)
56 if (a
) // found one and removed it
57 _posqueue
[i
] = _posqueue
[i
+1];
60 _posqueue
[BUTTONS
-1] = a
;
65 void OBActions::buttonPressHandler(const XButtonEvent
&e
)
67 OtkEventHandler::buttonPressHandler(e
);
70 // run the PRESS python hook
71 OBWidget
*w
= dynamic_cast<OBWidget
*>
72 (Openbox::instance
->findHandler(e
.window
));
73 assert(w
); // everything should be a widget
75 // kill off the Button1Mask etc, only want the modifiers
76 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
77 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
79 OBClient
*c
= Openbox::instance
->findClient(e
.window
);
83 screen
= otk::OBDisplay::findScreen(e
.root
)->screen();
84 MouseData
data(screen
, c
, e
.time
, state
, e
.button
, w
->mcontext(),
86 Openbox::instance
->bindings()->fireButton(&data
);
88 if (_button
) return; // won't count toward CLICK events
94 void OBActions::buttonReleaseHandler(const XButtonEvent
&e
)
96 OtkEventHandler::buttonReleaseHandler(e
);
99 OBWidget
*w
= dynamic_cast<OBWidget
*>
100 (Openbox::instance
->findHandler(e
.window
));
101 assert(w
); // everything should be a widget
103 // not for the button we're watching?
104 if (_button
!= e
.button
) return;
108 // find the area of the window
109 XWindowAttributes attr
;
110 if (!XGetWindowAttributes(otk::OBDisplay::display
, e
.window
, &attr
)) return;
112 // if not on the window any more, it isnt a CLICK
113 if (!(e
.same_screen
&& e
.x
>= 0 && e
.y
>= 0 &&
114 e
.x
< attr
.width
&& e
.y
< attr
.height
))
117 // run the CLICK python hook
118 // kill off the Button1Mask etc, only want the modifiers
119 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
120 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
122 OBClient
*c
= Openbox::instance
->findClient(e
.window
);
124 screen
= c
->screen();
126 screen
= otk::OBDisplay::findScreen(e
.root
)->screen();
127 MouseData
data(screen
, c
, e
.time
, state
, e
.button
, w
->mcontext(),
129 Openbox::instance
->bindings()->fireButton(&data
);
132 // XXX: dont load this every time!!@*
134 if (!python_get_long("double_click_delay", &dblclick
))
137 if (e
.time
- _release
.time
< (unsigned)dblclick
&&
138 _release
.win
== e
.window
&& _release
.button
== e
.button
) {
140 // run the DOUBLECLICK python hook
141 data
.action
= MouseDoubleClick
;
142 Openbox::instance
->bindings()->fireButton(&data
);
144 // reset so you cant triple click for 2 doubleclicks
149 // save the button release, might be part of a double click
150 _release
.win
= e
.window
;
151 _release
.button
= e
.button
;
152 _release
.time
= e
.time
;
157 void OBActions::enterHandler(const XCrossingEvent
&e
)
159 OtkEventHandler::enterHandler(e
);
161 // run the ENTER python hook
163 OBClient
*c
= Openbox::instance
->findClient(e
.window
);
165 screen
= c
->screen();
167 screen
= otk::OBDisplay::findScreen(e
.root
)->screen();
168 EventData
data(screen
, c
, EventEnterWindow
, e
.state
);
169 Openbox::instance
->bindings()->fireEvent(&data
);
173 void OBActions::leaveHandler(const XCrossingEvent
&e
)
175 OtkEventHandler::leaveHandler(e
);
177 // run the LEAVE python hook
179 OBClient
*c
= Openbox::instance
->findClient(e
.window
);
181 screen
= c
->screen();
183 screen
= otk::OBDisplay::findScreen(e
.root
)->screen();
184 EventData
data(screen
, c
, EventLeaveWindow
, e
.state
);
185 Openbox::instance
->bindings()->fireEvent(&data
);
189 void OBActions::keyPressHandler(const XKeyEvent
&e
)
191 OtkEventHandler::keyPressHandler(e
);
193 // kill off the Button1Mask etc, only want the modifiers
194 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
195 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
196 Openbox::instance
->bindings()->
197 fireKey(otk::OBDisplay::findScreen(e
.root
)->screen(),
198 state
, e
.keycode
, e
.time
);
202 void OBActions::motionHandler(const XMotionEvent
&e
)
204 OtkEventHandler::motionHandler(e
);
206 if (!e
.same_screen
) return; // this just gets stupid
208 int x_root
= e
.x_root
, y_root
= e
.y_root
;
210 // compress changes to a window into a single change
212 while (XCheckTypedEvent(otk::OBDisplay::display
, e
.type
, &ce
)) {
213 if (ce
.xmotion
.window
!= e
.window
) {
214 XPutBackEvent(otk::OBDisplay::display
, &ce
);
222 OBWidget
*w
= dynamic_cast<OBWidget
*>
223 (Openbox::instance
->findHandler(e
.window
));
224 assert(w
); // everything should be a widget
226 // run the MOTION python hook
227 // kill off the Button1Mask etc, only want the modifiers
228 unsigned int state
= e
.state
& (ControlMask
| ShiftMask
| Mod1Mask
|
229 Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
);
230 unsigned int button
= _posqueue
[0]->button
;
232 OBClient
*c
= Openbox::instance
->findClient(e
.window
);
234 screen
= c
->screen();
236 screen
= otk::OBDisplay::findScreen(e
.root
)->screen();
237 MouseData
data(screen
, c
, e
.time
, state
, button
, w
->mcontext(), MouseMotion
,
238 x_root
, y_root
, _posqueue
[0]->pos
, _posqueue
[0]->clientarea
);
239 Openbox::instance
->bindings()->fireButton(&data
);
242 void OBActions::mapRequestHandler(const XMapRequestEvent
&e
)
244 OtkEventHandler::mapRequestHandler(e
);
245 // do this in OBScreen::manageWindow
248 void OBActions::unmapHandler(const XUnmapEvent
&e
)
250 OtkEventHandler::unmapHandler(e
);
251 // do this in OBScreen::unmanageWindow
254 void OBActions::destroyHandler(const XDestroyWindowEvent
&e
)
256 OtkEventHandler::destroyHandler(e
);
257 // do this in OBScreen::unmanageWindow
261 void OBActions::xkbHandler(const XkbEvent
&e
)
266 OtkEventHandler::xkbHandler(e
);
268 switch (((XkbAnyEvent
*)&e
)->xkb_type
) {
270 w
= ((XkbBellNotifyEvent
*)&e
)->window
;
271 OBClient
*c
= Openbox::instance
->findClient(w
);
273 screen
= c
->screen();
275 screen
= Openbox::instance
->focusedScreen()->number();
276 EventData
data(screen
, c
, EventBell
, 0);
277 Openbox::instance
->bindings()->fireEvent(&data
);
This page took 0.050964 seconds and 4 git commands to generate.