aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMark Tiefenbruck <mark@fluxbox.org>2008-05-12 19:16:37 (GMT)
committerMark Tiefenbruck <mark@fluxbox.org>2008-05-12 19:16:37 (GMT)
commitdcdc78332431ff2b258c54a99d6fac382c6a0595 (patch)
treec667adfc3cf2a2a90972d1342147f31bd6beeb40 /src
parenta56492c0d538c9c3a019812558938df0b6afedeb (diff)
downloadfluxbox_pavel-dcdc78332431ff2b258c54a99d6fac382c6a0595.zip
fluxbox_pavel-dcdc78332431ff2b258c54a99d6fac382c6a0595.tar.bz2
only reload the keys file if the contents have changed
Diffstat (limited to 'src')
-rw-r--r--src/Keys.cc37
-rw-r--r--src/Keys.hh23
-rw-r--r--src/fluxbox.cc6
-rw-r--r--src/fluxbox.hh1
4 files changed, 25 insertions, 42 deletions
diff --git a/src/Keys.cc b/src/Keys.cc
index eb3d9d5..ec1fde0 100644
--- a/src/Keys.cc
+++ b/src/Keys.cc
@@ -170,7 +170,9 @@ Keys::t_key::~t_key() {
170 170
171 171
172 172
173Keys::Keys() : next_key(0) { } 173Keys::Keys(): next_key(0) {
174 m_reloader.setReloadCmd(FbTk::RefCount<FbTk::Command<void> >(new FbTk::SimpleCommand<Keys>(*this, &Keys::reload)));
175}
174 176
175Keys::~Keys() { 177Keys::~Keys() {
176 ungrabKeys(); 178 ungrabKeys();
@@ -255,27 +257,25 @@ void Keys::grabWindow(Window win) {
255/** 257/**
256 Load and grab keys 258 Load and grab keys
257 TODO: error checking 259 TODO: error checking
258 @return true on success else false
259*/ 260*/
260bool Keys::load(const char *filename) { 261void Keys::reload() {
261 // an intentionally empty file will still have one root mapping 262 // an intentionally empty file will still have one root mapping
262 bool firstload = m_map.empty(); 263 bool firstload = m_map.empty();
263 264
264 if (!filename) { 265 if (m_filename.empty()) {
265 if (firstload) 266 if (firstload)
266 loadDefaults(); 267 loadDefaults();
267 return false; 268 return;
268 } 269 }
269 270
270 FbTk::App::instance()->sync(false); 271 FbTk::App::instance()->sync(false);
271 272
272 // open the file 273 // open the file
273 ifstream infile(filename); 274 ifstream infile(m_filename.c_str());
274 if (!infile) { 275 if (!infile) {
275 if (firstload) 276 if (firstload)
276 loadDefaults(); 277 loadDefaults();
277 278 return; // failed to open file
278 return false; // failed to open file
279 } 279 }
280 280
281 // free memory of previous grabs 281 // free memory of previous grabs
@@ -301,9 +301,7 @@ bool Keys::load(const char *filename) {
301 } 301 }
302 } // end while eof 302 } // end while eof
303 303
304 m_filename = filename;
305 keyMode("default"); 304 keyMode("default");
306 return true;
307} 305}
308 306
309/** 307/**
@@ -321,19 +319,6 @@ void Keys::loadDefaults() {
321 keyMode("default"); 319 keyMode("default");
322} 320}
323 321
324bool Keys::save(const char *filename) const {
325 //!!
326 //!! TODO: fix keybinding saving
327 //!! (we probably need to save key actions
328 //!! as strings instead of creating new Commands)
329
330 // open file for writing
331 // ofstream outfile(filename);
332 // if (!outfile)
333 return false;
334 // return true;
335}
336
337bool Keys::addBinding(const string &linebuffer) { 322bool Keys::addBinding(const string &linebuffer) {
338 323
339 vector<string> val; 324 vector<string> val;
@@ -583,8 +568,10 @@ void Keys::unregisterWindow(Window win) {
583 deletes the tree and load configuration 568 deletes the tree and load configuration
584 returns true on success else false 569 returns true on success else false
585*/ 570*/
586bool Keys::reconfigure(const char *filename) { 571void Keys::reconfigure() {
587 return load(filename); 572 m_filename = FbTk::StringUtil::expandFilename(Fluxbox::instance()->getKeysFilename());
573 m_reloader.setMainFile(m_filename);
574 m_reloader.checkReload();
588} 575}
589 576
590void Keys::keyMode(const string& keyMode) { 577void Keys::keyMode(const string& keyMode) {
diff --git a/src/Keys.hh b/src/Keys.hh
index 7ebb0a7..68ff4ec 100644
--- a/src/Keys.hh
+++ b/src/Keys.hh
@@ -23,6 +23,7 @@
23#define KEYS_HH 23#define KEYS_HH
24 24
25#include "FbTk/NotCopyable.hh" 25#include "FbTk/NotCopyable.hh"
26#include "FbTk/AutoReloadHelper.hh"
26 27
27#include <X11/Xlib.h> 28#include <X11/Xlib.h>
28#include <string> 29#include <string>
@@ -57,17 +58,6 @@ public:
57 /// destructor 58 /// destructor
58 ~Keys(); 59 ~Keys();
59 60
60 /**
61 Load configuration from file
62 @return true on success, else false
63 */
64 bool load(const char *filename = 0);
65 /**
66 Save keybindings to a file
67 Note: the file will be overwritten
68 @return true on success, else false
69 */
70 bool save(const char *filename = 0) const;
71 /// bind a key action from a string 61 /// bind a key action from a string
72 /// @return false on failure 62 /// @return false on failure
73 bool addBinding(const std::string &binding); 63 bool addBinding(const std::string &binding);
@@ -83,12 +73,12 @@ public:
83 /// unregister window 73 /// unregister window
84 void unregisterWindow(Window win); 74 void unregisterWindow(Window win);
85 75
76 const std::string& filename() const { return m_filename; }
86 /** 77 /**
87 Reload configuration from filename 78 Reload configuration from filename
88 @return true on success, else false 79 @return true on success, else false
89 */ 80 */
90 bool reconfigure(const char *filename); 81 void reconfigure();
91 const std::string& filename() const { return m_filename; }
92 void keyMode(const std::string& keyMode); 82 void keyMode(const std::string& keyMode);
93private: 83private:
94 class t_key; // helper class to build a 'keytree' 84 class t_key; // helper class to build a 'keytree'
@@ -104,13 +94,18 @@ private:
104 void ungrabButtons(); 94 void ungrabButtons();
105 void grabWindow(Window win); 95 void grabWindow(Window win);
106 96
107 // Load default keybindings for when there are errors loading the initial one 97 /**
98 Load configuration from file
99 */
100 void reload();
101 // Load default keybindings for when there are errors loading the keys file
108 void loadDefaults(); 102 void loadDefaults();
109 void setKeyMode(t_key *keyMode); 103 void setKeyMode(t_key *keyMode);
110 104
111 105
112 // member variables 106 // member variables
113 std::string m_filename; 107 std::string m_filename;
108 FbTk::AutoReloadHelper m_reloader;
114 t_key *m_keylist; 109 t_key *m_keylist;
115 keyspace_t m_map; 110 keyspace_t m_map;
116 111
diff --git a/src/fluxbox.cc b/src/fluxbox.cc
index 70503a5..076ae45 100644
--- a/src/fluxbox.cc
+++ b/src/fluxbox.cc
@@ -307,7 +307,7 @@ Fluxbox::Fluxbox(int argc, char **argv, const char *dpy_name, const char *rcfile
307 // Create keybindings handler and load keys file 307 // Create keybindings handler and load keys file
308 // Note: this needs to be done before creating screens 308 // Note: this needs to be done before creating screens
309 m_key.reset(new Keys); 309 m_key.reset(new Keys);
310 m_key->load(StringUtil::expandFilename(*m_rc_keyfile).c_str()); 310 m_key->reconfigure();
311 311
312 vector<int> screens; 312 vector<int> screens;
313 int i; 313 int i;
@@ -751,7 +751,7 @@ void Fluxbox::handleEvent(XEvent * const e) {
751 XRefreshKeyboardMapping(&e->xmapping); 751 XRefreshKeyboardMapping(&e->xmapping);
752 FbTk::KeyUtil::instance().init(); // reinitialise the key utils 752 FbTk::KeyUtil::instance().init(); // reinitialise the key utils
753 // reconfigure keys (if the mapping changes, they don't otherwise update 753 // reconfigure keys (if the mapping changes, they don't otherwise update
754 m_key->reconfigure(StringUtil::expandFilename(*m_rc_keyfile).c_str()); 754 m_key->reconfigure();
755 } 755 }
756 break; 756 break;
757 case CreateNotify: 757 case CreateNotify:
@@ -1443,7 +1443,7 @@ void Fluxbox::real_reconfigure() {
1443 for_each(m_screen_list.begin(), m_screen_list.end(), mem_fun(&BScreen::reconfigure)); 1443 for_each(m_screen_list.begin(), m_screen_list.end(), mem_fun(&BScreen::reconfigure));
1444 1444
1445 //reconfigure keys 1445 //reconfigure keys
1446 m_key->reconfigure(StringUtil::expandFilename(*m_rc_keyfile).c_str()); 1446 m_key->reconfigure();
1447 1447
1448 // and atomhandlers 1448 // and atomhandlers
1449 for (AtomHandlerContainerIt it= m_atomhandler.begin(); 1449 for (AtomHandlerContainerIt it= m_atomhandler.begin();
diff --git a/src/fluxbox.hh b/src/fluxbox.hh
index 8b22a04..fc86125 100644
--- a/src/fluxbox.hh
+++ b/src/fluxbox.hh
@@ -120,6 +120,7 @@ public:
120 const std::string &getMenuFilename() const { return *m_rc_menufile; } 120 const std::string &getMenuFilename() const { return *m_rc_menufile; }
121 const std::string &getSlitlistFilename() const { return *m_rc_slitlistfile; } 121 const std::string &getSlitlistFilename() const { return *m_rc_slitlistfile; }
122 const std::string &getAppsFilename() const { return *m_rc_appsfile; } 122 const std::string &getAppsFilename() const { return *m_rc_appsfile; }
123 const std::string &getKeysFilename() const { return *m_rc_keyfile; }
123 int colorsPerChannel() const { return *m_rc_colors_per_channel; } 124 int colorsPerChannel() const { return *m_rc_colors_per_channel; }
124 int getTabsPadding() const { return *m_rc_tabs_padding; } 125 int getTabsPadding() const { return *m_rc_tabs_padding; }
125 126