]> Dogcows Code - chaz/openbox/commitdiff
python has begun!
authorDana Jansens <danakj@orodu.net>
Thu, 19 Dec 2002 23:54:41 +0000 (23:54 +0000)
committerDana Jansens <danakj@orodu.net>
Thu, 19 Dec 2002 23:54:41 +0000 (23:54 +0000)
configure.ac
src/Makefile.am
src/main.cc
src/openbox.cc
src/openbox.hh
src/python.cc [new file with mode: 0644]
src/python.hh [new file with mode: 0644]
src/python_client.cc [new file with mode: 0644]
src/python_client.hh [new file with mode: 0644]

index 7f631a4de86466a04af2b485e6fdc4b09cd9ce8d..08b6c1c2be6eb1cdc41759d89807cf1f66cc0873 100644 (file)
@@ -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 @@ AC_CHECK_LIB([python2.2], [Py_Initialize],
   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
index d2119f90a65cf52e2293782b175ac69bf1fa27d0..1cc23cf4a0e07b61dfddef7d008a21cff64992bd 100644 (file)
@@ -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
 
index 5b6c7885d66a8e15ae1d1bb55aac8acacc5890d9..1d6ce0b1e3e4360792517fb3c5f201484726c14c 100644 (file)
@@ -30,7 +30,7 @@ int main(int argc, char **argv) {
 
   ob::Openbox openbox(argc, argv);
   //ob::Blackbox blackbox(argc, argv, 0);
-  
+
   //Blackbox blackbox(argv, session_display, rc_file);
   openbox.eventLoop();
 
index 18c4a5ca6e45697e874176b06e2e705adadec955..f16d3464f0cd9fb5d60769025a9690387f24d673 100644 (file)
@@ -9,6 +9,7 @@
 #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 @@ Openbox::Openbox(int argc, char **argv)
   _doshutdown = false;
   _rcfilepath = otk::expandTilde("~/.openbox/rc3");
 
+  _pyclients = PyDict_New();
+  assert(_pyclients);
+
   parseCommandLine(argc, argv);
 
   // TEMPORARY: using the xrdb rc3
@@ -149,7 +153,19 @@ Openbox::Openbox(int argc, char **argv)
     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::eventLoop()
 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);
 }
 
 
index abdcfef386968d922e4a301b285678a82f6a585a..83891828b5a4303173c509f0d7bccb74520b250e 100644 (file)
@@ -18,6 +18,7 @@ extern "C" {
 #include <vector>
 #include <map>
 
+#include "python.hh"
 #include "otk/screeninfo.hh"
 #include "otk/timerqueuemanager.hh"
 #include "otk/property.hh"
@@ -93,6 +94,7 @@ private:
 
   //! A list of all managed clients
   ClientMap _clients;
+  PyObject *_pyclients; // PyDictObject
 
   //! A list of all the managed screens
   ScreenList _screens;
@@ -169,6 +171,8 @@ public:
   //! 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.
diff --git a/src/python.cc b/src/python.cc
new file mode 100644 (file)
index 0000000..e338b02
--- /dev/null
@@ -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);
+}
+}
+
+}
diff --git a/src/python.hh b/src/python.hh
new file mode 100644 (file)
index 0000000..61272a8
--- /dev/null
@@ -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
diff --git a/src/python_client.cc b/src/python_client.cc
new file mode 100644 (file)
index 0000000..3758e42
--- /dev/null
@@ -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 */
+};
+
+}
+}
diff --git a/src/python_client.hh b/src/python_client.hh
new file mode 100644 (file)
index 0000000..32b0c45
--- /dev/null
@@ -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
This page took 0.036668 seconds and 4 git commands to generate.