all repos — openbox @ 579ed5aa8d1b33a69476c2182a98ebc30557f096

openbox fork - make it a bit more like ryudo

src/openbox.i (raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-

%module openbox

%{
#ifdef HAVE_CONFIG_H
#  include "../config.h"
#endif

#include "openbox.hh"
#include "screen.hh"
#include "client.hh"
#include "bindings.hh"
#include "actions.hh"
%}

%include "stl.i"
%include "exception.i"
//%include std_list.i
//%template(ClientList) std::list<OBClient*>;

%ignore ob::Openbox::instance;
%inline %{
  ob::Openbox *Openbox_instance() { return ob::Openbox::instance; }
%};

// stuff for scripting callbacks!
%inline %{
  enum ActionType {
    Action_ButtonPress,
    Action_Click,
    Action_DoubleClick,
    Action_EnterWindow,
    Action_LeaveWindow,
    Action_KeyPress,
    Action_MouseMotion,
    Action_NewWindow,
    Action_CloseWindow
  };
  enum WidgetType {
    Type_Frame,
    Type_Titlebar,
    Type_Handle,
    Type_Plate,
    Type_Label,
    Type_MaximizeButton,
    Type_CloseButton,
    Type_IconifyButton,
    Type_StickyButton,
    Type_LeftGrip,
    Type_RightGrip,
    Type_Window,
    Type_Root
  };
%}
%rename(register) python_register;
%inline %{
/*PyObject * python_register(int action, PyObject *func, bool infront = false)
{
  if (!PyCallable_Check(func)) {
    PyErr_SetString(PyExc_TypeError, "Invalid callback function.");
    return NULL;
  }

  if (!ob::Openbox::instance->actions()->registerCallback(
        (ob::OBActions::ActionType)action, func, infront)) {
    PyErr_SetString(PyExc_RuntimeError, "Unable to register action callback.");
    return NULL;
  }
  Py_INCREF(Py_None); return Py_None;
}

PyObject * unregister(int action, PyObject *func)
{
  if (!PyCallable_Check(func)) {
    PyErr_SetString(PyExc_TypeError, "Invalid callback function.");
    return NULL;
  }

  if (!ob::Openbox::instance->actions()->unregisterCallback(
        (ob::OBActions::ActionType)action, func)) {
    PyErr_SetString(PyExc_RuntimeError, "Unable to unregister action callback.");
    return NULL;
  }
  Py_INCREF(Py_None); return Py_None;
}

PyObject * unregister_all(int action)
{
  if (!ob::Openbox::instance->actions()->unregisterAllCallbacks(
        (ob::OBActions::ActionType)action)) {
    PyErr_SetString(PyExc_RuntimeError,
                    "Unable to unregister action callbacks.");
    return NULL;
  }
  Py_INCREF(Py_None); return Py_None;
}
*/
PyObject * mbind(const std::string &button, MouseContext context,
                 PyObject *func)
{
  if (!PyCallable_Check(func)) {
    PyErr_SetString(PyExc_TypeError, "Invalid callback function.");
    return NULL;
  }
  
  if (!ob::Openbox::instance->bindings()->add(vectkeylist, func)) {
    PyErr_SetString(PyExc_RuntimeError,"Unable to add binding.");
    return NULL;
  }
  Py_INCREF(Py_None); return Py_None;
}

PyObject * kbind(PyObject *keylist, KeyContext context, PyObject *func)
{
  if (!PyCallable_Check(func)) {
    PyErr_SetString(PyExc_TypeError, "Invalid callback function.");
    return NULL;
  }
  if (!PyList_Check(keylist)) {
    PyErr_SetString(PyExc_TypeError, "Invalid keylist. Not a list.");
    return NULL;
  }

  ob::OBBindings::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 NULL;
    }
    vectkeylist.push_back(PyString_AsString(str));
  }

  if (!ob::Openbox::instance->bindings()->add(vectkeylist, func)) {
    PyErr_SetString(PyExc_RuntimeError,"Unable to add binding.");
    return NULL;
  }
  Py_INCREF(Py_None); return Py_None;
}

PyObject * kunbind(PyObject *keylist)
{
  if (!PyList_Check(keylist)) {
    PyErr_SetString(PyExc_TypeError, "Invalid keylist. Not a list.");
    return NULL;
  }

  ob::OBBindings::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 NULL;
    }
    vectkeylist.push_back(PyString_AsString(str));
  }

  ob::Openbox::instance->bindings()->remove(vectkeylist);
  Py_INCREF(Py_None); return Py_None;
}

void kunbind_all()
{
  ob::Openbox::instance->bindings()->removeAll();
}

void set_reset_key(const std::string &key)
{
  ob::Openbox::instance->bindings()->setResetKey(key);
}
%}

%ignore ob::OBScreen::clients;
%{
  #include <iterator>
%}
%extend ob::OBScreen {
  OBClient *client(int i) {
    if (i >= (int)self->clients.size())
      return NULL;
    ob::OBScreen::ClientList::iterator it = self->clients.begin();
    std::advance(it,i);
    return *it;
  }
  int clientCount() const {
    return (int) self->clients.size();
  }
};

%import "../otk/eventdispatcher.hh"
%import "../otk/eventhandler.hh"
%import "widget.hh"
%import "actions.hh"

%include "openbox.hh"
%include "screen.hh"
%include "client.hh"
%include "python.hh"

// for Mod1Mask etc
%include "X11/X.h"