From 1ecc9ef56e74e6eea3d6cecb77a76562b8e103d7 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 c74cce6..4db6af7 100644 --- a/src/FbCommands.cc +++ b/src/FbCommands.cc @@ -448,7 +448,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() { @@ -295,8 +299,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; @@ -304,12 +309,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(); @@ -619,16 +624,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 43f4445..2dc1c10 100644 --- a/src/Keys.hh +++ b/src/Keys.hh @@ -23,6 +23,7 @@ #define KEYS_HH #include "FbTk/NotCopyable.hh" +#include "FbTk/Signal.hh" #include #include @@ -35,7 +36,7 @@ namespace FbTk { class AutoReloadHelper; } -class Keys:private FbTk::NotCopyable { +class Keys: private FbTk::NotCopyable, private FbTk::SignalTracker { public: // contexts for events @@ -79,7 +80,6 @@ public: /// grab keys again when keymap changes void regrab(); - const std::string& filename() const { return m_filename; } /** Load configuration from file */ @@ -87,7 +87,6 @@ public: /** Reload configuration if keys file has changed */ - void reconfigure(); void keyMode(const std::string& keyMode); bool inKeychain() const { return saved_keymode != 0; } @@ -112,7 +111,6 @@ private: // member variables - std::string m_filename; FbTk::AutoReloadHelper* m_reloader; t_key *m_keylist; keyspace_t m_map; diff --git a/src/fluxbox.cc b/src/fluxbox.cc index 5032a32..4f41e4d 100644 --- a/src/fluxbox.cc +++ b/src/fluxbox.cc @@ -356,7 +356,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; @@ -1194,7 +1193,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