From 496d73d89994d868f5dc45a5ea6cefe40a74f148 Mon Sep 17 00:00:00 2001 From: akir Date: Mon, 18 Oct 2004 01:26:54 +0000 Subject: rewritten fluxbox-restart code, all destructors are called before the new program is started. the former method didnt do that. --- src/fluxbox.cc | 16 ++++++++-------- src/fluxbox.hh | 34 +++++++++++++++++++++------------- src/main.cc | 34 +++++++++++++++++++++++++--------- 3 files changed, 54 insertions(+), 30 deletions(-) diff --git a/src/fluxbox.cc b/src/fluxbox.cc index 3563c8c..cfceaf7 100644 --- a/src/fluxbox.cc +++ b/src/fluxbox.cc @@ -22,7 +22,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: fluxbox.cc,v 1.258 2004/10/10 16:06:23 akir Exp $ +// $Id: fluxbox.cc,v 1.259 2004/10/18 01:26:54 akir Exp $ #include "fluxbox.hh" @@ -238,6 +238,7 @@ Fluxbox::Fluxbox(int argc, char **argv, const char *dpy_name, const char *rcfile m_rc_file(rcfilename ? rcfilename : ""), m_argv(argv), m_argc(argc), m_starting(true), + m_restarting(false), m_shutdown(false), m_server_grabs(0), m_randr_event_type(0), @@ -457,6 +458,7 @@ Fluxbox::Fluxbox(int argc, char **argv, const char *dpy_name, const char *rcfile Fluxbox::~Fluxbox() { + // destroy toolbars while (!m_toolbars.empty()) { delete m_toolbars.back(); @@ -1357,14 +1359,11 @@ void Fluxbox::removeGroupSearch(Window window) { void Fluxbox::restart(const char *prog) { shutdown(); + m_restarting = true; + if (prog) { - execlp(prog, prog, 0); - perror(prog); + m_restart_argument = prog; } - - // fall back in case the above execlp doesn't work - execvp(m_argv[0], m_argv); - execvp(StringUtil::basename(m_argv[0]).c_str(), m_argv); } /// prepares fluxbox for a shutdown @@ -1377,7 +1376,8 @@ void Fluxbox::shutdown() { XSetInputFocus(FbTk::App::instance()->display(), PointerRoot, None, CurrentTime); //send shutdown to all screens - for_each(m_screen_list.begin(), m_screen_list.end(), mem_fun(&BScreen::shutdown)); + for_each(m_screen_list.begin(), + m_screen_list.end(), mem_fun(&BScreen::shutdown)); sync(false); diff --git a/src/fluxbox.hh b/src/fluxbox.hh index 0b67b44..021619b 100644 --- a/src/fluxbox.hh +++ b/src/fluxbox.hh @@ -22,7 +22,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: fluxbox.hh,v 1.92 2004/10/10 16:06:24 akir Exp $ +// $Id: fluxbox.hh,v 1.93 2004/10/18 01:26:54 akir Exp $ #ifndef FLUXBOX_HH #define FLUXBOX_HH @@ -83,7 +83,7 @@ public: Fluxbox(int argc, char **argv, const char * dpy_name= 0, const char *rcfilename = 0); virtual ~Fluxbox(); - + static Fluxbox *instance() { return s_singleton; } /// main event loop void eventLoop(); @@ -98,7 +98,7 @@ public: WinClient *searchWindow(Window); inline WinClient *getFocusedWindow() { return m_focused_window; } - + BScreen *searchScreen(Window w); inline unsigned int getDoubleClickInterval() const { return *m_rc_double_click_interval; } @@ -138,7 +138,7 @@ public: inline int getNum() const { return m_num; } Layer &operator=(int num) { m_num = num; return *this; } - + private: int m_num; }; @@ -193,17 +193,20 @@ public: void checkMenu(); void hideExtraMenus(BScreen &screen); - + /// handle any system signal sent to the application void handleSignal(int signum); void update(FbTk::Subject *changed); void attachSignals(FluxboxWindow &win); void attachSignals(WinClient &winclient); - + void timed_reconfigure(); bool isStartup() const { return m_starting; } + bool isRestarting() const { return m_restarting; } + + const std::string &getRestartArgument() const { return m_restart_argument; } /// get screen from number BScreen *findScreen(int num); @@ -221,6 +224,7 @@ public: // screen we are watching for modifier changes BScreen *watchingScreen() { return m_watching_screen; } const XEvent &lastEvent() const { return m_last_event; } + private: typedef struct MenuTimestamp { @@ -232,24 +236,24 @@ private: std::string getRcFilename(); void load_rc(); - void reload_rc(); + void real_rereadMenu(); void real_reconfigure(); void handleEvent(XEvent *xe); - + void setupConfigFiles(); void handleButtonEvent(XButtonEvent &be); void handleUnmapNotify(XUnmapEvent &ue); void handleClientMessage(XClientMessageEvent &ce); void handleKeyEvent(XKeyEvent &ke); void setTitlebar(std::vector& dir, const char *arg); - + std::auto_ptr m_fbatoms; FbTk::ResourceManager m_resourcemanager, &m_screen_rm; - + //--- Resources FbTk::Resource m_rc_tabs, m_rc_ignoreborder; @@ -258,11 +262,11 @@ private: m_rc_double_click_interval, m_rc_update_delay_time, m_rc_tabs_padding, m_rc_focused_tab_min_width; - FbTk::Resource m_rc_stylefile, + FbTk::Resource m_rc_stylefile, m_rc_menufile, m_rc_keyfile, m_rc_slitlistfile, m_rc_groupfile; - + FbTk::Resource m_rc_titlebar_left, m_rc_titlebar_right; FbTk::Resource m_rc_tabs_attach_area; FbTk::Resource m_rc_cache_life, m_rc_cache_max; @@ -277,7 +281,7 @@ private: // The group leader (which may not be mapped, so may not have a WinClient) // will have it's window being the group index std::multimap m_group_search; - + std::list m_menu_timestamps; typedef std::list ScreenList; ScreenList m_screen_list; @@ -297,6 +301,9 @@ private: std::string m_rc_file; ///< resource filename char **m_argv; int m_argc; + + std::string m_restart_argument; ///< what to restart + XEvent m_last_event; FbTk::Timer m_reconfig_timer; ///< when we execute reconfig command we must wait at least to next event round @@ -315,6 +322,7 @@ private: Toolbars m_toolbars; bool m_starting; + bool m_restarting; bool m_shutdown; int m_server_grabs; int m_randr_event_type; ///< the type number of randr event diff --git a/src/main.cc b/src/main.cc index b7fb949..137d1de 100644 --- a/src/main.cc +++ b/src/main.cc @@ -20,7 +20,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: main.cc,v 1.32 2004/10/11 22:48:35 rathnor Exp $ +// $Id: main.cc,v 1.33 2004/10/18 01:26:54 akir Exp $ #include "fluxbox.hh" #include "version.h" @@ -28,6 +28,7 @@ #include "FbTk/Theme.hh" #include "FbTk/I18n.hh" +#include "FbTk/StringUtil.hh" #ifdef HAVE_CONFIG_H #include "config.h" @@ -73,10 +74,10 @@ void showInfo(ostream &ostr) { #endif // __fluxbox_compiler_version ostr<eventLoop(); - exitcode = EXIT_SUCCESS; + exitcode = EXIT_SUCCESS; } catch (std::out_of_range &oor) { cerr<<"Fluxbox: "<<_FBTEXT(main, ErrorOutOfRange, "Out of range", "Error message")<<": "<isRestarting(); + const std::string restart_argument(fluxbox->getRestartArgument()); + // destroy fluxbox fluxbox.reset(0); @@ -280,5 +285,16 @@ int main(int argc, char **argv) { if (errbuf != 0) cerr.rdbuf(errbuf); + if (restarting) { + if (restart_argument.c_str()) { + execlp(restart_argument.c_str(), restart_argument.c_str(), 0); + perror(restart_argument.c_str()); + } + + // fall back in case the above execlp doesn't work + execvp(argv[0], argv); + execvp(FbTk::StringUtil::basename(argv[0]).c_str(), argv); + } + return exitcode; } -- cgit v0.11.2