all repos — openbox @ a6661d587cd043e1894418c091b8dbd4e18a7d55

openbox fork - make it a bit more like ryudo

bindings work. now they have a reset key too.
Dana Jansens danakj@orodu.net
commit

a6661d587cd043e1894418c091b8dbd4e18a7d55

parent

d7a30f93b517ac76816d0acea92e9c56ad5d6594

M otk/display.ccotk/display.cc

@@ -227,5 +227,24 @@ XUngrabButton(otk::OBDisplay::display, button, modifiers | _mask_list[cnt],

grab_window); } +void OBDisplay::grabKey(unsigned int keycode, unsigned int modifiers, + Window grab_window, bool owner_events, + int pointer_mode, int keyboard_mode, + bool allow_scroll_lock) +{ + unsigned int length = (allow_scroll_lock) ? 8 / 2: + 8; + for (size_t cnt = 0; cnt < length; ++cnt) + XGrabKey(otk::OBDisplay::display, keycode, modifiers | _mask_list[cnt], + grab_window, owner_events, pointer_mode, keyboard_mode); +} + +void OBDisplay::ungrabKey(unsigned int keycode, unsigned int modifiers, + Window grab_window) +{ + for (size_t cnt = 0; cnt < 8; ++cnt) + XUngrabKey(otk::OBDisplay::display, keycode, modifiers | _mask_list[cnt], + grab_window); +} }
M otk/display.hhotk/display.hh

@@ -116,7 +116,7 @@ Window grab_window);

static void grabKey(unsigned int keycode, unsigned int modifiers, Window grab_window, bool owner_events, int pointer_mode, int keyboard_mode, bool allow_scroll_lock); - static void ungrabKey(unsigned int button, unsigned int modifiers, + static void ungrabKey(unsigned int keycode, unsigned int modifiers, Window grab_window); };
M otk/otk_wrap.ccotk/otk_wrap.cc

