From b34824a4e2ddc0247099fa1b3952de426bfde05b Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Wed, 25 Dec 2002 04:54:44 +0000 Subject: global python scripts. client motion/resizing is all done via python now --- src/Makefile.am | 4 +- src/actions.cc | 117 +++++++++++++--------------------------------------- src/actions.hh | 23 ++--------- src/openbox.cc | 21 ++++++---- src/openbox.i | 20 ++++++++- src/openbox_wrap.cc | 32 ++++++++++++++ src/python.cc | 15 ++++++- src/python.hh | 3 +- src/widget.hh | 1 + 9 files changed, 115 insertions(+), 121 deletions(-) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 222b770c..5ea811f0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,11 +1,13 @@ localedir=$(datadir)/locale +scriptdir = $(libdir)/openbox/python DEFAULT_MENU=$(pkgdatadir)/menu DEFAULT_STYLE=$(pkgdatadir)/styles/mbdtex CPPFLAGS=$(XFT_CFLAGS) $(PYTHON_CFLAGS) @CPPFLAGS@ \ -DDEFAULTMENU=\"$(DEFAULT_MENU)\" \ -DDEFAULTSTYLE=\"$(DEFAULT_STYLE)\" \ --DLOCALEDIR=\"$(localedir)\" +-DLOCALEDIR=\"$(localedir)\" \ +-DSCRIPTDIR=\"$(scriptdir)\" LIBS=$(XFT_LIBS) $(PYTHON_LIBS) @LIBS@ diff --git a/src/actions.cc b/src/actions.cc index d2b4ceef..0dbe4640 100644 --- a/src/actions.cc +++ b/src/actions.cc @@ -16,14 +16,10 @@ namespace ob { const unsigned int OBActions::DOUBLECLICKDELAY = 300; -const int OBActions::BUTTONS; OBActions::OBActions() : _button(0) { - for (int i=0; i0;) - _posqueue[i] = _posqueue[--i]; - _posqueue[0] = a; - a->button = e.button; - a->pos.setPoint(e.x_root, e.y_root); - - OBClient *c = Openbox::instance->findClient(e.window); - // if it's not defined, they should have clicked on the root window, so this - // area would be meaningless anyways - if (c) a->clientarea = c->area(); } -void OBActions::removePress(const XButtonEvent &e) -{ - ButtonPressAction *a = 0; - for (int i=0; ibutton == e.button) - a = _posqueue[i]; - if (a) // found one and removed it - _posqueue[i] = _posqueue[i+1]; - } - if (a) { // found one - _posqueue[BUTTONS-1] = a; - a->button = 0; - } -} void OBActions::buttonPressHandler(const XButtonEvent &e) { OtkEventHandler::buttonPressHandler(e); - insertPress(e); - // XXX: run the PRESS guile hook + // run the PRESS guile hook OBWidget *w = dynamic_cast (Openbox::instance->findHandler(e.window)); - printf("GUILE: PRESS: win %lx type %d modifiers %u button %u time %lx\n", - (long)e.window, (w ? w->type():-1), e.state, e.button, e.time); python_callback(Action_ButtonPress, e.window, (OBWidget::WidgetType)(w ? w->type():-1), - e.state, e.button, e.time); + e.state, e.button, e.x_root, e.y_root, e.time); if (_button) return; // won't count toward CLICK events @@ -90,14 +51,14 @@ void OBActions::buttonPressHandler(const XButtonEvent &e) void OBActions::buttonReleaseHandler(const XButtonEvent &e) { OtkEventHandler::buttonReleaseHandler(e); - removePress(e); - // XXX: run the RELEASE guile hook OBWidget *w = dynamic_cast (Openbox::instance->findHandler(e.window)); - printf("GUILE: RELEASE: win %lx type %d, modifiers %u button %u time %lx\n", - (long)e.window, (w ? w->type():-1), e.state, e.button, e.time); + // run the RELEASE guile hook + python_callback(Action_ButtonRelease, e.window, + (OBWidget::WidgetType)(w ? w->type():-1), + e.state, e.button, e.x_root, e.y_root, e.time); // not for the button we're watching? if (_button != e.button) return; @@ -113,16 +74,18 @@ void OBActions::buttonReleaseHandler(const XButtonEvent &e) e.x < attr.width && e.y < attr.height)) return; - // XXX: run the CLICK guile hook - printf("GUILE: CLICK: win %lx type %d modifiers %u button %u time %lx\n", - (long)e.window, (w ? w->type():-1), e.state, e.button, e.time); + // run the CLICK guile hook + python_callback(Action_Click, e.window, + (OBWidget::WidgetType)(w ? w->type():-1), + e.state, e.button, e.time); if (e.time - _release.time < DOUBLECLICKDELAY && _release.win == e.window && _release.button == e.button) { - // XXX: run the DOUBLECLICK guile hook - printf("GUILE: DOUBLECLICK: win %lx type %d modifiers %u button %u time %lx\n", - (long)e.window, (w ? w->type():-1), e.state, e.button, e.time); + // run the DOUBLECLICK guile hook + python_callback(Action_DoubleClick, e.window, + (OBWidget::WidgetType)(w ? w->type():-1), + e.state, e.button, e.time); // reset so you cant triple click for 2 doubleclicks _release.win = 0; @@ -141,12 +104,12 @@ void OBActions::enterHandler(const XCrossingEvent &e) { OtkEventHandler::enterHandler(e); - // XXX: run the ENTER guile hook OBWidget *w = dynamic_cast (Openbox::instance->findHandler(e.window)); - printf("GUILE: ENTER: win %lx type %d modifiers %u\n", - (long)e.window, (w ? w->type():-1), e.state); + // run the ENTER guile hook + python_callback(Action_EnterWindow, e.window, + (OBWidget::WidgetType)(w ? w->type():-1), e.state); } @@ -154,23 +117,24 @@ void OBActions::leaveHandler(const XCrossingEvent &e) { OtkEventHandler::leaveHandler(e); - // XXX: run the LEAVE guile hook OBWidget *w = dynamic_cast (Openbox::instance->findHandler(e.window)); - printf("GUILE: LEAVE: win %lx type %d modifiers %u\n", - (long)e.window, (w ? w->type():-1), e.state); + // run the LEAVE guile hook + python_callback(Action_LeaveWindow, e.window, + (OBWidget::WidgetType)(w ? w->type():-1), e.state); } void OBActions::keyPressHandler(const XKeyEvent &e) { - // XXX: run the KEY guile hook OBWidget *w = dynamic_cast (Openbox::instance->findHandler(e.window)); - printf("GUILE: KEY: win %lx type %d modifiers %u keycode %u\n", - (long)e.window, (w ? w->type():-1), e.state, e.keycode); + // run the KEY guile hook + python_callback(Action_KeyPress, e.window, + (OBWidget::WidgetType)(w ? w->type():-1), + e.state, e.keycode); } @@ -196,35 +160,12 @@ void OBActions::motionHandler(const XMotionEvent &e) OBWidget *w = dynamic_cast (Openbox::instance->findHandler(e.window)); - _dx = x_root - _posqueue[0]->pos.x(); - _dy = y_root - _posqueue[0]->pos.y(); - // XXX: i can envision all sorts of crazy shit with this.. gestures, etc - printf("GUILE: MOTION: win %lx type %d modifiers %u x %d y %d\n", - (long)e.window, (w ? w->type():-1), e.state, _dx, _dy); - - OBClient *c = Openbox::instance->findClient(e.window); - if (w && c) { - switch (w->type()) { - case OBWidget::Type_Titlebar: - case OBWidget::Type_Label: - c->move(_posqueue[0]->clientarea.x() + _dx, - _posqueue[0]->clientarea.y() + _dy); - break; - case OBWidget::Type_LeftGrip: - c->resize(OBClient::TopRight, - _posqueue[0]->clientarea.width() - _dx, - _posqueue[0]->clientarea.height() + _dy); - break; - case OBWidget::Type_RightGrip: - c->resize(OBClient::TopLeft, - _posqueue[0]->clientarea.width() + _dx, - _posqueue[0]->clientarea.height() + _dy); - break; - default: - break; - } - } + // maybe that should all be done via python tho.. + // run the simple MOTION guile hook for now... + python_callback(Action_MouseMotion, e.window, + (OBWidget::WidgetType)(w ? w->type():-1), + e.state, e.x_root, e.y_root, e.time); } diff --git a/src/actions.hh b/src/actions.hh index 1a8d02c4..4cf37ef1 100644 --- a/src/actions.hh +++ b/src/actions.hh @@ -23,9 +23,12 @@ namespace ob { */ class OBActions : public otk::OtkEventHandler { public: + // update the same enum in openbox.i when making changes to this enum ActionType { Action_ButtonPress, Action_ButtonRelease, + Action_Click, + Action_DoubleClick, Action_EnterWindow, Action_LeaveWindow, Action_KeyPress, @@ -40,35 +43,15 @@ public: ButtonReleaseAction() { win = 0; button = 0; time = 0; } }; - struct ButtonPressAction { - unsigned int button; - otk::Point pos; - otk::Rect clientarea; - ButtonPressAction() { button = 0; } - }; - private: // milliseconds XXX: config option static const unsigned int DOUBLECLICKDELAY; - static const int BUTTONS = 5; //! The mouse button currently being watched from a press for a CLICK unsigned int _button; //! The last button release processed for CLICKs ButtonReleaseAction _release; - //! The point where the mouse was when each mouse button was pressed - /*! - Used for motion events as the starting position. - */ - ButtonPressAction *_posqueue[BUTTONS]; - //! The delta x/y of the last motion sequence - int _dx, _dy; - //! Insert a button/position in the _posqueue - void insertPress(const XButtonEvent &e); - //! Remove a button/position from the _posqueue - void removePress(const XButtonEvent &e); - public: //! Constructs an OBActions object OBActions(); diff --git a/src/openbox.cc b/src/openbox.cc index aa61a313..cf41975d 100644 --- a/src/openbox.cc +++ b/src/openbox.cc @@ -82,6 +82,17 @@ void Openbox::signalHandler(int signal) } +static void runPython(const char *s) { + FILE *rcpyfd = fopen(s, "r"); + if (!rcpyfd) { + printf("failed to load python file %s\n", s); + } else { + PyRun_SimpleFile(rcpyfd, const_cast(s)); + fclose(rcpyfd); + } +} + + Openbox::Openbox(int argc, char **argv) : otk::OtkEventDispatcher(), otk::OtkEventHandler() @@ -150,13 +161,9 @@ Openbox::Openbox(int argc, char **argv) init_openbox(); PyRun_SimpleString("from _otk import *; from _openbox import *;"); PyRun_SimpleString("openbox = Openbox_instance()"); - FILE *rcpyfd = fopen(_scriptfilepath.c_str(), "r"); - if (!rcpyfd) { - printf("failed to load python file %s\n", _scriptfilepath.c_str()); - } else { - PyRun_SimpleFile(rcpyfd, const_cast(_scriptfilepath.c_str())); - fclose(rcpyfd); - } + + runPython(SCRIPTDIR"/clientmotion.py"); // moving and resizing clients + runPython(_scriptfilepath.c_str()); // initialize all the screens OBScreen *screen; diff --git a/src/openbox.i b/src/openbox.i index 1ff7d357..ef82956b 100644 --- a/src/openbox.i +++ b/src/openbox.i @@ -23,17 +23,33 @@ ob::Openbox *Openbox_instance() { return ob::Openbox::instance; } %}; -// stuff for registering callbacks! - +// stuff for scripting callbacks! %inline %{ enum ActionType { Action_ButtonPress, Action_ButtonRelease, + Action_Click, + Action_DoubleClick, Action_EnterWindow, Action_LeaveWindow, Action_KeyPress, Action_MouseMotion }; + enum WidgetType { + Type_Frame, + Type_Titlebar, + Type_Handle, + Type_Plate, + Type_Label, + Type_MaximizeButton, + Type_CloseButton, + Type_IconifyButton, + Type_StickyButton, + Type_LeftGrip, + Type_RightGrip, + Type_Client, + Type_Root + }; %} %ignore ob::python_callback; %rename(register) ob::python_register; diff --git a/src/openbox_wrap.cc b/src/openbox_wrap.cc index 5e50bd01..75c9a376 100644 --- a/src/openbox_wrap.cc +++ b/src/openbox_wrap.cc @@ -777,11 +777,28 @@ static std::string SwigString_AsString(PyObject* o) { enum ActionType { Action_ButtonPress, Action_ButtonRelease, + Action_Click, + Action_DoubleClick, Action_EnterWindow, Action_LeaveWindow, Action_KeyPress, Action_MouseMotion }; + enum WidgetType { + Type_Frame, + Type_Titlebar, + Type_Handle, + Type_Plate, + Type_Label, + Type_MaximizeButton, + Type_CloseButton, + Type_IconifyButton, + Type_StickyButton, + Type_LeftGrip, + Type_RightGrip, + Type_Client, + Type_Root + }; #include @@ -2475,10 +2492,25 @@ _swigt__p_XUnmapEvent, static swig_const_info swig_const_table[] = { { SWIG_PY_INT, (char *)"Action_ButtonPress", (long) Action_ButtonPress, 0, 0, 0}, { SWIG_PY_INT, (char *)"Action_ButtonRelease", (long) Action_ButtonRelease, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"Action_Click", (long) Action_Click, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"Action_DoubleClick", (long) Action_DoubleClick, 0, 0, 0}, { SWIG_PY_INT, (char *)"Action_EnterWindow", (long) Action_EnterWindow, 0, 0, 0}, { SWIG_PY_INT, (char *)"Action_LeaveWindow", (long) Action_LeaveWindow, 0, 0, 0}, { SWIG_PY_INT, (char *)"Action_KeyPress", (long) Action_KeyPress, 0, 0, 0}, { SWIG_PY_INT, (char *)"Action_MouseMotion", (long) Action_MouseMotion, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"Type_Frame", (long) Type_Frame, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"Type_Titlebar", (long) Type_Titlebar, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"Type_Handle", (long) Type_Handle, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"Type_Plate", (long) Type_Plate, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"Type_Label", (long) Type_Label, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"Type_MaximizeButton", (long) Type_MaximizeButton, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"Type_CloseButton", (long) Type_CloseButton, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"Type_IconifyButton", (long) Type_IconifyButton, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"Type_StickyButton", (long) Type_StickyButton, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"Type_LeftGrip", (long) Type_LeftGrip, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"Type_RightGrip", (long) Type_RightGrip, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"Type_Client", (long) Type_Client, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"Type_Root", (long) Type_Root, 0, 0, 0}, { SWIG_PY_INT, (char *)"Openbox_State_Starting", (long) ob::Openbox::State_Starting, 0, 0, 0}, { SWIG_PY_INT, (char *)"Openbox_State_Normal", (long) ob::Openbox::State_Normal, 0, 0, 0}, { SWIG_PY_INT, (char *)"Openbox_State_Exiting", (long) ob::Openbox::State_Exiting, 0, 0, 0}, diff --git a/src/python.cc b/src/python.cc index a00bc245..d44b2d48 100644 --- a/src/python.cc +++ b/src/python.cc @@ -55,14 +55,25 @@ bool python_unregister(int action, PyObject *callback) void python_callback(OBActions::ActionType action, Window window, OBWidget::WidgetType type, unsigned int state, - long d1, long d2) + long d1, long d2, long d3, long d4) { PyObject *arglist; PyObject *result; assert(action >= 0 && action < OBActions::NUM_ACTIONS); - arglist = Py_BuildValue("iliill", action, window, type, state, d1, d2); + if (d4 != LONG_MIN) + arglist = Py_BuildValue("iliillll", action, window, type, state, + d1, d2, d3, d4); + else if (d3 != LONG_MIN) + arglist = Py_BuildValue("iliilll", action, window, type, state, + d1, d2, d3); + else if (d2 != LONG_MIN) + arglist = Py_BuildValue("iliill", action, window, type, state, d1, d2); + else if (d1 != LONG_MIN) + arglist = Py_BuildValue("iliil", action, window, type, state, d1); + else + arglist = Py_BuildValue("ilii", action, window, type, state); FunctionList::iterator it, end = callbacks[action].end(); for (it = callbacks[action].begin(); it != end; ++it) { diff --git a/src/python.hh b/src/python.hh index 7fc178eb..6ca4e1c5 100644 --- a/src/python.hh +++ b/src/python.hh @@ -20,7 +20,8 @@ bool python_unregister(int action, PyObject *callback); void python_callback(OBActions::ActionType action, Window window, OBWidget::WidgetType type, unsigned int state, - long d1 = 0, long d2 = 0); + long d1 = LONG_MIN, long d2 = LONG_MIN, + long d3 = LONG_MIN, long d4 = LONG_MIN); } diff --git a/src/widget.hh b/src/widget.hh index 2af01e24..e51189d6 100644 --- a/src/widget.hh +++ b/src/widget.hh @@ -6,6 +6,7 @@ namespace ob { class OBWidget { public: + // update the enum in openbox.i to match this one enum WidgetType { Type_Frame, Type_Titlebar, -- cgit v1.2.3