2002-12-30 06:31:45 +00:00
|
|
|
// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
|
2002-12-04 04:11:24 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "../config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "actions.hh"
|
2003-01-10 06:16:42 +00:00
|
|
|
#include "widgetbase.hh"
|
2002-12-18 11:34:29 +00:00
|
|
|
#include "openbox.hh"
|
2002-12-18 16:07:44 +00:00
|
|
|
#include "client.hh"
|
2003-01-09 22:54:31 +00:00
|
|
|
#include "screen.hh"
|
2002-12-25 02:19:49 +00:00
|
|
|
#include "python.hh"
|
2002-12-30 22:27:46 +00:00
|
|
|
#include "bindings.hh"
|
2002-12-04 10:06:35 +00:00
|
|
|
#include "otk/display.hh"
|
2002-12-04 04:11:24 +00:00
|
|
|
|
2002-12-04 07:12:13 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2002-12-04 04:11:24 +00:00
|
|
|
namespace ob {
|
|
|
|
|
2003-01-11 19:42:43 +00:00
|
|
|
const int Actions::BUTTONS;
|
2002-12-04 07:12:13 +00:00
|
|
|
|
2003-01-11 19:42:43 +00:00
|
|
|
Actions::Actions()
|
2002-12-04 08:30:32 +00:00
|
|
|
: _button(0)
|
2002-12-04 04:11:24 +00:00
|
|
|
{
|
2003-01-03 02:48:25 +00:00
|
|
|
for (int i=0; i<BUTTONS; ++i)
|
|
|
|
_posqueue[i] = new ButtonPressAction();
|
2002-12-04 04:11:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-11 19:42:43 +00:00
|
|
|
Actions::~Actions()
|
2002-12-04 04:11:24 +00:00
|
|
|
{
|
2003-01-03 02:48:25 +00:00
|
|
|
for (int i=0; i<BUTTONS; ++i)
|
|
|
|
delete _posqueue[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-11 19:42:43 +00:00
|
|
|
void Actions::insertPress(const XButtonEvent &e)
|
2003-01-03 02:48:25 +00:00
|
|
|
{
|
|
|
|
ButtonPressAction *a = _posqueue[BUTTONS - 1];
|
2003-01-11 11:16:36 +00:00
|
|
|
// rm'd the last one, shift them all down one
|
|
|
|
for (int i = BUTTONS-1; i > 0; --i) {
|
|
|
|
_posqueue[i] = _posqueue[i-1];
|
|
|
|
}
|
2003-01-03 02:48:25 +00:00
|
|
|
_posqueue[0] = a;
|
|
|
|
a->button = e.button;
|
|
|
|
a->pos.setPoint(e.x_root, e.y_root);
|
|
|
|
|
2003-01-11 19:42:43 +00:00
|
|
|
Client *c = Openbox::instance->findClient(e.window);
|
2003-01-03 02:48:25 +00:00
|
|
|
if (c) a->clientarea = c->area();
|
2002-12-04 10:06:35 +00:00
|
|
|
}
|
|
|
|
|
2003-01-11 19:42:43 +00:00
|
|
|
void Actions::removePress(const XButtonEvent &e)
|
2003-01-03 02:48:25 +00:00
|
|
|
{
|
2003-01-11 11:16:36 +00:00
|
|
|
int i;
|
2003-01-03 02:48:25 +00:00
|
|
|
ButtonPressAction *a = 0;
|
2003-01-11 11:16:36 +00:00
|
|
|
for (i=0; i<BUTTONS-1; ++i)
|
|
|
|
if (_posqueue[i]->button == e.button) {
|
2003-01-03 02:48:25 +00:00
|
|
|
a = _posqueue[i];
|
2003-01-11 11:16:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (a) { // found one, remove it and shift the rest up one
|
|
|
|
for (; i < BUTTONS-1; ++i)
|
2003-01-03 02:48:25 +00:00
|
|
|
_posqueue[i] = _posqueue[i+1];
|
|
|
|
_posqueue[BUTTONS-1] = a;
|
|
|
|
}
|
2003-01-11 11:16:36 +00:00
|
|
|
_posqueue[BUTTONS-1]->button = 0;
|
2003-01-03 02:48:25 +00:00
|
|
|
}
|
2002-12-04 10:06:35 +00:00
|
|
|
|
2003-01-11 19:42:43 +00:00
|
|
|
void Actions::buttonPressHandler(const XButtonEvent &e)
|
2002-12-04 07:12:13 +00:00
|
|
|
{
|
2003-01-11 19:42:43 +00:00
|
|
|
otk::EventHandler::buttonPressHandler(e);
|
2003-01-03 02:48:25 +00:00
|
|
|
insertPress(e);
|
2002-12-04 08:30:32 +00:00
|
|
|
|
2002-12-31 09:17:16 +00:00
|
|
|
// run the PRESS python hook
|
2003-01-11 19:42:43 +00:00
|
|
|
WidgetBase *w = dynamic_cast<WidgetBase*>
|
2002-12-18 11:34:29 +00:00
|
|
|
(Openbox::instance->findHandler(e.window));
|
2003-01-03 05:26:04 +00:00
|
|
|
assert(w); // everything should be a widget
|
|
|
|
|
2003-01-06 06:03:38 +00:00
|
|
|
// kill off the Button1Mask etc, only want the modifiers
|
2003-01-03 05:26:04 +00:00
|
|
|
unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask |
|
|
|
|
Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
|
2003-01-09 22:54:31 +00:00
|
|
|
int screen;
|
2003-01-11 19:42:43 +00:00
|
|
|
Client *c = Openbox::instance->findClient(e.window);
|
2003-01-09 22:54:31 +00:00
|
|
|
if (c)
|
|
|
|
screen = c->screen();
|
|
|
|
else
|
2003-01-11 19:42:43 +00:00
|
|
|
screen = otk::Display::findScreen(e.root)->screen();
|
2003-01-10 03:11:48 +00:00
|
|
|
MouseData data(screen, c, e.time, state, e.button, w->mcontext(),
|
|
|
|
MousePress);
|
2003-01-09 22:54:31 +00:00
|
|
|
Openbox::instance->bindings()->fireButton(&data);
|
2002-12-04 07:12:13 +00:00
|
|
|
|
|
|
|
if (_button) return; // won't count toward CLICK events
|
|
|
|
|
2002-12-04 07:55:52 +00:00
|
|
|
_button = e.button;
|
2003-01-10 19:17:26 +00:00
|
|
|
|
|
|
|
if (w->mcontext() == MC_Window) {
|
|
|
|
/*
|
|
|
|
Because of how events are grabbed on the client window, we can't get
|
|
|
|
ButtonRelease events, so instead we simply manufacture them here, so that
|
|
|
|
clicks/doubleclicks etc still work.
|
|
|
|
*/
|
2003-01-10 19:31:44 +00:00
|
|
|
//XButtonEvent ev = e;
|
|
|
|
//ev.type = ButtonRelease;
|
|
|
|
buttonReleaseHandler(e);
|
2003-01-10 19:17:26 +00:00
|
|
|
}
|
2002-12-04 07:12:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-11 19:42:43 +00:00
|
|
|
void Actions::buttonReleaseHandler(const XButtonEvent &e)
|
2002-12-04 07:12:13 +00:00
|
|
|
{
|
2003-01-11 19:42:43 +00:00
|
|
|
otk::EventHandler::buttonReleaseHandler(e);
|
2003-01-03 02:48:25 +00:00
|
|
|
removePress(e);
|
2002-12-04 08:30:32 +00:00
|
|
|
|
2003-01-11 19:42:43 +00:00
|
|
|
WidgetBase *w = dynamic_cast<WidgetBase*>
|
2002-12-18 11:34:29 +00:00
|
|
|
(Openbox::instance->findHandler(e.window));
|
2003-01-03 05:26:04 +00:00
|
|
|
assert(w); // everything should be a widget
|
2002-12-18 11:34:29 +00:00
|
|
|
|
2002-12-04 07:55:52 +00:00
|
|
|
// not for the button we're watching?
|
2002-12-04 08:12:09 +00:00
|
|
|
if (_button != e.button) return;
|
2002-12-04 07:12:13 +00:00
|
|
|
|
|
|
|
_button = 0;
|
|
|
|
|
2002-12-04 07:55:52 +00:00
|
|
|
// find the area of the window
|
|
|
|
XWindowAttributes attr;
|
2003-01-11 19:42:43 +00:00
|
|
|
if (!XGetWindowAttributes(otk::Display::display, e.window, &attr)) return;
|
2002-12-04 07:55:52 +00:00
|
|
|
|
|
|
|
// if not on the window any more, it isnt a CLICK
|
|
|
|
if (!(e.same_screen && e.x >= 0 && e.y >= 0 &&
|
|
|
|
e.x < attr.width && e.y < attr.height))
|
|
|
|
return;
|
2002-12-04 07:12:13 +00:00
|
|
|
|
2002-12-31 09:17:16 +00:00
|
|
|
// run the CLICK python hook
|
2003-01-06 06:03:38 +00:00
|
|
|
// kill off the Button1Mask etc, only want the modifiers
|
2003-01-03 05:26:04 +00:00
|
|
|
unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask |
|
|
|
|
Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
|
2003-01-09 22:54:31 +00:00
|
|
|
int screen;
|
2003-01-11 19:42:43 +00:00
|
|
|
Client *c = Openbox::instance->findClient(e.window);
|
2003-01-09 22:54:31 +00:00
|
|
|
if (c)
|
|
|
|
screen = c->screen();
|
|
|
|
else
|
2003-01-11 19:42:43 +00:00
|
|
|
screen = otk::Display::findScreen(e.root)->screen();
|
2003-01-10 03:11:48 +00:00
|
|
|
MouseData data(screen, c, e.time, state, e.button, w->mcontext(),
|
|
|
|
MouseClick);
|
2003-01-09 22:54:31 +00:00
|
|
|
Openbox::instance->bindings()->fireButton(&data);
|
2003-01-03 05:26:04 +00:00
|
|
|
|
2002-12-04 07:12:13 +00:00
|
|
|
|
2003-01-03 21:36:09 +00:00
|
|
|
// XXX: dont load this every time!!@*
|
|
|
|
long dblclick;
|
|
|
|
if (!python_get_long("double_click_delay", &dblclick))
|
|
|
|
dblclick = 300;
|
|
|
|
|
|
|
|
if (e.time - _release.time < (unsigned)dblclick &&
|
2002-12-04 08:12:09 +00:00
|
|
|
_release.win == e.window && _release.button == e.button) {
|
2002-12-04 07:12:13 +00:00
|
|
|
|
2002-12-31 09:17:16 +00:00
|
|
|
// run the DOUBLECLICK python hook
|
2003-01-09 22:54:31 +00:00
|
|
|
data.action = MouseDoubleClick;
|
|
|
|
Openbox::instance->bindings()->fireButton(&data);
|
2002-12-30 22:27:46 +00:00
|
|
|
|
2002-12-04 08:12:09 +00:00
|
|
|
// reset so you cant triple click for 2 doubleclicks
|
|
|
|
_release.win = 0;
|
|
|
|
_release.button = 0;
|
|
|
|
_release.time = 0;
|
|
|
|
} else {
|
|
|
|
// save the button release, might be part of a double click
|
|
|
|
_release.win = e.window;
|
|
|
|
_release.button = e.button;
|
|
|
|
_release.time = e.time;
|
2002-12-04 07:12:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-11 19:42:43 +00:00
|
|
|
void Actions::enterHandler(const XCrossingEvent &e)
|
2002-12-04 07:12:13 +00:00
|
|
|
{
|
2003-01-11 19:42:43 +00:00
|
|
|
otk::EventHandler::enterHandler(e);
|
2002-12-04 08:30:32 +00:00
|
|
|
|
2002-12-31 09:17:16 +00:00
|
|
|
// run the ENTER python hook
|
2003-01-09 22:54:31 +00:00
|
|
|
int screen;
|
2003-01-11 19:42:43 +00:00
|
|
|
Client *c = Openbox::instance->findClient(e.window);
|
2003-01-09 22:54:31 +00:00
|
|
|
if (c)
|
|
|
|
screen = c->screen();
|
|
|
|
else
|
2003-01-11 19:42:43 +00:00
|
|
|
screen = otk::Display::findScreen(e.root)->screen();
|
2003-01-09 22:54:31 +00:00
|
|
|
EventData data(screen, c, EventEnterWindow, e.state);
|
|
|
|
Openbox::instance->bindings()->fireEvent(&data);
|
2002-12-04 07:12:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-11 19:42:43 +00:00
|
|
|
void Actions::leaveHandler(const XCrossingEvent &e)
|
2002-12-04 07:12:13 +00:00
|
|
|
{
|
2003-01-11 19:42:43 +00:00
|
|
|
otk::EventHandler::leaveHandler(e);
|
2002-12-04 07:12:13 +00:00
|
|
|
|
2002-12-31 09:17:16 +00:00
|
|
|
// run the LEAVE python hook
|
2003-01-09 22:54:31 +00:00
|
|
|
int screen;
|
2003-01-11 19:42:43 +00:00
|
|
|
Client *c = Openbox::instance->findClient(e.window);
|
2003-01-09 22:54:31 +00:00
|
|
|
if (c)
|
|
|
|
screen = c->screen();
|
|
|
|
else
|
2003-01-11 19:42:43 +00:00
|
|
|
screen = otk::Display::findScreen(e.root)->screen();
|
2003-01-09 22:54:31 +00:00
|
|
|
EventData data(screen, c, EventLeaveWindow, e.state);
|
|
|
|
Openbox::instance->bindings()->fireEvent(&data);
|
2002-12-04 07:12:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-11 19:42:43 +00:00
|
|
|
void Actions::keyPressHandler(const XKeyEvent &e)
|
2002-12-04 07:12:13 +00:00
|
|
|
{
|
2003-01-11 19:42:43 +00:00
|
|
|
otk::EventHandler::keyPressHandler(e);
|
2002-12-18 11:34:29 +00:00
|
|
|
|
2003-01-06 06:03:38 +00:00
|
|
|
// kill off the Button1Mask etc, only want the modifiers
|
2003-01-03 05:26:04 +00:00
|
|
|
unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask |
|
|
|
|
Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
|
2003-01-07 02:24:43 +00:00
|
|
|
Openbox::instance->bindings()->
|
2003-01-11 19:42:43 +00:00
|
|
|
fireKey(otk::Display::findScreen(e.root)->screen(),
|
2003-01-07 02:24:43 +00:00
|
|
|
state, e.keycode, e.time);
|
2002-12-04 07:12:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-11 19:42:43 +00:00
|
|
|
void Actions::motionHandler(const XMotionEvent &e)
|
2002-12-04 07:12:13 +00:00
|
|
|
{
|
2003-01-11 19:42:43 +00:00
|
|
|
otk::EventHandler::motionHandler(e);
|
2003-01-03 21:36:09 +00:00
|
|
|
|
2002-12-04 11:50:20 +00:00
|
|
|
if (!e.same_screen) return; // this just gets stupid
|
|
|
|
|
2002-12-18 16:31:16 +00:00
|
|
|
int x_root = e.x_root, y_root = e.y_root;
|
|
|
|
|
|
|
|
// compress changes to a window into a single change
|
|
|
|
XEvent ce;
|
2003-01-11 19:42:43 +00:00
|
|
|
while (XCheckTypedEvent(otk::Display::display, e.type, &ce)) {
|
2002-12-18 16:31:16 +00:00
|
|
|
if (ce.xmotion.window != e.window) {
|
2003-01-11 19:42:43 +00:00
|
|
|
XPutBackEvent(otk::Display::display, &ce);
|
2002-12-18 16:31:16 +00:00
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
x_root = e.x_root;
|
|
|
|
y_root = e.y_root;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-11 19:42:43 +00:00
|
|
|
WidgetBase *w = dynamic_cast<WidgetBase*>
|
2002-12-18 11:34:29 +00:00
|
|
|
(Openbox::instance->findHandler(e.window));
|
2003-01-03 05:26:04 +00:00
|
|
|
assert(w); // everything should be a widget
|
|
|
|
|
|
|
|
// run the MOTION python hook
|
2003-01-06 06:03:38 +00:00
|
|
|
// kill off the Button1Mask etc, only want the modifiers
|
2003-01-03 05:26:04 +00:00
|
|
|
unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask |
|
|
|
|
Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
|
|
|
|
unsigned int button = _posqueue[0]->button;
|
2003-01-09 22:54:31 +00:00
|
|
|
int screen;
|
2003-01-11 19:42:43 +00:00
|
|
|
Client *c = Openbox::instance->findClient(e.window);
|
2003-01-09 22:54:31 +00:00
|
|
|
if (c)
|
|
|
|
screen = c->screen();
|
|
|
|
else
|
2003-01-11 19:42:43 +00:00
|
|
|
screen = otk::Display::findScreen(e.root)->screen();
|
2003-01-10 03:11:48 +00:00
|
|
|
MouseData data(screen, c, e.time, state, button, w->mcontext(), MouseMotion,
|
|
|
|
x_root, y_root, _posqueue[0]->pos, _posqueue[0]->clientarea);
|
|
|
|
Openbox::instance->bindings()->fireButton(&data);
|
2002-12-04 07:12:13 +00:00
|
|
|
}
|
|
|
|
|
2003-01-11 19:42:43 +00:00
|
|
|
void Actions::mapRequestHandler(const XMapRequestEvent &e)
|
2002-12-31 09:17:16 +00:00
|
|
|
{
|
2003-01-11 19:42:43 +00:00
|
|
|
otk::EventHandler::mapRequestHandler(e);
|
|
|
|
// do this in Screen::manageWindow
|
2002-12-31 09:17:16 +00:00
|
|
|
}
|
|
|
|
|
2003-01-11 19:42:43 +00:00
|
|
|
void Actions::unmapHandler(const XUnmapEvent &e)
|
2002-12-31 09:17:16 +00:00
|
|
|
{
|
2003-01-11 19:42:43 +00:00
|
|
|
otk::EventHandler::unmapHandler(e);
|
|
|
|
// do this in Screen::unmanageWindow
|
2002-12-31 09:17:16 +00:00
|
|
|
}
|
|
|
|
|
2003-01-11 19:42:43 +00:00
|
|
|
void Actions::destroyHandler(const XDestroyWindowEvent &e)
|
2002-12-31 09:17:16 +00:00
|
|
|
{
|
2003-01-11 19:42:43 +00:00
|
|
|
otk::EventHandler::destroyHandler(e);
|
|
|
|
// do this in Screen::unmanageWindow
|
2002-12-31 09:17:16 +00:00
|
|
|
}
|
2002-12-04 07:12:13 +00:00
|
|
|
|
2003-01-09 22:54:31 +00:00
|
|
|
#ifdef XKB
|
2003-01-11 19:42:43 +00:00
|
|
|
void Actions::xkbHandler(const XkbEvent &e)
|
2003-01-09 22:54:31 +00:00
|
|
|
{
|
|
|
|
Window w;
|
|
|
|
int screen;
|
|
|
|
|
2003-01-11 19:42:43 +00:00
|
|
|
otk::EventHandler::xkbHandler(e);
|
2003-01-09 22:54:31 +00:00
|
|
|
|
|
|
|
switch (((XkbAnyEvent*)&e)->xkb_type) {
|
|
|
|
case XkbBellNotify:
|
|
|
|
w = ((XkbBellNotifyEvent*)&e)->window;
|
2003-01-11 19:42:43 +00:00
|
|
|
Client *c = Openbox::instance->findClient(w);
|
2003-01-09 22:54:31 +00:00
|
|
|
if (c)
|
|
|
|
screen = c->screen();
|
|
|
|
else
|
|
|
|
screen = Openbox::instance->focusedScreen()->number();
|
|
|
|
EventData data(screen, c, EventBell, 0);
|
|
|
|
Openbox::instance->bindings()->fireEvent(&data);
|
|
|
|
break;
|
|
|
|
}
|
2002-12-04 04:11:24 +00:00
|
|
|
}
|
2003-01-09 22:54:31 +00:00
|
|
|
#endif // XKB
|
|
|
|
|
|
|
|
}
|
|
|
|
|