]>
Dogcows Code - chaz/openbox/blob - src/actions.cc
d2b4ceef34344e95960e1129a5a435c43af234ef
1 // -*- mode: C++; indent-tabs-mode: nil; -*-
4 # include "../config.h"
12 #include "otk/display.hh"
18 const unsigned int OBActions::DOUBLECLICKDELAY
= 300;
19 const int OBActions::BUTTONS
;
21 OBActions::OBActions()
24 for (int i
=0; i
<BUTTONS
; ++i
)
25 _posqueue
[i
] = new ButtonPressAction();
27 // XXX: load a configuration out of somewhere
32 OBActions::~OBActions()
34 for (int i
=0; i
<BUTTONS
; ++i
)
39 void OBActions::insertPress(const XButtonEvent
&e
)
41 ButtonPressAction
*a
= _posqueue
[BUTTONS
- 1];
42 for (int i
=BUTTONS
-1; i
>0;)
43 _posqueue
[i
] = _posqueue
[--i
];
46 a
->pos
.setPoint(e
.x_root
, e
.y_root
);
48 OBClient
*c
= Openbox::instance
->findClient(e
.window
);
49 // if it's not defined, they should have clicked on the root window, so this
50 // area would be meaningless anyways
51 if (c
) a
->clientarea
= c
->area();
54 void OBActions::removePress(const XButtonEvent
&e
)
56 ButtonPressAction
*a
= 0;
57 for (int i
=0; i
<BUTTONS
; ++i
) {
58 if (_posqueue
[i
]->button
== e
.button
)
60 if (a
) // found one and removed it
61 _posqueue
[i
] = _posqueue
[i
+1];
64 _posqueue
[BUTTONS
-1] = a
;
69 void OBActions::buttonPressHandler(const XButtonEvent
&e
)
71 OtkEventHandler::buttonPressHandler(e
);
74 // XXX: run the PRESS guile hook
75 OBWidget
*w
= dynamic_cast<OBWidget
*>
76 (Openbox::instance
->findHandler(e
.window
));
78 printf("GUILE: PRESS: win %lx type %d modifiers %u button %u time %lx\n",
79 (long)e
.window
, (w
? w
->type():-1), e
.state
, e
.button
, e
.time
);
80 python_callback(Action_ButtonPress
, e
.window
,
81 (OBWidget::WidgetType
)(w
? w
->type():-1),
82 e
.state
, e
.button
, e
.time
);
84 if (_button
) return; // won't count toward CLICK events
90 void OBActions::buttonReleaseHandler(const XButtonEvent
&e
)
92 OtkEventHandler::buttonReleaseHandler(e
);
95 // XXX: run the RELEASE guile hook
96 OBWidget
*w
= dynamic_cast<OBWidget
*>
97 (Openbox::instance
->findHandler(e
.window
));
99 printf("GUILE: RELEASE: win %lx type %d, modifiers %u button %u time %lx\n",
100 (long)e
.window
, (w
? w
->type():-1), e
.state
, e
.button
, e
.time
);
102 // not for the button we're watching?
103 if (_button
!= e
.button
) return;
107 // find the area of the window
108 XWindowAttributes attr
;
109 if (!XGetWindowAttributes(otk::OBDisplay::display
, e
.window
, &attr
)) return;
111 // if not on the window any more, it isnt a CLICK
112 if (!(e
.same_screen
&& e
.x
>= 0 && e
.y
>= 0 &&
113 e
.x
< attr
.width
&& e
.y
< attr
.height
))
116 // XXX: run the CLICK guile hook
117 printf("GUILE: CLICK: win %lx type %d modifiers %u button %u time %lx\n",
118 (long)e
.window
, (w
? w
->type():-1), e
.state
, e
.button
, e
.time
);
120 if (e
.time
- _release
.time
< DOUBLECLICKDELAY
&&
121 _release
.win
== e
.window
&& _release
.button
== e
.button
) {
123 // XXX: run the DOUBLECLICK guile hook
124 printf("GUILE: DOUBLECLICK: win %lx type %d modifiers %u button %u time %lx\n",
125 (long)e
.window
, (w
? w
->type():-1), e
.state
, e
.button
, e
.time
);
127 // reset so you cant triple click for 2 doubleclicks
132 // save the button release, might be part of a double click
133 _release
.win
= e
.window
;
134 _release
.button
= e
.button
;
135 _release
.time
= e
.time
;
140 void OBActions::enterHandler(const XCrossingEvent
&e
)
142 OtkEventHandler::enterHandler(e
);
144 // XXX: run the ENTER guile hook
145 OBWidget
*w
= dynamic_cast<OBWidget
*>
146 (Openbox::instance
->findHandler(e
.window
));
148 printf("GUILE: ENTER: win %lx type %d modifiers %u\n",
149 (long)e
.window
, (w
? w
->type():-1), e
.state
);
153 void OBActions::leaveHandler(const XCrossingEvent
&e
)
155 OtkEventHandler::leaveHandler(e
);
157 // XXX: run the LEAVE guile hook
158 OBWidget
*w
= dynamic_cast<OBWidget
*>
159 (Openbox::instance
->findHandler(e
.window
));
161 printf("GUILE: LEAVE: win %lx type %d modifiers %u\n",
162 (long)e
.window
, (w
? w
->type():-1), e
.state
);
166 void OBActions::keyPressHandler(const XKeyEvent
&e
)
168 // XXX: run the KEY guile hook
169 OBWidget
*w
= dynamic_cast<OBWidget
*>
170 (Openbox::instance
->findHandler(e
.window
));
172 printf("GUILE: KEY: win %lx type %d modifiers %u keycode %u\n",
173 (long)e
.window
, (w
? w
->type():-1), e
.state
, e
.keycode
);
177 void OBActions::motionHandler(const XMotionEvent
&e
)
179 if (!e
.same_screen
) return; // this just gets stupid
181 int x_root
= e
.x_root
, y_root
= e
.y_root
;
183 // compress changes to a window into a single change
185 while (XCheckTypedEvent(otk::OBDisplay::display
, e
.type
, &ce
)) {
186 if (ce
.xmotion
.window
!= e
.window
) {
187 XPutBackEvent(otk::OBDisplay::display
, &ce
);
196 OBWidget
*w
= dynamic_cast<OBWidget
*>
197 (Openbox::instance
->findHandler(e
.window
));
199 _dx
= x_root
- _posqueue
[0]->pos
.x();
200 _dy
= y_root
- _posqueue
[0]->pos
.y();
202 // XXX: i can envision all sorts of crazy shit with this.. gestures, etc
203 printf("GUILE: MOTION: win %lx type %d modifiers %u x %d y %d\n",
204 (long)e
.window
, (w
? w
->type():-1), e
.state
, _dx
, _dy
);
206 OBClient
*c
= Openbox::instance
->findClient(e
.window
);
209 case OBWidget::Type_Titlebar
:
210 case OBWidget::Type_Label
:
211 c
->move(_posqueue
[0]->clientarea
.x() + _dx
,
212 _posqueue
[0]->clientarea
.y() + _dy
);
214 case OBWidget::Type_LeftGrip
:
215 c
->resize(OBClient::TopRight
,
216 _posqueue
[0]->clientarea
.width() - _dx
,
217 _posqueue
[0]->clientarea
.height() + _dy
);
219 case OBWidget::Type_RightGrip
:
220 c
->resize(OBClient::TopLeft
,
221 _posqueue
[0]->clientarea
.width() + _dx
,
222 _posqueue
[0]->clientarea
.height() + _dy
);
This page took 0.052408 seconds and 4 git commands to generate.