bindings work. now they have a reset key too.
This commit is contained in:
parent
d7a30f93b5
commit
a6661d587c
11 changed files with 275 additions and 161 deletions
|
@ -227,5 +227,24 @@ void OBDisplay::ungrabButton(unsigned int button, unsigned int modifiers,
|
|||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -116,7 +116,7 @@ public:
|
|||
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);
|
||||
};
|
||||
|
||||
|
|
|
@ -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) {
|
||||
PyObject *resultobj;
|
||||
otk::OBDisplay *arg1 = (otk::OBDisplay *) 0 ;
|
||||
|
@ -12946,6 +13008,8 @@ static PyMethodDef SwigMethods[] = {
|
|||
{ (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 },
|
||||
|
|
|
@ -26,6 +26,7 @@ def def_motion_release(action, win, type, modifiers, button, xroot, yroot,
|
|||
global posqueue
|
||||
for i in posqueue:
|
||||
if i[0] == button:
|
||||
print "hi"
|
||||
client = Openbox_findClient(openbox, win)
|
||||
if client:
|
||||
delete_Rect(i[3])
|
||||
|
|
126
src/bindings.cc
126
src/bindings.cc
|
@ -21,38 +21,6 @@ extern "C" {
|
|||
|
||||
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 @@ bool OBBindings::translate(const std::string &str, Binding &b,
|
|||
|
||||
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 @@ bool OBBindings::translate(const std::string &str, Binding &b,
|
|||
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 @@ BindingTree *OBBindings::buildtree(const StringVect &keylist, int id) const
|
|||
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 @@ bool OBBindings::add_mouse(const std::string &button, int id)
|
|||
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 @@ 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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
BindingTree *p = _mousetree;
|
||||
|
@ -428,6 +396,14 @@ void OBBindings::grabKeys(bool grab)
|
|||
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) {
|
||||
|
|
|
@ -28,7 +28,6 @@ typedef struct 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 @@ private:
|
|||
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 @@ private:
|
|||
void assimilate(BindingTree *node);
|
||||
|
||||
void grabMouseOnAll(bool grab);
|
||||
void grabKeys(bool grab);
|
||||
|
||||
public:
|
||||
//! Initializes an OBBinding object
|
||||
|
@ -109,18 +109,13 @@ public:
|
|||
*/
|
||||
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);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -149,25 +149,6 @@ Openbox::Openbox(int argc, char **argv)
|
|||
_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 @@ Openbox::Openbox(int argc, char **argv)
|
|||
::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
|
||||
|
||||
std::for_each(_screens.begin(), _screens.end(), otk::PointerAssassin());
|
||||
|
||||
delete _bindings;
|
||||
delete _actions;
|
||||
delete _property;
|
||||
|
||||
std::for_each(_screens.begin(), _screens.end(), otk::PointerAssassin());
|
||||
|
||||
delete _property;
|
||||
|
||||
// close the X display
|
||||
otk::OBDisplay::destroy();
|
||||
}
|
||||
|
|
|
@ -11,9 +11,9 @@
|
|||
#include "screen.hh"
|
||||
#include "client.hh"
|
||||
#include "python.hh"
|
||||
#include "bindings.hh"
|
||||
%}
|
||||
|
||||
|
||||
%include stl.i
|
||||
//%include std_list.i
|
||||
//%template(ClientList) std::list<OBClient*>;
|
||||
|
@ -58,6 +58,7 @@
|
|||
%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;
|
||||
|
|
|
@ -645,33 +645,34 @@ SWIG_InstallConstants(PyObject *d, swig_const_info constants[]) {
|
|||
|
||||
/* -------- 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 @@ static swig_type_info *swig_types[27];
|
|||
#include "screen.hh"
|
||||
#include "client.hh"
|
||||
#include "python.hh"
|
||||
#include "bindings.hh"
|
||||
|
||||
|
||||
#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) {
|
||||
PyObject *resultobj;
|
||||
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) {
|
||||
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 @@ static PyMethodDef SwigMethods[] = {
|
|||
{ (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__OBClientTo_p_ob__OBWidget(void *x) {
|
|||
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"
|
|||
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,
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "python.hh"
|
||||
#include "openbox.hh"
|
||||
#include "otk/display.hh"
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
@ -11,8 +12,7 @@ namespace ob {
|
|||
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 @@ bool python_bind_key(PyObject *keylist, PyObject *callback)
|
|||
|
||||
// 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 @@ bool python_unbind_key(PyObject *keylist)
|
|||
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 @@ 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
|
||||
// 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 @@ bool python_unbind_mouse(const std::string &button)
|
|||
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 {
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue