From b35dae95a5cdb902f1661b9572af47c3f55c975c Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Fri, 3 Jan 2003 02:48:25 +0000 Subject: [PATCH] new mouse button code is seeming to work. you can move windows --- src/actions.cc | 97 +++++++-- src/actions.hh | 24 ++- src/bindings.cc | 204 ++++++++++++++++--- src/bindings.hh | 45 +++-- src/frame.cc | 4 +- src/openbox.cc | 5 +- src/openbox.i | 147 -------------- src/openbox_wrap.cc | 464 +++++++++++++++----------------------------- src/python.cc | 142 +++++++++++++- src/python.hh | 32 ++- src/screen.cc | 4 + 11 files changed, 624 insertions(+), 544 deletions(-) diff --git a/src/actions.cc b/src/actions.cc index 26805df3..c04457da 100644 --- a/src/actions.cc +++ b/src/actions.cc @@ -17,31 +17,69 @@ namespace ob { const unsigned int OBActions::DOUBLECLICKDELAY = 300; +const int OBActions::BUTTONS; OBActions::OBActions() : _button(0) { - // XXX: load a configuration out of somewhere - + 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 (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); // run the PRESS python hook OBWidget *w = dynamic_cast (Openbox::instance->findHandler(e.window)); - doCallback(Action_ButtonPress, e.window, +/* doCallback(Action_ButtonPress, e.window, (OBWidget::WidgetType)(w ? w->type():-1), - e.state, e.button, e.x_root, e.y_root, e.time); + e.state, e.button, e.x_root, e.y_root, e.time);*/ + if (w) { + Openbox::instance->bindings()->fire(MousePress, w->type(), e.window, + e.state, e.button, + e.x_root, e.y_root, e.time); + } else + assert(false); // why isnt there a type? if (_button) return; // won't count toward CLICK events @@ -52,6 +90,7 @@ void OBActions::buttonPressHandler(const XButtonEvent &e) void OBActions::buttonReleaseHandler(const XButtonEvent &e) { OtkEventHandler::buttonReleaseHandler(e); + removePress(e); OBWidget *w = dynamic_cast (Openbox::instance->findHandler(e.window)); @@ -71,17 +110,29 @@ void OBActions::buttonReleaseHandler(const XButtonEvent &e) return; // run the CLICK python hook - doCallback(Action_Click, e.window, +/* doCallback(Action_Click, e.window, (OBWidget::WidgetType)(w ? w->type():-1), - e.state, e.button, e.x_root, e.y_root, e.time); + e.state, e.button, e.x_root, e.y_root, e.time);*/ + if (w) { + Openbox::instance->bindings()->fire(MouseClick, w->type(), e.window, + e.state, e.button, + e.x_root, e.y_root, e.time); + } else + assert(false); // why isnt there a type? if (e.time - _release.time < DOUBLECLICKDELAY && _release.win == e.window && _release.button == e.button) { // run the DOUBLECLICK python hook - doCallback(Action_DoubleClick, e.window, +/* doCallback(Action_DoubleClick, e.window, (OBWidget::WidgetType)(w ? w->type():-1), - e.state, e.button, e.x_root, e.y_root, e.time); + e.state, e.button, e.x_root, e.y_root, e.time);*/ + if (w) { + Openbox::instance->bindings()->fire(MouseDoubleClick, w->type(), + e.window, e.state, e.button, + e.x_root, e.y_root, e.time); + } else + assert(false); // why isnt there a type? // reset so you cant triple click for 2 doubleclicks _release.win = 0; @@ -149,16 +200,24 @@ void OBActions::motionHandler(const XMotionEvent &e) } } - + _dx = x_root - _posqueue[0]->pos.x(); _posqueue[0]->pos.setX(x_root); + _dy = y_root - _posqueue[0]->pos.y(); _posqueue[0]->pos.setY(y_root); + OBWidget *w = dynamic_cast (Openbox::instance->findHandler(e.window)); // XXX: i can envision all sorts of crazy shit with this.. gestures, etc // maybe that should all be done via python tho.. (or radial menus!) // run the simple MOTION python hook for now... - doCallback(Action_MouseMotion, e.window, +/* doCallback(Action_MouseMotion, e.window, (OBWidget::WidgetType)(w ? w->type():-1), - e.state, (unsigned)-1, x_root, y_root, e.time); + e.state, (unsigned)-1, x_root, y_root, e.time);*/ + if (w) { + Openbox::instance->bindings()->fire(MouseMotion, w->type(), e.window, + e.state, _posqueue[0]->button, + _dx, _dy, e.time); + } else + assert(false); // why isnt there a type? } void OBActions::mapRequestHandler(const XMapRequestEvent &e) @@ -190,16 +249,16 @@ void OBActions::doCallback(ActionType action, Window window, _callbacks.equal_range(action); CallbackMap::iterator it; - for (it = it_pair.first; it != it_pair.second; ++it) - python_callback(it->second, action, window, type, state, - button, xroot, yroot, time); +// for (it = it_pair.first; it != it_pair.second; ++it) +// python_callback(it->second, action, window, type, state, +// button, xroot, yroot, time); + // XXX do a callback } bool OBActions::registerCallback(ActionType action, PyObject *func, bool atfront) { - if (action < 0 || action >= OBActions::NUM_ACTIONS || - action == OBActions::Action_KeyPress) { + if (action < 0 || action >= OBActions::NUM_ACTIONS) { return false; } if (!func) @@ -222,8 +281,7 @@ bool OBActions::registerCallback(ActionType action, PyObject *func, bool OBActions::unregisterCallback(ActionType action, PyObject *func) { - if (action < 0 || action >= OBActions::NUM_ACTIONS || - action == OBActions::Action_KeyPress) { + if (action < 0 || action >= OBActions::NUM_ACTIONS) { return false; } if (!func) @@ -245,8 +303,7 @@ bool OBActions::unregisterCallback(ActionType action, PyObject *func) bool OBActions::unregisterAllCallbacks(ActionType action) { - if (action < 0 || action >= OBActions::NUM_ACTIONS || - action == OBActions::Action_KeyPress) { + if (action < 0 || action >= OBActions::NUM_ACTIONS) { return false; } diff --git a/src/actions.hh b/src/actions.hh index 98325e87..4a658061 100644 --- a/src/actions.hh +++ b/src/actions.hh @@ -29,13 +29,8 @@ class OBActions : public otk::OtkEventHandler { public: // update the same enum in openbox.i when making changes to this enum ActionType { - Action_ButtonPress, - Action_Click, - Action_DoubleClick, Action_EnterWindow, Action_LeaveWindow, - Action_KeyPress, - Action_MouseMotion, Action_NewWindow, Action_CloseWindow, NUM_ACTIONS @@ -47,16 +42,35 @@ public: Time time; 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; + + void insertPress(const XButtonEvent &e); + void removePress(const XButtonEvent &e); + typedef std::multimap CallbackMap; typedef std::pair CallbackMapPair; CallbackMap _callbacks; diff --git a/src/bindings.cc b/src/bindings.cc index d6bf85d0..ba92b4c9 100644 --- a/src/bindings.cc +++ b/src/bindings.cc @@ -106,26 +106,26 @@ bool OBBindings::translate(const std::string &str, Binding &b,bool askey) const } } -static void destroytree(BindingTree *tree) +static void destroytree(KeyBindingTree *tree) { while (tree) { - BindingTree *c = tree->first_child; + KeyBindingTree *c = tree->first_child; delete tree; tree = c; } } -BindingTree *OBBindings::buildtree(const StringVect &keylist, +KeyBindingTree *OBBindings::buildtree(const StringVect &keylist, PyObject *callback) const { if (keylist.empty()) return 0; // nothing in the list.. return 0 - BindingTree *ret = 0, *p; + KeyBindingTree *ret = 0, *p; StringVect::const_reverse_iterator it, end = keylist.rend(); for (it = keylist.rbegin(); it != end; ++it) { p = ret; - ret = new BindingTree(callback); + ret = new KeyBindingTree(callback); if (!p) ret->chain = false; // only the first built node ret->first_child = p; if (!translate(*it, ret->binding)) { @@ -139,7 +139,7 @@ BindingTree *OBBindings::buildtree(const StringVect &keylist, OBBindings::OBBindings() - : _curpos(&_tree), + : _curpos(&_keytree), _resetkey(0,0), _timer(Openbox::instance->timerManager(), (otk::OBTimeoutHandler)reset, this) @@ -157,15 +157,15 @@ OBBindings::~OBBindings() } -void OBBindings::assimilate(BindingTree *node) +void OBBindings::assimilate(KeyBindingTree *node) { - BindingTree *a, *b, *tmp, *last; + KeyBindingTree *a, *b, *tmp, *last; - if (!_tree.first_child) { + if (!_keytree.first_child) { // there are no nodes at this level yet - _tree.first_child = node; + _keytree.first_child = node; } else { - a = _tree.first_child; + a = _keytree.first_child; last = a; b = node; while (a) { @@ -189,10 +189,10 @@ void OBBindings::assimilate(BindingTree *node) } -PyObject *OBBindings::find(BindingTree *search, bool *conflict) const { +PyObject *OBBindings::find(KeyBindingTree *search, bool *conflict) const { *conflict = false; - BindingTree *a, *b; - a = _tree.first_child; + KeyBindingTree *a, *b; + a = _keytree.first_child; b = search; while (a && b) { if (a->binding != b->binding) { @@ -217,7 +217,7 @@ PyObject *OBBindings::find(BindingTree *search, bool *conflict) const { bool OBBindings::add(const StringVect &keylist, PyObject *callback) { - BindingTree *tree; + KeyBindingTree *tree; bool conflict; if (!(tree = buildtree(keylist, callback))) @@ -246,7 +246,7 @@ bool OBBindings::remove(const StringVect &keylist) { assert(false); // XXX: function not implemented yet - BindingTree *tree; + KeyBindingTree *tree; bool conflict; if (!(tree = buildtree(keylist, 0))) @@ -256,7 +256,7 @@ bool OBBindings::remove(const StringVect &keylist) if (func) { grabKeys(false); - _curpos = &_tree; + _curpos = &_keytree; // XXX do shit here ... Py_DECREF(func); @@ -280,14 +280,14 @@ void OBBindings::setResetKey(const std::string &key) } -static void remove_branch(BindingTree *first) +static void remove_branch(KeyBindingTree *first) { - BindingTree *p = first; + KeyBindingTree *p = first; while (p) { if (p->first_child) remove_branch(p->first_child); - BindingTree *s = p->next_sibling; + KeyBindingTree *s = p->next_sibling; Py_XDECREF(p->callback); delete p; p = s; @@ -297,9 +297,9 @@ static void remove_branch(BindingTree *first) void OBBindings::removeAll() { - if (_tree.first_child) { - remove_branch(_tree.first_child); - _tree.first_child = 0; + if (_keytree.first_child) { + remove_branch(_keytree.first_child); + _keytree.first_child = 0; } } @@ -309,7 +309,7 @@ void OBBindings::grabKeys(bool grab) for (int i = 0; i < Openbox::instance->screenCount(); ++i) { Window root = otk::OBDisplay::screenInfo(i)->rootWindow(); - BindingTree *p = _curpos->first_child; + KeyBindingTree *p = _curpos->first_child; while (p) { if (grab) { otk::OBDisplay::grabKey(p->binding.key, p->binding.modifiers, @@ -338,7 +338,7 @@ void OBBindings::fire(unsigned int modifiers, unsigned int key, Time time) if (key == _resetkey.key && modifiers == _resetkey.modifiers) { reset(this); } else { - BindingTree *p = _curpos->first_child; + KeyBindingTree *p = _curpos->first_child; while (p) { if (p->binding.key == key && p->binding.modifiers == modifiers) { if (p->chain) { @@ -364,8 +364,160 @@ void OBBindings::reset(OBBindings *self) { self->_timer.stop(); self->grabKeys(false); - self->_curpos = &self->_tree; + self->_curpos = &self->_keytree; self->grabKeys(true); } + +bool OBBindings::addButton(const std::string &but, MouseContext context, + MouseAction action, PyObject *callback) +{ + assert(context >= 0 && context < NUM_MOUSE_CONTEXT); + + Binding b(0,0); + if (!translate(but, b, false)) + return false; + + ButtonBindingList::iterator it, end = _buttons[context].end(); + + // look for a duplicate binding + for (it = _buttons[context].begin(); it != end; ++it) + if ((*it)->binding.key == b.key && + (*it)->binding.modifiers == b.modifiers) { + ButtonBinding::CallbackList::iterator c_it, + c_end = (*it)->callback[action].end(); + for (c_it = (*it)->callback[action].begin(); c_it != c_end; ++c_it) + if (*c_it == callback) + return true; // already bound + break; + } + + ButtonBinding *bind; + + // the binding didnt exist yet, add it + if (it == end) { + bind = new ButtonBinding(); + bind->binding.key = b.key; + bind->binding.modifiers = b.modifiers; + _buttons[context].push_back(bind); + printf("adding %d.%d to %d\n", b.key, b.modifiers, context); + // XXX GRAB the new button everywhere! + } else + bind = *it; + bind->callback[action].push_back(callback); + Py_INCREF(callback); + return true; +} + +void OBBindings::grabButtons(bool grab, OBClient *client) +{ + for (int i = 0; i < NUM_MOUSE_CONTEXT; ++i) { + Window win[3] = {0, 0, 0}; // at most 2 windows + switch (i) { + case MC_Frame: + win[0] = client->frame->window(); + break; + case MC_Titlebar: + win[0] = client->frame->titlebar(); + win[1] = client->frame->label(); + break; + case MC_Window: + win[0] = client->frame->plate(); + break; + case MC_MaximizeButton: +// win[0] = client->frame->button_max(); + break; + case MC_CloseButton: +// win[0] = client->frame->button_close(); + break; + case MC_IconifyButton: +// win[0] = client->frame->button_iconify(); + break; + case MC_StickyButton: +// win[0] = client->frame->button_stick(); + break; + case MC_Grip: +// win[0] = client->frame->grip_left(); +// win[1] = client->frame->grip_right(); + break; + case MC_Root: +// win[0] = otk::OBDisplay::screenInfo(client->screen())->rootWindow(); + break; + case MC_MenuItem: + break; + default: + assert(false); // invalid mouse context + } + ButtonBindingList::iterator it, end = _buttons[i].end(); + for (it = _buttons[i].begin(); it != end; ++it) + for (Window *w = win; *w; ++w) { + if (grab) { + otk::OBDisplay::grabButton((*it)->binding.key, + (*it)->binding.modifiers, *w, false, + ButtonPressMask | ButtonMotionMask | + ButtonReleaseMask, GrabModeAsync, + GrabModeAsync, None, None, false); + } + else + otk::OBDisplay::ungrabButton((*it)->binding.key, + (*it)->binding.modifiers, *w); + } + } +} + +void OBBindings::fire(MouseAction action, OBWidget::WidgetType type, + Window win, unsigned int modifiers, unsigned int button, + int xroot, int yroot, Time time) +{ + assert(action >= 0 && action < NUM_MOUSE_ACTION); + + MouseContext context; + switch (type) { + case OBWidget::Type_Frame: + context = MC_Frame; break; + case OBWidget::Type_Titlebar: + context = MC_Titlebar; break; + case OBWidget::Type_Handle: + context = MC_Frame; break; + case OBWidget::Type_Plate: + context = MC_Window; break; + case OBWidget::Type_Label: + context = MC_Titlebar; break; + case OBWidget::Type_MaximizeButton: + context = MC_MaximizeButton; break; + case OBWidget::Type_CloseButton: + context = MC_CloseButton; break; + case OBWidget::Type_IconifyButton: + context = MC_IconifyButton; break; + case OBWidget::Type_StickyButton: + context = MC_StickyButton; break; + case OBWidget::Type_LeftGrip: + context = MC_Grip; break; + case OBWidget::Type_RightGrip: + context = MC_Grip; break; + case OBWidget::Type_Client: + context = MC_Window; break; + case OBWidget::Type_Root: + context = MC_Root; break; + default: + assert(false); // unhandled type + } + + modifiers &= (ControlMask | ShiftMask | Mod1Mask | Mod2Mask | Mod3Mask | + Mod4Mask | Mod5Mask); + + printf("but.mods %d.%d\n", button, modifiers); + + ButtonBindingList::iterator it, end = _buttons[context].end(); + for (it = _buttons[context].begin(); it != end; ++it) + if ((*it)->binding.key == button && + (*it)->binding.modifiers == modifiers) { + ButtonBinding::CallbackList::iterator c_it, + c_end = (*it)->callback[action].end(); + for (c_it = (*it)->callback[action].begin(); c_it != c_end; ++c_it) + python_callback(*c_it, action, win, context, modifiers, + button, xroot, yroot, time); + } +} + } diff --git a/src/bindings.hh b/src/bindings.hh index ee1c7c66..51e2b213 100644 --- a/src/bindings.hh +++ b/src/bindings.hh @@ -7,6 +7,7 @@ */ #include "actions.hh" +#include "python.hh" #include "otk/timer.hh" extern "C" { @@ -32,22 +33,30 @@ typedef struct Binding { Binding(unsigned int mod, unsigned int k) { modifiers = mod; key = k; } } Binding; -typedef struct BindingTree { +typedef struct KeyBindingTree { Binding binding; PyObject *callback; // the callback given for the binding in add() bool chain; // true if this is a chain to another key (not an action) - struct BindingTree *next_sibling; // the next binding in the tree at the same + struct KeyBindingTree *next_sibling; // the next binding in the tree at the same // level - struct BindingTree *first_child; // the first child of this binding (next + struct KeyBindingTree *first_child; // the first child of this binding (next // binding in a chained sequence). - BindingTree(PyObject *callback) : binding(0, 0) { + KeyBindingTree(PyObject *callback) : binding(0, 0) { this->callback = callback; chain = true; next_sibling = first_child = 0; } - BindingTree() : binding(0, 0) { + KeyBindingTree() : binding(0, 0) { this->callback = 0; chain = true; next_sibling = first_child = 0; } -} BindingTree; +} KeyBindingTree; + +typedef struct ButtonBinding { + Binding binding; + typedef std::list CallbackList; + CallbackList callback[NUM_MOUSE_ACTION]; + ButtonBinding() : binding(0, 0) { + } +}; class OBBindings { public: @@ -55,19 +64,24 @@ public: typedef std::vector StringVect; private: - BindingTree _tree; // root node of the tree (this doesn't have siblings!) - BindingTree *_curpos; // position in the keytree + // root node of the tree (this doesn't have siblings!) + KeyBindingTree _keytree; + KeyBindingTree *_curpos; // position in the keytree Binding _resetkey; // the key which resets the key chain status otk::OBTimer _timer; - PyObject *find(BindingTree *search, bool *conflict) const; - BindingTree *buildtree(const StringVect &keylist, PyObject *callback) const; - void assimilate(BindingTree *node); + PyObject *find(KeyBindingTree *search, bool *conflict) const; + KeyBindingTree *buildtree(const StringVect &keylist, + PyObject *callback) const; + void assimilate(KeyBindingTree *node); static void reset(OBBindings *self); // the timer's timeout function + typedef std::list ButtonBindingList; + ButtonBindingList _buttons[NUM_MOUSE_CONTEXT]; + public: //! Initializes an OBBindings object OBBindings(); @@ -100,6 +114,15 @@ public: void setResetKey(const std::string &key); void grabKeys(bool grab); + + bool addButton(const std::string &but, MouseContext context, + MouseAction action, PyObject *callback); + + void grabButtons(bool grab, OBClient *client); + + void fire(MouseAction action, OBWidget::WidgetType type, Window win, + unsigned int modifiers, unsigned int button, + int xroot, int yroot, Time time); }; } diff --git a/src/frame.cc b/src/frame.cc index d7ad2722..e7f310a0 100644 --- a/src/frame.cc +++ b/src/frame.cc @@ -72,7 +72,7 @@ OBFrame::~OBFrame() void OBFrame::grabButtons(bool grab) { - _plate.grabButtons(grab); +/* _plate.grabButtons(grab); // grab any requested buttons on the entire frame std::vector grabs; @@ -92,7 +92,7 @@ void OBFrame::grabButtons(bool grab) otk::OBDisplay::ungrabButton(b.key, b.modifiers, _window); } } - } + }*/ } diff --git a/src/openbox.cc b/src/openbox.cc index 437e5ead..230c749d 100644 --- a/src/openbox.cc +++ b/src/openbox.cc @@ -173,11 +173,10 @@ Openbox::~Openbox() { _state = State_Exiting; // time to kill everything - delete _bindings; - delete _actions; - std::for_each(_screens.begin(), _screens.end(), otk::PointerAssassin()); + delete _bindings; + delete _actions; delete _property; python_destroy(); diff --git a/src/openbox.i b/src/openbox.i index dfd532f3..aeae40dd 100644 --- a/src/openbox.i +++ b/src/openbox.i @@ -24,154 +24,7 @@ ob::Openbox *Openbox_instance() { return ob::Openbox::instance; } %}; -// stuff for scripting callbacks! -%inline %{ - enum ActionType { - Action_ButtonPress, - Action_Click, - Action_DoubleClick, - Action_EnterWindow, - Action_LeaveWindow, - Action_KeyPress, - Action_MouseMotion, - Action_NewWindow, - Action_CloseWindow - }; - 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_Window, - Type_Root - }; -%} %rename(register) python_register; -%inline %{ -/*PyObject * python_register(int action, PyObject *func, bool infront = false) -{ - if (!PyCallable_Check(func)) { - PyErr_SetString(PyExc_TypeError, "Invalid callback function."); - return NULL; - } - - if (!ob::Openbox::instance->actions()->registerCallback( - (ob::OBActions::ActionType)action, func, infront)) { - PyErr_SetString(PyExc_RuntimeError, "Unable to register action callback."); - return NULL; - } - Py_INCREF(Py_None); return Py_None; -} - -PyObject * unregister(int action, PyObject *func) -{ - if (!PyCallable_Check(func)) { - PyErr_SetString(PyExc_TypeError, "Invalid callback function."); - return NULL; - } - - if (!ob::Openbox::instance->actions()->unregisterCallback( - (ob::OBActions::ActionType)action, func)) { - PyErr_SetString(PyExc_RuntimeError, "Unable to unregister action callback."); - return NULL; - } - Py_INCREF(Py_None); return Py_None; -} - -PyObject * unregister_all(int action) -{ - if (!ob::Openbox::instance->actions()->unregisterAllCallbacks( - (ob::OBActions::ActionType)action)) { - PyErr_SetString(PyExc_RuntimeError, - "Unable to unregister action callbacks."); - return NULL; - } - Py_INCREF(Py_None); return Py_None; -} -*/ -PyObject * mbind(const std::string &button, MouseContext context, - PyObject *func) -{ - if (!PyCallable_Check(func)) { - PyErr_SetString(PyExc_TypeError, "Invalid callback function."); - return NULL; - } - - if (!ob::Openbox::instance->bindings()->add(vectkeylist, func)) { - PyErr_SetString(PyExc_RuntimeError,"Unable to add binding."); - return NULL; - } - Py_INCREF(Py_None); return Py_None; -} - -PyObject * kbind(PyObject *keylist, KeyContext context, PyObject *func) -{ - if (!PyCallable_Check(func)) { - PyErr_SetString(PyExc_TypeError, "Invalid callback function."); - return NULL; - } - if (!PyList_Check(keylist)) { - PyErr_SetString(PyExc_TypeError, "Invalid keylist. Not a list."); - return NULL; - } - - ob::OBBindings::StringVect vectkeylist; - for (int i = 0, end = PyList_Size(keylist); i < end; ++i) { - PyObject *str = PyList_GetItem(keylist, i); - if (!PyString_Check(str)) { - PyErr_SetString(PyExc_TypeError, - "Invalid keylist. It must contain only strings."); - return NULL; - } - vectkeylist.push_back(PyString_AsString(str)); - } - - if (!ob::Openbox::instance->bindings()->add(vectkeylist, func)) { - PyErr_SetString(PyExc_RuntimeError,"Unable to add binding."); - return NULL; - } - Py_INCREF(Py_None); return Py_None; -} - -PyObject * kunbind(PyObject *keylist) -{ - if (!PyList_Check(keylist)) { - PyErr_SetString(PyExc_TypeError, "Invalid keylist. Not a list."); - return NULL; - } - - ob::OBBindings::StringVect vectkeylist; - for (int i = 0, end = PyList_Size(keylist); i < end; ++i) { - PyObject *str = PyList_GetItem(keylist, i); - if (!PyString_Check(str)) { - PyErr_SetString(PyExc_TypeError, - "Invalid keylist. It must contain only strings."); - return NULL; - } - vectkeylist.push_back(PyString_AsString(str)); - } - - ob::Openbox::instance->bindings()->remove(vectkeylist); - Py_INCREF(Py_None); return Py_None; -} - -void kunbind_all() -{ - ob::Openbox::instance->bindings()->removeAll(); -} - -void set_reset_key(const std::string &key) -{ - ob::Openbox::instance->bindings()->setResetKey(key); -} -%} %ignore ob::OBScreen::clients; %{ diff --git a/src/openbox_wrap.cc b/src/openbox_wrap.cc index fba10b1f..00dbdf71 100644 --- a/src/openbox_wrap.cc +++ b/src/openbox_wrap.cc @@ -650,29 +650,28 @@ SWIG_InstallConstants(PyObject *d, swig_const_info constants[]) { #define SWIGTYPE_p_ob__Cursors swig_types[2] #define SWIGTYPE_p_ob__OBScreen swig_types[3] #define SWIGTYPE_p_otk__Style swig_types[4] -#define SWIGTYPE_p_KeyContext swig_types[5] -#define SWIGTYPE_p_ob__OBFrame swig_types[6] -#define SWIGTYPE_p_XReparentEvent swig_types[7] -#define SWIGTYPE_p_ob__OBClient swig_types[8] -#define SWIGTYPE_p_ob__Openbox swig_types[9] -#define SWIGTYPE_p_otk__Strut swig_types[10] -#define SWIGTYPE_p_XShapeEvent swig_types[11] -#define SWIGTYPE_p_XConfigureRequestEvent swig_types[12] -#define SWIGTYPE_p_otk__OtkEventHandler swig_types[13] +#define SWIGTYPE_p_ob__OBFrame swig_types[5] +#define SWIGTYPE_p_XReparentEvent swig_types[6] +#define SWIGTYPE_p_ob__OBClient swig_types[7] +#define SWIGTYPE_p_ob__Openbox swig_types[8] +#define SWIGTYPE_p_otk__Strut swig_types[9] +#define SWIGTYPE_p_XShapeEvent swig_types[10] +#define SWIGTYPE_p_XConfigureRequestEvent swig_types[11] +#define SWIGTYPE_p_otk__OtkEventHandler swig_types[12] +#define SWIGTYPE_p_otk__Rect swig_types[13] #define SWIGTYPE_p_ob__OBWidget swig_types[14] -#define SWIGTYPE_p_otk__Rect swig_types[15] -#define SWIGTYPE_p_XFocusChangeEvent swig_types[16] -#define SWIGTYPE_p_XClientMessageEvent swig_types[17] -#define SWIGTYPE_p_otk__OBProperty swig_types[18] -#define SWIGTYPE_p_otk__OtkEventDispatcher swig_types[19] -#define SWIGTYPE_p_XPropertyEvent swig_types[20] -#define SWIGTYPE_p_XDestroyWindowEvent swig_types[21] +#define SWIGTYPE_p_XFocusChangeEvent swig_types[15] +#define SWIGTYPE_p_XClientMessageEvent swig_types[16] +#define SWIGTYPE_p_otk__OBProperty swig_types[17] +#define SWIGTYPE_p_otk__OtkEventDispatcher swig_types[18] +#define SWIGTYPE_p_XPropertyEvent swig_types[19] +#define SWIGTYPE_p_XDestroyWindowEvent swig_types[20] +#define SWIGTYPE_p_otk__BImageControl swig_types[21] #define SWIGTYPE_p_PyObject swig_types[22] -#define SWIGTYPE_p_otk__BImageControl swig_types[23] -#define SWIGTYPE_p_ob__OBBindings swig_types[24] -#define SWIGTYPE_p_ob__MwmHints swig_types[25] -#define SWIGTYPE_p_XUnmapEvent swig_types[26] -static swig_type_info *swig_types[28]; +#define SWIGTYPE_p_ob__OBBindings swig_types[23] +#define SWIGTYPE_p_ob__MwmHints swig_types[24] +#define SWIGTYPE_p_XUnmapEvent swig_types[25] +static swig_type_info *swig_types[27]; /* -------- TYPES TABLE (END) -------- */ @@ -779,151 +778,6 @@ static std::string SwigString_AsString(PyObject* o) { ob::Openbox *Openbox_instance() { return ob::Openbox::instance; } - enum ActionType { - Action_ButtonPress, - Action_Click, - Action_DoubleClick, - Action_EnterWindow, - Action_LeaveWindow, - Action_KeyPress, - Action_MouseMotion, - Action_NewWindow, - Action_CloseWindow - }; - 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_Window, - Type_Root - }; - - -/*PyObject * python_register(int action, PyObject *func, bool infront = false) -{ - if (!PyCallable_Check(func)) { - PyErr_SetString(PyExc_TypeError, "Invalid callback function."); - return NULL; - } - - if (!ob::Openbox::instance->actions()->registerCallback( - (ob::OBActions::ActionType)action, func, infront)) { - PyErr_SetString(PyExc_RuntimeError, "Unable to register action callback."); - return NULL; - } - Py_INCREF(Py_None); return Py_None; -} - -PyObject * unregister(int action, PyObject *func) -{ - if (!PyCallable_Check(func)) { - PyErr_SetString(PyExc_TypeError, "Invalid callback function."); - return NULL; - } - - if (!ob::Openbox::instance->actions()->unregisterCallback( - (ob::OBActions::ActionType)action, func)) { - PyErr_SetString(PyExc_RuntimeError, "Unable to unregister action callback."); - return NULL; - } - Py_INCREF(Py_None); return Py_None; -} - -PyObject * unregister_all(int action) -{ - if (!ob::Openbox::instance->actions()->unregisterAllCallbacks( - (ob::OBActions::ActionType)action)) { - PyErr_SetString(PyExc_RuntimeError, - "Unable to unregister action callbacks."); - return NULL; - } - Py_INCREF(Py_None); return Py_None; -} -*/ -PyObject * mbind(const std::string &button, KeyContext context, PyObject *func) -{ - if (!PyCallable_Check(func)) { - PyErr_SetString(PyExc_TypeError, "Invalid callback function."); - return NULL; - } - - if (!ob::Openbox::instance->bindings()->add(vectkeylist, func)) { - PyErr_SetString(PyExc_RuntimeError,"Unable to add binding."); - return NULL; - } - Py_INCREF(Py_None); return Py_None; -} - -PyObject * kbind(PyObject *keylist, KeyContext context, PyObject *func) -{ - if (!PyCallable_Check(func)) { - PyErr_SetString(PyExc_TypeError, "Invalid callback function."); - return NULL; - } - if (!PyList_Check(keylist)) { - PyErr_SetString(PyExc_TypeError, "Invalid keylist. Not a list."); - return NULL; - } - - ob::OBBindings::StringVect vectkeylist; - for (int i = 0, end = PyList_Size(keylist); i < end; ++i) { - PyObject *str = PyList_GetItem(keylist, i); - if (!PyString_Check(str)) { - PyErr_SetString(PyExc_TypeError, - "Invalid keylist. It must contain only strings."); - return NULL; - } - vectkeylist.push_back(PyString_AsString(str)); - } - - if (!ob::Openbox::instance->bindings()->add(vectkeylist, func)) { - PyErr_SetString(PyExc_RuntimeError,"Unable to add binding."); - return NULL; - } - Py_INCREF(Py_None); return Py_None; -} - -PyObject * kunbind(PyObject *keylist) -{ - if (!PyList_Check(keylist)) { - PyErr_SetString(PyExc_TypeError, "Invalid keylist. Not a list."); - return NULL; - } - - ob::OBBindings::StringVect vectkeylist; - for (int i = 0, end = PyList_Size(keylist); i < end; ++i) { - PyObject *str = PyList_GetItem(keylist, i); - if (!PyString_Check(str)) { - PyErr_SetString(PyExc_TypeError, - "Invalid keylist. It must contain only strings."); - return NULL; - } - vectkeylist.push_back(PyString_AsString(str)); - } - - ob::Openbox::instance->bindings()->remove(vectkeylist); - Py_INCREF(Py_None); return Py_None; -} - -void kunbind_all() -{ - ob::Openbox::instance->bindings()->removeAll(); -} - -void set_reset_key(const std::string &key) -{ - ob::Openbox::instance->bindings()->setResetKey(key); -} - - #include ob::OBClient *ob_OBScreen_client(ob::OBScreen *self,int i){ @@ -953,118 +807,6 @@ static PyObject *_wrap_Openbox_instance(PyObject *self, PyObject *args) { } -static PyObject *_wrap_mbind(PyObject *self, PyObject *args) { - PyObject *resultobj; - std::string *arg1 = 0 ; - KeyContext arg2 ; - PyObject *arg3 = (PyObject *) 0 ; - PyObject *result; - std::string temp1 ; - KeyContext *argp2 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - PyObject * obj2 = 0 ; - - if(!PyArg_ParseTuple(args,(char *)"OOO:mbind",&obj0,&obj1,&obj2)) goto fail; - { - if (PyString_Check(obj0)) { - temp1 = std::string(PyString_AsString(obj0)); - arg1 = &temp1; - }else { - SWIG_exception(SWIG_TypeError, "string expected"); - } - } - if ((SWIG_ConvertPtr(obj1,(void **) &argp2, SWIGTYPE_p_KeyContext,SWIG_POINTER_EXCEPTION) == -1)) SWIG_fail; - arg2 = *argp2; - arg3 = obj2; - result = (PyObject *)mbind((std::string const &)*arg1,arg2,arg3); - - resultobj = result; - return resultobj; - fail: - return NULL; -} - - -static PyObject *_wrap_kbind(PyObject *self, PyObject *args) { - PyObject *resultobj; - PyObject *arg1 = (PyObject *) 0 ; - KeyContext arg2 ; - PyObject *arg3 = (PyObject *) 0 ; - PyObject *result; - KeyContext *argp2 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - PyObject * obj2 = 0 ; - - if(!PyArg_ParseTuple(args,(char *)"OOO:kbind",&obj0,&obj1,&obj2)) goto fail; - arg1 = obj0; - if ((SWIG_ConvertPtr(obj1,(void **) &argp2, SWIGTYPE_p_KeyContext,SWIG_POINTER_EXCEPTION) == -1)) SWIG_fail; - arg2 = *argp2; - arg3 = obj2; - result = (PyObject *)kbind(arg1,arg2,arg3); - - resultobj = result; - return resultobj; - fail: - return NULL; -} - - -static PyObject *_wrap_kunbind(PyObject *self, PyObject *args) { - PyObject *resultobj; - PyObject *arg1 = (PyObject *) 0 ; - PyObject *result; - PyObject * obj0 = 0 ; - - if(!PyArg_ParseTuple(args,(char *)"O:kunbind",&obj0)) goto fail; - arg1 = obj0; - result = (PyObject *)kunbind(arg1); - - resultobj = result; - return resultobj; - fail: - return NULL; -} - - -static PyObject *_wrap_kunbind_all(PyObject *self, PyObject *args) { - PyObject *resultobj; - - if(!PyArg_ParseTuple(args,(char *)":kunbind_all")) goto fail; - kunbind_all(); - - Py_INCREF(Py_None); resultobj = Py_None; - return resultobj; - fail: - return NULL; -} - - -static PyObject *_wrap_set_reset_key(PyObject *self, PyObject *args) { - PyObject *resultobj; - std::string *arg1 = 0 ; - std::string temp1 ; - PyObject * obj0 = 0 ; - - if(!PyArg_ParseTuple(args,(char *)"O:set_reset_key",&obj0)) goto fail; - { - if (PyString_Check(obj0)) { - temp1 = std::string(PyString_AsString(obj0)); - arg1 = &temp1; - }else { - SWIG_exception(SWIG_TypeError, "string expected"); - } - } - set_reset_key((std::string const &)*arg1); - - Py_INCREF(Py_None); resultobj = Py_None; - return resultobj; - fail: - return NULL; -} - - static PyObject *_wrap_Cursors_session_set(PyObject *self, PyObject *args) { PyObject *resultobj; ob::Cursors *arg1 = (ob::Cursors *) 0 ; @@ -2727,13 +2469,113 @@ static PyObject * OBClient_swigregister(PyObject *self, PyObject *args) { Py_INCREF(obj); return Py_BuildValue((char *)""); } +static PyObject *_wrap_mbind(PyObject *self, PyObject *args) { + PyObject *resultobj; + std::string *arg1 = 0 ; + int arg2 ; + int arg3 ; + PyObject *arg4 = (PyObject *) 0 ; + PyObject *result; + std::string temp1 ; + PyObject * obj0 = 0 ; + PyObject * obj3 = 0 ; + + if(!PyArg_ParseTuple(args,(char *)"OiiO:mbind",&obj0,&arg2,&arg3,&obj3)) goto fail; + { + if (PyString_Check(obj0)) { + temp1 = std::string(PyString_AsString(obj0)); + arg1 = &temp1; + }else { + SWIG_exception(SWIG_TypeError, "string expected"); + } + } + arg4 = obj3; + result = (PyObject *)ob::mbind((std::string const &)*arg1,(ob::MouseContext )arg2,(ob::MouseAction )arg3,arg4); + + resultobj = result; + return resultobj; + fail: + return NULL; +} + + +static PyObject *_wrap_kbind(PyObject *self, PyObject *args) { + PyObject *resultobj; + PyObject *arg1 = (PyObject *) 0 ; + int arg2 ; + PyObject *arg3 = (PyObject *) 0 ; + PyObject *result; + PyObject * obj0 = 0 ; + PyObject * obj2 = 0 ; + + if(!PyArg_ParseTuple(args,(char *)"OiO:kbind",&obj0,&arg2,&obj2)) goto fail; + arg1 = obj0; + arg3 = obj2; + result = (PyObject *)ob::kbind(arg1,(ob::KeyContext )arg2,arg3); + + resultobj = result; + return resultobj; + fail: + return NULL; +} + + +static PyObject *_wrap_kunbind(PyObject *self, PyObject *args) { + PyObject *resultobj; + PyObject *arg1 = (PyObject *) 0 ; + PyObject *result; + PyObject * obj0 = 0 ; + + if(!PyArg_ParseTuple(args,(char *)"O:kunbind",&obj0)) goto fail; + arg1 = obj0; + result = (PyObject *)ob::kunbind(arg1); + + resultobj = result; + return resultobj; + fail: + return NULL; +} + + +static PyObject *_wrap_kunbind_all(PyObject *self, PyObject *args) { + PyObject *resultobj; + + if(!PyArg_ParseTuple(args,(char *)":kunbind_all")) goto fail; + ob::kunbind_all(); + + Py_INCREF(Py_None); resultobj = Py_None; + return resultobj; + fail: + return NULL; +} + + +static PyObject *_wrap_set_reset_key(PyObject *self, PyObject *args) { + PyObject *resultobj; + std::string *arg1 = 0 ; + std::string temp1 ; + PyObject * obj0 = 0 ; + + if(!PyArg_ParseTuple(args,(char *)"O:set_reset_key",&obj0)) goto fail; + { + if (PyString_Check(obj0)) { + temp1 = std::string(PyString_AsString(obj0)); + arg1 = &temp1; + }else { + SWIG_exception(SWIG_TypeError, "string expected"); + } + } + ob::set_reset_key((std::string const &)*arg1); + + Py_INCREF(Py_None); resultobj = Py_None; + return resultobj; + fail: + return NULL; +} + + static PyMethodDef SwigMethods[] = { { (char *)"Openbox_instance", _wrap_Openbox_instance, METH_VARARGS }, - { (char *)"mbind", _wrap_mbind, METH_VARARGS }, - { (char *)"kbind", _wrap_kbind, METH_VARARGS }, - { (char *)"kunbind", _wrap_kunbind, METH_VARARGS }, - { (char *)"kunbind_all", _wrap_kunbind_all, METH_VARARGS }, - { (char *)"set_reset_key", _wrap_set_reset_key, METH_VARARGS }, { (char *)"Cursors_session_set", _wrap_Cursors_session_set, METH_VARARGS }, { (char *)"Cursors_session_get", _wrap_Cursors_session_get, METH_VARARGS }, { (char *)"Cursors_move_set", _wrap_Cursors_move_set, METH_VARARGS }, @@ -2827,6 +2669,11 @@ static PyMethodDef SwigMethods[] = { { (char *)"OBClient_destroyHandler", _wrap_OBClient_destroyHandler, METH_VARARGS }, { (char *)"OBClient_reparentHandler", _wrap_OBClient_reparentHandler, METH_VARARGS }, { (char *)"OBClient_swigregister", OBClient_swigregister, METH_VARARGS }, + { (char *)"mbind", _wrap_mbind, METH_VARARGS }, + { (char *)"kbind", _wrap_kbind, METH_VARARGS }, + { (char *)"kunbind", _wrap_kunbind, METH_VARARGS }, + { (char *)"kunbind_all", _wrap_kunbind_all, METH_VARARGS }, + { (char *)"set_reset_key", _wrap_set_reset_key, METH_VARARGS }, { NULL, NULL } }; @@ -2853,7 +2700,6 @@ static swig_type_info _swigt__p_ob__OBActions[] = {{"_p_ob__OBActions", 0, "ob:: static swig_type_info _swigt__p_ob__Cursors[] = {{"_p_ob__Cursors", 0, "ob::Cursors *", 0},{"_p_ob__Cursors"},{0}}; static swig_type_info _swigt__p_ob__OBScreen[] = {{"_p_ob__OBScreen", 0, "ob::OBScreen *", 0},{"_p_ob__OBScreen"},{0}}; static swig_type_info _swigt__p_otk__Style[] = {{"_p_otk__Style", 0, "otk::Style *", 0},{"_p_otk__Style"},{0}}; -static swig_type_info _swigt__p_KeyContext[] = {{"_p_KeyContext", 0, "KeyContext *", 0},{"_p_KeyContext"},{0}}; static swig_type_info _swigt__p_ob__OBFrame[] = {{"_p_ob__OBFrame", 0, "ob::OBFrame *", 0},{"_p_ob__OBFrame"},{0}}; static swig_type_info _swigt__p_XReparentEvent[] = {{"_p_XReparentEvent", 0, "XReparentEvent *", 0},{"_p_XReparentEvent"},{0}}; static swig_type_info _swigt__p_ob__OBClient[] = {{"_p_ob__OBClient", 0, "ob::OBClient *", 0},{"_p_ob__OBClient"},{0}}; @@ -2862,16 +2708,16 @@ static swig_type_info _swigt__p_otk__Strut[] = {{"_p_otk__Strut", 0, "otk::Strut static swig_type_info _swigt__p_XShapeEvent[] = {{"_p_XShapeEvent", 0, "XShapeEvent *", 0},{"_p_XShapeEvent"},{0}}; static swig_type_info _swigt__p_XConfigureRequestEvent[] = {{"_p_XConfigureRequestEvent", 0, "XConfigureRequestEvent *", 0},{"_p_XConfigureRequestEvent"},{0}}; static swig_type_info _swigt__p_otk__OtkEventHandler[] = {{"_p_otk__OtkEventHandler", 0, "otk::OtkEventHandler *", 0},{"_p_ob__OBActions", _p_ob__OBActionsTo_p_otk__OtkEventHandler},{"_p_otk__OtkEventHandler"},{"_p_ob__Openbox", _p_ob__OpenboxTo_p_otk__OtkEventHandler},{"_p_ob__OBClient", _p_ob__OBClientTo_p_otk__OtkEventHandler},{0}}; -static swig_type_info _swigt__p_ob__OBWidget[] = {{"_p_ob__OBWidget", 0, "ob::OBWidget *", 0},{"_p_ob__OBWidget"},{"_p_ob__OBClient", _p_ob__OBClientTo_p_ob__OBWidget},{0}}; static swig_type_info _swigt__p_otk__Rect[] = {{"_p_otk__Rect", 0, "otk::Rect *", 0},{"_p_otk__Rect"},{0}}; +static swig_type_info _swigt__p_ob__OBWidget[] = {{"_p_ob__OBWidget", 0, "ob::OBWidget *", 0},{"_p_ob__OBWidget"},{"_p_ob__OBClient", _p_ob__OBClientTo_p_ob__OBWidget},{0}}; static swig_type_info _swigt__p_XFocusChangeEvent[] = {{"_p_XFocusChangeEvent", 0, "XFocusChangeEvent *", 0},{"_p_XFocusChangeEvent"},{0}}; static swig_type_info _swigt__p_XClientMessageEvent[] = {{"_p_XClientMessageEvent", 0, "XClientMessageEvent *", 0},{"_p_XClientMessageEvent"},{0}}; static swig_type_info _swigt__p_otk__OBProperty[] = {{"_p_otk__OBProperty", 0, "otk::OBProperty *", 0},{"_p_otk__OBProperty"},{0}}; static swig_type_info _swigt__p_otk__OtkEventDispatcher[] = {{"_p_otk__OtkEventDispatcher", 0, "otk::OtkEventDispatcher *", 0},{"_p_otk__OtkEventDispatcher"},{"_p_ob__Openbox", _p_ob__OpenboxTo_p_otk__OtkEventDispatcher},{0}}; static swig_type_info _swigt__p_XPropertyEvent[] = {{"_p_XPropertyEvent", 0, "XPropertyEvent *", 0},{"_p_XPropertyEvent"},{0}}; static swig_type_info _swigt__p_XDestroyWindowEvent[] = {{"_p_XDestroyWindowEvent", 0, "XDestroyWindowEvent *", 0},{"_p_XDestroyWindowEvent"},{0}}; -static swig_type_info _swigt__p_PyObject[] = {{"_p_PyObject", 0, "PyObject *", 0},{"_p_PyObject"},{0}}; static swig_type_info _swigt__p_otk__BImageControl[] = {{"_p_otk__BImageControl", 0, "otk::BImageControl *", 0},{"_p_otk__BImageControl"},{0}}; +static swig_type_info _swigt__p_PyObject[] = {{"_p_PyObject", 0, "PyObject *", 0},{"_p_PyObject"},{0}}; static swig_type_info _swigt__p_ob__OBBindings[] = {{"_p_ob__OBBindings", 0, "ob::OBBindings *", 0},{"_p_ob__OBBindings"},{0}}; static swig_type_info _swigt__p_ob__MwmHints[] = {{"_p_ob__MwmHints", 0, "ob::MwmHints *", 0},{"_p_ob__MwmHints"},{0}}; static swig_type_info _swigt__p_XUnmapEvent[] = {{"_p_XUnmapEvent", 0, "XUnmapEvent *", 0},{"_p_XUnmapEvent"},{0}}; @@ -2882,7 +2728,6 @@ _swigt__p_ob__OBActions, _swigt__p_ob__Cursors, _swigt__p_ob__OBScreen, _swigt__p_otk__Style, -_swigt__p_KeyContext, _swigt__p_ob__OBFrame, _swigt__p_XReparentEvent, _swigt__p_ob__OBClient, @@ -2891,16 +2736,16 @@ _swigt__p_otk__Strut, _swigt__p_XShapeEvent, _swigt__p_XConfigureRequestEvent, _swigt__p_otk__OtkEventHandler, -_swigt__p_ob__OBWidget, _swigt__p_otk__Rect, +_swigt__p_ob__OBWidget, _swigt__p_XFocusChangeEvent, _swigt__p_XClientMessageEvent, _swigt__p_otk__OBProperty, _swigt__p_otk__OtkEventDispatcher, _swigt__p_XPropertyEvent, _swigt__p_XDestroyWindowEvent, -_swigt__p_PyObject, _swigt__p_otk__BImageControl, +_swigt__p_PyObject, _swigt__p_ob__OBBindings, _swigt__p_ob__MwmHints, _swigt__p_XUnmapEvent, @@ -2911,28 +2756,6 @@ _swigt__p_XUnmapEvent, /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */ static swig_const_info swig_const_table[] = { -{ SWIG_PY_INT, (char *)"Action_ButtonPress", (long) Action_ButtonPress, 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 *)"Action_NewWindow", (long) Action_NewWindow, 0, 0, 0}, -{ SWIG_PY_INT, (char *)"Action_CloseWindow", (long) Action_CloseWindow, 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_Window", (long) Type_Window, 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}, @@ -2980,6 +2803,25 @@ static swig_const_info swig_const_table[] = { { SWIG_PY_INT, (char *)"OBClient_State_Toggle", (long) ob::OBClient::State_Toggle, 0, 0, 0}, { SWIG_PY_INT, (char *)"OBClient_event_mask", (long) ob::OBClient::event_mask, 0, 0, 0}, { SWIG_PY_INT, (char *)"OBClient_no_propagate_mask", (long) ob::OBClient::no_propagate_mask, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"MC_Frame", (long) ob::MC_Frame, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"MC_Titlebar", (long) ob::MC_Titlebar, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"MC_Window", (long) ob::MC_Window, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"MC_MaximizeButton", (long) ob::MC_MaximizeButton, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"MC_CloseButton", (long) ob::MC_CloseButton, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"MC_IconifyButton", (long) ob::MC_IconifyButton, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"MC_StickyButton", (long) ob::MC_StickyButton, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"MC_Grip", (long) ob::MC_Grip, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"MC_Root", (long) ob::MC_Root, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"MC_MenuItem", (long) ob::MC_MenuItem, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"NUM_MOUSE_CONTEXT", (long) ob::NUM_MOUSE_CONTEXT, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"MousePress", (long) ob::MousePress, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"MouseClick", (long) ob::MouseClick, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"MouseDoubleClick", (long) ob::MouseDoubleClick, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"MouseMotion", (long) ob::MouseMotion, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"NUM_MOUSE_ACTION", (long) ob::NUM_MOUSE_ACTION, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"KC_Menu", (long) ob::KC_Menu, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"KC_All", (long) ob::KC_All, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"NUM_KEY_CONTEXT", (long) ob::NUM_KEY_CONTEXT, 0, 0, 0}, { SWIG_PY_INT, (char *)"X_PROTOCOL", (long) 11, 0, 0, 0}, { SWIG_PY_INT, (char *)"X_PROTOCOL_REVISION", (long) 0, 0, 0, 0}, { SWIG_PY_INT, (char *)"None", (long) 0L, 0, 0, 0}, diff --git a/src/python.cc b/src/python.cc index f1b7f43c..edadbc25 100644 --- a/src/python.cc +++ b/src/python.cc @@ -24,9 +24,9 @@ static PyObject *obdict = NULL; typedef struct { PyObject_HEAD; - OBActions::ActionType action; + MouseAction action; Window window; - OBWidget::WidgetType type; + MouseContext context; unsigned int state; unsigned int button; int xroot; @@ -64,10 +64,10 @@ PyObject *ActionData_window(ActionData *self, PyObject *args) return PyLong_FromLong(self->window); } -PyObject *ActionData_target(ActionData *self, PyObject *args) +PyObject *ActionData_context(ActionData *self, PyObject *args) { - if(!PyArg_ParseTuple(args,":target")) return NULL; - return PyLong_FromLong((int)self->type); + if(!PyArg_ParseTuple(args,":context")) return NULL; + return PyLong_FromLong((int)self->context); } PyObject *ActionData_modifiers(ActionData *self, PyObject *args) @@ -114,8 +114,8 @@ static PyMethodDef ActionData_methods[] = { "Return the action being executed."}, {"window", (PyCFunction)ActionData_window, METH_VARARGS, "Return the client window id."}, - {"target", (PyCFunction)ActionData_target, METH_VARARGS, - "Return the target type that the action is occuring on."}, + {"context", (PyCFunction)ActionData_context, METH_VARARGS, + "Return the context that the action is occuring in."}, {"modifiers", (PyCFunction)ActionData_modifiers, METH_VARARGS, "Return the modifier keys state."}, {"button", (PyCFunction)ActionData_button, METH_VARARGS, @@ -258,8 +258,8 @@ static void call(PyObject *func, PyObject *data) Py_DECREF(arglist); } -void python_callback(PyObject *func, OBActions::ActionType action, - Window window, OBWidget::WidgetType type, +void python_callback(PyObject *func, MouseAction action, + Window window, MouseContext context, unsigned int state, unsigned int button, int xroot, int yroot, Time time) { @@ -268,7 +268,7 @@ void python_callback(PyObject *func, OBActions::ActionType action, ActionData *data = PyObject_New(ActionData, &ActionData_Type); data->action = action; data->window = window; - data->type = type; + data->context= context; data->state = state; data->button = button; data->xroot = xroot; @@ -316,4 +316,126 @@ bool python_get_stringlist(const char *name, std::vector *value) return true; } +// ************************************* // +// Stuff for calling from Python scripts // +// ************************************* // + +/* +PyObject * python_register(int action, PyObject *func, bool infront = false) +{ + if (!PyCallable_Check(func)) { + PyErr_SetString(PyExc_TypeError, "Invalid callback function."); + return NULL; + } + + if (!ob::Openbox::instance->actions()->registerCallback( + (ob::OBActions::ActionType)action, func, infront)) { + PyErr_SetString(PyExc_RuntimeError, "Unable to register action callback."); + return NULL; + } + Py_INCREF(Py_None); return Py_None; +} + +PyObject *unregister(int action, PyObject *func) +{ + if (!PyCallable_Check(func)) { + PyErr_SetString(PyExc_TypeError, "Invalid callback function."); + return NULL; + } + + if (!ob::Openbox::instance->actions()->unregisterCallback( + (ob::OBActions::ActionType)action, func)) { + PyErr_SetString(PyExc_RuntimeError, "Unable to unregister action callback."); + return NULL; + } + Py_INCREF(Py_None); return Py_None; +} + +PyObject *unregister_all(int action) +{ + if (!ob::Openbox::instance->actions()->unregisterAllCallbacks( + (ob::OBActions::ActionType)action)) { + PyErr_SetString(PyExc_RuntimeError, + "Unable to unregister action callbacks."); + return NULL; + } + Py_INCREF(Py_None); return Py_None; +} +*/ +PyObject * mbind(const std::string &button, ob::MouseContext context, + ob::MouseAction action, PyObject *func) +{ + if (!PyCallable_Check(func)) { + PyErr_SetString(PyExc_TypeError, "Invalid callback function."); + return NULL; + } + + if (!ob::Openbox::instance->bindings()->addButton(button, context, + action, func)) { + PyErr_SetString(PyExc_RuntimeError,"Unable to add binding."); + return NULL; + } + Py_INCREF(Py_None); return Py_None; +} + +PyObject * kbind(PyObject *keylist, ob::KeyContext context, PyObject *func) +{ + if (!PyCallable_Check(func)) { + PyErr_SetString(PyExc_TypeError, "Invalid callback function."); + return NULL; + } + if (!PyList_Check(keylist)) { + PyErr_SetString(PyExc_TypeError, "Invalid keylist. Not a list."); + return NULL; + } + + ob::OBBindings::StringVect vectkeylist; + for (int i = 0, end = PyList_Size(keylist); i < end; ++i) { + PyObject *str = PyList_GetItem(keylist, i); + if (!PyString_Check(str)) { + PyErr_SetString(PyExc_TypeError, + "Invalid keylist. It must contain only strings."); + return NULL; + } + vectkeylist.push_back(PyString_AsString(str)); + } + + if (!ob::Openbox::instance->bindings()->add(vectkeylist, func)) { + PyErr_SetString(PyExc_RuntimeError,"Unable to add binding."); + return NULL; + } + Py_INCREF(Py_None); return Py_None; +} + +PyObject * kunbind(PyObject *keylist) +{ + if (!PyList_Check(keylist)) { + PyErr_SetString(PyExc_TypeError, "Invalid keylist. Not a list."); + return NULL; + } + + ob::OBBindings::StringVect vectkeylist; + for (int i = 0, end = PyList_Size(keylist); i < end; ++i) { + PyObject *str = PyList_GetItem(keylist, i); + if (!PyString_Check(str)) { + PyErr_SetString(PyExc_TypeError, + "Invalid keylist. It must contain only strings."); + return NULL; + } + vectkeylist.push_back(PyString_AsString(str)); + } + + ob::Openbox::instance->bindings()->remove(vectkeylist); + Py_INCREF(Py_None); return Py_None; +} + +void kunbind_all() +{ + ob::Openbox::instance->bindings()->removeAll(); +} + +void set_reset_key(const std::string &key) +{ + ob::Openbox::instance->bindings()->setResetKey(key); +} } diff --git a/src/python.hh b/src/python.hh index c3dabeb8..c5e566f4 100644 --- a/src/python.hh +++ b/src/python.hh @@ -6,15 +6,13 @@ @brief wee */ -#include "actions.hh" -#include "widget.hh" -#include "bindings.hh" - extern "C" { +#include #include } #include +#include namespace ob { @@ -29,22 +27,30 @@ enum MouseContext { MC_Grip, MC_Root, MC_MenuItem, - MC_All, NUM_MOUSE_CONTEXT -} +}; + +enum MouseAction { + MousePress, + MouseClick, + MouseDoubleClick, + MouseMotion, + NUM_MOUSE_ACTION +}; + enum KeyContext { KC_Menu, KC_All, NUM_KEY_CONTEXT -} +}; #ifndef SWIG void python_init(char *argv0); void python_destroy(); bool python_exec(const std::string &path); -void python_callback(PyObject *func, OBActions::ActionType action, - Window window, OBWidget::WidgetType type, +void python_callback(PyObject *func, MouseAction action, + Window window, MouseContext context, unsigned int state, unsigned int button, int xroot, int yroot, Time time); @@ -56,6 +62,14 @@ bool python_get_string(const char *name, std::string *value); bool python_get_stringlist(const char *name, std::vector *value); #endif +PyObject * mbind(const std::string &button, ob::MouseContext context, + ob::MouseAction action, PyObject *func); + +PyObject * kbind(PyObject *keylist, ob::KeyContext context, PyObject *func); +PyObject * kunbind(PyObject *keylist); +void kunbind_all(); +void set_reset_key(const std::string &key); + } #endif // __python_hh diff --git a/src/screen.cc b/src/screen.cc index da603ed8..0116e470 100644 --- a/src/screen.cc +++ b/src/screen.cc @@ -404,6 +404,8 @@ void OBScreen::manageWindow(Window window) clients.push_back(client); // update the root properties setClientList(); + + Openbox::instance->bindings()->grabButtons(true, client); } @@ -411,6 +413,8 @@ void OBScreen::unmanageWindow(OBClient *client) { OBFrame *frame = client->frame; + Openbox::instance->bindings()->grabButtons(false, client); + // XXX: pass around focus if this window was focused // remove from the wm's map -- 2.39.2