1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
11 #include "bindings.hh"
12 #include "otk/display.hh"
30 void Actions::buttonPressHandler(const XButtonEvent &e)
32 otk::EventHandler::buttonPressHandler(e);
34 MouseContext::MC context;
35 EventHandler *h = openbox->findHandler(e.window);
36 Frame *f = dynamic_cast<Frame*>(h);
38 context= f->mouseContext(e.window);
39 else if (dynamic_cast<Client*>(h))
40 context = MouseContext::Window;
41 else if (dynamic_cast<Screen*>(h))
42 context = MouseContext::Root;
44 return; // not a valid mouse context
48 switch(_press.button) {
49 case Button1: mask = Button1Mask; break;
50 case Button2: mask = Button2Mask; break;
51 case Button3: mask = Button3Mask; break;
52 case Button4: mask = Button4Mask; break;
53 case Button5: mask = Button5Mask; break;
54 default: mask = 0; // on other buttons we have to assume its not pressed...
56 // was the button released but we didnt get the event? (pointergrabs cause
58 if (!(e.state & mask))
62 // run the PRESS python hook
63 // kill off the Button1Mask etc, only want the modifiers
64 unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask |
65 Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
67 Client *c = openbox->findClient(e.window);
71 screen = otk::display->findScreen(e.root)->screen();
72 MouseData data(screen, c, e.time, state, e.button, context,
74 openbox->bindings()->fireButton(&data);
76 if (_press.button) return; // won't count toward CLICK events
78 _press.win = e.window;
79 _press.button = e.button;
80 _press.pos = otk::Point(e.x_root, e.y_root);
82 _press.clientarea = c->area();
84 printf("press queue %u pressed %u\n", _press.button, e.button);
86 if (context == MouseContext::Window) {
88 Because of how events are grabbed on the client window, we can't get
89 ButtonRelease events, so instead we simply manufacture them here, so that
90 clicks/doubleclicks etc still work.
92 //XButtonEvent ev = e;
93 //ev.type = ButtonRelease;
94 buttonReleaseHandler(e);
99 void Actions::buttonReleaseHandler(const XButtonEvent &e)
101 otk::EventHandler::buttonReleaseHandler(e);
103 MouseContext::MC context;
104 EventHandler *h = openbox->findHandler(e.window);
105 Frame *f = dynamic_cast<Frame*>(h);
107 context= f->mouseContext(e.window);
108 else if (dynamic_cast<Client*>(h))
109 context = MouseContext::Window;
110 else if (dynamic_cast<Screen*>(h))
111 context = MouseContext::Root;
113 return; // not a valid mouse context
115 // run the RELEASE python hook
116 // kill off the Button1Mask etc, only want the modifiers
117 unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask |
118 Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
120 Client *c = openbox->findClient(e.window);
122 screen = c->screen();
124 screen = otk::display->findScreen(e.root)->screen();
125 MouseData data(screen, c, e.time, state, e.button, context,
126 MouseAction::Release);
127 openbox->bindings()->fireButton(&data);
129 // not for the button we're watching?
130 if (_press.button != e.button) return;
135 // find the area of the window
136 XWindowAttributes attr;
137 if (!XGetWindowAttributes(**otk::display, e.window, &attr)) return;
139 // if not on the window any more, it isnt a CLICK
140 if (!(e.same_screen && e.x >= 0 && e.y >= 0 &&
141 e.x < attr.width && e.y < attr.height))
144 // run the CLICK python hook
145 data.action = MouseAction::Click;
146 openbox->bindings()->fireButton(&data);
149 python_get_long("double_click_delay", &dblclick);
150 if (e.time - _release.time < (unsigned)dblclick &&
151 _release.win == e.window && _release.button == e.button) {
153 // run the DOUBLECLICK python hook
154 data.action = MouseAction::DoubleClick;
155 openbox->bindings()->fireButton(&data);
157 // reset so you cant triple click for 2 doubleclicks
162 // save the button release, might be part of a double click
163 _release.win = e.window;
164 _release.button = e.button;
165 _release.time = e.time;
170 void Actions::enterHandler(const XCrossingEvent &e)
172 otk::EventHandler::enterHandler(e);
174 // run the ENTER python hook
176 Client *c = openbox->findClient(e.window);
178 screen = c->screen();
180 screen = otk::display->findScreen(e.root)->screen();
181 EventData data(screen, c, EventAction::EnterWindow, e.state);
182 openbox->bindings()->fireEvent(&data);
186 void Actions::leaveHandler(const XCrossingEvent &e)
188 otk::EventHandler::leaveHandler(e);
190 // run the LEAVE python hook
192 Client *c = openbox->findClient(e.window);
194 screen = c->screen();
196 screen = otk::display->findScreen(e.root)->screen();
197 EventData data(screen, c, EventAction::LeaveWindow, e.state);
198 openbox->bindings()->fireEvent(&data);
202 void Actions::keyPressHandler(const XKeyEvent &e)
204 otk::EventHandler::keyPressHandler(e);
206 // kill off the Button1Mask etc, only want the modifiers
207 unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask |
208 Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
210 // add to the state the mask of the modifier being pressed, if it is
211 // a modifier key being pressed (this is a little ugly..)
212 const XModifierKeymap *map = otk::display->modifierMap();
213 const int mask_table[] = {
214 ShiftMask, LockMask, ControlMask, Mod1Mask,
215 Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask
217 KeyCode *kp = map->modifiermap;
218 for (int i = 0, n = sizeof(mask_table)/sizeof(mask_table[0]); i < n; ++i) {
219 for (int k = 0; k < map->max_keypermod; ++k) {
220 if (*kp == e.keycode) { // found the keycode
221 state |= mask_table[i]; // add the mask for it
222 i = n; // cause the first loop to break;
223 break; // get outta here!
229 openbox->bindings()->
230 fireKey(otk::display->findScreen(e.root)->screen(),
231 state, e.keycode, e.time, KeyAction::Press);
235 void Actions::keyReleaseHandler(const XKeyEvent &e)
237 otk::EventHandler::keyReleaseHandler(e);
239 // kill off the Button1Mask etc, only want the modifiers
240 unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask |
241 Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
243 // remove from the state the mask of the modifier being released, if it is
244 // a modifier key being released (this is a little ugly..)
245 const XModifierKeymap *map = otk::display->modifierMap();
246 const int mask_table[] = {
247 ShiftMask, LockMask, ControlMask, Mod1Mask,
248 Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask
250 KeyCode *kp = map->modifiermap;
251 for (int i = 0, n = sizeof(mask_table)/sizeof(mask_table[0]); i < n; ++i) {
252 for (int k = 0; k < map->max_keypermod; ++k) {
253 if (*kp == e.keycode) { // found the keycode
254 state &= ~mask_table[i]; // remove the mask for it
255 i = n; // cause the first loop to break;
256 break; // get outta here!
262 openbox->bindings()->
263 fireKey(otk::display->findScreen(e.root)->screen(),
264 state, e.keycode, e.time, KeyAction::Release);
268 void Actions::motionHandler(const XMotionEvent &e)
270 otk::EventHandler::motionHandler(e);
272 if (!e.same_screen) return; // this just gets stupid
274 if (e.window != _press.win) return;
276 MouseContext::MC context;
277 EventHandler *h = openbox->findHandler(e.window);
278 Frame *f = dynamic_cast<Frame*>(h);
280 context= f->mouseContext(e.window);
281 else if (dynamic_cast<Client*>(h))
282 context = MouseContext::Window;
283 else if (dynamic_cast<Screen*>(h))
284 context = MouseContext::Root;
286 return; // not a valid mouse context
288 int x_root = e.x_root, y_root = e.y_root;
290 // compress changes to a window into a single change
292 while (XCheckTypedWindowEvent(**otk::display, e.window, e.type, &ce)) {
298 Client *c = openbox->findClient(e.window);
300 screen = c->screen();
302 screen = otk::display->findScreen(e.root)->screen();
305 int dx = x_root - _press.pos.x();
306 int dy = y_root - _press.pos.y();
308 python_get_long("drag_threshold", &threshold);
309 if (!(std::abs(dx) >= threshold || std::abs(dy) >= threshold))
310 return; // not at the threshold yet
312 _dragging = true; // in a drag now
314 // check if the movement is more than the threshold
316 // run the MOTION python hook
317 // kill off the Button1Mask etc, only want the modifiers
318 unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask |
319 Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
320 unsigned int button = _press.button;
321 MouseData data(screen, c, e.time, state, button, context,
322 MouseAction::Motion, x_root, y_root,
323 _press.pos, _press.clientarea);
324 openbox->bindings()->fireButton(&data);
328 void Actions::xkbHandler(const XkbEvent &e)
333 otk::EventHandler::xkbHandler(e);
335 switch (((XkbAnyEvent*)&e)->xkb_type) {
337 w = ((XkbBellNotifyEvent*)&e)->window;
338 Client *c = openbox->findClient(w);
340 screen = c->screen();
342 screen = openbox->focusedScreen()->number();
343 EventData data(screen, c, EventAction::Bell, 0);
344 openbox->bindings()->fireEvent(&data);