@@ -5605,6 +5605,68 @@ return NULL;

} +static PyObject *_wrap_OBDisplay_grabKey(PyObject *self, PyObject *args) { + PyObject *resultobj; + unsigned int arg1 ; + unsigned int arg2 ; + Window arg3 ; + bool arg4 ; + int arg5 ; + int arg6 ; + bool arg7 ; + Window *argp3 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + PyObject * obj2 = 0 ; + PyObject * obj3 = 0 ; + PyObject * obj6 = 0 ; + + if(!PyArg_ParseTuple(args,(char *)"OOOOiiO:OBDisplay_grabKey",&obj0,&obj1,&obj2,&obj3,&arg5,&arg6,&obj6)) goto fail; + arg1 = (unsigned int) PyInt_AsLong(obj0); + if (PyErr_Occurred()) SWIG_fail; + arg2 = (unsigned int) PyInt_AsLong(obj1); + if (PyErr_Occurred()) SWIG_fail; + if ((SWIG_ConvertPtr(obj2,(void **) &argp3, SWIGTYPE_p_Window,SWIG_POINTER_EXCEPTION) == -1)) SWIG_fail; + arg3 = *argp3; + arg4 = (bool) PyInt_AsLong(obj3); + if (PyErr_Occurred()) SWIG_fail; + arg7 = (bool) PyInt_AsLong(obj6); + if (PyErr_Occurred()) SWIG_fail; + otk::OBDisplay::grabKey(arg1,arg2,arg3,arg4,arg5,arg6,arg7); + + Py_INCREF(Py_None); resultobj = Py_None; + return resultobj; + fail: + return NULL; +} + + +static PyObject *_wrap_OBDisplay_ungrabKey(PyObject *self, PyObject *args) { + PyObject *resultobj; + unsigned int arg1 ; + unsigned int arg2 ; + Window arg3 ; + Window *argp3 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + PyObject * obj2 = 0 ; + + if(!PyArg_ParseTuple(args,(char *)"OOO:OBDisplay_ungrabKey",&obj0,&obj1,&obj2)) goto fail; + arg1 = (unsigned int) PyInt_AsLong(obj0); + if (PyErr_Occurred()) SWIG_fail; + arg2 = (unsigned int) PyInt_AsLong(obj1); + if (PyErr_Occurred()) SWIG_fail; + if ((SWIG_ConvertPtr(obj2,(void **) &argp3, SWIGTYPE_p_Window,SWIG_POINTER_EXCEPTION) == -1)) SWIG_fail; + arg3 = *argp3; + otk::OBDisplay::ungrabKey(arg1,arg2,arg3); + + Py_INCREF(Py_None); resultobj = Py_None; + return resultobj; + fail: + return NULL; +} + + static PyObject *_wrap_delete_OBDisplay(PyObject *self, PyObject *args) { PyObject *resultobj; otk::OBDisplay *arg1 = (otk::OBDisplay *) 0 ;

@@ -12946,6 +13008,8 @@ { (char *)"OBDisplay_grab", _wrap_OBDisplay_grab, METH_VARARGS },

{ (char *)"OBDisplay_ungrab", _wrap_OBDisplay_ungrab, METH_VARARGS }, { (char *)"OBDisplay_grabButton", _wrap_OBDisplay_grabButton, METH_VARARGS }, { (char *)"OBDisplay_ungrabButton", _wrap_OBDisplay_ungrabButton, METH_VARARGS }, + { (char *)"OBDisplay_grabKey", _wrap_OBDisplay_grabKey, METH_VARARGS }, + { (char *)"OBDisplay_ungrabKey", _wrap_OBDisplay_ungrabKey, METH_VARARGS }, { (char *)"delete_OBDisplay", _wrap_delete_OBDisplay, METH_VARARGS }, { (char *)"OBDisplay_swigregister", OBDisplay_swigregister, METH_VARARGS }, { (char *)"BFont_fallbackFont", _wrap_BFont_fallbackFont, METH_VARARGS },
M scripts/clientmotion.pyscripts/clientmotion.py

@@ -26,6 +26,7 @@ time):

global posqueue for i in posqueue: if i[0] == button: + print "hi" client = Openbox_findClient(openbox, win) if client: delete_Rect(i[3])
M src/bindings.ccsrc/bindings.cc

@@ -21,38 +21,6 @@ }

namespace ob { -#include <stdio.h> -static void print_branch(const BindingTree *first, std::string str) -{ - const BindingTree *p = first; - - while (p) { - if (p->first_child) - print_branch(p->first_child, str + " " + p->text); - if (!p->chain) - printf("%d%s\n", p->id, (str + " " + p->text).c_str()); - p = p->next_sibling; - } -} - - -void OBBindings::display() -{ - if (_keytree.first_child) { - printf("Key Tree:\n"); - print_branch(_keytree.first_child, ""); - } - if (_mousetree) { - printf("Mouse Tree:\n"); - BindingTree *p = _mousetree; - while (p) { - printf("%d %s\n", p->id, p->text.c_str()); - p = p->next_sibling; - } - } -} - - static bool buttonvalue(const std::string &button, unsigned int *val) { if (button == "1" || button == "Button1") {

@@ -116,7 +84,7 @@ end = str.find_first_of('-', begin);

std::string mod(str, begin, end-begin); if (!modvalue(mod, &modval)) { -// printf(_("Invalid modifier element in key binding: %s\n"), mod.c_str()); + printf(_("Invalid modifier element in key binding: %s\n"), mod.c_str()); return false; }

@@ -127,11 +95,19 @@ // set the binding

b.modifiers = modval; if (askey) { KeySym sym = XStringToKeysym(const_cast<char *>(key.c_str())); - if (sym == NoSymbol) return false; - b.key = XKeysymToKeycode(otk::OBDisplay::display, sym); + if (sym == NoSymbol) { + printf(_("Invalid Key name in key binding: %s\n"), key.c_str()); + return false; + } + if (!(b.key = XKeysymToKeycode(otk::OBDisplay::display, sym))) + printf(_("No valid keycode for Key in key binding: %s\n"), key.c_str()); return b.key != 0; } else { - return buttonvalue(key, &b.key); + if (!buttonvalue(key, &b.key)) { + printf(_("Invalid Button name in mouse binding: %s\n"), key.c_str()); + return false; + } else + return true; } }

@@ -161,15 +137,15 @@ destroytree(ret);

ret = 0; break; } - ret->text = *it; // XXX: rm me } return ret; } OBBindings::OBBindings() - : _curpos(&_keytree), _mousetree(0) + : _curpos(&_keytree), _mousetree(0), _resetkey(0,0) { + setResetKey("C-g"); // set the default reset key }

