From b34824a4e2ddc0247099fa1b3952de426bfde05b Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Wed, 25 Dec 2002 04:54:44 +0000 Subject: [PATCH] global python scripts. client motion/resizing is all done via python now --- Makefile.am | 2 +- configure.ac | 1 + otk/Makefile.am | 2 +- otk/otk_wrap.cc | 230 ++++++++++++++++++++++++++++++++++++++-- otk/rect.hh | 6 ++ scripts/Makefile.am | 9 ++ scripts/clientmotion.py | 77 ++++++++++++++ src/Makefile.am | 4 +- src/actions.cc | 117 +++++--------------- src/actions.hh | 23 +--- src/openbox.cc | 21 ++-- src/openbox.i | 20 +++- src/openbox_wrap.cc | 32 ++++++ src/python.cc | 15 ++- src/python.hh | 3 +- src/widget.hh | 1 + 16 files changed, 434 insertions(+), 129 deletions(-) create mode 100644 scripts/Makefile.am create mode 100644 scripts/clientmotion.py diff --git a/Makefile.am b/Makefile.am index b964ab70..3532967b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,6 @@ # Makefile.am for Openbox -SUBDIRS = intl po m4 data doc otk src +SUBDIRS = intl po m4 data doc otk src scripts MAINTAINERCLEANFILES = aclocal.m4 config.h.in configure Makefile.in stamp-h.in .PHONY: doc diff --git a/configure.ac b/configure.ac index 6b177856..6e44de3d 100644 --- a/configure.ac +++ b/configure.ac @@ -340,6 +340,7 @@ AC_CONFIG_FILES([Makefile intl/Makefile otk/Makefile src/Makefile + scripts/Makefile util/Makefile util/epist/Makefile doc/Makefile diff --git a/otk/Makefile.am b/otk/Makefile.am index 2ca5f35a..fc28a36a 100644 --- a/otk/Makefile.am +++ b/otk/Makefile.am @@ -27,7 +27,7 @@ otk.i: $(wildcard *.hh) touch $@ otk_wrap.cc: otk.i - swig $(filter -I%,$(CFLAGS)) -python -c++ -nodefault -o $@ $< + swig $(filter -I%,$(CFLAGS)) -python -c++ -o $@ $< # local dependencies application.o: application.cc application.hh eventdispatcher.hh \ diff --git a/otk/otk_wrap.cc b/otk/otk_wrap.cc index 30ed4cfd..73f9bea6 100644 --- a/otk/otk_wrap.cc +++ b/otk/otk_wrap.cc @@ -834,19 +834,19 @@ static void _SWIG_exception(int code, const char *msg) { #include -PyObject* SwigInt_FromBool(bool b) { +static PyObject* SwigInt_FromBool(bool b) { return PyInt_FromLong(b ? 1L : 0L); } -double SwigNumber_Check(PyObject* o) { +static double SwigNumber_Check(PyObject* o) { return PyFloat_Check(o) || PyInt_Check(o); } -double SwigNumber_AsDouble(PyObject* o) { +static double SwigNumber_AsDouble(PyObject* o) { return (PyFloat_Check(o) ? PyFloat_AsDouble(o) : double(PyInt_AsLong(o))); } -PyObject* SwigString_FromString(const std::string& s) { +static PyObject* SwigString_FromString(const std::string& s) { return PyString_FromString(s.c_str()); } -std::string SwigString_AsString(PyObject* o) { +static std::string SwigString_AsString(PyObject* o) { return std::string(PyString_AsString(o)); } @@ -3783,6 +3783,36 @@ static PyObject * OtkApplication_swigregister(PyObject *self, PyObject *args) { Py_INCREF(obj); return Py_BuildValue((char *)""); } +static PyObject *_wrap_new_PointerAssassin(PyObject *self, PyObject *args) { + PyObject *resultobj; + otk::PointerAssassin *result; + + if(!PyArg_ParseTuple(args,(char *)":new_PointerAssassin")) goto fail; + result = (otk::PointerAssassin *)new otk::PointerAssassin(); + + resultobj = SWIG_NewPointerObj((void *) result, SWIGTYPE_p_otk__PointerAssassin, 1); + return resultobj; + fail: + return NULL; +} + + +static PyObject *_wrap_delete_PointerAssassin(PyObject *self, PyObject *args) { + PyObject *resultobj; + otk::PointerAssassin *arg1 = (otk::PointerAssassin *) 0 ; + PyObject * obj0 = 0 ; + + if(!PyArg_ParseTuple(args,(char *)"O:delete_PointerAssassin",&obj0)) goto fail; + if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_otk__PointerAssassin,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail; + delete arg1; + + Py_INCREF(Py_None); resultobj = Py_None; + return resultobj; + fail: + return NULL; +} + + static PyObject * PointerAssassin_swigregister(PyObject *self, PyObject *args) { PyObject *obj; if (!PyArg_ParseTuple(args,(char*)"O", &obj)) return NULL; @@ -5591,6 +5621,22 @@ static PyObject *_wrap_OBDisplay_ungrabButton(PyObject *self, PyObject *args) { } +static PyObject *_wrap_delete_OBDisplay(PyObject *self, PyObject *args) { + PyObject *resultobj; + otk::OBDisplay *arg1 = (otk::OBDisplay *) 0 ; + PyObject * obj0 = 0 ; + + if(!PyArg_ParseTuple(args,(char *)"O:delete_OBDisplay",&obj0)) goto fail; + if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_otk__OBDisplay,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail; + delete arg1; + + Py_INCREF(Py_None); resultobj = Py_None; + return resultobj; + fail: + return NULL; +} + + static PyObject * OBDisplay_swigregister(PyObject *self, PyObject *args) { PyObject *obj; if (!PyArg_ParseTuple(args,(char*)"O", &obj)) return NULL; @@ -6016,6 +6062,22 @@ static PyObject *_wrap_BGCCacheItem_gc(PyObject *self, PyObject *args) { } +static PyObject *_wrap_delete_BGCCacheItem(PyObject *self, PyObject *args) { + PyObject *resultobj; + otk::BGCCacheItem *arg1 = (otk::BGCCacheItem *) 0 ; + PyObject * obj0 = 0 ; + + if(!PyArg_ParseTuple(args,(char *)"O:delete_BGCCacheItem",&obj0)) goto fail; + if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_otk__BGCCacheItem,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail; + delete arg1; + + Py_INCREF(Py_None); resultobj = Py_None; + return resultobj; + fail: + return NULL; +} + + static PyObject * BGCCacheItem_swigregister(PyObject *self, PyObject *args) { PyObject *obj; if (!PyArg_ParseTuple(args,(char*)"O", &obj)) return NULL; @@ -6844,6 +6906,22 @@ static PyObject *_wrap_Point_setPoint(PyObject *self, PyObject *args) { } +static PyObject *_wrap_delete_Point(PyObject *self, PyObject *args) { + PyObject *resultobj; + otk::Point *arg1 = (otk::Point *) 0 ; + PyObject * obj0 = 0 ; + + if(!PyArg_ParseTuple(args,(char *)"O:delete_Point",&obj0)) goto fail; + if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_otk__Point,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail; + delete arg1; + + Py_INCREF(Py_None); resultobj = Py_None; + return resultobj; + fail: + return NULL; +} + + static PyObject * Point_swigregister(PyObject *self, PyObject *args) { PyObject *obj; if (!PyArg_ParseTuple(args,(char*)"O", &obj)) return NULL; @@ -7643,6 +7721,26 @@ static PyObject *_wrap_new_Rect__SWIG_2(PyObject *self, PyObject *args) { static PyObject *_wrap_new_Rect__SWIG_3(PyObject *self, PyObject *args) { + PyObject *resultobj; + otk::Rect *arg1 = 0 ; + otk::Rect *result; + PyObject * obj0 = 0 ; + + if(!PyArg_ParseTuple(args,(char *)"O:new_Rect",&obj0)) goto fail; + if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_otk__Rect,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail; + if (arg1 == NULL) { + PyErr_SetString(PyExc_TypeError,"null reference"); SWIG_fail; + } + result = (otk::Rect *)new otk::Rect((otk::Rect const &)*arg1); + + resultobj = SWIG_NewPointerObj((void *) result, SWIGTYPE_p_otk__Rect, 1); + return resultobj; + fail: + return NULL; +} + + +static PyObject *_wrap_new_Rect__SWIG_4(PyObject *self, PyObject *args) { PyObject *resultobj; XRectangle *arg1 = 0 ; otk::Rect *result; @@ -7678,7 +7776,7 @@ static PyObject *_wrap_new_Rect(PyObject *self, PyObject *args) { int _v; { void *ptr; - if (SWIG_ConvertPtr(argv[0], (void **) &ptr, SWIGTYPE_p_XRectangle, 0) == -1) { + if (SWIG_ConvertPtr(argv[0], (void **) &ptr, SWIGTYPE_p_otk__Rect, 0) == -1) { _v = 0; PyErr_Clear(); }else { @@ -7689,6 +7787,21 @@ static PyObject *_wrap_new_Rect(PyObject *self, PyObject *args) { return _wrap_new_Rect__SWIG_3(self,args); } } + if (argc == 1) { + int _v; + { + void *ptr; + if (SWIG_ConvertPtr(argv[0], (void **) &ptr, SWIGTYPE_p_XRectangle, 0) == -1) { + _v = 0; + PyErr_Clear(); + }else { + _v = 1; + } + } + if (_v) { + return _wrap_new_Rect__SWIG_4(self,args); + } + } if (argc == 2) { int _v; { @@ -8693,6 +8806,22 @@ static PyObject *_wrap_Rect_contains(PyObject *self, PyObject *args) { } +static PyObject *_wrap_delete_Rect(PyObject *self, PyObject *args) { + PyObject *resultobj; + otk::Rect *arg1 = (otk::Rect *) 0 ; + PyObject * obj0 = 0 ; + + if(!PyArg_ParseTuple(args,(char *)"O:delete_Rect",&obj0)) goto fail; + if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_otk__Rect,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail; + delete arg1; + + Py_INCREF(Py_None); resultobj = Py_None; + return resultobj; + fail: + return NULL; +} + + static PyObject * Rect_swigregister(PyObject *self, PyObject *args) { PyObject *obj; if (!PyArg_ParseTuple(args,(char*)"O", &obj)) return NULL; @@ -8887,6 +9016,22 @@ static PyObject *_wrap_ScreenInfo_displayString(PyObject *self, PyObject *args) } +static PyObject *_wrap_delete_ScreenInfo(PyObject *self, PyObject *args) { + PyObject *resultobj; + otk::ScreenInfo *arg1 = (otk::ScreenInfo *) 0 ; + PyObject * obj0 = 0 ; + + if(!PyArg_ParseTuple(args,(char *)"O:delete_ScreenInfo",&obj0)) goto fail; + if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_otk__ScreenInfo,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail; + delete arg1; + + Py_INCREF(Py_None); resultobj = Py_None; + return resultobj; + fail: + return NULL; +} + + static PyObject * ScreenInfo_swigregister(PyObject *self, PyObject *args) { PyObject *obj; if (!PyArg_ParseTuple(args,(char*)"O", &obj)) return NULL; @@ -9116,6 +9261,22 @@ static PyObject *_wrap_new_Strut(PyObject *self, PyObject *args) { } +static PyObject *_wrap_delete_Strut(PyObject *self, PyObject *args) { + PyObject *resultobj; + otk::Strut *arg1 = (otk::Strut *) 0 ; + PyObject * obj0 = 0 ; + + if(!PyArg_ParseTuple(args,(char *)"O:delete_Strut",&obj0)) goto fail; + if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_otk__Strut,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail; + delete arg1; + + Py_INCREF(Py_None); resultobj = Py_None; + return resultobj; + fail: + return NULL; +} + + static PyObject * Strut_swigregister(PyObject *self, PyObject *args) { PyObject *obj; if (!PyArg_ParseTuple(args,(char*)"O", &obj)) return NULL; @@ -9239,6 +9400,36 @@ static PyObject *_wrap_PixmapMask_h_get(PyObject *self, PyObject *args) { } +static PyObject *_wrap_new_PixmapMask(PyObject *self, PyObject *args) { + PyObject *resultobj; + otk::PixmapMask *result; + + if(!PyArg_ParseTuple(args,(char *)":new_PixmapMask")) goto fail; + result = (otk::PixmapMask *)new otk::PixmapMask(); + + resultobj = SWIG_NewPointerObj((void *) result, SWIGTYPE_p_otk__PixmapMask, 1); + return resultobj; + fail: + return NULL; +} + + +static PyObject *_wrap_delete_PixmapMask(PyObject *self, PyObject *args) { + PyObject *resultobj; + otk::PixmapMask *arg1 = (otk::PixmapMask *) 0 ; + PyObject * obj0 = 0 ; + + if(!PyArg_ParseTuple(args,(char *)"O:delete_PixmapMask",&obj0)) goto fail; + if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_otk__PixmapMask,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail; + delete arg1; + + Py_INCREF(Py_None); resultobj = Py_None; + return resultobj; + fail: + return NULL; +} + + static PyObject * PixmapMask_swigregister(PyObject *self, PyObject *args) { PyObject *obj; if (!PyArg_ParseTuple(args,(char*)"O", &obj)) return NULL; @@ -11870,6 +12061,22 @@ static PyObject *_wrap_BTexture_render(PyObject *self, PyObject *args) { } +static PyObject *_wrap_delete_BTexture(PyObject *self, PyObject *args) { + PyObject *resultobj; + otk::BTexture *arg1 = (otk::BTexture *) 0 ; + PyObject * obj0 = 0 ; + + if(!PyArg_ParseTuple(args,(char *)"O:delete_BTexture",&obj0)) goto fail; + if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_otk__BTexture,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail; + delete arg1; + + Py_INCREF(Py_None); resultobj = Py_None; + return resultobj; + fail: + return NULL; +} + + static PyObject * BTexture_swigregister(PyObject *self, PyObject *args) { PyObject *obj; if (!PyArg_ParseTuple(args,(char*)"O", &obj)) return NULL; @@ -12663,6 +12870,8 @@ static PyMethodDef SwigMethods[] = { { (char *)"OtkApplication_isDockable", _wrap_OtkApplication_isDockable, METH_VARARGS }, { (char *)"OtkApplication_getStyle", _wrap_OtkApplication_getStyle, METH_VARARGS }, { (char *)"OtkApplication_swigregister", OtkApplication_swigregister, METH_VARARGS }, + { (char *)"new_PointerAssassin", _wrap_new_PointerAssassin, METH_VARARGS }, + { (char *)"delete_PointerAssassin", _wrap_delete_PointerAssassin, METH_VARARGS }, { (char *)"PointerAssassin_swigregister", PointerAssassin_swigregister, METH_VARARGS }, { (char *)"new_OtkButton", _wrap_new_OtkButton, METH_VARARGS }, { (char *)"delete_OtkButton", _wrap_delete_OtkButton, METH_VARARGS }, @@ -12725,6 +12934,7 @@ static PyMethodDef SwigMethods[] = { { (char *)"OBDisplay_ungrab", _wrap_OBDisplay_ungrab, METH_VARARGS }, { (char *)"OBDisplay_grabButton", _wrap_OBDisplay_grabButton, METH_VARARGS }, { (char *)"OBDisplay_ungrabButton", _wrap_OBDisplay_ungrabButton, METH_VARARGS }, + { (char *)"delete_OBDisplay", _wrap_delete_OBDisplay, METH_VARARGS }, { (char *)"OBDisplay_swigregister", OBDisplay_swigregister, METH_VARARGS }, { (char *)"BFont_fallbackFont", _wrap_BFont_fallbackFont, METH_VARARGS }, { (char *)"BFont_setFallbackFont", _wrap_BFont_setFallbackFont, METH_VARARGS }, @@ -12740,6 +12950,7 @@ static PyMethodDef SwigMethods[] = { { (char *)"delete_BGCCacheContext", _wrap_delete_BGCCacheContext, METH_VARARGS }, { (char *)"BGCCacheContext_swigregister", BGCCacheContext_swigregister, METH_VARARGS }, { (char *)"BGCCacheItem_gc", _wrap_BGCCacheItem_gc, METH_VARARGS }, + { (char *)"delete_BGCCacheItem", _wrap_delete_BGCCacheItem, METH_VARARGS }, { (char *)"BGCCacheItem_swigregister", BGCCacheItem_swigregister, METH_VARARGS }, { (char *)"new_BGCCache", _wrap_new_BGCCache, METH_VARARGS }, { (char *)"delete_BGCCache", _wrap_delete_BGCCache, METH_VARARGS }, @@ -12781,6 +12992,7 @@ static PyMethodDef SwigMethods[] = { { (char *)"Point_setY", _wrap_Point_setY, METH_VARARGS }, { (char *)"Point_y", _wrap_Point_y, METH_VARARGS }, { (char *)"Point_setPoint", _wrap_Point_setPoint, METH_VARARGS }, + { (char *)"delete_Point", _wrap_delete_Point, METH_VARARGS }, { (char *)"Point_swigregister", Point_swigregister, METH_VARARGS }, { (char *)"new_OBProperty", _wrap_new_OBProperty, METH_VARARGS }, { (char *)"delete_OBProperty", _wrap_delete_OBProperty, METH_VARARGS }, @@ -12812,6 +13024,7 @@ static PyMethodDef SwigMethods[] = { { (char *)"Rect_valid", _wrap_Rect_valid, METH_VARARGS }, { (char *)"Rect_intersects", _wrap_Rect_intersects, METH_VARARGS }, { (char *)"Rect_contains", _wrap_Rect_contains, METH_VARARGS }, + { (char *)"delete_Rect", _wrap_delete_Rect, METH_VARARGS }, { (char *)"Rect_swigregister", Rect_swigregister, METH_VARARGS }, { (char *)"new_ScreenInfo", _wrap_new_ScreenInfo, METH_VARARGS }, { (char *)"ScreenInfo_visual", _wrap_ScreenInfo_visual, METH_VARARGS }, @@ -12823,6 +13036,7 @@ static PyMethodDef SwigMethods[] = { { (char *)"ScreenInfo_width", _wrap_ScreenInfo_width, METH_VARARGS }, { (char *)"ScreenInfo_height", _wrap_ScreenInfo_height, METH_VARARGS }, { (char *)"ScreenInfo_displayString", _wrap_ScreenInfo_displayString, METH_VARARGS }, + { (char *)"delete_ScreenInfo", _wrap_delete_ScreenInfo, METH_VARARGS }, { (char *)"ScreenInfo_swigregister", ScreenInfo_swigregister, METH_VARARGS }, { (char *)"Strut_top_set", _wrap_Strut_top_set, METH_VARARGS }, { (char *)"Strut_top_get", _wrap_Strut_top_get, METH_VARARGS }, @@ -12833,6 +13047,7 @@ static PyMethodDef SwigMethods[] = { { (char *)"Strut_right_set", _wrap_Strut_right_set, METH_VARARGS }, { (char *)"Strut_right_get", _wrap_Strut_right_get, METH_VARARGS }, { (char *)"new_Strut", _wrap_new_Strut, METH_VARARGS }, + { (char *)"delete_Strut", _wrap_delete_Strut, METH_VARARGS }, { (char *)"Strut_swigregister", Strut_swigregister, METH_VARARGS }, { (char *)"PixmapMask_mask_set", _wrap_PixmapMask_mask_set, METH_VARARGS }, { (char *)"PixmapMask_mask_get", _wrap_PixmapMask_mask_get, METH_VARARGS }, @@ -12840,6 +13055,8 @@ static PyMethodDef SwigMethods[] = { { (char *)"PixmapMask_w_get", _wrap_PixmapMask_w_get, METH_VARARGS }, { (char *)"PixmapMask_h_set", _wrap_PixmapMask_h_set, METH_VARARGS }, { (char *)"PixmapMask_h_get", _wrap_PixmapMask_h_get, METH_VARARGS }, + { (char *)"new_PixmapMask", _wrap_new_PixmapMask, METH_VARARGS }, + { (char *)"delete_PixmapMask", _wrap_delete_PixmapMask, METH_VARARGS }, { (char *)"PixmapMask_swigregister", PixmapMask_swigregister, METH_VARARGS }, { (char *)"Style_image_control_set", _wrap_Style_image_control_set, METH_VARARGS }, { (char *)"Style_image_control_get", _wrap_Style_image_control_get, METH_VARARGS }, @@ -12970,6 +13187,7 @@ static PyMethodDef SwigMethods[] = { { (char *)"BTexture_description", _wrap_BTexture_description, METH_VARARGS }, { (char *)"BTexture_setDescription", _wrap_BTexture_setDescription, METH_VARARGS }, { (char *)"BTexture_render", _wrap_BTexture_render, METH_VARARGS }, + { (char *)"delete_BTexture", _wrap_delete_BTexture, METH_VARARGS }, { (char *)"BTexture_swigregister", BTexture_swigregister, METH_VARARGS }, { (char *)"new_OBTimer", _wrap_new_OBTimer, METH_VARARGS }, { (char *)"delete_OBTimer", _wrap_delete_OBTimer, METH_VARARGS }, diff --git a/otk/rect.hh b/otk/rect.hh index 23ca0d12..65a679c7 100644 --- a/otk/rect.hh +++ b/otk/rect.hh @@ -35,6 +35,12 @@ public: inline Rect(const Point &location, const Point &size) : _x1(location.x()), _y1(location.y()), _x2(size.x() + location.x() - 1), _y2(size.y() + location.y() - 1) { } + //! Constructs a Rect from another Rect + /*! + @param rect The rectangle from which to construct this new one + */ + inline Rect(const Rect &rect) + : _x1(rect._x1), _y1(rect._y1), _x2(rect._x2), _y2(rect._y2) { } //! Constructs a Rect from an XRectangle inline explicit Rect(const XRectangle& xrect) : _x1(xrect.x), _y1(xrect.y), _x2(xrect.width + xrect.x - 1), diff --git a/scripts/Makefile.am b/scripts/Makefile.am new file mode 100644 index 00000000..b1cecc47 --- /dev/null +++ b/scripts/Makefile.am @@ -0,0 +1,9 @@ +scriptdir = $(libdir)/openbox/python +MAINTAINERCLEANFILES = Makefile.in +script_DATA = clientmotion.py +EXTRA_DIST = $(script_DATA) + +distclean-local: + rm -f *\~ .\#* +uninstall-am: + rmdir -p $(scriptdir) diff --git a/scripts/clientmotion.py b/scripts/clientmotion.py new file mode 100644 index 00000000..857d6377 --- /dev/null +++ b/scripts/clientmotion.py @@ -0,0 +1,77 @@ +posqueue = []; + +def motion_press(action, win, type, modifiers, button, xroot, yroot, time): + client = Openbox_findClient(openbox, win) + + global posqueue + newi = [button, xroot, yroot] + if client: + newi.append(new_Rect(OBClient_area(client))) + posqueue.append(newi) + + # ButtonPressAction *a = _posqueue[BUTTONS - 1]; + # for (int i=BUTTONS-1; i>0;) + # _posqueue[i] = _posqueue[--i]; + # _posqueue[0] = a; + # a->button = e.button; + # a->pos.setPoint(e.x_root, e.y_root); + + # OBClient *c = Openbox::instance->findClient(e.window); + # // if it's not defined, they should have clicked on the root window, so this + # // area would be meaningless anyways + # if (c) a->clientarea = c->area(); + +def motion_release(action, win, type, modifiers, button, xroot, yroot, time): + global posqueue + for i in posqueue: + if i[0] == button: + #delete_Rect i[3] + posqueue.remove(i) + break + + # ButtonPressAction *a = 0; + # for (int i=0; ibutton == e.button) + # a = _posqueue[i]; + # if (a) // found one and removed it + # _posqueue[i] = _posqueue[i+1]; + # } + # if (a) { // found one + # _posqueue[BUTTONS-1] = a; + # a->button = 0; + # } + + +def motion(action, win, type, modifiers, xroot, yroot, time): + client = Openbox_findClient(openbox, win) + + global posqueue + dx = xroot - posqueue[0][1] + dy = yroot - posqueue[0][2] + # _dx = x_root - _posqueue[0]->pos.x(); + # _dy = y_root - _posqueue[0]->pos.y(); + + if not client: + return + area = posqueue[0][3] # A Rect + if (type == Type_Titlebar) or (type == Type_Label): + OBClient_move(client, Rect_x(area) + dx, Rect_y(area) + dy) + # c->move(_posqueue[0]->clientarea.x() + _dx, + # _posqueue[0]->clientarea.y() + _dy); + elif type == Type_LeftGrip: + OBClient_resize(client, OBClient_TopRight, + Rect_width(area) - dx, Rect_height(area) + dy) + # c->resize(OBClient::TopRight, + # _posqueue[0]->clientarea.width() - _dx, + # _posqueue[0]->clientarea.height() + _dy); + elif type == Type_RightGrip: + OBClient_resize(client, OBClient_TopLeft, + Rect_width(area) + dx, Rect_height(area) + dy) + # c->resize(OBClient::TopLeft, + # _posqueue[0]->clientarea.width() + _dx, + # _posqueue[0]->clientarea.height() + _dy); + + +register(Action_ButtonPress, motion_press) +register(Action_ButtonRelease, motion_release) +register(Action_MouseMotion, motion) diff --git a/src/Makefile.am b/src/Makefile.am index 222b770c..5ea811f0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,11 +1,13 @@ localedir=$(datadir)/locale +scriptdir = $(libdir)/openbox/python DEFAULT_MENU=$(pkgdatadir)/menu DEFAULT_STYLE=$(pkgdatadir)/styles/mbdtex CPPFLAGS=$(XFT_CFLAGS) $(PYTHON_CFLAGS) @CPPFLAGS@ \ -DDEFAULTMENU=\"$(DEFAULT_MENU)\" \ -DDEFAULTSTYLE=\"$(DEFAULT_STYLE)\" \ --DLOCALEDIR=\"$(localedir)\" +-DLOCALEDIR=\"$(localedir)\" \ +-DSCRIPTDIR=\"$(scriptdir)\" LIBS=$(XFT_LIBS) $(PYTHON_LIBS) @LIBS@ diff --git a/src/actions.cc b/src/actions.cc index d2b4ceef..0dbe4640 100644 --- a/src/actions.cc +++ b/src/actions.cc @@ -16,14 +16,10 @@ namespace ob { const unsigned int OBActions::DOUBLECLICKDELAY = 300; -const int OBActions::BUTTONS; OBActions::OBActions() : _button(0) { - for (int i=0; i0;) - _posqueue[i] = _posqueue[--i]; - _posqueue[0] = a; - a->button = e.button; - a->pos.setPoint(e.x_root, e.y_root); - - OBClient *c = Openbox::instance->findClient(e.window); - // if it's not defined, they should have clicked on the root window, so this - // area would be meaningless anyways - if (c) a->clientarea = c->area(); } -void OBActions::removePress(const XButtonEvent &e) -{ - ButtonPressAction *a = 0; - for (int i=0; ibutton == e.button) - a = _posqueue[i]; - if (a) // found one and removed it - _posqueue[i] = _posqueue[i+1]; - } - if (a) { // found one - _posqueue[BUTTONS-1] = a; - a->button = 0; - } -} void OBActions::buttonPressHandler(const XButtonEvent &e) { OtkEventHandler::buttonPressHandler(e); - insertPress(e); - // XXX: run the PRESS guile hook + // run the PRESS guile hook OBWidget *w = dynamic_cast (Openbox::instance->findHandler(e.window)); - printf("GUILE: PRESS: win %lx type %d modifiers %u button %u time %lx\n", - (long)e.window, (w ? w->type():-1), e.state, e.button, e.time); python_callback(Action_ButtonPress, e.window, (OBWidget::WidgetType)(w ? w->type():-1), - e.state, e.button, e.time); + e.state, e.button, e.x_root, e.y_root, e.time); if (_button) return; // won't count toward CLICK events @@ -90,14 +51,14 @@ void OBActions::buttonPressHandler(const XButtonEvent &e) void OBActions::buttonReleaseHandler(const XButtonEvent &e) { OtkEventHandler::buttonReleaseHandler(e); - removePress(e); - // XXX: run the RELEASE guile hook OBWidget *w = dynamic_cast (Openbox::instance->findHandler(e.window)); - printf("GUILE: RELEASE: win %lx type %d, modifiers %u button %u time %lx\n", - (long)e.window, (w ? w->type():-1), e.state, e.button, e.time); + // run the RELEASE guile hook + python_callback(Action_ButtonRelease, e.window, + (OBWidget::WidgetType)(w ? w->type():-1), + e.state, e.button, e.x_root, e.y_root, e.time); // not for the button we're watching? if (_button != e.button) return; @@ -113,16 +74,18 @@ void OBActions::buttonReleaseHandler(const XButtonEvent &e) e.x < attr.width && e.y < attr.height)) return; - // XXX: run the CLICK guile hook - printf("GUILE: CLICK: win %lx type %d modifiers %u button %u time %lx\n", - (long)e.window, (w ? w->type():-1), e.state, e.button, e.time); + // run the CLICK guile hook + python_callback(Action_Click, e.window, + (OBWidget::WidgetType)(w ? w->type():-1), + e.state, e.button, e.time); if (e.time - _release.time < DOUBLECLICKDELAY && _release.win == e.window && _release.button == e.button) { - // XXX: run the DOUBLECLICK guile hook - printf("GUILE: DOUBLECLICK: win %lx type %d modifiers %u button %u time %lx\n", - (long)e.window, (w ? w->type():-1), e.state, e.button, e.time); + // run the DOUBLECLICK guile hook + python_callback(Action_DoubleClick, e.window, + (OBWidget::WidgetType)(w ? w->type():-1), + e.state, e.button, e.time); // reset so you cant triple click for 2 doubleclicks _release.win = 0; @@ -141,12 +104,12 @@ void OBActions::enterHandler(const XCrossingEvent &e) { OtkEventHandler::enterHandler(e); - // XXX: run the ENTER guile hook OBWidget *w = dynamic_cast (Openbox::instance->findHandler(e.window)); - printf("GUILE: ENTER: win %lx type %d modifiers %u\n", - (long)e.window, (w ? w->type():-1), e.state); + // run the ENTER guile hook + python_callback(Action_EnterWindow, e.window, + (OBWidget::WidgetType)(w ? w->type():-1), e.state); } @@ -154,23 +117,24 @@ void OBActions::leaveHandler(const XCrossingEvent &e) { OtkEventHandler::leaveHandler(e); - // XXX: run the LEAVE guile hook OBWidget *w = dynamic_cast (Openbox::instance->findHandler(e.window)); - printf("GUILE: LEAVE: win %lx type %d modifiers %u\n", - (long)e.window, (w ? w->type():-1), e.state); + // run the LEAVE guile hook + python_callback(Action_LeaveWindow, e.window, + (OBWidget::WidgetType)(w ? w->type():-1), e.state); } void OBActions::keyPressHandler(const XKeyEvent &e) { - // XXX: run the KEY guile hook OBWidget *w = dynamic_cast (Openbox::instance->findHandler(e.window)); - printf("GUILE: KEY: win %lx type %d modifiers %u keycode %u\n", - (long)e.window, (w ? w->type():-1), e.state, e.keycode); + // run the KEY guile hook + python_callback(Action_KeyPress, e.window, + (OBWidget::WidgetType)(w ? w->type():-1), + e.state, e.keycode); } @@ -196,35 +160,12 @@ void OBActions::motionHandler(const XMotionEvent &e) OBWidget *w = dynamic_cast (Openbox::instance->findHandler(e.window)); - _dx = x_root - _posqueue[0]->pos.x(); - _dy = y_root - _posqueue[0]->pos.y(); - // XXX: i can envision all sorts of crazy shit with this.. gestures, etc - printf("GUILE: MOTION: win %lx type %d modifiers %u x %d y %d\n", - (long)e.window, (w ? w->type():-1), e.state, _dx, _dy); - - OBClient *c = Openbox::instance->findClient(e.window); - if (w && c) { - switch (w->type()) { - case OBWidget::Type_Titlebar: - case OBWidget::Type_Label: - c->move(_posqueue[0]->clientarea.x() + _dx, - _posqueue[0]->clientarea.y() + _dy); - break; - case OBWidget::Type_LeftGrip: - c->resize(OBClient::TopRight, - _posqueue[0]->clientarea.width() - _dx, - _posqueue[0]->clientarea.height() + _dy); - break; - case OBWidget::Type_RightGrip: - c->resize(OBClient::TopLeft, - _posqueue[0]->clientarea.width() + _dx, - _posqueue[0]->clientarea.height() + _dy); - break; - default: - break; - } - } + // maybe that should all be done via python tho.. + // run the simple MOTION guile hook for now... + python_callback(Action_MouseMotion, e.window, + (OBWidget::WidgetType)(w ? w->type():-1), + e.state, e.x_root, e.y_root, e.time); } diff --git a/src/actions.hh b/src/actions.hh index 1a8d02c4..4cf37ef1 100644 --- a/src/actions.hh +++ b/src/actions.hh @@ -23,9 +23,12 @@ namespace ob { */ class OBActions : public otk::OtkEventHandler { public: + // update the same enum in openbox.i when making changes to this enum ActionType { Action_ButtonPress, Action_ButtonRelease, + Action_Click, + Action_DoubleClick, Action_EnterWindow, Action_LeaveWindow, Action_KeyPress, @@ -40,35 +43,15 @@ public: ButtonReleaseAction() { win = 0; button = 0; time = 0; } }; - struct ButtonPressAction { - unsigned int button; - otk::Point pos; - otk::Rect clientarea; - ButtonPressAction() { button = 0; } - }; - private: // milliseconds XXX: config option static const unsigned int DOUBLECLICKDELAY; - static const int BUTTONS = 5; //! The mouse button currently being watched from a press for a CLICK unsigned int _button; //! The last button release processed for CLICKs ButtonReleaseAction _release; - //! The point where the mouse was when each mouse button was pressed - /*! - Used for motion events as the starting position. - */ - ButtonPressAction *_posqueue[BUTTONS]; - //! The delta x/y of the last motion sequence - int _dx, _dy; - //! Insert a button/position in the _posqueue - void insertPress(const XButtonEvent &e); - //! Remove a button/position from the _posqueue - void removePress(const XButtonEvent &e); - public: //! Constructs an OBActions object OBActions(); diff --git a/src/openbox.cc b/src/openbox.cc index aa61a313..cf41975d 100644 --- a/src/openbox.cc +++ b/src/openbox.cc @@ -82,6 +82,17 @@ void Openbox::signalHandler(int signal) } +static void runPython(const char *s) { + FILE *rcpyfd = fopen(s, "r"); + if (!rcpyfd) { + printf("failed to load python file %s\n", s); + } else { + PyRun_SimpleFile(rcpyfd, const_cast(s)); + fclose(rcpyfd); + } +} + + Openbox::Openbox(int argc, char **argv) : otk::OtkEventDispatcher(), otk::OtkEventHandler() @@ -150,13 +161,9 @@ Openbox::Openbox(int argc, char **argv) init_openbox(); PyRun_SimpleString("from _otk import *; from _openbox import *;"); PyRun_SimpleString("openbox = Openbox_instance()"); - FILE *rcpyfd = fopen(_scriptfilepath.c_str(), "r"); - if (!rcpyfd) { - printf("failed to load python file %s\n", _scriptfilepath.c_str()); - } else { - PyRun_SimpleFile(rcpyfd, const_cast(_scriptfilepath.c_str())); - fclose(rcpyfd); - } + + runPython(SCRIPTDIR"/clientmotion.py"); // moving and resizing clients + runPython(_scriptfilepath.c_str()); // initialize all the screens OBScreen *screen; diff --git a/src/openbox.i b/src/openbox.i index 1ff7d357..ef82956b 100644 --- a/src/openbox.i +++ b/src/openbox.i @@ -23,17 +23,33 @@ ob::Openbox *Openbox_instance() { return ob::Openbox::instance; } %}; -// stuff for registering callbacks! - +// stuff for scripting callbacks! %inline %{ enum ActionType { Action_ButtonPress, Action_ButtonRelease, + Action_Click, + Action_DoubleClick, Action_EnterWindow, Action_LeaveWindow, Action_KeyPress, Action_MouseMotion }; + 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_Client, + Type_Root + }; %} %ignore ob::python_callback; %rename(register) ob::python_register; diff --git a/src/openbox_wrap.cc b/src/openbox_wrap.cc index 5e50bd01..75c9a376 100644 --- a/src/openbox_wrap.cc +++ b/src/openbox_wrap.cc @@ -777,11 +777,28 @@ static std::string SwigString_AsString(PyObject* o) { enum ActionType { Action_ButtonPress, Action_ButtonRelease, + Action_Click, + Action_DoubleClick, Action_EnterWindow, Action_LeaveWindow, Action_KeyPress, Action_MouseMotion }; + 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_Client, + Type_Root + }; #include @@ -2475,10 +2492,25 @@ _swigt__p_XUnmapEvent, static swig_const_info swig_const_table[] = { { SWIG_PY_INT, (char *)"Action_ButtonPress", (long) Action_ButtonPress, 0, 0, 0}, { SWIG_PY_INT, (char *)"Action_ButtonRelease", (long) Action_ButtonRelease, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"Action_Click", (long) Action_Click, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"Action_DoubleClick", (long) Action_DoubleClick, 0, 0, 0}, { SWIG_PY_INT, (char *)"Action_EnterWindow", (long) Action_EnterWindow, 0, 0, 0}, { SWIG_PY_INT, (char *)"Action_LeaveWindow", (long) Action_LeaveWindow, 0, 0, 0}, { SWIG_PY_INT, (char *)"Action_KeyPress", (long) Action_KeyPress, 0, 0, 0}, { SWIG_PY_INT, (char *)"Action_MouseMotion", (long) Action_MouseMotion, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"Type_Frame", (long) Type_Frame, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"Type_Titlebar", (long) Type_Titlebar, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"Type_Handle", (long) Type_Handle, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"Type_Plate", (long) Type_Plate, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"Type_Label", (long) Type_Label, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"Type_MaximizeButton", (long) Type_MaximizeButton, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"Type_CloseButton", (long) Type_CloseButton, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"Type_IconifyButton", (long) Type_IconifyButton, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"Type_StickyButton", (long) Type_StickyButton, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"Type_LeftGrip", (long) Type_LeftGrip, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"Type_RightGrip", (long) Type_RightGrip, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"Type_Client", (long) Type_Client, 0, 0, 0}, +{ SWIG_PY_INT, (char *)"Type_Root", (long) Type_Root, 0, 0, 0}, { SWIG_PY_INT, (char *)"Openbox_State_Starting", (long) ob::Openbox::State_Starting, 0, 0, 0}, { SWIG_PY_INT, (char *)"Openbox_State_Normal", (long) ob::Openbox::State_Normal, 0, 0, 0}, { SWIG_PY_INT, (char *)"Openbox_State_Exiting", (long) ob::Openbox::State_Exiting, 0, 0, 0}, diff --git a/src/python.cc b/src/python.cc index a00bc245..d44b2d48 100644 --- a/src/python.cc +++ b/src/python.cc @@ -55,14 +55,25 @@ bool python_unregister(int action, PyObject *callback) void python_callback(OBActions::ActionType action, Window window, OBWidget::WidgetType type, unsigned int state, - long d1, long d2) + long d1, long d2, long d3, long d4) { PyObject *arglist; PyObject *result; assert(action >= 0 && action < OBActions::NUM_ACTIONS); - arglist = Py_BuildValue("iliill", action, window, type, state, d1, d2); + if (d4 != LONG_MIN) + arglist = Py_BuildValue("iliillll", action, window, type, state, + d1, d2, d3, d4); + else if (d3 != LONG_MIN) + arglist = Py_BuildValue("iliilll", action, window, type, state, + d1, d2, d3); + else if (d2 != LONG_MIN) + arglist = Py_BuildValue("iliill", action, window, type, state, d1, d2); + else if (d1 != LONG_MIN) + arglist = Py_BuildValue("iliil", action, window, type, state, d1); + else + arglist = Py_BuildValue("ilii", action, window, type, state); FunctionList::iterator it, end = callbacks[action].end(); for (it = callbacks[action].begin(); it != end; ++it) { diff --git a/src/python.hh b/src/python.hh index 7fc178eb..6ca4e1c5 100644 --- a/src/python.hh +++ b/src/python.hh @@ -20,7 +20,8 @@ bool python_unregister(int action, PyObject *callback); void python_callback(OBActions::ActionType action, Window window, OBWidget::WidgetType type, unsigned int state, - long d1 = 0, long d2 = 0); + long d1 = LONG_MIN, long d2 = LONG_MIN, + long d3 = LONG_MIN, long d4 = LONG_MIN); } diff --git a/src/widget.hh b/src/widget.hh index 2af01e24..e51189d6 100644 --- a/src/widget.hh +++ b/src/widget.hh @@ -6,6 +6,7 @@ namespace ob { class OBWidget { public: + // update the enum in openbox.i to match this one enum WidgetType { Type_Frame, Type_Titlebar, -- 2.39.2