move the Openbox::instance pointer to simply "openbox".
[mikachu/openbox.git] / src / openbox.i
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2
3 %module openbox
4
5 %{
6 #ifdef HAVE_CONFIG_H
7 #  include "../config.h"
8 #endif
9
10 #include "openbox.hh"
11 #include "screen.hh"
12 #include "client.hh"
13 #include "bindings.hh"
14 #include "actions.hh"
15 #include "python.hh"
16 #include "otk/otk.hh"
17 %}
18
19 %include "stl.i"
20 //%include std_list.i
21 //%template(ClientList) std::list<Client*>;
22
23 %ignore ob::openbox;
24 %inline %{
25   ob::Openbox *Openbox_instance() { return ob::openbox; }
26 %};
27
28 %{
29 namespace ob {
30 void python_callback(PyObject *func, MouseData *data)
31 {
32   PyObject *arglist;
33   PyObject *result;
34
35   arglist = Py_BuildValue("(O)", SWIG_NewPointerObj((void *) data,
36                                                     SWIGTYPE_p_ob__MouseData,
37                                                     0));
38   
39   // call the callback
40   result = PyEval_CallObject(func, arglist);
41   if (!result || PyErr_Occurred()) {
42     // an exception occured in the script, display it
43     PyErr_Print();
44   }
45
46   Py_XDECREF(result);
47   Py_DECREF(arglist);
48 }
49
50 void python_callback(PyObject *func, EventData *data)
51 {
52   PyObject *arglist;
53   PyObject *result;
54
55   arglist = Py_BuildValue("(O)", SWIG_NewPointerObj((void *) data,
56                                                     SWIGTYPE_p_ob__EventData,
57                                                     0));
58   
59   // call the callback
60   result = PyEval_CallObject(func, arglist);
61   if (!result || PyErr_Occurred()) {
62     // an exception occured in the script, display it
63     PyErr_Print();
64   }
65
66   Py_XDECREF(result);
67   Py_DECREF(arglist);
68 }
69
70 void python_callback(PyObject *func, KeyData *data)
71 {
72   PyObject *arglist;
73   PyObject *result;
74
75   arglist = Py_BuildValue("(O)", SWIG_NewPointerObj((void *) data,
76                                                     SWIGTYPE_p_ob__KeyData,
77                                                     0));
78   
79   // call the callback
80   result = PyEval_CallObject(func, arglist);
81   if (!result || PyErr_Occurred()) {
82     // an exception occured in the script, display it
83     PyErr_Print();
84   }
85
86   Py_XDECREF(result);
87   Py_DECREF(arglist);
88 }
89
90 }
91 %}
92
93 %ignore ob::Screen::clients;
94 %{
95   #include <iterator>
96 %}
97 %extend ob::Screen {
98   Client *client(int i) {
99     if (i < 0 || i >= (int)self->clients.size())
100       return NULL;
101     ob::Client::List::iterator it = self->clients.begin();
102     std::advance(it,i);
103     return *it;
104   }
105   int clientCount() const {
106     return (int) self->clients.size();
107   }
108 };
109
110 %ignore otk::Display::display;
111 %inline %{
112   Display *Display_display() { return otk::Display::display; }
113 %};
114
115 %include "../otk/ustring.i"
116
117 %include "../otk/display.hh"
118 %include "../otk/point.hh"
119 %include "../otk/property.hh"
120 %include "../otk/rect.hh"
121 %include "../otk/screeninfo.hh"
122 %include "../otk/strut.hh"
123
124 %include "../otk/eventhandler.hh"
125 %include "../otk/eventdispatcher.hh"
126
127 %import "widgetbase.hh"
128 %import "actions.hh"
129
130 %include "openbox.hh"
131 %include "screen.hh"
132 %include "client.hh"
133 %include "python.hh"
134
135 // for Mod1Mask etc
136 %include "X11/X.h"