all repos — openbox @ 06388d73b75d985ab10586bd116de7fac4ea2b8e

openbox fork - make it a bit more like ryudo

restart works
Dana Jansens danakj@orodu.net
commit

06388d73b75d985ab10586bd116de7fac4ea2b8e

parent

a9a5f0d7510be5dbf8ae1db99e6c1c01035503d9

M otk/otk_wrap.ccotk/otk_wrap.cc

@@ -12800,7 +12800,7 @@ }else {

SWIG_exception(SWIG_TypeError, "string expected"); } } - result = basename((std::string const &)*arg1); + result = otk::basename((std::string const &)*arg1); { resultobj = PyString_FromString((&result)->c_str());
M otk/util.ccotk/util.cc

@@ -101,14 +101,12 @@ tmp.insert(tmp.begin(), '-');

return tmp; } -} - -#ifndef HAVE_BASENAME string basename (const string& path) { string::size_type slash = path.rfind('/'); if (slash == string::npos) return path; return path.substr(slash+1); } -#endif // HAVE_BASENAME + +}
M otk/util.hhotk/util.hh

@@ -40,10 +40,9 @@ { return itostring((unsigned long) i); }

inline std::string itostring(int i) { return itostring((long) i); } -} -#ifndef HAVE_BASENAME std::string basename(const std::string& path); -#endif + +} #endif
M scripts/builtins.pyscripts/builtins.py

@@ -61,6 +61,9 @@

def execute(bin, screen = 0): Openbox_execute(openbox, screen, bin) +def restart(data): + Openbox_restart(openbox, "") + def toggle_shade(data): print "toggle_shade"
M src/openbox.ccsrc/openbox.cc

@@ -88,8 +88,9 @@

Openbox::instance = this; _displayreq = (char*) 0; - _argv0 = argv[0]; - _doshutdown = false; + _argv = argv; + _shutdown = false; + _restart = false; _rcfilepath = otk::expandTilde("~/.openbox/rc3"); _scriptfilepath = otk::expandTilde("~/.openbox/user.py"); _focused_client = 0;

@@ -172,6 +173,8 @@ Openbox::~Openbox()

