From 105bd729e8341bacce630f2780f0a9a5a0102526 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Fri, 3 Jan 2003 16:06:10 +0000 Subject: [PATCH] provide capabilities to execute a command --- src/openbox.cc | 21 +++++++++++++++++++++ src/openbox.hh | 3 +++ src/openbox_wrap.cc | 29 +++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/src/openbox.cc b/src/openbox.cc index 655fe0d5..4d2f1024 100644 --- a/src/openbox.cc +++ b/src/openbox.cc @@ -326,5 +326,26 @@ void Openbox::setFocusedClient(OBClient *c) } } +void Openbox::execute(int screen, const std::string &bin) +{ +#ifdef __EMX__ + // XXX: whats this for? windows? + spawnlp(P_NOWAIT, "cmd.exe", "cmd.exe", "/c", bin.c_str(), NULL); +#else // __EMX__ + if (screen >= ScreenCount(otk::OBDisplay::display)) + screen = 0; + const std::string &dstr = + otk::OBDisplay::screenInfo(screen)->displayString(); + + if (! fork()) { + setsid(); + int ret = putenv(const_cast(dstr.c_str())); + assert(ret != -1); + ret = execl("/bin/sh", "/bin/sh", "-c", bin.c_str(), NULL); + exit(ret); + } +#endif // __EMX__ +} + } diff --git a/src/openbox.hh b/src/openbox.hh index 1a537dcd..a141ae2b 100644 --- a/src/openbox.hh +++ b/src/openbox.hh @@ -240,6 +240,9 @@ public: manager can be destroyed. */ inline void shutdown() { _doshutdown = true; } + + //! Executes a command on a screen + void execute(int screen, const std::string &bin); }; } diff --git a/src/openbox_wrap.cc b/src/openbox_wrap.cc index 90cd3a97..bbdbaa86 100644 --- a/src/openbox_wrap.cc +++ b/src/openbox_wrap.cc @@ -1309,6 +1309,34 @@ static PyObject *_wrap_Openbox_shutdown(PyObject *self, PyObject *args) { } +static PyObject *_wrap_Openbox_execute(PyObject *self, PyObject *args) { + PyObject *resultobj; + ob::Openbox *arg1 = (ob::Openbox *) 0 ; + int arg2 ; + std::string *arg3 = 0 ; + std::string temp3 ; + PyObject * obj0 = 0 ; + PyObject * obj2 = 0 ; + + if(!PyArg_ParseTuple(args,(char *)"OiO:Openbox_execute",&obj0,&arg2,&obj2)) goto fail; + if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_ob__Openbox,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail; + { + if (PyString_Check(obj2)) { + temp3 = std::string(PyString_AsString(obj2)); + arg3 = &temp3; + }else { + SWIG_exception(SWIG_TypeError, "string expected"); + } + } + (arg1)->execute(arg2,(std::string const &)*arg3); + + Py_INCREF(Py_None); resultobj = Py_None; + return resultobj; + fail: + return NULL; +} + + static PyObject * Openbox_swigregister(PyObject *self, PyObject *args) { PyObject *obj; if (!PyArg_ParseTuple(args,(char*)"O", &obj)) return NULL; @@ -2604,6 +2632,7 @@ static PyMethodDef SwigMethods[] = { { (char *)"Openbox_setFocusedClient", _wrap_Openbox_setFocusedClient, METH_VARARGS }, { (char *)"Openbox_focusedScreen", _wrap_Openbox_focusedScreen, METH_VARARGS }, { (char *)"Openbox_shutdown", _wrap_Openbox_shutdown, METH_VARARGS }, + { (char *)"Openbox_execute", _wrap_Openbox_execute, METH_VARARGS }, { (char *)"Openbox_swigregister", Openbox_swigregister, METH_VARARGS }, { (char *)"OBScreen_client", _wrap_OBScreen_client, METH_VARARGS }, { (char *)"OBScreen_clientCount", _wrap_OBScreen_clientCount, METH_VARARGS }, -- 2.39.2