bindings work. now they have a reset key too.

This commit is contained in:
Dana Jansens 2002-12-31 06:59:46 +00:00
parent d7a30f93b5
commit a6661d587c
11 changed files with 275 additions and 161 deletions

View file

@ -227,5 +227,24 @@ void OBDisplay::ungrabButton(unsigned int button, unsigned int modifiers,
grab_window); 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);
}
} }

View file

@ -116,7 +116,7 @@ public:
static void grabKey(unsigned int keycode, unsigned int modifiers, static void grabKey(unsigned int keycode, unsigned int modifiers,
Window grab_window, bool owner_events, Window grab_window, bool owner_events,
int pointer_mode, int keyboard_mode, bool allow_scroll_lock); 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); Window grab_window);
}; };

View file

@ -5605,6 +5605,68 @@ static PyObject *_wrap_OBDisplay_ungrabButton(PyObject *self, PyObject *args) {
} }
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) { static PyObject *_wrap_delete_OBDisplay(PyObject *self, PyObject *args) {
PyObject *resultobj; PyObject *resultobj;
otk::OBDisplay *arg1 = (otk::OBDisplay *) 0 ; otk::OBDisplay *arg1 = (otk::OBDisplay *) 0 ;
@ -12946,6 +13008,8 @@ static PyMethodDef SwigMethods[] = {
{ (char *)"OBDisplay_ungrab", _wrap_OBDisplay_ungrab, METH_VARARGS }, { (char *)"OBDisplay_ungrab", _wrap_OBDisplay_ungrab, METH_VARARGS },
{ (char *)"OBDisplay_grabButton", _wrap_OBDisplay_grabButton, METH_VARARGS }, { (char *)"OBDisplay_grabButton", _wrap_OBDisplay_grabButton, METH_VARARGS },
{ (char *)"OBDisplay_ungrabButton", _wrap_OBDisplay_ungrabButton, 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 *)"delete_OBDisplay", _wrap_delete_OBDisplay, METH_VARARGS },
{ (char *)"OBDisplay_swigregister", OBDisplay_swigregister, METH_VARARGS }, { (char *)"OBDisplay_swigregister", OBDisplay_swigregister, METH_VARARGS },
{ (char *)"BFont_fallbackFont", _wrap_BFont_fallbackFont, METH_VARARGS }, { (char *)"BFont_fallbackFont", _wrap_BFont_fallbackFont, METH_VARARGS },

View file

@ -26,6 +26,7 @@ def def_motion_release(action, win, type, modifiers, button, xroot, yroot,
global posqueue global posqueue
for i in posqueue: for i in posqueue:
if i[0] == button: if i[0] == button:
print "hi"
client = Openbox_findClient(openbox, win) client = Openbox_findClient(openbox, win)
if client: if client:
delete_Rect(i[3]) delete_Rect(i[3])

View file

@ -21,38 +21,6 @@ extern "C" {
namespace ob { 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) static bool buttonvalue(const std::string &button, unsigned int *val)
{ {
if (button == "1" || button == "Button1") { if (button == "1" || button == "Button1") {
@ -116,7 +84,7 @@ bool OBBindings::translate(const std::string &str, Binding &b,
std::string mod(str, begin, end-begin); std::string mod(str, begin, end-begin);
if (!modvalue(mod, &modval)) { 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; return false;
} }
@ -127,11 +95,19 @@ bool OBBindings::translate(const std::string &str, Binding &b,
b.modifiers = modval; b.modifiers = modval;
if (askey) { if (askey) {
KeySym sym = XStringToKeysym(const_cast<char *>(key.c_str())); KeySym sym = XStringToKeysym(const_cast<char *>(key.c_str()));
if (sym == NoSymbol) return false; if (sym == NoSymbol) {
b.key = XKeysymToKeycode(otk::OBDisplay::display, sym); 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; return b.key != 0;
} else { } 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 @@ BindingTree *OBBindings::buildtree(const StringVect &keylist, int id) const
ret = 0; ret = 0;
break; break;
} }
ret->text = *it; // XXX: rm me
} }
return ret; return ret;
} }
OBBindings::OBBindings() 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 @@ bool OBBindings::add_mouse(const std::string &button, int id)
grabMouseOnAll(false); // ungrab everything grabMouseOnAll(false); // ungrab everything
*newp = new BindingTree(id); *newp = new BindingTree(id);
(*newp)->text = button;
(*newp)->chain = false; (*newp)->chain = false;
(*newp)->binding.key = n.binding.key; (*newp)->binding.key = n.binding.key;
(*newp)->binding.modifiers = n.binding.modifiers; (*newp)->binding.modifiers = n.binding.modifiers;
@ -333,6 +308,18 @@ int OBBindings::remove_key(const StringVect &keylist)
} }
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) static void remove_branch(BindingTree *first)
{ {
BindingTree *p = first; BindingTree *p = first;
@ -363,25 +350,6 @@ void OBBindings::remove_all()
} }
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) void OBBindings::grabMouse(bool grab, const OBClient *client)
{ {
BindingTree *p = _mousetree; BindingTree *p = _mousetree;
@ -428,6 +396,14 @@ void OBBindings::grabKeys(bool grab)
root); root);
p = p->next_sibling; 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) unsigned int modifiers, unsigned int key, Time time)
{ {
if (type == OBActions::Action_KeyPress) { if (type == OBActions::Action_KeyPress) {
BindingTree *p = _curpos->first_child; if (key == _resetkey.key && modifiers == _resetkey.modifiers) {
while (p) { grabKeys(false);
if (p->binding.key == key && p->binding.modifiers == modifiers) { _curpos = &_keytree;
if (p->chain) { grabKeys(true);
grabKeys(false); } else {
_curpos = p; BindingTree *p = _curpos->first_child;
grabKeys(true); while (p) {
} else { if (p->binding.key == key && p->binding.modifiers == modifiers) {
python_callback_binding(p->id, type, window, modifiers, key, time); if (p->chain) {
_curpos = &_keytree; 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 { } else {
BindingTree *p = _mousetree; BindingTree *p = _mousetree;
while (p) { while (p) {

View file

@ -28,7 +28,6 @@ typedef struct Binding {
typedef struct BindingTree { typedef struct BindingTree {
Binding binding; Binding binding;
std::string text;
int id; // the id given for the binding in add() int id; // the id given for the binding in add()
bool chain; // true if this is a chain to another key (not an action) bool chain; // true if this is a chain to another key (not an action)
@ -54,6 +53,8 @@ private:
BindingTree *_curpos; // position in the keytree BindingTree *_curpos; // position in the keytree
BindingTree *_mousetree; // this tree is a list. it has only siblings 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; int find_key(BindingTree *search) const;
bool translate(const std::string &str, Binding &b, bool askey) const; bool translate(const std::string &str, Binding &b, bool askey) const;
@ -61,7 +62,6 @@ private:
void assimilate(BindingTree *node); void assimilate(BindingTree *node);
void grabMouseOnAll(bool grab); void grabMouseOnAll(bool grab);
void grabKeys(bool grab);
public: public:
//! Initializes an OBBinding object //! Initializes an OBBinding object
@ -109,18 +109,13 @@ public:
*/ */
int find_key(const StringVect &keylist); 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, void fire(OBActions::ActionType type, Window window, unsigned int modifiers,
unsigned int key, Time time); unsigned int key, Time time);
void setResetKey(const std::string &key);
void grabMouse(bool grab, const OBClient *client); void grabMouse(bool grab, const OBClient *client);
void grabKeys(bool grab);
}; };
} }

View file

@ -149,25 +149,6 @@ Openbox::Openbox(int argc, char **argv)
_actions = new OBActions(); _actions = new OBActions();
_bindings = new OBBindings(); _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 setMasterHandler(_actions); // set as the master event handler
// create the mouse cursors we'll use // create the mouse cursors we'll use
@ -205,6 +186,9 @@ Openbox::Openbox(int argc, char **argv)
::exit(1); ::exit(1);
} }
// grab any keys set up before the screens existed
_bindings->grabKeys(true);
// set up input focus // set up input focus
_focused_screen = _screens[0]; _focused_screen = _screens[0];
setFocusedClient(0); setFocusedClient(0);
@ -217,12 +201,13 @@ Openbox::~Openbox()
{ {
_state = State_Exiting; // time to kill everything _state = State_Exiting; // time to kill everything
std::for_each(_screens.begin(), _screens.end(), otk::PointerAssassin());
delete _bindings; delete _bindings;
delete _actions; delete _actions;
delete _property;
std::for_each(_screens.begin(), _screens.end(), otk::PointerAssassin());
delete _property;
// close the X display // close the X display
otk::OBDisplay::destroy(); otk::OBDisplay::destroy();
} }

View file

@ -11,9 +11,9 @@
#include "screen.hh" #include "screen.hh"
#include "client.hh" #include "client.hh"
#include "python.hh" #include "python.hh"
#include "bindings.hh"
%} %}
%include stl.i %include stl.i
//%include std_list.i //%include std_list.i
//%template(ClientList) std::list<OBClient*>; //%template(ClientList) std::list<OBClient*>;
@ -58,6 +58,7 @@
%rename(unregister_all) ob::python_unregister_all; %rename(unregister_all) ob::python_unregister_all;
%rename(bind_key) ob::python_bind_key; %rename(bind_key) ob::python_bind_key;
%rename(unbind_key) ob::python_unbind_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(bind_mouse) ob::python_bind_mouse;
%rename(unbind_mouse) ob::python_unbind_mouse; %rename(unbind_mouse) ob::python_unbind_mouse;
%rename(unbind_all) ob::python_unbind_all; %rename(unbind_all) ob::python_unbind_all;

View file

@ -645,33 +645,34 @@ SWIG_InstallConstants(PyObject *d, swig_const_info constants[]) {
/* -------- TYPES TABLE (BEGIN) -------- */ /* -------- TYPES TABLE (BEGIN) -------- */
#define SWIGTYPE_p_otk__OBTimerQueueManager swig_types[0] #define SWIGTYPE_p_ob__OBActions__ActionType swig_types[0]
#define SWIGTYPE_p_ob__Cursors swig_types[1] #define SWIGTYPE_p_otk__OBTimerQueueManager swig_types[1]
#define SWIGTYPE_p_ob__OBScreen swig_types[2] #define SWIGTYPE_p_ob__Cursors swig_types[2]
#define SWIGTYPE_p_otk__Style swig_types[3] #define SWIGTYPE_p_ob__OBScreen swig_types[3]
#define SWIGTYPE_p_ob__OBFrame swig_types[4] #define SWIGTYPE_p_otk__Style swig_types[4]
#define SWIGTYPE_p_XReparentEvent swig_types[5] #define SWIGTYPE_p_ob__OBFrame swig_types[5]
#define SWIGTYPE_p_ob__OBClient swig_types[6] #define SWIGTYPE_p_XReparentEvent swig_types[6]
#define SWIGTYPE_p_ob__Openbox swig_types[7] #define SWIGTYPE_p_ob__OBClient swig_types[7]
#define SWIGTYPE_p_otk__Strut swig_types[8] #define SWIGTYPE_p_ob__Openbox swig_types[8]
#define SWIGTYPE_p_XShapeEvent swig_types[9] #define SWIGTYPE_p_otk__Strut swig_types[9]
#define SWIGTYPE_p_XConfigureRequestEvent swig_types[10] #define SWIGTYPE_p_XShapeEvent swig_types[10]
#define SWIGTYPE_p_otk__OtkEventHandler swig_types[11] #define SWIGTYPE_p_XConfigureRequestEvent swig_types[11]
#define SWIGTYPE_p_otk__Rect swig_types[12] #define SWIGTYPE_p_otk__OtkEventHandler swig_types[12]
#define SWIGTYPE_p_ob__OBWidget swig_types[13] #define SWIGTYPE_p_otk__Rect swig_types[13]
#define SWIGTYPE_p_XFocusChangeEvent swig_types[14] #define SWIGTYPE_p_ob__OBWidget swig_types[14]
#define SWIGTYPE_p_XClientMessageEvent swig_types[15] #define SWIGTYPE_p_XFocusChangeEvent swig_types[15]
#define SWIGTYPE_p_otk__OBProperty swig_types[16] #define SWIGTYPE_p_XClientMessageEvent swig_types[16]
#define SWIGTYPE_p_otk__OtkEventDispatcher swig_types[17] #define SWIGTYPE_p_otk__OBProperty swig_types[17]
#define SWIGTYPE_p_XPropertyEvent swig_types[18] #define SWIGTYPE_p_otk__OtkEventDispatcher swig_types[18]
#define SWIGTYPE_p_XDestroyWindowEvent swig_types[19] #define SWIGTYPE_p_XPropertyEvent swig_types[19]
#define SWIGTYPE_p_otk__BImageControl swig_types[20] #define SWIGTYPE_p_XDestroyWindowEvent swig_types[20]
#define SWIGTYPE_p_PyObject swig_types[21] #define SWIGTYPE_p_otk__BImageControl swig_types[21]
#define SWIGTYPE_p_ob__OBBindings swig_types[22] #define SWIGTYPE_p_PyObject swig_types[22]
#define SWIGTYPE_p_ob__MwmHints swig_types[23] #define SWIGTYPE_p_ob__OBBindings swig_types[23]
#define SWIGTYPE_p_otk__Configuration swig_types[24] #define SWIGTYPE_p_ob__MwmHints swig_types[24]
#define SWIGTYPE_p_XUnmapEvent swig_types[25] #define SWIGTYPE_p_otk__Configuration swig_types[25]
static swig_type_info *swig_types[27]; #define SWIGTYPE_p_XUnmapEvent swig_types[26]
static swig_type_info *swig_types[28];
/* -------- TYPES TABLE (END) -------- */ /* -------- TYPES TABLE (END) -------- */
@ -691,6 +692,7 @@ static swig_type_info *swig_types[27];
#include "screen.hh" #include "screen.hh"
#include "client.hh" #include "client.hh"
#include "python.hh" #include "python.hh"
#include "bindings.hh"
#define SWIG_MemoryError 1 #define SWIG_MemoryError 1
@ -2606,6 +2608,30 @@ static PyObject *_wrap_unbind_key(PyObject *self, PyObject *args) {
} }
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) { static PyObject *_wrap_bind_mouse(PyObject *self, PyObject *args) {
PyObject *resultobj; PyObject *resultobj;
std::string *arg1 = 0 ; std::string *arg1 = 0 ;
@ -2661,12 +2687,46 @@ static PyObject *_wrap_unbind_mouse(PyObject *self, PyObject *args) {
static PyObject *_wrap_unbind_all(PyObject *self, PyObject *args) { static PyObject *_wrap_unbind_all(PyObject *self, PyObject *args) {
PyObject *resultobj; PyObject *resultobj;
bool result;
if(!PyArg_ParseTuple(args,(char *)":unbind_all")) goto fail; 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; return resultobj;
fail: fail:
return NULL; return NULL;
@ -2774,9 +2834,11 @@ static PyMethodDef SwigMethods[] = {
{ (char *)"unregister_all", _wrap_unregister_all, METH_VARARGS }, { (char *)"unregister_all", _wrap_unregister_all, METH_VARARGS },
{ (char *)"bind_key", _wrap_bind_key, METH_VARARGS }, { (char *)"bind_key", _wrap_bind_key, METH_VARARGS },
{ (char *)"unbind_key", _wrap_unbind_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 *)"bind_mouse", _wrap_bind_mouse, METH_VARARGS },
{ (char *)"unbind_mouse", _wrap_unbind_mouse, METH_VARARGS }, { (char *)"unbind_mouse", _wrap_unbind_mouse, METH_VARARGS },
{ (char *)"unbind_all", _wrap_unbind_all, METH_VARARGS }, { (char *)"unbind_all", _wrap_unbind_all, METH_VARARGS },
{ (char *)"python_callback_binding", _wrap_python_callback_binding, METH_VARARGS },
{ NULL, NULL } { NULL, NULL }
}; };
@ -2795,6 +2857,7 @@ static void *_p_ob__OBClientTo_p_ob__OBWidget(void *x) {
static void *_p_ob__OpenboxTo_p_otk__OtkEventDispatcher(void *x) { static void *_p_ob__OpenboxTo_p_otk__OtkEventDispatcher(void *x) {
return (void *)((otk::OtkEventDispatcher *) ((ob::Openbox *) 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_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__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_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"
static swig_type_info _swigt__p_XUnmapEvent[] = {{"_p_XUnmapEvent", 0, "XUnmapEvent *", 0},{"_p_XUnmapEvent"},{0}}; static swig_type_info _swigt__p_XUnmapEvent[] = {{"_p_XUnmapEvent", 0, "XUnmapEvent *", 0},{"_p_XUnmapEvent"},{0}};
static swig_type_info *swig_types_initial[] = { static swig_type_info *swig_types_initial[] = {
_swigt__p_ob__OBActions__ActionType,
_swigt__p_otk__OBTimerQueueManager, _swigt__p_otk__OBTimerQueueManager,
_swigt__p_ob__Cursors, _swigt__p_ob__Cursors,
_swigt__p_ob__OBScreen, _swigt__p_ob__OBScreen,

View file

@ -2,6 +2,7 @@
#include "python.hh" #include "python.hh"
#include "openbox.hh" #include "openbox.hh"
#include "otk/display.hh"
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
@ -11,8 +12,7 @@ namespace ob {
typedef std::vector<PyObject*> FunctionList; typedef std::vector<PyObject*> FunctionList;
static FunctionList callbacks[OBActions::NUM_ACTIONS]; static FunctionList callbacks[OBActions::NUM_ACTIONS];
static FunctionList keyfuncs; static FunctionList bindfuncs;
static FunctionList mousefuncs;
bool python_register(int action, PyObject *callback) bool python_register(int action, PyObject *callback)
{ {
@ -160,10 +160,10 @@ bool python_bind_key(PyObject *keylist, PyObject *callback)
// the id is what the binding class can call back with so it doesnt have to // the id is what the binding class can call back with so it doesnt have to
// worry about the python function pointer // worry about the python function pointer
int id = keyfuncs.size(); int id = bindfuncs.size();
if (Openbox::instance->bindings()->add_key(vectkeylist, id)) { if (Openbox::instance->bindings()->add_key(vectkeylist, id)) {
Py_XINCREF(callback); // Add a reference to new callback Py_XINCREF(callback); // Add a reference to new callback
keyfuncs.push_back(callback); bindfuncs.push_back(callback);
return true; return true;
} else { } else {
PyErr_SetString(PyExc_AssertionError,"Unable to create binding. Invalid."); PyErr_SetString(PyExc_AssertionError,"Unable to create binding. Invalid.");
@ -192,17 +192,22 @@ bool python_unbind_key(PyObject *keylist)
int id; int id;
if ((id = if ((id =
Openbox::instance->bindings()->remove_key(vectkeylist)) >= 0) { Openbox::instance->bindings()->remove_key(vectkeylist)) >= 0) {
assert(keyfuncs[id]); // shouldn't be able to remove it twice assert(bindfuncs[id]); // shouldn't be able to remove it twice
Py_XDECREF(keyfuncs[id]); // Dispose of previous callback Py_XDECREF(bindfuncs[id]); // Dispose of previous callback
// important note: we don't erase the item from the list cuz that would // 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. // ruin all the id's that are in use. simply nullify it.
keyfuncs[id] = 0; bindfuncs[id] = 0;
return true; return true;
} }
return false; 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) bool python_bind_mouse(const std::string &button, PyObject *callback)
{ {
if (!PyCallable_Check(callback)) { if (!PyCallable_Check(callback)) {
@ -212,10 +217,10 @@ bool python_bind_mouse(const std::string &button, PyObject *callback)
// the id is what the binding class can call back with so it doesnt have to // the id is what the binding class can call back with so it doesnt have to
// worry about the python function pointer // worry about the python function pointer
int id = mousefuncs.size(); int id = bindfuncs.size();
if (Openbox::instance->bindings()->add_mouse(button, id)) { if (Openbox::instance->bindings()->add_mouse(button, id)) {
Py_XINCREF(callback); // Add a reference to new callback Py_XINCREF(callback); // Add a reference to new callback
mousefuncs.push_back(callback); bindfuncs.push_back(callback);
return true; return true;
} else { } else {
PyErr_SetString(PyExc_AssertionError,"Unable to create binding. Invalid."); PyErr_SetString(PyExc_AssertionError,"Unable to create binding. Invalid.");
@ -228,21 +233,20 @@ bool python_unbind_mouse(const std::string &button)
int id; int id;
if ((id = if ((id =
Openbox::instance->bindings()->remove_mouse(button)) >= 0) { Openbox::instance->bindings()->remove_mouse(button)) >= 0) {
assert(mousefuncs[id]); // shouldn't be able to remove it twice assert(bindfuncs[id]); // shouldn't be able to remove it twice
Py_XDECREF(mousefuncs[id]); // Dispose of previous callback Py_XDECREF(bindfuncs[id]); // Dispose of previous callback
// important note: we don't erase the item from the list cuz that would // 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. // ruin all the id's that are in use. simply nullify it.
mousefuncs[id] = 0; bindfuncs[id] = 0;
return true; return true;
} }
return false; return false;
} }
bool python_unbind_all() void python_unbind_all()
{ {
Openbox::instance->bindings()->remove_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, Window window, unsigned int state,
unsigned int keybutton, Time time) unsigned int keybutton, Time time)
{ {
PyObject *func;
assert(action >= 0 && action < OBActions::NUM_ACTIONS); assert(action >= 0 && action < OBActions::NUM_ACTIONS);
if (action == OBActions::Action_KeyPress) if (!bindfuncs[id]) return; // the key was unbound
func = keyfuncs[id];
else
func = mousefuncs[id];
if (!func) return;
PyObject *arglist; PyObject *arglist;
PyObject *result; 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 // call the callback
result = PyEval_CallObject(func, arglist); result = PyEval_CallObject(bindfuncs[id], arglist);
if (result) { if (result) {
Py_DECREF(result); Py_DECREF(result);
} else { } else {

View file

@ -44,6 +44,8 @@ bool python_bind_key(PyObject *keylist, PyObject *callback);
bool python_unbind_key(PyObject *keylist); bool python_unbind_key(PyObject *keylist);
void python_set_reset_key(const std::string &key);
//! Adds a mouse binding //! Adds a mouse binding
/*! /*!
Bindings do not generate motion events. You can only handle motion events by 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_mouse(const std::string &button);
bool python_unbind_all(); void python_unbind_all();
//! Fire a python callback function //! Fire a python callback function
void python_callback(OBActions::ActionType action, Window window, void python_callback(OBActions::ActionType action, Window window,