From ec8876890c0e03c5775906c8095db3b6f76cbdce Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Sun, 10 Jul 2011 16:10:39 +0200 Subject: Attach a modifiedSig handler to the session.keyFile resource --- src/FbCommands.cc | 2 +- src/Keys.cc | 21 ++++++++------------- src/Keys.hh | 6 ++---- src/fluxbox.cc | 2 -- src/fluxbox.hh | 2 +- 5 files changed, 12 insertions(+), 21 deletions(-) diff --git a/src/FbCommands.cc b/src/FbCommands.cc index d52084e..b7bd309 100644 --- a/src/FbCommands.cc +++ b/src/FbCommands.cc @@ -460,7 +460,7 @@ BindKeyCmd::BindKeyCmd(const string &keybind):m_keybind(keybind) { } void BindKeyCmd::execute() { if (Fluxbox::instance()->keys() != 0) { if (Fluxbox::instance()->keys()->addBinding(m_keybind)) { - ofstream ofile(Fluxbox::instance()->keys()->filename().c_str(), ios::app); + ofstream ofile(Fluxbox::instance()->getKeysResource()->c_str(), ios::app); if (!ofile) return; ofile<setReloadCmd(FbTk::RefCount >(new FbTk::SimpleCommand(*this, &Keys::reload))); + m_reloader->setMainFile(*Fluxbox::instance()->getKeysResource()); + join(Fluxbox::instance()->getKeysResource().modifiedSig(), + MemFun(*m_reloader, &FbTk::AutoReloadHelper::setMainFile)); } Keys::~Keys() { @@ -282,8 +286,9 @@ void Keys::grabWindow(Window win) { void Keys::reload() { // an intentionally empty file will still have one root mapping bool firstload = m_map.empty(); + const std::string filename = FbTk::StringUtil::expandFilename(*Fluxbox::instance()->getKeysResource()); - if (m_filename.empty()) { + if (filename.empty()) { if (firstload) loadDefaults(); return; @@ -291,12 +296,12 @@ void Keys::reload() { FbTk::App::instance()->sync(false); - if (! FbTk::FileUtil::isRegularFile(m_filename.c_str())) { + if (! FbTk::FileUtil::isRegularFile(filename.c_str())) { return; } // open the file - ifstream infile(m_filename.c_str()); + ifstream infile(filename.c_str()); if (!infile) { if (firstload) loadDefaults(); @@ -607,16 +612,6 @@ void Keys::unregisterWindow(Window win) { m_window_map.erase(win); } -/** - deletes the tree and load configuration - returns true on success else false -*/ -void Keys::reconfigure() { - m_filename = FbTk::StringUtil::expandFilename(Fluxbox::instance()->getKeysFilename()); - m_reloader->setMainFile(m_filename); - m_reloader->checkReload(); -} - void Keys::regrab() { setKeyMode(m_keylist); } diff --git a/src/Keys.hh b/src/Keys.hh index 7a6b3b8..076387b 100644 --- a/src/Keys.hh +++ b/src/Keys.hh @@ -24,6 +24,7 @@ #include "FbTk/NotCopyable.hh" #include "FbTk/RefCount.hh" +#include "FbTk/Signal.hh" #include #include @@ -36,7 +37,7 @@ namespace FbTk { class AutoReloadHelper; } -class Keys:private FbTk::NotCopyable { +class Keys: private FbTk::NotCopyable, private FbTk::SignalTracker { public: // contexts for events @@ -80,7 +81,6 @@ public: /// grab keys again when keymap changes void regrab(); - const std::string& filename() const { return m_filename; } /** Load configuration from file */ @@ -88,7 +88,6 @@ public: /** Reload configuration if keys file has changed */ - void reconfigure(); void keyMode(const std::string& keyMode); bool inKeychain() const { return saved_keymode != 0; } @@ -114,7 +113,6 @@ private: // member variables - std::string m_filename; FbTk::AutoReloadHelper* m_reloader; RefKey m_keylist; keyspace_t m_map; diff --git a/src/fluxbox.cc b/src/fluxbox.cc index 1cf97a4..b20b589 100644 --- a/src/fluxbox.cc +++ b/src/fluxbox.cc @@ -354,7 +354,6 @@ Fluxbox::Fluxbox(int argc, char **argv, // Create keybindings handler and load keys file // Note: this needs to be done before creating screens m_key.reset(new Keys); - m_key->reconfigure(); vector screens; int i; @@ -1193,7 +1192,6 @@ void Fluxbox::reconfigure() { void Fluxbox::real_reconfigure() { STLUtil::forAll(m_screen_list, mem_fun(&BScreen::reconfigure)); - m_key->reconfigure(); } BScreen *Fluxbox::findScreen(int id) { diff --git a/src/fluxbox.hh b/src/fluxbox.hh index f8a27bc..3e9e8d6 100644 --- a/src/fluxbox.hh +++ b/src/fluxbox.hh @@ -121,8 +121,8 @@ public: const std::string &getStyleOverlayFilename() const { return *m_rc_styleoverlayfile; } const std::string &getMenuFilename() const { return *m_rc_menufile; } - const std::string &getKeysFilename() const { return *m_rc_keyfile; } FbTk::StringResource &getAppsResource() { return m_rc_appsfile; } + FbTk::StringResource &getKeysResource() { return m_rc_keyfile; } int colorsPerChannel() const { return *m_rc_colors_per_channel; } int getTabsPadding() const { return *m_rc_tabs_padding; } -- cgit v0.11.2