all repos — openbox @ 700984bd150d98a6876c117c2e1b1b3c72cffce1

openbox fork - make it a bit more like ryudo

python has begun!
Dana Jansens danakj@orodu.net
commit

700984bd150d98a6876c117c2e1b1b3c72cffce1

parent

977ecf1f1e82f385a542648b545a0d0877febaf0

M configure.acconfigure.ac

@@ -75,7 +75,7 @@ CFLAGS="$CFLAGS $DEBUG"

dnl Check for Python AC_CHECK_HEADER([python2.2/Python.h], - PYTHON_CFLAGS="-Ipython2.2", + , AC_MSG_ERROR([Openbox requires the use of Python 2.2. This is its secret special formula for extreme sexiness. See http://www.python.org ]))

@@ -84,7 +84,6 @@ PYTHON_LDFLAGS="-lpython2.2 -Xlinker -export-dynamic",

AC_MSG_ERROR([Openbox requires the use of Python 2.2. This is its secret special formula for extreme sexiness. See http://www.python.org ])) -AC_SUBST([PYTHON_CFLAGS]) AC_SUBST([PYTHON_LDFLAGS]) dnl Check for X headers and libraries
M src/Makefile.amsrc/Makefile.am

@@ -2,7 +2,7 @@ localedir=$(datadir)/locale

DEFAULT_MENU=$(pkgdatadir)/menu DEFAULT_STYLE=$(pkgdatadir)/styles/mbdtex -CPPFLAGS=$(XFT_CFLAGS) $(PYTHON_CFLAGS) @CPPFLAGS@ \ +CPPFLAGS=$(XFT_CFLAGS) @CPPFLAGS@ \ -DDEFAULTMENU=\"$(DEFAULT_MENU)\" \ -DDEFAULTSTYLE=\"$(DEFAULT_STYLE)\" \ -DLOCALEDIR=\"$(localedir)\"

@@ -17,7 +17,7 @@ openbox3_LDADD=../otk/libotk.a @LIBINTL@

openbox3_SOURCES= actions.cc client.cc frame.cc openbox.cc screen.cc \ main.cc rootwindow.cc backgroundwidget.cc labelwidget.cc \ - buttonwidget.cc + buttonwidget.cc python.cc python_client.cc MAINTAINERCLEANFILES= Makefile.in
M src/main.ccsrc/main.cc

@@ -30,7 +30,7 @@ textdomain(PACKAGE);

ob::Openbox openbox(argc, argv); //ob::Blackbox blackbox(argc, argv, 0); - + //Blackbox blackbox(argv, session_display, rc_file); openbox.eventLoop();
M src/openbox.ccsrc/openbox.cc

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

#include "client.hh" #include "screen.hh" #include "actions.hh" +#include "python_client.hh" #include "otk/property.hh" #include "otk/display.hh" #include "otk/assassin.hh"

@@ -90,6 +91,9 @@ _argv0 = argv[0];

_doshutdown = false; _rcfilepath = otk::expandTilde("~/.openbox/rc3"); + _pyclients = PyDict_New(); + assert(_pyclients); + parseCommandLine(argc, argv); // TEMPORARY: using the xrdb rc3

@@ -149,7 +153,19 @@ if (_screens.empty()) {

printf(_("No screens were found without a window manager. Exiting.\n")); ::exit(1); } - + + // initialize the python interface + Py_SetProgramName(argv[0]); + Py_Initialize(); + initopenbox(); // initialize the static 'openbox' module + FILE *rcpyfd = fopen("/home/natas/.openbox/user.py", "r"); + if (!rcpyfd) { + printf("failed to load python file /home/natas/.openbox/user.py\n"); + } else { + PyRun_SimpleFile(rcpyfd, "/home/natas/.openbox/user.py"); + fclose(rcpyfd); + } + _state = State_Normal; // done starting }

@@ -261,6 +277,12 @@

void Openbox::addClient(Window window, OBClient *client) { _clients[window] = client; + + // maintain the python list here too + PyClientObject* pyclient = PyObject_New(PyClientObject, &PyClient_Type); + pyclient->window = window; + pyclient->client = client; + PyDict_SetItem(_pyclients, PyLong_FromLong(window), (PyObject*)pyclient); }
M src/openbox.hhsrc/openbox.hh

@@ -18,6 +18,7 @@ #include <string>

#include <vector> #include <map> +#include "python.hh" #include "otk/screeninfo.hh" #include "otk/timerqueuemanager.hh" #include "otk/property.hh"

@@ -93,6 +94,7 @@ char *_argv0;

//! A list of all managed clients ClientMap _clients; + PyObject *_pyclients; // PyDictObject //! A list of all the managed screens ScreenList _screens;

@@ -168,6 +170,8 @@ }

//! Returns the mouse cursors used throughout Openbox inline const Cursors &cursors() const { return _cursors; } + + inline PyObject *pyclients() const { return _pyclients; } //! The main function of the Openbox class /*!
A src/python.cc

@@ -0,0 +1,45 @@

+// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- + +#ifdef HAVE_CONFIG_H +# include "../config.h" +#endif + +#include "python.hh" +#include "python_client.hh" +#include "openbox.hh" + +namespace ob { + +extern "C" { + +static PyObject *shit(PyObject *self, PyObject *args) +{ + if (!PyArg_ParseTuple(args, ":shit")) + return NULL; + + printf("SHIT CALLED!@!\n"); + + return Py_None; +} + + + +static PyMethodDef OBMethods[] = { + {"shit", shit, METH_VARARGS, + "Do some shit, yo!"}, + + {"get_client_dict", get_client_dict, METH_VARARGS, + "Get the list of all clients"}, + + {NULL, NULL, 0, NULL} +}; + +void initopenbox() +{ + PyClient_Type.ob_type = &PyType_Type; + + Py_InitModule("openbox", OBMethods); +} +} + +}
A src/python.hh

@@ -0,0 +1,20 @@

+// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- +#ifndef __python_hh +#define __python_hh + +/*! @file python.hh + @brief Python stuff +*/ + +#include <python2.2/Python.h> + +namespace ob { + +extern "C" { + +void initopenbox(); + +} +} + +#endif // __python_hh
A src/python_client.cc

@@ -0,0 +1,69 @@

+// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- + +#ifdef HAVE_CONFIG_H +# include "../config.h" +#endif + +#include "python_client.hh" +#include "openbox.hh" + +namespace ob { + +extern "C" { + +PyObject *get_client_dict(PyObject* self, PyObject* args) +{ + if (!PyArg_ParseTuple(args, ":get_client_dict")) + return NULL; + return PyDictProxy_New(Openbox::instance->pyclients()); +} + + + +PyObject *getWindow(PyObject* self, PyObject* args) +{ + if (!PyArg_ParseTuple(args, ":getWindow")) + return NULL; + return PyLong_FromLong(((PyClientObject*)self)->window); +} + + + +static PyMethodDef attr_methods[] = { + {"getWindow", getWindow, METH_VARARGS, + "Return the window id."}, + {NULL, NULL, 0, NULL} /* sentinel */ +}; + +static PyObject *getattr(PyObject *obj, char *name) +{ + return Py_FindMethod(attr_methods, obj, name); +} + + + +static void client_dealloc(PyObject* self) +{ + PyObject_Del(self); +} + +PyTypeObject PyClient_Type = { + PyObject_HEAD_INIT(NULL) + 0, + "Client", + sizeof(PyClientObject), + 0, + client_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + getattr, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash */ +}; + +} +}
A src/python_client.hh

@@ -0,0 +1,29 @@

+// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- +#ifndef __pythonclient_hh +#define __pythonclient_hh + +/*! @file python_client.hh + @brief Python stuff +*/ + +#include "python.hh" +#include "client.hh" + +namespace ob { + +extern "C" { + +typedef struct { + PyObject_HEAD + Window window; + OBClient *client; +} PyClientObject; + +extern PyTypeObject PyClient_Type; + +PyObject *get_client_dict(PyObject* self, PyObject* args); + +} +} + +#endif // __pythonclient_hh