@@ -199,7 +175,6 @@

grabMouseOnAll(false); // ungrab everything *newp = new BindingTree(id); - (*newp)->text = button; (*newp)->chain = false; (*newp)->binding.key = n.binding.key; (*newp)->binding.modifiers = n.binding.modifiers;

@@ -333,6 +308,18 @@

} +void OBBindings::setResetKey(const std::string &key) +{ + Binding b(0, 0); + if (translate(key, b, true)) { + grabKeys(false); + _resetkey.key = b.key; + _resetkey.modifiers = b.modifiers; + grabKeys(true); + } +} + + static void remove_branch(BindingTree *first) { BindingTree *p = first;

@@ -363,25 +350,6 @@ _mousetree = 0;

} -void OBBindings::process(unsigned int modifiers, unsigned int key) -{ - BindingTree *c = _curpos->first_child; - - while (c) { - if (c->binding.key == key && c->binding.modifiers == modifiers) { - _curpos = c; - break; - } - } - if (c) { - if (!_curpos->chain) { - // XXX execute command for _curpos->id - _curpos = &_keytree; // back to the start - } - } -} - - void OBBindings::grabMouse(bool grab, const OBClient *client) { BindingTree *p = _mousetree;

@@ -428,6 +396,14 @@ otk::OBDisplay::ungrabKey(p->binding.key, p->binding.modifiers,

root); p = p->next_sibling; } + + if (grab) + otk::OBDisplay::grabKey(_resetkey.key, _resetkey.modifiers, + root, true, GrabModeAsync, GrabModeAsync, + false); + else + otk::OBDisplay::ungrabKey(_resetkey.key, _resetkey.modifiers, + root); } }

