]> Dogcows Code - chaz/openbox/commitdiff
restart works
authorDana Jansens <danakj@orodu.net>
Fri, 3 Jan 2003 22:06:08 +0000 (22:06 +0000)
committerDana Jansens <danakj@orodu.net>
Fri, 3 Jan 2003 22:06:08 +0000 (22:06 +0000)
otk/otk_wrap.cc
otk/util.cc
otk/util.hh
scripts/builtins.py
src/openbox.cc
src/openbox.hh
src/openbox_wrap.cc
src/screen.hh

index f5562ad83242553f37d216b830c5ad51a167ed92..7373d9f8cc2c69cd3e5fb6e31a7c88d7d2eb3d9d 100644 (file)
@@ -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());
index 91d6f13a5471f98b69c71744216a03f3c638c571..ebca51d51ef0f6fe38c4a4ee4fcbebdaa4c3fe62 100644 (file)
@@ -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
+
+}
 
index aac92560ed64d42158208d30ef55942f348b7cfb..2664c1faa78d8674ac782d9887a4785d3d3450d4 100644 (file)
@@ -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
index 29079126809e6922db6fc987d57ae4e6d57b4abe..ed8f66ecc60d8846acf40883792ca3bb12060ef3 100644 (file)
@@ -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"
 
index 71eb4d9b3aefc801a5df940b9cc737af6b741778..6ed00a2c84bbff5d4cd377af961d69bdf05a0999 100644 (file)
@@ -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();
   }
 }
 
index a141ae2b3f5ba1603a5678bfb8357bc3a7b0abeb..80b20a168e70eaf59e013aa63a315849f3372983 100644 (file)
@@ -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);
index ecc21e32741cff7c2210a400dbd58eb56d192fc1..583e9d40727b875e944f49dcfb19c44dc9dc561e 100644 (file)
@@ -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 },
index 5af79366acf764a3d60dc703bf60b1f43d97fcc5..fa28676498fb7409a06aaec7fc5bb322ce6e4734 100644 (file)
@@ -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
This page took 0.039927 seconds and 4 git commands to generate.