summaryrefslogtreecommitdiff
path: root/wrap
diff options
context:
space:
mode:
authorDana Jansens <danakj@orodu.net>2003-02-05 15:38:29 +0000
committerDana Jansens <danakj@orodu.net>2003-02-05 15:38:29 +0000
commit7c8c9e998ffc3a9b22e15feeffe77823142ce531 (patch)
tree703b1db62f68f85d97a01a265fd73d18d9b24682 /wrap
parentffea5b55912ea936c84ce3d17577e9532a81cae4 (diff)
new swig build system. much better. yay.
Diffstat (limited to 'wrap')
-rw-r--r--wrap/.cvsignore6
-rw-r--r--wrap/Makefile.am47
-rw-r--r--wrap/callback.i208
-rw-r--r--wrap/ob.i102
-rw-r--r--wrap/otk.i21
5 files changed, 356 insertions, 28 deletions
diff --git a/wrap/.cvsignore b/wrap/.cvsignore
index 63aba835..ffdd1bdd 100644
--- a/wrap/.cvsignore
+++ b/wrap/.cvsignore
@@ -7,3 +7,9 @@ otkpy.la
otkpy_la-wrap_otk.lo
otkpy_la-wrap_otk.o
wrap_otk.cc
+ob.py
+obpy.la
+obpy_la-wrap_ob.lo
+wrap_ob.cc
+wrap_ob.lo
+wrap_otk.lo
diff --git a/wrap/Makefile.am b/wrap/Makefile.am
index 7c8e603a..ec7b0b48 100644
--- a/wrap/Makefile.am
+++ b/wrap/Makefile.am
@@ -1,35 +1,48 @@
-# XXX - INSTALL THIS GLOBALLY!#&@(!!!
-pythondir = $(libdir)/openbox/python
+oblibdir = $(libdir)/openbox
-CXXFLAGS = $(XFT_CFLAGS) $(filter-out -W -Wall,@CXXFLAGS@)
+#pythondir = $(oblibdir)/python
+obpythondir = $(oblibdir)/python
-INCLUDES = -I.. -I../swig
+CPPFLAGS = $(XFT_CFLAGS) $(SWIG_PYTHON_CFLAGS) @CPPFLAGS@
+CXXFLAGS = $(filter-out -W -Wall,@CXXFLAGS@)
+LDFLAGS = -module -avoid-version
+INCLUDES = -I.. -I../otk -I../src
-python_LTLIBRARIES = otkpy.la
+obpython_LTLIBRARIES = otkpy.la obpy.la
+obpython_PYTHON = otk.py ob.py
-otkpy_la_CXXFLAGS = $(PYTHON_CFLAGS)
-otkpy_la_LDFLAGS = -module
otkpy_la_SOURCES = wrap_otk.cc
-otkpy_la_LIBADD = ../otk/libotk.la
+#otkpy_la_LIBADD = ../otk/libotk.la # do this for the global version of otk
-CLEANFILES = wrap_* otk.py
-MAINTAINERCLEANFILES = Makefile.in
+obpy_la_SOURCES = wrap_ob.cc
-python_PYTHON = otk.py
+CLEANFILES = wrap_* *.py
+MAINTAINERCLEANFILES = Makefile.in
install-exec-hook:
- $(mkinstalldirs) "$(DESTDIR)$(pythondir)"
- cd "$(DESTDIR)$(pythondir)" && \
+ $(mkinstalldirs) "$(DESTDIR)$(obpythondir)"
+ cd "$(DESTDIR)$(obpythondir)" && \
$(RM) -f _otk.so && $(LN_S) otkpy.so _otk.so
+ $(mkinstalldirs) "$(DESTDIR)$(obpythondir)"
+ cd "$(DESTDIR)$(obpythondir)" && \
+ $(RM) -f _ob.so && $(LN_S) obpy.so _ob.so
-uninstall-local:
- rm -f "$(DESTDIR)$(pythondir)/_otk.so"
+uninstall-am:
+ $(RM) "$(DESTDIR)$(obpythondir)/_otk.so"
+ $(RM) "$(DESTDIR)$(obpythondir)/_ob.so"
+ rmdir -p $(obpythondir) || true
%.py: wrap_%.cc
otk.i: $(wildcard ../otk/*.hh)
@touch $@
-wrap_%.cc: %.i
- swig $(INCLUDES) $(filter -I%,$(CXXFLAGS)) -python -shadow -c++ -nodefault -o $@ $<
+ob.i: $(addprefix ../src/,openbox.hh screen.hh client.hh python.hh frame.hh)
+ @touch $@
+
+wrap_otk.cc: otk.i
+ $(SWIG) $(SWIG_PYTHON_OPT) $(INCLUDES) $(filter -I%,$(CPPFLAGS)) -nodefault -o $@ $<
+
+wrap_ob.cc: ob.i callback.i
+ $(SWIG) $(SWIG_PYTHON_OPT) $(INCLUDES) $(filter -I%,$(CPPFLAGS)) -nodefault -o $@ $<
diff --git a/wrap/callback.i b/wrap/callback.i
new file mode 100644
index 00000000..c4bec257
--- /dev/null
+++ b/wrap/callback.i
@@ -0,0 +1,208 @@
+// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
+
+%{
+/*
+ Calls a python callback for the MouseCallback function type
+ */
+static void PythonMouseCallback(ob::MouseData *data, void *pyfunc)
+{
+ PyObject *func, *arglist, *pdata;
+ PyObject *result;
+ double dres = 0;
+
+ func = (PyObject*) pyfunc;
+
+ pdata = SWIG_NewPointerObj((void *) data, SWIGTYPE_p_ob__MouseData, 0);
+ arglist = Py_BuildValue("(O)", pdata);
+ Py_DECREF(pdata);
+
+ // 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);
+}
+
+/*
+ Calls a python callback for the KeyCallback function type
+ */
+static void PythonKeyCallback(ob::KeyData *data, void *pyfunc)
+{
+ PyObject *func, *arglist, *pdata;
+ PyObject *result;
+ double dres = 0;
+
+ func = (PyObject*) pyfunc;
+
+ pdata = SWIG_NewPointerObj((void *) data, SWIGTYPE_p_ob__KeyData, 0);
+ arglist = Py_BuildValue("(O)", pdata);
+ Py_DECREF(pdata);
+
+ // 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);
+}
+
+/*
+ Calls a python callback for the EventCallback function type
+ */
+static void PythonEventCallback(ob::EventData *data, void *pyfunc)
+{
+ PyObject *func, *arglist, *pdata;
+ PyObject *result;
+ double dres = 0;
+
+ func = (PyObject*) pyfunc;
+
+ pdata = SWIG_NewPointerObj((void *) data, SWIGTYPE_p_ob__EventData, 0);
+ arglist = Py_BuildValue("(O)", pdata);
+ Py_DECREF(pdata);
+
+ // 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);
+}
+%}
+
+// for all of these, PyErr_SetString is called before they return a false!
+%exception mbind {
+ $action
+ if (!result) return NULL;
+}
+%exception kbind {
+ $action
+ if (!result) return NULL;
+}
+%exception ebind {
+ $action
+ if (!result) return NULL;
+}
+%exception kgrab {
+ $action
+ if (!result) return NULL;
+}
+%exception mgrab {
+ $action
+ if (!result) return NULL;
+}
+
+// Grab a Python function object as a Python object.
+%typemap(python,in) PyObject *func {
+ if (!PyCallable_Check($input)) {
+ PyErr_SetString(PyExc_TypeError, "Excepting a callable object.");
+ return NULL;
+ }
+ $1 = $input;
+}
+
+%inline %{
+bool mbind(const std::string &button, ob::MouseContext::MC context,
+ ob::MouseAction::MA action, PyObject *func)
+{
+ if(context < 0 || context >= ob::MouseContext::NUM_MOUSE_CONTEXT) {
+ PyErr_SetString(PyExc_ValueError, "Invalid MouseContext");
+ return false;
+ }
+ if(action < 0 || action >= ob::MouseAction::NUM_MOUSE_ACTION) {
+ PyErr_SetString(PyExc_ValueError, "Invalid MouseAction");
+ return false;
+ }
+
+ if (!ob::openbox->bindings()->addButton(button, context,
+ action, PythonMouseCallback, func)) {
+ PyErr_SetString(PyExc_RuntimeError,"Unable to add binding.");
+ return false;
+ }
+ return true;
+}
+
+bool ebind(ob::EventAction::EA action, PyObject *func)
+{
+ if(action < 0 || action >= ob::EventAction::NUM_EVENT_ACTION) {
+ PyErr_SetString(PyExc_ValueError, "Invalid EventAction");
+ return false;
+ }
+
+ if (!ob::openbox->bindings()->addEvent(action, PythonEventCallback, func)) {
+ PyErr_SetString(PyExc_RuntimeError,"Unable to add binding.");
+ return false;
+ }
+ return true;
+}
+
+bool kgrab(int screen, PyObject *func)
+{
+ if (!ob::openbox->bindings()->grabKeyboard(screen,
+ PythonKeyCallback, func)) {
+ PyErr_SetString(PyExc_RuntimeError,"Unable to grab keybaord.");
+ return false;
+ }
+ return true;
+}
+
+void kungrab()
+{
+ ob::openbox->bindings()->ungrabKeyboard();
+}
+
+bool mgrab(int screen)
+{
+ if (!ob::openbox->bindings()->grabPointer(screen)) {
+ PyErr_SetString(PyExc_RuntimeError,"Unable to grab pointer.");
+ return false;
+ }
+ return true;
+}
+
+void mungrab()
+{
+ ob::openbox->bindings()->ungrabPointer();
+}
+
+bool kbind(PyObject *keylist, ob::KeyContext::KC context, PyObject *func)
+{
+ if (!PyList_Check(keylist)) {
+ PyErr_SetString(PyExc_TypeError, "Invalid keylist. Not a list.");
+ return false;
+ }
+ if(context < 0 || context >= ob::KeyContext::NUM_KEY_CONTEXT) {
+ PyErr_SetString(PyExc_ValueError, "Invalid KeyContext");
+ return false;
+ }
+
+ ob::Bindings::StringVect vectkeylist;
+ for (int i = 0, end = PyList_Size(keylist); i < end; ++i) {
+ PyObject *str = PyList_GetItem(keylist, i);
+ if (!PyString_Check(str)) {
+ PyErr_SetString(PyExc_TypeError,
+ "Invalid keylist. It must contain only strings.");
+ return false;
+ }
+ vectkeylist.push_back(PyString_AsString(str));
+ }
+
+ (void)context; // XXX use this sometime!
+ if (!ob::openbox->bindings()->addKey(vectkeylist, PythonKeyCallback, func)) {
+ PyErr_SetString(PyExc_RuntimeError,"Unable to add binding.");
+ return false;
+ }
+ return true;
+}
+
+%};
diff --git a/wrap/ob.i b/wrap/ob.i
new file mode 100644
index 00000000..b4c94622
--- /dev/null
+++ b/wrap/ob.i
@@ -0,0 +1,102 @@
+// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
+
+%module ob
+
+%{
+#ifdef HAVE_CONFIG_H
+# include "../config.h"
+#endif
+
+#include "frame.hh"
+#include "openbox.hh"
+#include "screen.hh"
+#include "client.hh"
+#include "bindings.hh"
+#include "actions.hh"
+#include "python.hh"
+#include "otk/otk.hh"
+%}
+
+%include "stl.i"
+//%include std_list.i
+//%template(ClientList) std::list<Client*>;
+%include "callback.i"
+
+%immutable ob::openbox;
+/*
+%ignore ob::openbox;
+%inline %{
+ ob::Openbox *Openbox_instance() { return ob::openbox; }
+%};
+*/
+
+%ignore ob::Screen::clients;
+%{
+ #include <iterator>
+%}
+%extend ob::Screen {
+ Client *client(int i) {
+ if (i < 0 || i >= (int)self->clients.size())
+ return NULL;
+ ob::Client::List::iterator it = self->clients.begin();
+ std::advance(it,i);
+ return *it;
+ }
+ int clientCount() const {
+ return (int) self->clients.size();
+ }
+};
+
+%import "otk.i"
+
+%import "widgetbase.hh"
+%import "actions.hh"
+
+%include "openbox.hh"
+%include "screen.hh"
+%include "client.hh"
+%include "frame.hh"
+%include "python.hh"
+
+// for Window etc
+%import "X11/X.h"
+
+%inline %{
+void set_reset_key(const std::string &key)
+{
+ ob::openbox->bindings()->setResetKey(key);
+}
+
+void send_client_msg(Window target, Atom type, Window about,
+ long data, long data1, long data2,
+ long data3, long data4)
+{
+ XEvent e;
+ e.xclient.type = ClientMessage;
+ e.xclient.format = 32;
+ e.xclient.message_type = type;
+ e.xclient.window = about;
+ e.xclient.data.l[0] = data;
+ e.xclient.data.l[1] = data1;
+ e.xclient.data.l[2] = data2;
+ e.xclient.data.l[3] = data3;
+ e.xclient.data.l[4] = data4;
+
+ XSendEvent(**otk::display, target, false,
+ SubstructureRedirectMask | SubstructureNotifyMask,
+ &e);
+}
+
+void execute(const std::string &bin, int screen)
+{
+ if (screen >= ScreenCount(**otk::display))
+ screen = 0;
+ otk::bexec(bin, otk::display->screenInfo(screen)->displayString());
+}
+
+%};
+
+// globals
+%pythoncode %{
+openbox = cvar.openbox;
+%}
diff --git a/wrap/otk.i b/wrap/otk.i
index 5bf17a21..8d06d6f0 100644
--- a/wrap/otk.i
+++ b/wrap/otk.i
@@ -10,15 +10,8 @@
//%include std_list.i
%include "ustring.i"
-%ignore otk::display;
-%inline %{
- otk::Display *Display_instance() { return otk::display; }
-%};
-
-%ignore otk::Property::atoms;
-%inline %{
- const otk::Atoms& Property_atoms() { return otk::Property::atoms; }
-%};
+%immutable otk::display;
+%immutable otk::Property::atoms;
namespace otk {
/*%rename(setValue_bool) Configuration::setValue(std::string const &,bool);
@@ -77,5 +70,11 @@ namespace otk {
%include "timer.hh"
%include "util.hh"
-// for Mod1Mask etc
-%include "X11/X.h"
+// for Window etc
+%import "X11/X.h"
+
+// globals
+%pythoncode %{
+display = cvar.display;
+atoms = cvar.Property_atoms;
+%}