From f76da171aa060f1367a5deaf1aec3b3294302b5e Mon Sep 17 00:00:00 2001 From: simonb Date: Wed, 3 Oct 2007 22:44:08 +0000 Subject: load some default key bindings on error --- src/Keys.cc | 45 +++++++++++++++++++++++++++++++++++---------- src/Keys.hh | 3 +++ 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/Keys.cc b/src/Keys.cc index 86cb4d5..6d13cd4 100644 --- a/src/Keys.cc +++ b/src/Keys.cc @@ -187,22 +187,32 @@ void Keys::grabWindow(Window win) { @return true on success else false */ bool Keys::load(const char *filename) { - if (!filename) - return false; - - //free memory of previous grabs - deleteTree(); + // an intentionally empty file will still have one root mapping + bool firstload = m_map.empty(); - m_map["default:"] = new t_key(0,0,0,0); + if (!filename) { + if (firstload) + loadDefaults(); + return false; + } FbTk::App::instance()->sync(false); - //open the file + // open the file ifstream infile(filename); - if (!infile) - return false; // faild to open file + if (!infile) { + if (firstload) + loadDefaults(); - unsigned int current_line = 0;//so we can tell the user where the fault is + return false; // failed to open file + } + + // free memory of previous grabs + deleteTree(); + + m_map["default:"] = new t_key(0,0,0,0); + + unsigned int current_line = 0; //so we can tell the user where the fault is while (!infile.eof()) { string linebuffer; @@ -225,6 +235,21 @@ bool Keys::load(const char *filename) { return true; } +/** + * Load critical key/mouse bindings for when there are fatal errors reading the keyFile. + */ +void Keys::loadDefaults() { +#ifdef DEBUG + cerr<<"Loading default key bindings"<