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