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