summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--otk/otk_wrap.cc2
-rw-r--r--otk/util.cc6
-rw-r--r--otk/util.hh5
-rw-r--r--scripts/builtins.py3
-rw-r--r--src/openbox.cc27
-rw-r--r--src/openbox.hh20
-rw-r--r--src/openbox_wrap.cc49
-rw-r--r--src/screen.hh2
8 files changed, 97 insertions, 17 deletions
diff --git a/otk/otk_wrap.cc b/otk/otk_wrap.cc
index f5562ad8..7373d9f8 100644
--- a/otk/otk_wrap.cc
+++ b/otk/otk_wrap.cc
@@ -12800,7 +12800,7 @@ static PyObject *_wrap_basename(PyObject *self, PyObject *args) {
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());
diff --git a/otk/util.cc b/otk/util.cc
index 91d6f13a..ebca51d5 100644
--- a/otk/util.cc
+++ b/otk/util.cc
@@ -101,14 +101,12 @@ string itostring(long i) {
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
+
+}
diff --git a/otk/util.hh b/otk/util.hh
index aac92560..2664c1fa 100644
--- a/otk/util.hh
+++ b/otk/util.hh
@@ -40,10 +40,9 @@ inline std::string itostring(unsigned int i)
inline std::string itostring(int i)
{ return itostring((long) i); }
-}
-#ifndef HAVE_BASENAME
std::string basename(const std::string& path);
-#endif
+
+}
#endif
diff --git a/scripts/builtins.py b/scripts/builtins.py
index 29079126..ed8f66ec 100644
--- a/scripts/builtins.py
+++ b/scripts/builtins.py
@@ -61,6 +61,9 @@ def resize(data):
def execute(bin, screen = 0):
Openbox_execute(openbox, screen, bin)
+def restart(data):
+ Openbox_restart(openbox, "")
+
def toggle_shade(data):
print "toggle_shade"
diff --git a/src/openbox.cc b/src/openbox.cc
index 71eb4d9b..6ed00a2c 100644
--- a/src/openbox.cc
+++ b/src/openbox.cc
@@ -88,8 +88,9 @@ Openbox::Openbox(int argc, char **argv)
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 @@ Openbox::~Openbox()
// 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 @@ void Openbox::showHelp()
-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::showHelp()
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();
}
}
diff --git a/src/openbox.hh b/src/openbox.hh
index a141ae2b..80b20a16 100644
--- a/src/openbox.hh
+++ b/src/openbox.hh
@@ -91,8 +91,8 @@ private:
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 @@ private:
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 @@ public:
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);
diff --git a/src/openbox_wrap.cc b/src/openbox_wrap.cc
index ecc21e32..583e9d40 100644
--- a/src/openbox_wrap.cc
+++ b/src/openbox_wrap.cc
@@ -1309,6 +1309,36 @@ static PyObject *_wrap_Openbox_shutdown(PyObject *self, PyObject *args) {
}
+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 ;
@@ -1379,6 +1409,23 @@ static PyObject *_wrap_OBScreen_clientCount(PyObject *self, PyObject *args) {
}
+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;
+ fail:
+ return NULL;
+}
+
+
static PyObject *_wrap_OBScreen_managed(PyObject *self, PyObject *args) {
PyObject *resultobj;
ob::OBScreen *arg1 = (ob::OBScreen *) 0 ;
@@ -2626,10 +2673,12 @@ 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_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 },
diff --git a/src/screen.hh b/src/screen.hh
index 5af79366..fa286764 100644
--- a/src/screen.hh
+++ b/src/screen.hh
@@ -119,6 +119,8 @@ public:
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