@@ -436,23 +412,29 @@ void OBBindings::fire(OBActions::ActionType type, Window window,

unsigned int modifiers, unsigned int key, Time time) { if (type == OBActions::Action_KeyPress) { - BindingTree *p = _curpos->first_child; - while (p) { - if (p->binding.key == key && p->binding.modifiers == modifiers) { - if (p->chain) { - grabKeys(false); - _curpos = p; - grabKeys(true); - } else { - python_callback_binding(p->id, type, window, modifiers, key, time); - _curpos = &_keytree; + if (key == _resetkey.key && modifiers == _resetkey.modifiers) { + grabKeys(false); + _curpos = &_keytree; + grabKeys(true); + } else { + BindingTree *p = _curpos->first_child; + while (p) { + if (p->binding.key == key && p->binding.modifiers == modifiers) { + if (p->chain) { + grabKeys(false); + _curpos = p; + grabKeys(true); + } else { + python_callback_binding(p->id, type, window, modifiers, key, time); + grabKeys(false); + _curpos = &_keytree; + grabKeys(true); + } + break; } - break; + p = p->next_sibling; } - p = p->next_sibling; } - - assert(false); } else { BindingTree *p = _mousetree; while (p) {
M src/bindings.hhsrc/bindings.hh

@@ -28,7 +28,6 @@ } Binding;

typedef struct BindingTree { Binding binding; - std::string text; int id; // the id given for the binding in add() bool chain; // true if this is a chain to another key (not an action)

@@ -54,6 +53,8 @@ BindingTree _keytree; // root node of the tree (this doesn't have siblings!)

BindingTree *_curpos; // position in the keytree BindingTree *_mousetree; // this tree is a list. it has only siblings + + Binding _resetkey; // the key which resets the key chain status int find_key(BindingTree *search) const; bool translate(const std::string &str, Binding &b, bool askey) const;

@@ -61,7 +62,6 @@ BindingTree *buildtree(const StringVect &keylist, int id) const;

void assimilate(BindingTree *node); void grabMouseOnAll(bool grab); - void grabKeys(bool grab); public: //! Initializes an OBBinding object

@@ -109,18 +109,13 @@ any others; -2 if the keybinding conflicts with another.

*/ int find_key(const StringVect &keylist); - void process(unsigned int modifiers, unsigned int key); - - // XXX: need an exec() function or something that will be used by openbox - // and hold state for which chain we're in etc. (it could have a timer - // for reseting too...) - - void display(); - void fire(OBActions::ActionType type, Window window, unsigned int modifiers, unsigned int key, Time time); + void setResetKey(const std::string &key); + void grabMouse(bool grab, const OBClient *client); + void grabKeys(bool grab); }; }
M src/openbox.ccsrc/openbox.cc

@@ -149,25 +149,6 @@ _property = new otk::OBProperty();

_actions = new OBActions(); _bindings = new OBBindings(); - OBBindings::StringVect v; - v.push_back("C-A-x"); - v.push_back("C-y"); - v.push_back("v"); - _bindings->add_key(v, 1); - v.clear(); - v.push_back("C-x"); - v.push_back("C-z"); - v.push_back("a"); - _bindings->add_key(v, 2); - v.clear(); - v.push_back("C-a"); - _bindings->add_key(v, 3); - - _bindings->add_mouse("C-1", 1); - - printf("CHAINS:\n"); - _bindings->display(); - setMasterHandler(_actions); // set as the master event handler // create the mouse cursors we'll use

@@ -205,6 +186,9 @@ printf(_("No screens were found without a window manager. Exiting.\n"));

::exit(1); } + // grab any keys set up before the screens existed + _bindings->grabKeys(true); + // set up input focus _focused_screen = _screens[0]; setFocusedClient(0);

@@ -217,12 +201,13 @@ 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; - + // close the X display otk::OBDisplay::destroy(); }
M src/openbox.isrc/openbox.i

@@ -11,8 +11,8 @@ #include "openbox.hh"

#include "screen.hh" #include "client.hh" #include "python.hh" +#include "bindings.hh" %} - %include stl.i //%include std_list.i

@@ -58,6 +58,7 @@ %rename(unregister) ob::python_unregister;

%rename(unregister_all) ob::python_unregister_all; %rename(bind_key) ob::python_bind_key; %rename(unbind_key) ob::python_unbind_key; +%rename(set_reset_key) ob::python_set_reset_key; %rename(bind_mouse) ob::python_bind_mouse; %rename(unbind_mouse) ob::python_unbind_mouse; %rename(unbind_all) ob::python_unbind_all;
M src/openbox_wrap.ccsrc/openbox_wrap.cc

@@ -645,33 +645,34 @@

/* -------- TYPES TABLE (BEGIN) -------- */ -#define SWIGTYPE_p_otk__OBTimerQueueManager swig_types[0] -#define SWIGTYPE_p_ob__Cursors swig_types[1] -#define SWIGTYPE_p_ob__OBScreen swig_types[2] -#define SWIGTYPE_p_otk__Style swig_types[3] -#define SWIGTYPE_p_ob__OBFrame swig_types[4] -#define SWIGTYPE_p_XReparentEvent swig_types[5] -#define SWIGTYPE_p_ob__OBClient swig_types[6] -#define SWIGTYPE_p_ob__Openbox swig_types[7] -#define SWIGTYPE_p_otk__Strut swig_types[8] -#define SWIGTYPE_p_XShapeEvent swig_types[9] -#define SWIGTYPE_p_XConfigureRequestEvent swig_types[10] -#define SWIGTYPE_p_otk__OtkEventHandler swig_types[11] -#define SWIGTYPE_p_otk__Rect swig_types[12] -#define SWIGTYPE_p_ob__OBWidget swig_types[13] -#define SWIGTYPE_p_XFocusChangeEvent swig_types[14] -#define SWIGTYPE_p_XClientMessageEvent swig_types[15] -#define SWIGTYPE_p_otk__OBProperty swig_types[16] -#define SWIGTYPE_p_otk__OtkEventDispatcher swig_types[17] -#define SWIGTYPE_p_XPropertyEvent swig_types[18] -#define SWIGTYPE_p_XDestroyWindowEvent swig_types[19] -#define SWIGTYPE_p_otk__BImageControl swig_types[20] -#define SWIGTYPE_p_PyObject swig_types[21] -#define SWIGTYPE_p_ob__OBBindings swig_types[22] -#define SWIGTYPE_p_ob__MwmHints swig_types[23] -#define SWIGTYPE_p_otk__Configuration swig_types[24] -#define SWIGTYPE_p_XUnmapEvent swig_types[25] -static swig_type_info *swig_types[27]; +#define SWIGTYPE_p_ob__OBActions__ActionType swig_types[0] +#define SWIGTYPE_p_otk__OBTimerQueueManager swig_types[1] +#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_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_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_ob__OBBindings swig_types[23] +#define SWIGTYPE_p_ob__MwmHints swig_types[24] +#define SWIGTYPE_p_otk__Configuration swig_types[25] +#define SWIGTYPE_p_XUnmapEvent swig_types[26] +static swig_type_info *swig_types[28]; /* -------- TYPES TABLE (END) -------- */

@@ -691,6 +692,7 @@ #include "openbox.hh"

#include "screen.hh" #include "client.hh" #include "python.hh" +#include "bindings.hh" #define SWIG_MemoryError 1

@@ -2606,6 +2608,30 @@ 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::python_set_reset_key((std::string const &)*arg1); + + Py_INCREF(Py_None); resultobj = Py_None; + return resultobj; + fail: + return NULL; +} + + static PyObject *_wrap_bind_mouse(PyObject *self, PyObject *args) { PyObject *resultobj; std::string *arg1 = 0 ;

@@ -2661,12 +2687,46 @@

static PyObject *_wrap_unbind_all(PyObject *self, PyObject *args) { PyObject *resultobj; - bool result; if(!PyArg_ParseTuple(args,(char *)":unbind_all")) goto fail; - result = (bool)ob::python_unbind_all(); + ob::python_unbind_all(); - resultobj = PyInt_FromLong((long)result); + Py_INCREF(Py_None); resultobj = Py_None; + return resultobj; + fail: + return NULL; +} + + +static PyObject *_wrap_python_callback_binding(PyObject *self, PyObject *args) { + PyObject *resultobj; + int arg1 ; + ob::OBActions::ActionType arg2 ; + Window arg3 ; + unsigned int arg4 ; + unsigned int arg5 ; + Time arg6 ; + ob::OBActions::ActionType *argp2 ; + PyObject * obj1 = 0 ; + PyObject * obj2 = 0 ; + PyObject * obj3 = 0 ; + PyObject * obj4 = 0 ; + PyObject * obj5 = 0 ; + + if(!PyArg_ParseTuple(args,(char *)"iOOOOO:python_callback_binding",&arg1,&obj1,&obj2,&obj3,&obj4,&obj5)) goto fail; + if ((SWIG_ConvertPtr(obj1,(void **) &argp2, SWIGTYPE_p_ob__OBActions__ActionType,SWIG_POINTER_EXCEPTION) == -1)) SWIG_fail; + arg2 = *argp2; + arg3 = (Window) PyInt_AsLong(obj2); + if (PyErr_Occurred()) SWIG_fail; + arg4 = (unsigned int) PyInt_AsLong(obj3); + if (PyErr_Occurred()) SWIG_fail; + arg5 = (unsigned int) PyInt_AsLong(obj4); + if (PyErr_Occurred()) SWIG_fail; + arg6 = (Time) PyInt_AsLong(obj5); + if (PyErr_Occurred()) SWIG_fail; + ob::python_callback_binding(arg1,arg2,arg3,arg4,arg5,arg6); + + Py_INCREF(Py_None); resultobj = Py_None; return resultobj; fail: return NULL;

@@ -2774,9 +2834,11 @@ { (char *)"unregister", _wrap_unregister, METH_VARARGS },

{ (char *)"unregister_all", _wrap_unregister_all, METH_VARARGS }, { (char *)"bind_key", _wrap_bind_key, METH_VARARGS }, { (char *)"unbind_key", _wrap_unbind_key, METH_VARARGS }, + { (char *)"set_reset_key", _wrap_set_reset_key, METH_VARARGS }, { (char *)"bind_mouse", _wrap_bind_mouse, METH_VARARGS }, { (char *)"unbind_mouse", _wrap_unbind_mouse, METH_VARARGS }, { (char *)"unbind_all", _wrap_unbind_all, METH_VARARGS }, + { (char *)"python_callback_binding", _wrap_python_callback_binding, METH_VARARGS }, { NULL, NULL } };

@@ -2795,6 +2857,7 @@ }

static void *_p_ob__OpenboxTo_p_otk__OtkEventDispatcher(void *x) { return (void *)((otk::OtkEventDispatcher *) ((ob::Openbox *) x)); } +static swig_type_info _swigt__p_ob__OBActions__ActionType[] = {{"_p_ob__OBActions__ActionType", 0, "ob::OBActions::ActionType *", 0},{"_p_ob__OBActions__ActionType"},{0}}; static swig_type_info _swigt__p_otk__OBTimerQueueManager[] = {{"_p_otk__OBTimerQueueManager", 0, "otk::OBTimerQueueManager *", 0},{"_p_otk__OBTimerQueueManager"},{0}}; 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}};

@@ -2823,6 +2886,7 @@ static swig_type_info _swigt__p_otk__Configuration[] = {{"_p_otk__Configuration", 0, "otk::Configuration *", 0},{"_p_otk__Configuration"},{0}};

static swig_type_info _swigt__p_XUnmapEvent[] = {{"_p_XUnmapEvent", 0, "XUnmapEvent *", 0},{"_p_XUnmapEvent"},{0}}; static swig_type_info *swig_types_initial[] = { +_swigt__p_ob__OBActions__ActionType, _swigt__p_otk__OBTimerQueueManager, _swigt__p_ob__Cursors, _swigt__p_ob__OBScreen,
M src/python.ccsrc/python.cc

@@ -2,6 +2,7 @@ // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-

#include "python.hh" #include "openbox.hh" +#include "otk/display.hh" #include <vector> #include <algorithm>

@@ -11,8 +12,7 @@

typedef std::vector<PyObject*> FunctionList; static FunctionList callbacks[OBActions::NUM_ACTIONS]; -static FunctionList keyfuncs; -static FunctionList mousefuncs; +static FunctionList bindfuncs; bool python_register(int action, PyObject *callback) {

@@ -160,10 +160,10 @@ }

// the id is what the binding class can call back with so it doesnt have to // worry about the python function pointer - int id = keyfuncs.size(); + int id = bindfuncs.size(); if (Openbox::instance->bindings()->add_key(vectkeylist, id)) { Py_XINCREF(callback); // Add a reference to new callback - keyfuncs.push_back(callback); + bindfuncs.push_back(callback); return true; } else { PyErr_SetString(PyExc_AssertionError,"Unable to create binding. Invalid.");

@@ -192,17 +192,22 @@

int id; if ((id = Openbox::instance->bindings()->remove_key(vectkeylist)) >= 0) { - assert(keyfuncs[id]); // shouldn't be able to remove it twice - Py_XDECREF(keyfuncs[id]); // Dispose of previous callback + assert(bindfuncs[id]); // shouldn't be able to remove it twice + Py_XDECREF(bindfuncs[id]); // Dispose of previous callback // important note: we don't erase the item from the list cuz that would // ruin all the id's that are in use. simply nullify it. - keyfuncs[id] = 0; + bindfuncs[id] = 0; return true; } return false; } +void python_set_reset_key(const std::string &key) +{ + Openbox::instance->bindings()->setResetKey(key); +} + bool python_bind_mouse(const std::string &button, PyObject *callback) { if (!PyCallable_Check(callback)) {

@@ -212,10 +217,10 @@ }

// the id is what the binding class can call back with so it doesnt have to // worry about the python function pointer - int id = mousefuncs.size(); + int id = bindfuncs.size(); if (Openbox::instance->bindings()->add_mouse(button, id)) { Py_XINCREF(callback); // Add a reference to new callback - mousefuncs.push_back(callback); + bindfuncs.push_back(callback); return true; } else { PyErr_SetString(PyExc_AssertionError,"Unable to create binding. Invalid.");

@@ -228,21 +233,20 @@ {

int id; if ((id = Openbox::instance->bindings()->remove_mouse(button)) >= 0) { - assert(mousefuncs[id]); // shouldn't be able to remove it twice - Py_XDECREF(mousefuncs[id]); // Dispose of previous callback + assert(bindfuncs[id]); // shouldn't be able to remove it twice + Py_XDECREF(bindfuncs[id]); // Dispose of previous callback // important note: we don't erase the item from the list cuz that would // ruin all the id's that are in use. simply nullify it. - mousefuncs[id] = 0; + bindfuncs[id] = 0; return true; } return false; } -bool python_unbind_all() +void python_unbind_all() { Openbox::instance->bindings()->remove_all(); - return true; }

@@ -250,24 +254,21 @@ void python_callback_binding(int id, OBActions::ActionType action,

Window window, unsigned int state, unsigned int keybutton, Time time) { - PyObject *func; - assert(action >= 0 && action < OBActions::NUM_ACTIONS); - if (action == OBActions::Action_KeyPress) - func = keyfuncs[id]; - else - func = mousefuncs[id]; - - if (!func) return; + if (!bindfuncs[id]) return; // the key was unbound PyObject *arglist; PyObject *result; - arglist = Py_BuildValue("iliil", action, window, state, keybutton, time); + arglist = Py_BuildValue("ilisl", action, window, state, + XKeysymToString( + XKeycodeToKeysym(otk::OBDisplay::display, + keybutton, 0)), + time); // call the callback - result = PyEval_CallObject(func, arglist); + result = PyEval_CallObject(bindfuncs[id], arglist); if (result) { Py_DECREF(result); } else {
M src/python.hhsrc/python.hh

@@ -44,6 +44,8 @@ bool python_bind_key(PyObject *keylist, PyObject *callback);

bool python_unbind_key(PyObject *keylist); +void python_set_reset_key(const std::string &key); + //! Adds a mouse binding /*! Bindings do not generate motion events. You can only handle motion events by

@@ -54,7 +56,7 @@ bool python_bind_mouse(const std::string &button, PyObject *callback);

bool python_unbind_mouse(const std::string &button); -bool python_unbind_all(); +void python_unbind_all(); //! Fire a python callback function void python_callback(OBActions::ActionType action, Window window,