X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fpython.cc;h=445a9882bcf3ac4b2925e54154dc506789915001;hb=bd748f74022019c4c9ee3e078afcef14cf47d370;hp=60c3e012f2b4d3929897ed3471a53fdedd77cb8b;hpb=f5f0a2c2eda2ea8cb3cd5eecbe2b7e459ae5ba2e;p=chaz%2Fopenbox diff --git a/src/python.cc b/src/python.cc index 60c3e012..445a9882 100644 --- a/src/python.cc +++ b/src/python.cc @@ -27,6 +27,12 @@ static void dealloc(PyObject *self) PyObject_Del(self); } +PyObject *MotionData_screen(MotionData *self, PyObject *args) +{ + if(!PyArg_ParseTuple(args,":screen")) return NULL; + return PyLong_FromLong(self->screen); +} + PyObject *MotionData_window(MotionData *self, PyObject *args) { if(!PyArg_ParseTuple(args,":window")) return NULL; @@ -124,6 +130,8 @@ PyObject *MotionData_time(MotionData *self, PyObject *args) static PyMethodDef MotionData_methods[] = { {"action", (PyCFunction)MotionData_action, METH_VARARGS, "Return the action being executed."}, + {"screen", (PyCFunction)MotionData_screen, METH_VARARGS, + "Return the number of the screen the event is on."}, {"window", (PyCFunction)MotionData_window, METH_VARARGS, "Return the client window id."}, {"context", (PyCFunction)MotionData_context, METH_VARARGS, @@ -160,6 +168,8 @@ static PyMethodDef ButtonData_methods[] = { "Return the action being executed."}, {"context", (PyCFunction)MotionData_context, METH_VARARGS, "Return the context that the action is occuring in."}, + {"screen", (PyCFunction)MotionData_screen, METH_VARARGS, + "Return the number of the screen the event is on."}, {"window", (PyCFunction)MotionData_window, METH_VARARGS, "Return the client window id."}, {"modifiers", (PyCFunction)MotionData_modifiers, METH_VARARGS, @@ -184,6 +194,8 @@ PyObject *EventData_modifiers(EventData *self, PyObject *args) } static PyMethodDef EventData_methods[] = { + {"screen", (PyCFunction)MotionData_screen, METH_VARARGS, + "Return the number of the screen the event is on."}, {"window", (PyCFunction)MotionData_window, METH_VARARGS, "Return the client window id."}, {"action", (PyCFunction)EventData_action, METH_VARARGS, @@ -202,6 +214,8 @@ PyObject *KeyData_key(KeyData *self, PyObject *args) } static PyMethodDef KeyData_methods[] = { + {"screen", (PyCFunction)MotionData_screen, METH_VARARGS, + "Return the number of the screen the event is on."}, {"window", (PyCFunction)MotionData_window, METH_VARARGS, "Return the client window id."}, {"modifiers", (PyCFunction)MotionData_modifiers, METH_VARARGS, @@ -281,12 +295,14 @@ static PyTypeObject KeyData_Type = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; -MotionData *new_motion_data(Window window, Time time, unsigned int state, - unsigned int button, MouseContext context, - MouseAction action, int xroot, int yroot, - const otk::Point &initpos, const otk::Rect &initarea) +MotionData *new_motion_data(int screen, Window window, Time time, + unsigned int state, unsigned int button, + MouseContext context, MouseAction action, + int xroot, int yroot, const otk::Point &initpos, + const otk::Rect &initarea) { MotionData *data = PyObject_New(MotionData, &MotionData_Type); + data->screen = screen; data->window = window; data->time = time; data->state = state; @@ -304,11 +320,12 @@ MotionData *new_motion_data(Window window, Time time, unsigned int state, return data; } -ButtonData *new_button_data(Window window, Time time, unsigned int state, - unsigned int button, MouseContext context, - MouseAction action) +ButtonData *new_button_data(int screen, Window window, Time time, + unsigned int state, unsigned int button, + MouseContext context, MouseAction action) { ButtonData *data = PyObject_New(ButtonData, &ButtonData_Type); + data->screen = screen; data->window = window; data->time = time; data->state = state; @@ -318,20 +335,22 @@ ButtonData *new_button_data(Window window, Time time, unsigned int state, return data; } -EventData *new_event_data(Window window, EventAction action, +EventData *new_event_data(int screen, Window window, EventAction action, unsigned int state) { EventData *data = PyObject_New(EventData, &EventData_Type); + data->screen = screen; data->window = window; data->action = action; data->state = state; return data; } -KeyData *new_key_data(Window window, Time time, unsigned int state, - unsigned int key) +KeyData *new_key_data(int screen, Window window, Time time, unsigned int state, + unsigned int key) { KeyData *data = PyObject_New(KeyData, &KeyData_Type); + data->screen = screen; data->window = window; data->time = time; data->state = state; @@ -351,6 +370,7 @@ void python_init(char *argv0) init_openbox(); PyRun_SimpleString("from _otk import *; from _openbox import *;"); PyRun_SimpleString("openbox = Openbox_instance()"); + PyRun_SimpleString("display = OBDisplay_display()"); /* XXX sys.path.append('stuff') @@ -496,13 +516,17 @@ PyObject *kbind(PyObject *keylist, ob::KeyContext context, PyObject *func) Py_INCREF(Py_None); return Py_None; } -PyObject *kunbind(PyObject *keylist) +PyObject *kunbind(PyObject *keylist, PyObject *func) { if (!PyList_Check(keylist)) { PyErr_SetString(PyExc_TypeError, "Invalid keylist. Not a list."); return NULL; } - + if (!PyCallable_Check(func)) { + PyErr_SetString(PyExc_TypeError, "Invalid callback function."); + return NULL; + } + ob::OBBindings::StringVect vectkeylist; for (int i = 0, end = PyList_Size(keylist); i < end; ++i) { PyObject *str = PyList_GetItem(keylist, i); @@ -514,7 +538,10 @@ PyObject *kunbind(PyObject *keylist) vectkeylist.push_back(PyString_AsString(str)); } - ob::Openbox::instance->bindings()->removeKey(vectkeylist); + if (!ob::Openbox::instance->bindings()->removeKey(vectkeylist, func)) { + PyErr_SetString(PyExc_RuntimeError, "Could not remove callback."); + return NULL; + } Py_INCREF(Py_None); return Py_None; } @@ -528,4 +555,32 @@ void set_reset_key(const std::string &key) ob::Openbox::instance->bindings()->setResetKey(key); } +PyObject *send_client_msg(Window target, int type, Window about, + long data, long data1, long data2, + long data3, long data4) +{ + if (type < 0 || type >= otk::OBProperty::NUM_ATOMS) { + PyErr_SetString(PyExc_TypeError, + "Invalid atom type. Must be from otk::OBProperty::Atoms"); + return NULL; + } + + XEvent e; + e.xclient.type = ClientMessage; + e.xclient.format = 32; + e.xclient.message_type = + Openbox::instance->property()->atom((otk::OBProperty::Atoms)type); + e.xclient.window = about; + e.xclient.data.l[0] = data; + e.xclient.data.l[1] = data1; + e.xclient.data.l[2] = data2; + e.xclient.data.l[3] = data3; + e.xclient.data.l[4] = data4; + + XSendEvent(otk::OBDisplay::display, target, false, + SubstructureRedirectMask | SubstructureNotifyMask, + &e); + Py_INCREF(Py_None); return Py_None; +} + }