only reload the keys file if the contents have changed
Mark Tiefenbruck mark@fluxbox.org
5 files changed,
27 insertions(+),
42 deletions(-)
M
src/Keys.cc
→
src/Keys.cc
@@ -170,7 +170,9 @@ }
-Keys::Keys() : next_key(0) { } +Keys::Keys(): next_key(0) { + m_reloader.setReloadCmd(FbTk::RefCount<FbTk::Command<void> >(new FbTk::SimpleCommand<Keys>(*this, &Keys::reload))); +} Keys::~Keys() { ungrabKeys();@@ -255,27 +257,25 @@
/** Load and grab keys TODO: error checking - @return true on success else false */ -bool Keys::load(const char *filename) { +void Keys::reload() { // an intentionally empty file will still have one root mapping bool firstload = m_map.empty(); - if (!filename) { + if (m_filename.empty()) { if (firstload) loadDefaults(); - return false; + return; } FbTk::App::instance()->sync(false); // open the file - ifstream infile(filename); + ifstream infile(m_filename.c_str()); if (!infile) { if (firstload) loadDefaults(); - - return false; // failed to open file + return; // failed to open file } // free memory of previous grabs@@ -301,9 +301,7 @@ current_line<<"): "<<linebuffer<<endl;
} } // end while eof - m_filename = filename; keyMode("default"); - return true; } /**@@ -319,19 +317,6 @@ addBinding("OnDesktop Mouse1 :HideMenus");
addBinding("OnDesktop Mouse2 :WorkspaceMenu"); addBinding("OnDesktop Mouse3 :RootMenu"); keyMode("default"); -} - -bool Keys::save(const char *filename) const { - //!! - //!! TODO: fix keybinding saving - //!! (we probably need to save key actions - //!! as strings instead of creating new Commands) - - // open file for writing - // ofstream outfile(filename); - // if (!outfile) - return false; - // return true; } bool Keys::addBinding(const string &linebuffer) {@@ -583,8 +568,10 @@ /**
deletes the tree and load configuration returns true on success else false */ -bool Keys::reconfigure(const char *filename) { - return load(filename); +void Keys::reconfigure() { + m_filename = FbTk::StringUtil::expandFilename(Fluxbox::instance()->getKeysFilename()); + m_reloader.setMainFile(m_filename); + m_reloader.checkReload(); } void Keys::keyMode(const string& keyMode) {
M
src/Keys.hh
→
src/Keys.hh
@@ -23,6 +23,7 @@ #ifndef KEYS_HH
#define KEYS_HH #include "FbTk/NotCopyable.hh" +#include "FbTk/AutoReloadHelper.hh" #include <X11/Xlib.h> #include <string>@@ -57,17 +58,6 @@ explicit Keys();
/// destructor ~Keys(); - /** - Load configuration from file - @return true on success, else false - */ - bool load(const char *filename = 0); - /** - Save keybindings to a file - Note: the file will be overwritten - @return true on success, else false - */ - bool save(const char *filename = 0) const; /// bind a key action from a string /// @return false on failure bool addBinding(const std::string &binding);@@ -83,12 +73,12 @@ void registerWindow(Window win, FbTk::EventHandler &handler, int context);
/// unregister window void unregisterWindow(Window win); + const std::string& filename() const { return m_filename; } /** Reload configuration from filename @return true on success, else false */ - bool reconfigure(const char *filename); - const std::string& filename() const { return m_filename; } + void reconfigure(); void keyMode(const std::string& keyMode); private: class t_key; // helper class to build a 'keytree'@@ -104,13 +94,18 @@ void grabButton(unsigned int button, unsigned int mod, int context);
void ungrabButtons(); void grabWindow(Window win); - // Load default keybindings for when there are errors loading the initial one + /** + Load configuration from file + */ + void reload(); + // Load default keybindings for when there are errors loading the keys file void loadDefaults(); void setKeyMode(t_key *keyMode); // member variables std::string m_filename; + FbTk::AutoReloadHelper m_reloader; t_key *m_keylist; keyspace_t m_map;
M
src/fluxbox.cc
→
src/fluxbox.cc
@@ -307,7 +307,7 @@
// Create keybindings handler and load keys file // Note: this needs to be done before creating screens m_key.reset(new Keys); - m_key->load(StringUtil::expandFilename(*m_rc_keyfile).c_str()); + m_key->reconfigure(); vector<int> screens; int i;@@ -751,7 +751,7 @@ || e->xmapping.request == MappingModifier) {
XRefreshKeyboardMapping(&e->xmapping); FbTk::KeyUtil::instance().init(); // reinitialise the key utils // reconfigure keys (if the mapping changes, they don't otherwise update - m_key->reconfigure(StringUtil::expandFilename(*m_rc_keyfile).c_str()); + m_key->reconfigure(); } break; case CreateNotify:@@ -1443,7 +1443,7 @@ // reconfigure all screens
for_each(m_screen_list.begin(), m_screen_list.end(), mem_fun(&BScreen::reconfigure)); //reconfigure keys - m_key->reconfigure(StringUtil::expandFilename(*m_rc_keyfile).c_str()); + m_key->reconfigure(); // and atomhandlers for (AtomHandlerContainerIt it= m_atomhandler.begin();
M
src/fluxbox.hh
→
src/fluxbox.hh
@@ -120,6 +120,7 @@
const std::string &getMenuFilename() const { return *m_rc_menufile; } const std::string &getSlitlistFilename() const { return *m_rc_slitlistfile; } const std::string &getAppsFilename() const { return *m_rc_appsfile; } + const std::string &getKeysFilename() const { return *m_rc_keyfile; } int colorsPerChannel() const { return *m_rc_colors_per_channel; } int getTabsPadding() const { return *m_rc_tabs_padding; }