{ _state = State_Exiting; // time to kill everything + int first_screen = _screens.front()->number(); + std::for_each(_screens.begin(), _screens.end(), otk::PointerAssassin()); delete _bindings;

@@ -188,6 +191,20 @@ // this tends to block.. i honestly am not sure why. causing an x error in

// the shutdown process unblocks it. blackbox simply did a ::exit(0), so // all im gunna do is the same. //otk::OBDisplay::destroy(); + + if (_restart) { + if (!_restart_prog.empty()) { + const std::string &dstr = + otk::OBDisplay::screenInfo(first_screen)->displayString(); + putenv(const_cast<char *>(dstr.c_str())); + execlp(_restart_prog.c_str(), _restart_prog.c_str(), NULL); + perror(_restart_prog.c_str()); + } + + // fall back in case the above execlp doesn't work + execvp(_argv[0], _argv); + execvp(otk::basename(_argv[0]).c_str(), _argv); + } }

@@ -256,7 +273,7 @@ -rc <string> use alternate resource file.\n\

-menu <string> use alternate menu file.\n\ -script <string> use alternate startup script file.\n\ -version display version and exit.\n\ - -help display this help text and exit.\n\n"), _argv0); + -help display this help text and exit.\n\n"), _argv[0]); printf(_("Compile time options:\n\ Debugging: %s\n\

@@ -285,10 +302,10 @@

void Openbox::eventLoop() { - while (!_doshutdown) { + while (!_shutdown) { + _timermanager.fire(); dispatchEvents(); // from OtkEventDispatcher XFlush(otk::OBDisplay::display); // flush here before we go wait for timers - _timermanager.fire(); } }
M src/openbox.hhsrc/openbox.hh

@@ -91,8 +91,8 @@ */

std::string _scriptfilepath; //! The display requested by the user, or null to use the DISPLAY env var char *_displayreq; - //! The value of argv[0], i.e. how this application was executed - char *_argv0; + //! The value of argv, i.e. how this application was executed + char **_argv; //! A list of all managed clients ClientMap _clients;

@@ -131,7 +131,15 @@ //! Mouse cursors used throughout Openbox

Cursors _cursors; //! When set to true, the Openbox::eventLoop function will stop and return - bool _doshutdown; + bool _shutdown; + + //! When set to true, and Openbox is about to exit, it will spawn a new + //! process + bool _restart; + + //! If this contains anything, a restart will try to execute the program in + //! this variable, and will fallback to reexec'ing itself if that fails + std::string _restart_prog; //! The client with input focus /*!

@@ -239,7 +247,11 @@ /*!

Causes the Openbox::eventLoop function to stop looping, so that the window manager can be destroyed. */ - inline void shutdown() { _doshutdown = true; } + inline void shutdown() { _shutdown = true; } + + inline void restart(const std::string &bin = "") { + _shutdown = true; _restart = true; _restart_prog = bin; + } //! Executes a command on a screen void execute(int screen, const std::string &bin);
M src/openbox_wrap.ccsrc/openbox_wrap.cc

@@ -1309,6 +1309,36 @@ return NULL;

} +static PyObject *_wrap_Openbox_restart(PyObject *self, PyObject *args) { + PyObject *resultobj; + ob::Openbox *arg1 = (ob::Openbox *) 0 ; + std::string const &arg2_defvalue = "" ; + std::string *arg2 = (std::string *) &arg2_defvalue ; + std::string temp2 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + + if(!PyArg_ParseTuple(args,(char *)"O|O:Openbox_restart",&obj0,&obj1)) goto fail; + if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_ob__Openbox,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail; + if (obj1) { + { + if (PyString_Check(obj1)) { + temp2 = std::string(PyString_AsString(obj1)); + arg2 = &temp2; + }else { + SWIG_exception(SWIG_TypeError, "string expected"); + } + } + } + (arg1)->restart((std::string const &)*arg2); + + Py_INCREF(Py_None); resultobj = Py_None; + return resultobj; + fail: + return NULL; +} + + static PyObject *_wrap_Openbox_execute(PyObject *self, PyObject *args) { PyObject *resultobj; ob::Openbox *arg1 = (ob::Openbox *) 0 ;

@@ -1371,6 +1401,23 @@

if(!PyArg_ParseTuple(args,(char *)"O:OBScreen_clientCount",&obj0)) goto fail; if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_ob__OBScreen,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail; result = (int)ob_OBScreen_clientCount((ob::OBScreen const *)arg1); + + resultobj = PyInt_FromLong((long)result); + return resultobj; + fail: + return NULL; +} + + +static PyObject *_wrap_OBScreen_number(PyObject *self, PyObject *args) { + PyObject *resultobj; + ob::OBScreen *arg1 = (ob::OBScreen *) 0 ; + int result; + PyObject * obj0 = 0 ; + + if(!PyArg_ParseTuple(args,(char *)"O:OBScreen_number",&obj0)) goto fail; + if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_ob__OBScreen,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail; + result = (int)((ob::OBScreen const *)arg1)->number(); resultobj = PyInt_FromLong((long)result); return resultobj;

@@ -2626,10 +2673,12 @@ { (char *)"Openbox_focusedClient", _wrap_Openbox_focusedClient, METH_VARARGS },

{ (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_restart", _wrap_Openbox_restart, 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 }, + { (char *)"OBScreen_number", _wrap_OBScreen_number, METH_VARARGS }, { (char *)"OBScreen_managed", _wrap_OBScreen_managed, METH_VARARGS }, { (char *)"OBScreen_imageControl", _wrap_OBScreen_imageControl, METH_VARARGS }, { (char *)"OBScreen_area", _wrap_OBScreen_area, METH_VARARGS },
M src/screen.hhsrc/screen.hh

@@ -119,6 +119,8 @@ //! Destroys the OBScreen object

virtual ~OBScreen(); #endif + inline int number() const { return _number; } + //! Returns if the screen was successfully managed /*! If this is false, then the screen should be deleted and should NOT be