]> Dogcows Code - chaz/openbox/blob - src/actions.cc
keep a queue of press/releases and the positions, so that the first motion event...
[chaz/openbox] / src / actions.cc
1 // -*- mode: C++; indent-tabs-mode: nil; -*-
2
3 #ifdef HAVE_CONFIG_H
4 # include "../config.h"
5 #endif
6
7 #include "actions.hh"
8 #include "otk/display.hh"
9
10 #include <stdio.h>
11
12 namespace ob {
13
14 const unsigned int OBActions::DOUBLECLICKDELAY = 300;
15 const int OBActions::BUTTONS;
16
17 OBActions::OBActions()
18 : _button(0)
19 {
20 for (int i=0; i<BUTTONS; ++i)
21 _posqueue[i] = new ButtonPressAction();
22
23 // XXX: load a configuration out of somewhere
24
25 }
26
27
28 OBActions::~OBActions()
29 {
30 for (int i=0; i<BUTTONS; ++i)
31 delete _posqueue[i];
32 }
33
34
35 void OBActions::insertPress(const XButtonEvent &e)
36 {
37 ButtonPressAction *a = _posqueue[BUTTONS - 1];
38 for (int i=BUTTONS-1; i>0;)
39 _posqueue[i] = _posqueue[--i];
40 _posqueue[0] = a;
41 a->button = e.button;
42 a->pos.setPoint(e.x, e.y);
43 }
44
45 void OBActions::removePress(const XButtonEvent &e)
46 {
47 ButtonPressAction *a = 0;
48 for (int i=0; i<BUTTONS; ++i) {
49 if (_posqueue[i]->button == e.button)
50 a = _posqueue[i];
51 if (a) // found one and removed it
52 _posqueue[i] = _posqueue[i+1];
53 }
54 if (a) { // found one
55 _posqueue[BUTTONS-1] = a;
56 a->button = 0;
57 }
58 }
59
60 void OBActions::buttonPressHandler(const XButtonEvent &e)
61 {
62 OtkEventHandler::buttonPressHandler(e);
63 insertPress(e);
64
65 // XXX: run the PRESS guile hook
66 printf("GUILE: PRESS: win %lx modifiers %u button %u time %lx\n",
67 (long)e.window, e.state, e.button, e.time);
68
69 if (_button) return; // won't count toward CLICK events
70
71 _button = e.button;
72 }
73
74
75 void OBActions::buttonReleaseHandler(const XButtonEvent &e)
76 {
77 OtkEventHandler::buttonReleaseHandler(e);
78 removePress(e);
79
80 // XXX: run the RELEASE guile hook
81 printf("GUILE: RELEASE: win %lx modifiers %u button %u time %lx\n",
82 (long)e.window, e.state, e.button, e.time);
83
84 // not for the button we're watching?
85 if (_button != e.button) return;
86
87 _button = 0;
88
89 // find the area of the window
90 XWindowAttributes attr;
91 if (!XGetWindowAttributes(otk::OBDisplay::display, e.window, &attr)) return;
92
93 // if not on the window any more, it isnt a CLICK
94 if (!(e.same_screen && e.x >= 0 && e.y >= 0 &&
95 e.x < attr.width && e.y < attr.height))
96 return;
97
98 // XXX: run the CLICK guile hook
99 printf("GUILE: CLICK: win %lx modifiers %u button %u time %lx\n",
100 (long)e.window, e.state, e.button, e.time);
101
102 if (e.time - _release.time < DOUBLECLICKDELAY &&
103 _release.win == e.window && _release.button == e.button) {
104
105 // XXX: run the DOUBLECLICK guile hook
106 printf("GUILE: DOUBLECLICK: win %lx modifiers %u button %u time %lx\n",
107 (long)e.window, e.state, e.button, e.time);
108
109 // reset so you cant triple click for 2 doubleclicks
110 _release.win = 0;
111 _release.button = 0;
112 _release.time = 0;
113 } else {
114 // save the button release, might be part of a double click
115 _release.win = e.window;
116 _release.button = e.button;
117 _release.time = e.time;
118 }
119 }
120
121
122 void OBActions::enterHandler(const XCrossingEvent &e)
123 {
124 OtkEventHandler::enterHandler(e);
125
126 // XXX: run the ENTER guile hook
127 printf("GUILE: ENTER: win %lx modifiers %u\n", (long)e.window, e.state);
128 }
129
130
131 void OBActions::leaveHandler(const XCrossingEvent &e)
132 {
133 OtkEventHandler::leaveHandler(e);
134
135 // XXX: run the LEAVE guile hook
136 printf("GUILE: LEAVE: win %lx modifiers %u\n", (long)e.window, e.state);
137 }
138
139
140 void OBActions::keyPressHandler(const XKeyEvent &e)
141 {
142 // XXX: run the KEY guile hook
143 printf("GUILE: KEY: win %lx modifiers %u keycode %u\n",
144 (long)e.window, e.state, e.keycode);
145 }
146
147
148 void OBActions::motionHandler(const XMotionEvent &e)
149 {
150 // XXX: i can envision all sorts of crazy shit with this.. gestures, etc
151 printf("GUILE: MOTION: win %lx modifiers %u x %d y %d\n",
152 (long)e.window, e.state,
153 e.x - _posqueue[0]->pos.x(), e.y - _posqueue[0]->pos.y());
154 }
155
156
157 }
This page took 0.050436 seconds and 5 git commands to generate.