only reload the keys file if the contents have changed
This commit is contained in:
parent
a56492c0d5
commit
dcdc783324
5 changed files with 27 additions and 42 deletions
|
@ -1,6 +1,8 @@
|
|||
(Format: Year/Month/Day)
|
||||
Changes for 1.1
|
||||
*08/05/12:
|
||||
* Only reload the keys file if the contents have changed (Mark)
|
||||
Keys.cc/hh fluxbox.cc/hh
|
||||
* Modifying the apps file no longer requires a reconfigure (Mark)
|
||||
Remember.cc/hh
|
||||
*08/05/09:
|
||||
|
|
37
src/Keys.cc
37
src/Keys.cc
|
@ -170,7 +170,9 @@ Keys::t_key::~t_key() {
|
|||
|
||||
|
||||
|
||||
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 @@ void Keys::grabWindow(Window win) {
|
|||
/**
|
||||
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 @@ bool Keys::load(const char *filename) {
|
|||
}
|
||||
} // end while eof
|
||||
|
||||
m_filename = filename;
|
||||
keyMode("default");
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -321,19 +319,6 @@ void Keys::loadDefaults() {
|
|||
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) {
|
||||
|
||||
vector<string> val;
|
||||
|
@ -583,8 +568,10 @@ void Keys::unregisterWindow(Window win) {
|
|||
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) {
|
||||
|
|
23
src/Keys.hh
23
src/Keys.hh
|
@ -23,6 +23,7 @@
|
|||
#define KEYS_HH
|
||||
|
||||
#include "FbTk/NotCopyable.hh"
|
||||
#include "FbTk/AutoReloadHelper.hh"
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <string>
|
||||
|
@ -57,17 +58,6 @@ public:
|
|||
/// 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 @@ public:
|
|||
/// 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 @@ private:
|
|||
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;
|
||||
|
||||
|
|
|
@ -307,7 +307,7 @@ Fluxbox::Fluxbox(int argc, char **argv, const char *dpy_name, const char *rcfile
|
|||
// 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 @@ void Fluxbox::handleEvent(XEvent * const e) {
|
|||
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 @@ void Fluxbox::real_reconfigure() {
|
|||
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();
|
||||
|
|
|
@ -120,6 +120,7 @@ public:
|
|||
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; }
|
||||
|
||||
|
|
Loading…
Reference in a new issue