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
]))
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
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)\"
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
ob::Openbox openbox(argc, argv);
//ob::Blackbox blackbox(argc, argv, 0);
-
+
//Blackbox blackbox(argv, session_display, rc_file);
openbox.eventLoop();
#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"
_doshutdown = false;
_rcfilepath = otk::expandTilde("~/.openbox/rc3");
+ _pyclients = PyDict_New();
+ assert(_pyclients);
+
parseCommandLine(argc, argv);
// TEMPORARY: using the xrdb rc3
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
}
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);
}
#include <vector>
#include <map>
+#include "python.hh"
#include "otk/screeninfo.hh"
#include "otk/timerqueuemanager.hh"
#include "otk/property.hh"
//! A list of all managed clients
ClientMap _clients;
+ PyObject *_pyclients; // PyDictObject
//! A list of all the managed screens
ScreenList _screens;
//! 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
/*!
This function should be called after instantiating the Openbox class.
--- /dev/null
+// -*- 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);
+}
+}
+
+}
--- /dev/null
+// -*- 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
--- /dev/null
+// -*- 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 */
+};
+
+}
+}
--- /dev/null
+// -*- 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