new python callbacks data, infrastructure. going to rework bindings code. cvs wont work for shit now. but thats life.
This commit is contained in:
parent
b1739374a6
commit
345d957e1e
14 changed files with 1798 additions and 493 deletions
|
@ -11,6 +11,10 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <X11/keysym.h>
|
#include <X11/keysym.h>
|
||||||
|
|
||||||
|
#ifdef XKB
|
||||||
|
#include <X11/XKBlib.h>
|
||||||
|
#endif // XKB
|
||||||
|
|
||||||
#ifdef SHAPE
|
#ifdef SHAPE
|
||||||
#include <X11/extensions/shape.h>
|
#include <X11/extensions/shape.h>
|
||||||
#endif // SHAPE
|
#endif // SHAPE
|
||||||
|
@ -44,6 +48,8 @@ namespace otk {
|
||||||
|
|
||||||
|
|
||||||
Display *OBDisplay::display = (Display*) 0;
|
Display *OBDisplay::display = (Display*) 0;
|
||||||
|
bool OBDisplay::_xkb = false;
|
||||||
|
int OBDisplay::_xkb_event_basep = 0;
|
||||||
bool OBDisplay::_shape = false;
|
bool OBDisplay::_shape = false;
|
||||||
int OBDisplay::_shape_event_basep = 0;
|
int OBDisplay::_shape_event_basep = 0;
|
||||||
bool OBDisplay::_xinerama = false;
|
bool OBDisplay::_xinerama = false;
|
||||||
|
@ -107,6 +113,11 @@ line argument.\n\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// find the availability of X extensions we like to use
|
// find the availability of X extensions we like to use
|
||||||
|
#ifdef XKB
|
||||||
|
_xkb = XkbQueryExtension(display, &junk, &_xkb_event_basep, &junk, NULL,
|
||||||
|
NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef SHAPE
|
#ifdef SHAPE
|
||||||
_shape = XShapeQueryExtension(display, &_shape_event_basep, &junk);
|
_shape = XShapeQueryExtension(display, &_shape_event_basep, &junk);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -29,14 +29,19 @@ public:
|
||||||
typedef std::vector<ScreenInfo> ScreenInfoList;
|
typedef std::vector<ScreenInfo> ScreenInfoList;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Does the display have the Shape extention?
|
//! Does the display have the XKB extension?
|
||||||
|
static bool _xkb;
|
||||||
|
//! Base for events for the XKB extension
|
||||||
|
static int _xkb_event_basep;
|
||||||
|
|
||||||
|
//! Does the display have the Shape extension?
|
||||||
static bool _shape;
|
static bool _shape;
|
||||||
//! Base for events for the Shape extention
|
//! Base for events for the Shape extension
|
||||||
static int _shape_event_basep;
|
static int _shape_event_basep;
|
||||||
|
|
||||||
//! Does the display have the Xinerama extention?
|
//! Does the display have the Xinerama extension?
|
||||||
static bool _xinerama;
|
static bool _xinerama;
|
||||||
//! Base for events for the Xinerama extention
|
//! Base for events for the Xinerama extension
|
||||||
static int _xinerama_event_basep;
|
static int _xinerama_event_basep;
|
||||||
|
|
||||||
//! A list of all possible combinations of keyboard lock masks
|
//! A list of all possible combinations of keyboard lock masks
|
||||||
|
@ -99,11 +104,16 @@ public:
|
||||||
//! Find a ScreenInfo based on a root window
|
//! Find a ScreenInfo based on a root window
|
||||||
static const ScreenInfo* findScreen(Window root);
|
static const ScreenInfo* findScreen(Window root);
|
||||||
|
|
||||||
//! Returns if the display has the shape extention available
|
//! Returns if the display has the xkb extension available
|
||||||
|
inline static bool xkb() { return _xkb; }
|
||||||
|
//! Returns the xkb extension's event base
|
||||||
|
inline static int xkbEventBase() { return _xkb_event_basep; }
|
||||||
|
|
||||||
|
//! Returns if the display has the shape extension available
|
||||||
inline static bool shape() { return _shape; }
|
inline static bool shape() { return _shape; }
|
||||||
//! Returns the shape extension's event base
|
//! Returns the shape extension's event base
|
||||||
inline static int shapeEventBase() { return _shape_event_basep; }
|
inline static int shapeEventBase() { return _shape_event_basep; }
|
||||||
//! Returns if the display has the xinerama extention available
|
//! Returns if the display has the xinerama extension available
|
||||||
inline static bool xinerama() { return _xinerama; }
|
inline static bool xinerama() { return _xinerama; }
|
||||||
|
|
||||||
inline static unsigned int numLockMask() { return _numLockMask; }
|
inline static unsigned int numLockMask() { return _numLockMask; }
|
||||||
|
|
|
@ -91,6 +91,10 @@ void OtkEventHandler::handle(const XEvent &e)
|
||||||
if (e.type == otk::OBDisplay::shapeEventBase())
|
if (e.type == otk::OBDisplay::shapeEventBase())
|
||||||
return shapeHandler((*(XShapeEvent*)&e));
|
return shapeHandler((*(XShapeEvent*)&e));
|
||||||
#endif // SHAPE
|
#endif // SHAPE
|
||||||
|
#ifdef XKB
|
||||||
|
if (e.type == otk::OBDisplay::xkbEventBase())
|
||||||
|
return xkbHandler((*(XkbEvent*)&e));
|
||||||
|
#endif // XKB
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,11 @@ extern "C" {
|
||||||
#ifdef SHAPE
|
#ifdef SHAPE
|
||||||
#include <X11/extensions/shape.h>
|
#include <X11/extensions/shape.h>
|
||||||
#endif // SHAPE
|
#endif // SHAPE
|
||||||
|
|
||||||
|
#ifdef XKB
|
||||||
|
#include <X11/XKBlib.h>
|
||||||
|
#endif // XKB
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace otk {
|
namespace otk {
|
||||||
|
@ -120,10 +125,15 @@ public:
|
||||||
virtual void clientMessageHandler(const XClientMessageEvent &);
|
virtual void clientMessageHandler(const XClientMessageEvent &);
|
||||||
|
|
||||||
#if defined(SHAPE) || defined(DOXYGEN_IGNORE)
|
#if defined(SHAPE) || defined(DOXYGEN_IGNORE)
|
||||||
//! Called when a shape extention event fires
|
//! Called when a shape extension event fires
|
||||||
virtual void shapeHandler(const XShapeEvent &) {}
|
virtual void shapeHandler(const XShapeEvent &) {}
|
||||||
#endif // SHAPE
|
#endif // SHAPE
|
||||||
|
|
||||||
|
#if defined(XKB) || defined(DOXYGEN_IGNORE)
|
||||||
|
//! Called when an xkb extension event fires
|
||||||
|
virtual void xkbHandler(const XkbEvent &) {}
|
||||||
|
#endif // XKB
|
||||||
|
|
||||||
virtual ~OtkEventHandler();
|
virtual ~OtkEventHandler();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -5481,6 +5481,34 @@ static PyObject *_wrap_OBDisplay_findScreen(PyObject *self, PyObject *args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static PyObject *_wrap_OBDisplay_xkb(PyObject *self, PyObject *args) {
|
||||||
|
PyObject *resultobj;
|
||||||
|
bool result;
|
||||||
|
|
||||||
|
if(!PyArg_ParseTuple(args,(char *)":OBDisplay_xkb")) goto fail;
|
||||||
|
result = (bool)otk::OBDisplay::xkb();
|
||||||
|
|
||||||
|
resultobj = PyInt_FromLong((long)result);
|
||||||
|
return resultobj;
|
||||||
|
fail:
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static PyObject *_wrap_OBDisplay_xkbEventBase(PyObject *self, PyObject *args) {
|
||||||
|
PyObject *resultobj;
|
||||||
|
int result;
|
||||||
|
|
||||||
|
if(!PyArg_ParseTuple(args,(char *)":OBDisplay_xkbEventBase")) goto fail;
|
||||||
|
result = (int)otk::OBDisplay::xkbEventBase();
|
||||||
|
|
||||||
|
resultobj = PyInt_FromLong((long)result);
|
||||||
|
return resultobj;
|
||||||
|
fail:
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static PyObject *_wrap_OBDisplay_shape(PyObject *self, PyObject *args) {
|
static PyObject *_wrap_OBDisplay_shape(PyObject *self, PyObject *args) {
|
||||||
PyObject *resultobj;
|
PyObject *resultobj;
|
||||||
bool result;
|
bool result;
|
||||||
|
@ -12960,6 +12988,8 @@ static PyMethodDef SwigMethods[] = {
|
||||||
{ (char *)"OBDisplay_gcCache", _wrap_OBDisplay_gcCache, METH_VARARGS },
|
{ (char *)"OBDisplay_gcCache", _wrap_OBDisplay_gcCache, METH_VARARGS },
|
||||||
{ (char *)"OBDisplay_screenInfo", _wrap_OBDisplay_screenInfo, METH_VARARGS },
|
{ (char *)"OBDisplay_screenInfo", _wrap_OBDisplay_screenInfo, METH_VARARGS },
|
||||||
{ (char *)"OBDisplay_findScreen", _wrap_OBDisplay_findScreen, METH_VARARGS },
|
{ (char *)"OBDisplay_findScreen", _wrap_OBDisplay_findScreen, METH_VARARGS },
|
||||||
|
{ (char *)"OBDisplay_xkb", _wrap_OBDisplay_xkb, METH_VARARGS },
|
||||||
|
{ (char *)"OBDisplay_xkbEventBase", _wrap_OBDisplay_xkbEventBase, METH_VARARGS },
|
||||||
{ (char *)"OBDisplay_shape", _wrap_OBDisplay_shape, METH_VARARGS },
|
{ (char *)"OBDisplay_shape", _wrap_OBDisplay_shape, METH_VARARGS },
|
||||||
{ (char *)"OBDisplay_shapeEventBase", _wrap_OBDisplay_shapeEventBase, METH_VARARGS },
|
{ (char *)"OBDisplay_shapeEventBase", _wrap_OBDisplay_shapeEventBase, METH_VARARGS },
|
||||||
{ (char *)"OBDisplay_xinerama", _wrap_OBDisplay_xinerama, METH_VARARGS },
|
{ (char *)"OBDisplay_xinerama", _wrap_OBDisplay_xinerama, METH_VARARGS },
|
||||||
|
|
102
src/actions.cc
102
src/actions.cc
|
@ -8,6 +8,7 @@
|
||||||
#include "widget.hh"
|
#include "widget.hh"
|
||||||
#include "openbox.hh"
|
#include "openbox.hh"
|
||||||
#include "client.hh"
|
#include "client.hh"
|
||||||
|
#include "screen.hh"
|
||||||
#include "python.hh"
|
#include "python.hh"
|
||||||
#include "bindings.hh"
|
#include "bindings.hh"
|
||||||
#include "otk/display.hh"
|
#include "otk/display.hh"
|
||||||
|
@ -74,12 +75,15 @@ void OBActions::buttonPressHandler(const XButtonEvent &e)
|
||||||
// kill off the Button1Mask etc, only want the modifiers
|
// kill off the Button1Mask etc, only want the modifiers
|
||||||
unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask |
|
unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask |
|
||||||
Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
|
Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
|
||||||
ButtonData *data =
|
int screen;
|
||||||
new_button_data(otk::OBDisplay::findScreen(e.root)->screen(),
|
OBClient *c = Openbox::instance->findClient(e.window);
|
||||||
e.window, e.time, state, e.button, w->mcontext(),
|
if (c)
|
||||||
MousePress);
|
screen = c->screen();
|
||||||
Openbox::instance->bindings()->fireButton(data);
|
else
|
||||||
Py_DECREF((PyObject*)data);
|
screen = otk::OBDisplay::findScreen(e.root)->screen();
|
||||||
|
ButtonData data(screen, c, e.time, state, e.button, w->mcontext(),
|
||||||
|
MousePress);
|
||||||
|
Openbox::instance->bindings()->fireButton(&data);
|
||||||
|
|
||||||
if (_button) return; // won't count toward CLICK events
|
if (_button) return; // won't count toward CLICK events
|
||||||
|
|
||||||
|
@ -114,11 +118,15 @@ void OBActions::buttonReleaseHandler(const XButtonEvent &e)
|
||||||
// kill off the Button1Mask etc, only want the modifiers
|
// kill off the Button1Mask etc, only want the modifiers
|
||||||
unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask |
|
unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask |
|
||||||
Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
|
Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
|
||||||
ButtonData *data =
|
int screen;
|
||||||
new_button_data(otk::OBDisplay::findScreen(e.root)->screen(),
|
OBClient *c = Openbox::instance->findClient(e.window);
|
||||||
e.window, e.time, state, e.button, w->mcontext(),
|
if (c)
|
||||||
MouseClick);
|
screen = c->screen();
|
||||||
Openbox::instance->bindings()->fireButton(data);
|
else
|
||||||
|
screen = otk::OBDisplay::findScreen(e.root)->screen();
|
||||||
|
ButtonData data(screen, c, e.time, state, e.button, w->mcontext(),
|
||||||
|
MouseClick);
|
||||||
|
Openbox::instance->bindings()->fireButton(&data);
|
||||||
|
|
||||||
|
|
||||||
// XXX: dont load this every time!!@*
|
// XXX: dont load this every time!!@*
|
||||||
|
@ -130,8 +138,8 @@ void OBActions::buttonReleaseHandler(const XButtonEvent &e)
|
||||||
_release.win == e.window && _release.button == e.button) {
|
_release.win == e.window && _release.button == e.button) {
|
||||||
|
|
||||||
// run the DOUBLECLICK python hook
|
// run the DOUBLECLICK python hook
|
||||||
data->action = MouseDoubleClick;
|
data.action = MouseDoubleClick;
|
||||||
Openbox::instance->bindings()->fireButton(data);
|
Openbox::instance->bindings()->fireButton(&data);
|
||||||
|
|
||||||
// reset so you cant triple click for 2 doubleclicks
|
// reset so you cant triple click for 2 doubleclicks
|
||||||
_release.win = 0;
|
_release.win = 0;
|
||||||
|
@ -143,8 +151,6 @@ void OBActions::buttonReleaseHandler(const XButtonEvent &e)
|
||||||
_release.button = e.button;
|
_release.button = e.button;
|
||||||
_release.time = e.time;
|
_release.time = e.time;
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_DECREF((PyObject*)data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -153,11 +159,14 @@ void OBActions::enterHandler(const XCrossingEvent &e)
|
||||||
OtkEventHandler::enterHandler(e);
|
OtkEventHandler::enterHandler(e);
|
||||||
|
|
||||||
// run the ENTER python hook
|
// run the ENTER python hook
|
||||||
EventData *data =
|
int screen;
|
||||||
new_event_data(otk::OBDisplay::findScreen(e.root)->screen(),
|
OBClient *c = Openbox::instance->findClient(e.window);
|
||||||
e.window, EventEnterWindow, e.state);
|
if (c)
|
||||||
Openbox::instance->bindings()->fireEvent(data);
|
screen = c->screen();
|
||||||
Py_DECREF((PyObject*)data);
|
else
|
||||||
|
screen = otk::OBDisplay::findScreen(e.root)->screen();
|
||||||
|
EventData data(screen, c, EventEnterWindow, e.state);
|
||||||
|
Openbox::instance->bindings()->fireEvent(&data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -166,11 +175,14 @@ void OBActions::leaveHandler(const XCrossingEvent &e)
|
||||||
OtkEventHandler::leaveHandler(e);
|
OtkEventHandler::leaveHandler(e);
|
||||||
|
|
||||||
// run the LEAVE python hook
|
// run the LEAVE python hook
|
||||||
EventData *data =
|
int screen;
|
||||||
new_event_data(otk::OBDisplay::findScreen(e.root)->screen(),
|
OBClient *c = Openbox::instance->findClient(e.window);
|
||||||
e.window, EventLeaveWindow, e.state);
|
if (c)
|
||||||
Openbox::instance->bindings()->fireEvent(data);
|
screen = c->screen();
|
||||||
Py_DECREF((PyObject*)data);
|
else
|
||||||
|
screen = otk::OBDisplay::findScreen(e.root)->screen();
|
||||||
|
EventData data(screen, c, EventLeaveWindow, e.state);
|
||||||
|
Openbox::instance->bindings()->fireEvent(&data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -216,13 +228,15 @@ void OBActions::motionHandler(const XMotionEvent &e)
|
||||||
unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask |
|
unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask |
|
||||||
Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
|
Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
|
||||||
unsigned int button = _posqueue[0]->button;
|
unsigned int button = _posqueue[0]->button;
|
||||||
MotionData *data =
|
int screen;
|
||||||
new_motion_data(otk::OBDisplay::findScreen(e.root)->screen(),
|
OBClient *c = Openbox::instance->findClient(e.window);
|
||||||
e.window, e.time, state, button, w->mcontext(),
|
if (c)
|
||||||
MouseMotion, x_root, y_root, _posqueue[0]->pos,
|
screen = c->screen();
|
||||||
_posqueue[0]->clientarea);
|
else
|
||||||
Openbox::instance->bindings()->fireButton((ButtonData*)data);
|
screen = otk::OBDisplay::findScreen(e.root)->screen();
|
||||||
Py_DECREF((PyObject*)data);
|
MotionData data(screen, c, e.time, state, button, w->mcontext(), MouseMotion,
|
||||||
|
x_root, y_root, _posqueue[0]->pos, _posqueue[0]->clientarea);
|
||||||
|
Openbox::instance->bindings()->fireButton((ButtonData*)&data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OBActions::mapRequestHandler(const XMapRequestEvent &e)
|
void OBActions::mapRequestHandler(const XMapRequestEvent &e)
|
||||||
|
@ -243,4 +257,28 @@ void OBActions::destroyHandler(const XDestroyWindowEvent &e)
|
||||||
// do this in OBScreen::unmanageWindow
|
// do this in OBScreen::unmanageWindow
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef XKB
|
||||||
|
void OBActions::xkbHandler(const XkbEvent &e)
|
||||||
|
{
|
||||||
|
Window w;
|
||||||
|
int screen;
|
||||||
|
|
||||||
|
OtkEventHandler::xkbHandler(e);
|
||||||
|
|
||||||
|
switch (((XkbAnyEvent*)&e)->xkb_type) {
|
||||||
|
case XkbBellNotify:
|
||||||
|
w = ((XkbBellNotifyEvent*)&e)->window;
|
||||||
|
OBClient *c = Openbox::instance->findClient(w);
|
||||||
|
if (c)
|
||||||
|
screen = c->screen();
|
||||||
|
else
|
||||||
|
screen = Openbox::instance->focusedScreen()->number();
|
||||||
|
EventData data(screen, c, EventBell, 0);
|
||||||
|
Openbox::instance->bindings()->fireEvent(&data);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
#endif // XKB
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,6 +80,10 @@ public:
|
||||||
virtual void unmapHandler(const XUnmapEvent &e);
|
virtual void unmapHandler(const XUnmapEvent &e);
|
||||||
virtual void destroyHandler(const XDestroyWindowEvent &e);
|
virtual void destroyHandler(const XDestroyWindowEvent &e);
|
||||||
|
|
||||||
|
#ifdef XKB
|
||||||
|
virtual void xkbHandler(const XkbEvent &e);
|
||||||
|
#endif // XKB
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -387,14 +387,11 @@ void OBBindings::fireKey(int screen, unsigned int modifiers, unsigned int key,
|
||||||
grabKeys(true);
|
grabKeys(true);
|
||||||
otk::OBDisplay::ungrab();
|
otk::OBDisplay::ungrab();
|
||||||
} else {
|
} else {
|
||||||
Window win = None;
|
|
||||||
OBClient *c = Openbox::instance->focusedClient();
|
OBClient *c = Openbox::instance->focusedClient();
|
||||||
if (c) win = c->window();
|
KeyData data(screen, c, time, modifiers, key);
|
||||||
KeyData *data = new_key_data(screen, win, time, modifiers, key);
|
|
||||||
CallbackList::iterator it, end = p->callbacks.end();
|
CallbackList::iterator it, end = p->callbacks.end();
|
||||||
for (it = p->callbacks.begin(); it != end; ++it)
|
for (it = p->callbacks.begin(); it != end; ++it)
|
||||||
python_callback(*it, (PyObject*)data);
|
python_callback(*it, &data);
|
||||||
Py_XDECREF((PyObject*)data);
|
|
||||||
resetChains(this);
|
resetChains(this);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -540,7 +537,11 @@ bool OBBindings::addEvent(EventAction action, PyObject *callback)
|
||||||
if (action < 0 || action >= NUM_EVENTS) {
|
if (action < 0 || action >= NUM_EVENTS) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
#ifdef XKB
|
||||||
|
if (action == EventBell && _eventlist[action].empty())
|
||||||
|
XkbSelectEvents(otk::OBDisplay::display, XkbUseCoreKbd,
|
||||||
|
XkbBellNotifyMask, XkbBellNotifyMask);
|
||||||
|
#endif // XKB
|
||||||
_eventlist[action].push_back(callback);
|
_eventlist[action].push_back(callback);
|
||||||
Py_INCREF(callback);
|
Py_INCREF(callback);
|
||||||
return true;
|
return true;
|
||||||
|
@ -558,6 +559,11 @@ bool OBBindings::removeEvent(EventAction action, PyObject *callback)
|
||||||
if (it != _eventlist[action].end()) {
|
if (it != _eventlist[action].end()) {
|
||||||
Py_XDECREF(*it);
|
Py_XDECREF(*it);
|
||||||
_eventlist[action].erase(it);
|
_eventlist[action].erase(it);
|
||||||
|
#ifdef XKB
|
||||||
|
if (action == EventBell && _eventlist[action].empty())
|
||||||
|
XkbSelectEvents(otk::OBDisplay::display, XkbUseCoreKbd,
|
||||||
|
XkbBellNotifyMask, 0);
|
||||||
|
#endif // XKB
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -577,7 +583,7 @@ void OBBindings::fireEvent(EventData *data)
|
||||||
{
|
{
|
||||||
CallbackList::iterator c_it, c_end = _eventlist[data->action].end();
|
CallbackList::iterator c_it, c_end = _eventlist[data->action].end();
|
||||||
for (c_it = _eventlist[data->action].begin(); c_it != c_end; ++c_it)
|
for (c_it = _eventlist[data->action].begin(); c_it != c_end; ++c_it)
|
||||||
python_callback(*c_it, (PyObject*)data);
|
python_callback(*c_it, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -288,7 +288,8 @@ void Openbox::showHelp()
|
||||||
printf(_("Compile time options:\n\
|
printf(_("Compile time options:\n\
|
||||||
Debugging: %s\n\
|
Debugging: %s\n\
|
||||||
Shape: %s\n\
|
Shape: %s\n\
|
||||||
Xinerama: %s\n"),
|
Xinerama: %s\n\
|
||||||
|
Xkb: %s\n"),
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
_("yes"),
|
_("yes"),
|
||||||
#else // !DEBUG
|
#else // !DEBUG
|
||||||
|
@ -302,10 +303,16 @@ void Openbox::showHelp()
|
||||||
#endif // SHAPE
|
#endif // SHAPE
|
||||||
|
|
||||||
#ifdef XINERAMA
|
#ifdef XINERAMA
|
||||||
_("yes")
|
_("yes"),
|
||||||
#else // !XINERAMA
|
#else // !XINERAMA
|
||||||
_("no")
|
_("no"),
|
||||||
#endif // XINERAMA
|
#endif // XINERAMA
|
||||||
|
|
||||||
|
#ifdef XKB
|
||||||
|
_("yes")
|
||||||
|
#else // !XKB
|
||||||
|
_("no")
|
||||||
|
#endif // XKB
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -368,11 +375,8 @@ void Openbox::setFocusedClient(OBClient *c)
|
||||||
}
|
}
|
||||||
|
|
||||||
// call the python Focus callbacks
|
// call the python Focus callbacks
|
||||||
EventData *data = new_event_data(_focused_screen->number(),
|
EventData data(_focused_screen->number(), c, EventFocus, 0);
|
||||||
c ? c->window() : 0,
|
Openbox::instance->bindings()->fireEvent(&data);
|
||||||
EventFocus, 0);
|
|
||||||
Openbox::instance->bindings()->fireEvent(data);
|
|
||||||
Py_XDECREF((PyObject*)data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Openbox::execute(int screen, const std::string &bin)
|
void Openbox::execute(int screen, const std::string &bin)
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
#include "client.hh"
|
#include "client.hh"
|
||||||
#include "bindings.hh"
|
#include "bindings.hh"
|
||||||
#include "actions.hh"
|
#include "actions.hh"
|
||||||
|
#include "python.hh"
|
||||||
|
#include "otk/display.hh"
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%include "stl.i"
|
%include "stl.i"
|
||||||
|
@ -23,6 +25,91 @@
|
||||||
ob::Openbox *Openbox_instance() { return ob::Openbox::instance; }
|
ob::Openbox *Openbox_instance() { return ob::Openbox::instance; }
|
||||||
%};
|
%};
|
||||||
|
|
||||||
|
%{
|
||||||
|
namespace ob {
|
||||||
|
void python_callback(PyObject *func, MotionData *data)
|
||||||
|
{
|
||||||
|
PyObject *arglist;
|
||||||
|
PyObject *result;
|
||||||
|
|
||||||
|
arglist = Py_BuildValue("(O)", SWIG_NewPointerObj((void *) data,
|
||||||
|
SWIGTYPE_p_ob__MotionData,
|
||||||
|
0));
|
||||||
|
|
||||||
|
// call the callback
|
||||||
|
result = PyEval_CallObject(func, arglist);
|
||||||
|
if (!result || PyErr_Occurred()) {
|
||||||
|
// an exception occured in the script, display it
|
||||||
|
PyErr_Print();
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_XDECREF(result);
|
||||||
|
Py_DECREF(arglist);
|
||||||
|
}
|
||||||
|
|
||||||
|
void python_callback(PyObject *func, ButtonData *data)
|
||||||
|
{
|
||||||
|
PyObject *arglist;
|
||||||
|
PyObject *result;
|
||||||
|
|
||||||
|
arglist = Py_BuildValue("(O)", SWIG_NewPointerObj((void *) data,
|
||||||
|
SWIGTYPE_p_ob__ButtonData,
|
||||||
|
0));
|
||||||
|
|
||||||
|
// call the callback
|
||||||
|
result = PyEval_CallObject(func, arglist);
|
||||||
|
if (!result || PyErr_Occurred()) {
|
||||||
|
// an exception occured in the script, display it
|
||||||
|
PyErr_Print();
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_XDECREF(result);
|
||||||
|
Py_DECREF(arglist);
|
||||||
|
}
|
||||||
|
|
||||||
|
void python_callback(PyObject *func, EventData *data)
|
||||||
|
{
|
||||||
|
PyObject *arglist;
|
||||||
|
PyObject *result;
|
||||||
|
|
||||||
|
arglist = Py_BuildValue("(O)", SWIG_NewPointerObj((void *) data,
|
||||||
|
SWIGTYPE_p_ob__EventData,
|
||||||
|
0));
|
||||||
|
|
||||||
|
// call the callback
|
||||||
|
result = PyEval_CallObject(func, arglist);
|
||||||
|
if (!result || PyErr_Occurred()) {
|
||||||
|
// an exception occured in the script, display it
|
||||||
|
PyErr_Print();
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_XDECREF(result);
|
||||||
|
Py_DECREF(arglist);
|
||||||
|
}
|
||||||
|
|
||||||
|
void python_callback(PyObject *func, KeyData *data)
|
||||||
|
{
|
||||||
|
PyObject *arglist;
|
||||||
|
PyObject *result;
|
||||||
|
|
||||||
|
arglist = Py_BuildValue("(O)", SWIG_NewPointerObj((void *) data,
|
||||||
|
SWIGTYPE_p_ob__KeyData,
|
||||||
|
0));
|
||||||
|
|
||||||
|
// call the callback
|
||||||
|
result = PyEval_CallObject(func, arglist);
|
||||||
|
if (!result || PyErr_Occurred()) {
|
||||||
|
// an exception occured in the script, display it
|
||||||
|
PyErr_Print();
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_XDECREF(result);
|
||||||
|
Py_DECREF(arglist);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
%ignore ob::OBScreen::clients;
|
%ignore ob::OBScreen::clients;
|
||||||
%{
|
%{
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
|
1465
src/openbox_wrap.cc
1465
src/openbox_wrap.cc
File diff suppressed because it is too large
Load diff
368
src/python.cc
368
src/python.cc
|
@ -18,350 +18,6 @@ namespace ob {
|
||||||
|
|
||||||
static PyObject *obdict = NULL;
|
static PyObject *obdict = NULL;
|
||||||
|
|
||||||
// ************************************************************* //
|
|
||||||
// Define some custom types which are passed to python callbacks //
|
|
||||||
// ************************************************************* //
|
|
||||||
|
|
||||||
static void dealloc(PyObject *self)
|
|
||||||
{
|
|
||||||
PyObject_Del(self);
|
|
||||||
}
|
|
||||||
|
|
||||||
PyObject *MotionData_screen(MotionData *self, PyObject *args)
|
|
||||||
{
|
|
||||||
if(!PyArg_ParseTuple(args,":screen")) return NULL;
|
|
||||||
return PyLong_FromLong(self->screen);
|
|
||||||
}
|
|
||||||
|
|
||||||
PyObject *MotionData_window(MotionData *self, PyObject *args)
|
|
||||||
{
|
|
||||||
if(!PyArg_ParseTuple(args,":window")) return NULL;
|
|
||||||
return PyLong_FromLong(self->window);
|
|
||||||
}
|
|
||||||
|
|
||||||
PyObject *MotionData_context(MotionData *self, PyObject *args)
|
|
||||||
{
|
|
||||||
if(!PyArg_ParseTuple(args,":context")) return NULL;
|
|
||||||
return PyLong_FromLong((int)self->context);
|
|
||||||
}
|
|
||||||
|
|
||||||
PyObject *MotionData_action(MotionData *self, PyObject *args)
|
|
||||||
{
|
|
||||||
if(!PyArg_ParseTuple(args,":action")) return NULL;
|
|
||||||
return PyLong_FromLong((int)self->action);
|
|
||||||
}
|
|
||||||
|
|
||||||
PyObject *MotionData_modifiers(MotionData *self, PyObject *args)
|
|
||||||
{
|
|
||||||
if(!PyArg_ParseTuple(args,":modifiers")) return NULL;
|
|
||||||
return PyLong_FromUnsignedLong(self->state);
|
|
||||||
}
|
|
||||||
|
|
||||||
PyObject *MotionData_button(MotionData *self, PyObject *args)
|
|
||||||
{
|
|
||||||
if(!PyArg_ParseTuple(args,":button")) return NULL;
|
|
||||||
int b = 0;
|
|
||||||
switch (self->button) {
|
|
||||||
case Button5: b++;
|
|
||||||
case Button4: b++;
|
|
||||||
case Button3: b++;
|
|
||||||
case Button2: b++;
|
|
||||||
case Button1: b++;
|
|
||||||
default: ;
|
|
||||||
}
|
|
||||||
return PyLong_FromLong(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
PyObject *MotionData_xroot(MotionData *self, PyObject *args)
|
|
||||||
{
|
|
||||||
if(!PyArg_ParseTuple(args,":xroot")) return NULL;
|
|
||||||
return PyLong_FromLong(self->xroot);
|
|
||||||
}
|
|
||||||
|
|
||||||
PyObject *MotionData_yroot(MotionData *self, PyObject *args)
|
|
||||||
{
|
|
||||||
if(!PyArg_ParseTuple(args,":yroot")) return NULL;
|
|
||||||
return PyLong_FromLong(self->yroot);
|
|
||||||
}
|
|
||||||
|
|
||||||
PyObject *MotionData_pressx(MotionData *self, PyObject *args)
|
|
||||||
{
|
|
||||||
if(!PyArg_ParseTuple(args,":pressx")) return NULL;
|
|
||||||
return PyLong_FromLong(self->pressx);
|
|
||||||
}
|
|
||||||
|
|
||||||
PyObject *MotionData_pressy(MotionData *self, PyObject *args)
|
|
||||||
{
|
|
||||||
if(!PyArg_ParseTuple(args,":pressy")) return NULL;
|
|
||||||
return PyLong_FromLong(self->pressy);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PyObject *MotionData_press_clientx(MotionData *self, PyObject *args)
|
|
||||||
{
|
|
||||||
if(!PyArg_ParseTuple(args,":press_clientx")) return NULL;
|
|
||||||
return PyLong_FromLong(self->press_clientx);
|
|
||||||
}
|
|
||||||
|
|
||||||
PyObject *MotionData_press_clienty(MotionData *self, PyObject *args)
|
|
||||||
{
|
|
||||||
if(!PyArg_ParseTuple(args,":press_clienty")) return NULL;
|
|
||||||
return PyLong_FromLong(self->press_clienty);
|
|
||||||
}
|
|
||||||
|
|
||||||
PyObject *MotionData_press_clientwidth(MotionData *self, PyObject *args)
|
|
||||||
{
|
|
||||||
if(!PyArg_ParseTuple(args,":press_clientwidth")) return NULL;
|
|
||||||
return PyLong_FromLong(self->press_clientwidth);
|
|
||||||
}
|
|
||||||
|
|
||||||
PyObject *MotionData_press_clientheight(MotionData *self, PyObject *args)
|
|
||||||
{
|
|
||||||
if(!PyArg_ParseTuple(args,":press_clientheight")) return NULL;
|
|
||||||
return PyLong_FromLong(self->press_clientheight);
|
|
||||||
}
|
|
||||||
|
|
||||||
PyObject *MotionData_time(MotionData *self, PyObject *args)
|
|
||||||
{
|
|
||||||
if(!PyArg_ParseTuple(args,":time")) return NULL;
|
|
||||||
return PyLong_FromLong(self->time);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyMethodDef MotionData_methods[] = {
|
|
||||||
{"action", (PyCFunction)MotionData_action, METH_VARARGS,
|
|
||||||
"Return the action being executed."},
|
|
||||||
{"screen", (PyCFunction)MotionData_screen, METH_VARARGS,
|
|
||||||
"Return the number of the screen the event is on."},
|
|
||||||
{"window", (PyCFunction)MotionData_window, METH_VARARGS,
|
|
||||||
"Return the client window id."},
|
|
||||||
{"context", (PyCFunction)MotionData_context, METH_VARARGS,
|
|
||||||
"Return the context that the action is occuring in."},
|
|
||||||
{"modifiers", (PyCFunction)MotionData_modifiers, METH_VARARGS,
|
|
||||||
"Return the modifier keys state."},
|
|
||||||
{"button", (PyCFunction)MotionData_button, METH_VARARGS,
|
|
||||||
"Return the number of the pressed button (1-5)."},
|
|
||||||
{"xroot", (PyCFunction)MotionData_xroot, METH_VARARGS,
|
|
||||||
"Return the X-position of the mouse cursor on the root window."},
|
|
||||||
{"yroot", (PyCFunction)MotionData_yroot, METH_VARARGS,
|
|
||||||
"Return the Y-position of the mouse cursor on the root window."},
|
|
||||||
{"pressx", (PyCFunction)MotionData_pressx, METH_VARARGS,
|
|
||||||
"Return the X-position of the mouse cursor at the start of the drag."},
|
|
||||||
{"pressy", (PyCFunction)MotionData_pressy, METH_VARARGS,
|
|
||||||
"Return the Y-position of the mouse cursor at the start of the drag."},
|
|
||||||
{"press_clientx", (PyCFunction)MotionData_press_clientx, METH_VARARGS,
|
|
||||||
"Return the X-position of the client at the start of the drag."},
|
|
||||||
{"press_clienty", (PyCFunction)MotionData_press_clienty, METH_VARARGS,
|
|
||||||
"Return the Y-position of the client at the start of the drag."},
|
|
||||||
{"press_clientwidth", (PyCFunction)MotionData_press_clientwidth,
|
|
||||||
METH_VARARGS,
|
|
||||||
"Return the width of the client at the start of the drag."},
|
|
||||||
{"press_clientheight", (PyCFunction)MotionData_press_clientheight,
|
|
||||||
METH_VARARGS,
|
|
||||||
"Return the height of the client at the start of the drag."},
|
|
||||||
{"time", (PyCFunction)MotionData_time, METH_VARARGS,
|
|
||||||
"Return the time at which the event occured."},
|
|
||||||
{NULL, NULL, 0, NULL}
|
|
||||||
};
|
|
||||||
|
|
||||||
static PyMethodDef ButtonData_methods[] = {
|
|
||||||
{"action", (PyCFunction)MotionData_action, METH_VARARGS,
|
|
||||||
"Return the action being executed."},
|
|
||||||
{"context", (PyCFunction)MotionData_context, METH_VARARGS,
|
|
||||||
"Return the context that the action is occuring in."},
|
|
||||||
{"screen", (PyCFunction)MotionData_screen, METH_VARARGS,
|
|
||||||
"Return the number of the screen the event is on."},
|
|
||||||
{"window", (PyCFunction)MotionData_window, METH_VARARGS,
|
|
||||||
"Return the client window id."},
|
|
||||||
{"modifiers", (PyCFunction)MotionData_modifiers, METH_VARARGS,
|
|
||||||
"Return the modifier keys state."},
|
|
||||||
{"button", (PyCFunction)MotionData_button, METH_VARARGS,
|
|
||||||
"Return the number of the pressed button (1-5)."},
|
|
||||||
{"time", (PyCFunction)MotionData_time, METH_VARARGS,
|
|
||||||
"Return the time at which the event occured."},
|
|
||||||
{NULL, NULL, 0, NULL}
|
|
||||||
};
|
|
||||||
|
|
||||||
PyObject *EventData_action(EventData *self, PyObject *args)
|
|
||||||
{
|
|
||||||
if(!PyArg_ParseTuple(args,":action")) return NULL;
|
|
||||||
return PyLong_FromLong((int)self->action);
|
|
||||||
}
|
|
||||||
|
|
||||||
PyObject *EventData_modifiers(EventData *self, PyObject *args)
|
|
||||||
{
|
|
||||||
if(!PyArg_ParseTuple(args,":modifiers")) return NULL;
|
|
||||||
return PyLong_FromUnsignedLong(self->state);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyMethodDef EventData_methods[] = {
|
|
||||||
{"screen", (PyCFunction)MotionData_screen, METH_VARARGS,
|
|
||||||
"Return the number of the screen the event is on."},
|
|
||||||
{"window", (PyCFunction)MotionData_window, METH_VARARGS,
|
|
||||||
"Return the client window id."},
|
|
||||||
{"action", (PyCFunction)EventData_action, METH_VARARGS,
|
|
||||||
"Return the action being executed."},
|
|
||||||
{"modifiers", (PyCFunction)EventData_modifiers, METH_VARARGS,
|
|
||||||
"Return the modifier keys state."},
|
|
||||||
{NULL, NULL, 0, NULL}
|
|
||||||
};
|
|
||||||
|
|
||||||
PyObject *KeyData_key(KeyData *self, PyObject *args)
|
|
||||||
{
|
|
||||||
if(!PyArg_ParseTuple(args,":key")) return NULL;
|
|
||||||
return PyString_FromString(
|
|
||||||
XKeysymToString(XKeycodeToKeysym(otk::OBDisplay::display, self->key, 0)));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyMethodDef KeyData_methods[] = {
|
|
||||||
{"screen", (PyCFunction)MotionData_screen, METH_VARARGS,
|
|
||||||
"Return the number of the screen the event is on."},
|
|
||||||
{"window", (PyCFunction)MotionData_window, METH_VARARGS,
|
|
||||||
"Return the client window id."},
|
|
||||||
{"modifiers", (PyCFunction)MotionData_modifiers, METH_VARARGS,
|
|
||||||
"Return the modifier keys state."},
|
|
||||||
{"key", (PyCFunction)KeyData_key, METH_VARARGS,
|
|
||||||
"Return the name of the pressed key."},
|
|
||||||
{"time", (PyCFunction)MotionData_time, METH_VARARGS,
|
|
||||||
"Return the time at which the event occured."},
|
|
||||||
{NULL, NULL, 0, NULL}
|
|
||||||
};
|
|
||||||
|
|
||||||
static PyObject *MotionDataGetAttr(PyObject *obj, char *name)
|
|
||||||
{
|
|
||||||
return Py_FindMethod(MotionData_methods, obj, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *ButtonDataGetAttr(PyObject *obj, char *name)
|
|
||||||
{
|
|
||||||
return Py_FindMethod(ButtonData_methods, obj, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *EventDataGetAttr(PyObject *obj, char *name)
|
|
||||||
{
|
|
||||||
return Py_FindMethod(EventData_methods, obj, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *KeyDataGetAttr(PyObject *obj, char *name)
|
|
||||||
{
|
|
||||||
return Py_FindMethod(KeyData_methods, obj, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyTypeObject MotionData_Type = {
|
|
||||||
PyObject_HEAD_INIT(NULL)
|
|
||||||
0,
|
|
||||||
"MotionData",
|
|
||||||
sizeof(MotionData),
|
|
||||||
0,
|
|
||||||
dealloc,
|
|
||||||
0,
|
|
||||||
(getattrfunc)MotionDataGetAttr,
|
|
||||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
|
||||||
};
|
|
||||||
|
|
||||||
static PyTypeObject ButtonData_Type = {
|
|
||||||
PyObject_HEAD_INIT(NULL)
|
|
||||||
0,
|
|
||||||
"ButtonData",
|
|
||||||
sizeof(ButtonData),
|
|
||||||
0,
|
|
||||||
dealloc,
|
|
||||||
0,
|
|
||||||
(getattrfunc)ButtonDataGetAttr,
|
|
||||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
|
||||||
};
|
|
||||||
|
|
||||||
static PyTypeObject EventData_Type = {
|
|
||||||
PyObject_HEAD_INIT(NULL)
|
|
||||||
0,
|
|
||||||
"EventData",
|
|
||||||
sizeof(EventData),
|
|
||||||
0,
|
|
||||||
dealloc,
|
|
||||||
0,
|
|
||||||
(getattrfunc)EventDataGetAttr,
|
|
||||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
|
||||||
};
|
|
||||||
|
|
||||||
static PyTypeObject KeyData_Type = {
|
|
||||||
PyObject_HEAD_INIT(NULL)
|
|
||||||
0,
|
|
||||||
"KeyData",
|
|
||||||
sizeof(KeyData),
|
|
||||||
0,
|
|
||||||
dealloc,
|
|
||||||
0,
|
|
||||||
(getattrfunc)KeyDataGetAttr,
|
|
||||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
|
||||||
};
|
|
||||||
|
|
||||||
MotionData *new_motion_data(int screen, Window window, Time time,
|
|
||||||
unsigned int state, unsigned int button,
|
|
||||||
MouseContext context, MouseAction action,
|
|
||||||
int xroot, int yroot, const otk::Point &initpos,
|
|
||||||
const otk::Rect &initarea)
|
|
||||||
{
|
|
||||||
MotionData *data = PyObject_New(MotionData, &MotionData_Type);
|
|
||||||
data->screen = screen;
|
|
||||||
data->window = window;
|
|
||||||
data->time = time;
|
|
||||||
data->state = state;
|
|
||||||
data->button = button;
|
|
||||||
data->context= context;
|
|
||||||
data->action = action;
|
|
||||||
data->xroot = xroot;
|
|
||||||
data->yroot = yroot;
|
|
||||||
data->pressx = initpos.x();
|
|
||||||
data->pressy = initpos.y();
|
|
||||||
data->press_clientx = initarea.x();
|
|
||||||
data->press_clienty = initarea.y();
|
|
||||||
data->press_clientwidth = initarea.width();
|
|
||||||
data->press_clientheight = initarea.height();
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
ButtonData *new_button_data(int screen, Window window, Time time,
|
|
||||||
unsigned int state, unsigned int button,
|
|
||||||
MouseContext context, MouseAction action)
|
|
||||||
{
|
|
||||||
ButtonData *data = PyObject_New(ButtonData, &ButtonData_Type);
|
|
||||||
data->screen = screen;
|
|
||||||
data->window = window;
|
|
||||||
data->time = time;
|
|
||||||
data->state = state;
|
|
||||||
data->button = button;
|
|
||||||
data->context= context;
|
|
||||||
data->action = action;
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
EventData *new_event_data(int screen, Window window, EventAction action,
|
|
||||||
unsigned int state)
|
|
||||||
{
|
|
||||||
EventData *data = PyObject_New(EventData, &EventData_Type);
|
|
||||||
data->screen = screen;
|
|
||||||
data->window = window;
|
|
||||||
data->action = action;
|
|
||||||
data->state = state;
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
KeyData *new_key_data(int screen, Window window, Time time, unsigned int state,
|
|
||||||
unsigned int key)
|
|
||||||
{
|
|
||||||
KeyData *data = PyObject_New(KeyData, &KeyData_Type);
|
|
||||||
data->screen = screen;
|
|
||||||
data->window = window;
|
|
||||||
data->time = time;
|
|
||||||
data->state = state;
|
|
||||||
data->key = key;
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
// **************** //
|
|
||||||
// End custom types //
|
|
||||||
// **************** //
|
|
||||||
|
|
||||||
void python_init(char *argv0)
|
void python_init(char *argv0)
|
||||||
{
|
{
|
||||||
Py_SetProgramName(argv0);
|
Py_SetProgramName(argv0);
|
||||||
|
@ -375,16 +31,12 @@ void python_init(char *argv0)
|
||||||
/* XXX
|
/* XXX
|
||||||
sys.path.append('stuff')
|
sys.path.append('stuff')
|
||||||
install the .py wrappers, and include their path with this, then import em
|
install the .py wrappers, and include their path with this, then import em
|
||||||
|
and ~/.openbox/python/ !!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// set up access to the python global variables
|
// set up access to the python global variables
|
||||||
PyObject *obmodule = PyImport_AddModule("__main__");
|
PyObject *obmodule = PyImport_AddModule("__main__");
|
||||||
obdict = PyModule_GetDict(obmodule);
|
obdict = PyModule_GetDict(obmodule);
|
||||||
|
|
||||||
// set up the custom types
|
|
||||||
MotionData_Type.ob_type = &PyType_Type;
|
|
||||||
ButtonData_Type.ob_type = &PyType_Type;
|
|
||||||
KeyData_Type.ob_type = &PyType_Type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void python_destroy()
|
void python_destroy()
|
||||||
|
@ -404,24 +56,6 @@ bool python_exec(const std::string &path)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void python_callback(PyObject *func, PyObject *data)
|
|
||||||
{
|
|
||||||
PyObject *arglist;
|
|
||||||
PyObject *result;
|
|
||||||
|
|
||||||
arglist = Py_BuildValue("(O)", data);
|
|
||||||
|
|
||||||
// call the callback
|
|
||||||
result = PyEval_CallObject(func, arglist);
|
|
||||||
if (!result || PyErr_Occurred()) {
|
|
||||||
// an exception occured in the script, display it
|
|
||||||
PyErr_Print();
|
|
||||||
}
|
|
||||||
|
|
||||||
Py_XDECREF(result);
|
|
||||||
Py_DECREF(arglist);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool python_get_long(const char *name, long *value)
|
bool python_get_long(const char *name, long *value)
|
||||||
{
|
{
|
||||||
PyObject *val = PyDict_GetItemString(obdict, const_cast<char*>(name));
|
PyObject *val = PyDict_GetItemString(obdict, const_cast<char*>(name));
|
||||||
|
|
120
src/python.hh
120
src/python.hh
|
@ -9,6 +9,7 @@
|
||||||
#include "otk/point.hh"
|
#include "otk/point.hh"
|
||||||
#include "otk/rect.hh"
|
#include "otk/rect.hh"
|
||||||
#include "otk/property.hh"
|
#include "otk/property.hh"
|
||||||
|
#include "otk/display.hh"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
@ -20,6 +21,8 @@ extern "C" {
|
||||||
|
|
||||||
namespace ob {
|
namespace ob {
|
||||||
|
|
||||||
|
class OBClient;
|
||||||
|
|
||||||
enum MouseContext {
|
enum MouseContext {
|
||||||
MC_Frame,
|
MC_Frame,
|
||||||
MC_Titlebar,
|
MC_Titlebar,
|
||||||
|
@ -58,16 +61,15 @@ enum EventAction {
|
||||||
EventStartup,
|
EventStartup,
|
||||||
EventShutdown,
|
EventShutdown,
|
||||||
EventFocus,
|
EventFocus,
|
||||||
|
EventBell,
|
||||||
NUM_EVENTS
|
NUM_EVENTS
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef SWIG
|
|
||||||
|
|
||||||
// *** MotionData can be (and is) cast ButtonData!! (in actions.cc) *** //
|
// *** MotionData can be (and is) cast ButtonData!! (in actions.cc) *** //
|
||||||
typedef struct {
|
class MotionData {
|
||||||
PyObject_HEAD;
|
public:
|
||||||
int screen;
|
int screen;
|
||||||
Window window;
|
OBClient *client;
|
||||||
Time time;
|
Time time;
|
||||||
unsigned int state;
|
unsigned int state;
|
||||||
unsigned int button;
|
unsigned int button;
|
||||||
|
@ -81,60 +83,106 @@ typedef struct {
|
||||||
int press_clienty;
|
int press_clienty;
|
||||||
int press_clientwidth;
|
int press_clientwidth;
|
||||||
int press_clientheight;
|
int press_clientheight;
|
||||||
} MotionData;
|
|
||||||
|
MotionData(int screen, OBClient *client, Time time, unsigned int state,
|
||||||
|
unsigned int button, MouseContext context, MouseAction action,
|
||||||
|
int xroot, int yroot, const otk::Point &initpos,
|
||||||
|
const otk::Rect &initarea) {
|
||||||
|
this->screen = screen;
|
||||||
|
this->client = client;
|
||||||
|
this->time = time;
|
||||||
|
this->state = state;
|
||||||
|
this->button = button;
|
||||||
|
this->context= context;
|
||||||
|
this->action = action;
|
||||||
|
this->xroot = xroot;
|
||||||
|
this->yroot = yroot;
|
||||||
|
this->pressx = initpos.x();
|
||||||
|
this->pressy = initpos.y();
|
||||||
|
this->press_clientx = initarea.x();
|
||||||
|
this->press_clienty = initarea.y();
|
||||||
|
this->press_clientwidth = initarea.width();
|
||||||
|
this->press_clientheight = initarea.height();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// *** MotionData can be (and is) cast ButtonData!! (in actions.cc) *** //
|
// *** MotionData can be (and is) cast ButtonData!! (in actions.cc) *** //
|
||||||
typedef struct {
|
class ButtonData {
|
||||||
PyObject_HEAD;
|
public:
|
||||||
int screen;
|
int screen;
|
||||||
Window window;
|
OBClient *client;
|
||||||
Time time;
|
Time time;
|
||||||
unsigned int state;
|
unsigned int state;
|
||||||
unsigned int button;
|
unsigned int button;
|
||||||
MouseContext context;
|
MouseContext context;
|
||||||
MouseAction action;
|
MouseAction action;
|
||||||
} ButtonData;
|
|
||||||
|
|
||||||
typedef struct {
|
ButtonData(int screen, OBClient *client, Time time, unsigned int state,
|
||||||
PyObject_HEAD;
|
unsigned int button, MouseContext context, MouseAction action) {
|
||||||
|
this->screen = screen;
|
||||||
|
this->client = client;
|
||||||
|
this->time = time;
|
||||||
|
this->state = state;
|
||||||
|
this->button = button;
|
||||||
|
this->context= context;
|
||||||
|
this->action = action;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class EventData {
|
||||||
|
public:
|
||||||
int screen;
|
int screen;
|
||||||
Window window;
|
OBClient *client;
|
||||||
unsigned int state;
|
unsigned int state;
|
||||||
EventAction action;
|
EventAction action;
|
||||||
} EventData;
|
|
||||||
|
|
||||||
typedef struct {
|
EventData(int screen, OBClient *client, EventAction action,
|
||||||
PyObject_HEAD;
|
unsigned int state) {
|
||||||
|
this->screen = screen;
|
||||||
|
this->client = client;
|
||||||
|
this->action = action;
|
||||||
|
this->state = state;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class KeyData {
|
||||||
|
public:
|
||||||
int screen;
|
int screen;
|
||||||
Window window;
|
OBClient *client;
|
||||||
Time time;
|
Time time;
|
||||||
unsigned int state;
|
unsigned int state;
|
||||||
unsigned int key;
|
std::string key;
|
||||||
} KeyData;
|
|
||||||
|
KeyData(int screen, OBClient *client, Time time, unsigned int state,
|
||||||
|
unsigned int key) {
|
||||||
|
this->screen = screen;
|
||||||
|
this->client = client;
|
||||||
|
this->time = time;
|
||||||
|
this->state = state;
|
||||||
|
this->key = XKeysymToString(XKeycodeToKeysym(otk::OBDisplay::display,
|
||||||
|
key, 0));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef SWIG
|
||||||
|
|
||||||
void python_init(char *argv0);
|
void python_init(char *argv0);
|
||||||
void python_destroy();
|
void python_destroy();
|
||||||
bool python_exec(const std::string &path);
|
bool python_exec(const std::string &path);
|
||||||
|
|
||||||
MotionData *new_motion_data(int screen, Window window, Time time,
|
|
||||||
unsigned int state, unsigned int button,
|
|
||||||
MouseContext context, MouseAction action,
|
|
||||||
int xroot, int yroot, const otk::Point &initpos,
|
|
||||||
const otk::Rect &initarea);
|
|
||||||
ButtonData *new_button_data(int screen, Window window, Time time,
|
|
||||||
unsigned int state, unsigned int button,
|
|
||||||
MouseContext context, MouseAction action);
|
|
||||||
EventData *new_event_data(int screen, Window window, EventAction action,
|
|
||||||
unsigned int state);
|
|
||||||
KeyData *new_key_data(int screen, Window window, Time time, unsigned int state,
|
|
||||||
unsigned int key);
|
|
||||||
|
|
||||||
void python_callback(PyObject *func, PyObject *data);
|
|
||||||
|
|
||||||
bool python_get_long(const char *name, long *value);
|
bool python_get_long(const char *name, long *value);
|
||||||
bool python_get_string(const char *name, std::string *value);
|
bool python_get_string(const char *name, std::string *value);
|
||||||
bool python_get_stringlist(const char *name, std::vector<std::string> *value);
|
bool python_get_stringlist(const char *name, std::vector<std::string> *value);
|
||||||
#endif
|
|
||||||
|
/***********************************************
|
||||||
|
* These are found in openbox.i, not python.cc *
|
||||||
|
***********************************************/
|
||||||
|
void python_callback(PyObject *func, MotionData *data);
|
||||||
|
void python_callback(PyObject *func, ButtonData *data);
|
||||||
|
void python_callback(PyObject *func, EventData *data);
|
||||||
|
void python_callback(PyObject *func, KeyData *data);
|
||||||
|
|
||||||
|
#endif // SWIG
|
||||||
|
|
||||||
PyObject *mbind(const std::string &button, ob::MouseContext context,
|
PyObject *mbind(const std::string &button, ob::MouseContext context,
|
||||||
ob::MouseAction action, PyObject *func);
|
ob::MouseAction action, PyObject *func);
|
||||||
|
@ -148,7 +196,7 @@ void set_reset_key(const std::string &key);
|
||||||
PyObject *send_client_msg(Window target, int type, Window about,
|
PyObject *send_client_msg(Window target, int type, Window about,
|
||||||
long data, long data1 = 0, long data2 = 0,
|
long data, long data1 = 0, long data2 = 0,
|
||||||
long data3 = 0, long data4 = 0);
|
long data3 = 0, long data4 = 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // __python_hh
|
#endif // __python_hh
|
||||||
|
|
|
@ -140,9 +140,8 @@ OBScreen::OBScreen(int screen)
|
||||||
Openbox::instance->registerHandler(_info->rootWindow(), this);
|
Openbox::instance->registerHandler(_info->rootWindow(), this);
|
||||||
|
|
||||||
// call the python Startup callbacks
|
// call the python Startup callbacks
|
||||||
EventData *data = new_event_data(_number, 0, EventShutdown, 0);
|
EventData data(_number, 0, EventShutdown, 0);
|
||||||
Openbox::instance->bindings()->fireEvent(data);
|
Openbox::instance->bindings()->fireEvent(&data);
|
||||||
Py_XDECREF((PyObject*)data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -157,9 +156,8 @@ OBScreen::~OBScreen()
|
||||||
unmanageWindow(clients.front());
|
unmanageWindow(clients.front());
|
||||||
|
|
||||||
// call the python Shutdown callbacks
|
// call the python Shutdown callbacks
|
||||||
EventData *data = new_event_data(_number, 0, EventShutdown, 0);
|
EventData data(_number, 0, EventShutdown, 0);
|
||||||
Openbox::instance->bindings()->fireEvent(data);
|
Openbox::instance->bindings()->fireEvent(&data);
|
||||||
Py_XDECREF((PyObject*)data);
|
|
||||||
|
|
||||||
XDestroyWindow(otk::OBDisplay::display, _focuswindow);
|
XDestroyWindow(otk::OBDisplay::display, _focuswindow);
|
||||||
XDestroyWindow(otk::OBDisplay::display, _supportwindow);
|
XDestroyWindow(otk::OBDisplay::display, _supportwindow);
|
||||||
|
@ -497,9 +495,8 @@ void OBScreen::manageWindow(Window window)
|
||||||
client->positionRequested())) {
|
client->positionRequested())) {
|
||||||
// position the window intelligenty .. hopefully :)
|
// position the window intelligenty .. hopefully :)
|
||||||
// call the python PLACEWINDOW binding
|
// call the python PLACEWINDOW binding
|
||||||
EventData *data = new_event_data(_number, window, EventPlaceWindow, 0);
|
EventData data(_number, client, EventPlaceWindow, 0);
|
||||||
Openbox::instance->bindings()->fireEvent(data);
|
Openbox::instance->bindings()->fireEvent(&data);
|
||||||
Py_DECREF((PyObject*)data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the decoration frame for the client window
|
// create the decoration frame for the client window
|
||||||
|
@ -542,9 +539,8 @@ void OBScreen::manageWindow(Window window)
|
||||||
Openbox::instance->bindings()->grabButtons(true, client);
|
Openbox::instance->bindings()->grabButtons(true, client);
|
||||||
|
|
||||||
// call the python NEWWINDOW binding
|
// call the python NEWWINDOW binding
|
||||||
EventData *data = new_event_data(_number, window, EventNewWindow, 0);
|
EventData data(_number, client, EventNewWindow, 0);
|
||||||
Openbox::instance->bindings()->fireEvent(data);
|
Openbox::instance->bindings()->fireEvent(&data);
|
||||||
Py_DECREF((PyObject*)data);
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("Managed window 0x%lx\n", window);
|
printf("Managed window 0x%lx\n", window);
|
||||||
|
@ -557,10 +553,8 @@ void OBScreen::unmanageWindow(OBClient *client)
|
||||||
OBFrame *frame = client->frame;
|
OBFrame *frame = client->frame;
|
||||||
|
|
||||||
// call the python CLOSEWINDOW binding
|
// call the python CLOSEWINDOW binding
|
||||||
EventData *data = new_event_data(_number, client->window(),
|
EventData data(_number, client, EventCloseWindow, 0);
|
||||||
EventCloseWindow, 0);
|
Openbox::instance->bindings()->fireEvent(&data);
|
||||||
Openbox::instance->bindings()->fireEvent(data);
|
|
||||||
Py_DECREF((PyObject*)data);
|
|
||||||
|
|
||||||
Openbox::instance->bindings()->grabButtons(false, client);
|
Openbox::instance->bindings()->grabButtons(false, client);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue