From 31b47e78147ca20803b123f392bfd2002b70e052 Mon Sep 17 00:00:00 2001 From: Mathias Gumz Date: Thu, 14 Aug 2008 07:53:38 +0200 Subject: cleanup of some files --- src/FbMenu.cc | 1 + src/FbTk/AutoReloadHelper.cc | 14 +- src/FbTk/AutoReloadHelper.hh | 4 +- src/FbTk/ImageControl.cc | 4 +- src/Keys.cc | 13 +- src/Keys.hh | 4 +- src/Remember.cc | 439 +++++++++++++++++++++++++++++-------------- src/Remember.hh | 134 +------------ src/Slit.cc | 2 +- src/Window.cc | 31 +-- src/Window.hh | 1 - src/fluxbox.cc | 2 +- 12 files changed, 337 insertions(+), 312 deletions(-) diff --git a/src/FbMenu.cc b/src/FbMenu.cc index 12ee2f1..769241d 100644 --- a/src/FbMenu.cc +++ b/src/FbMenu.cc @@ -24,6 +24,7 @@ #include "fluxbox.hh" #include "Screen.hh" #include "WindowCmd.hh" +#include "FbTk/AutoReloadHelper.hh" FluxboxWindow *FbMenu::s_window = 0; diff --git a/src/FbTk/AutoReloadHelper.cc b/src/FbTk/AutoReloadHelper.cc index e3c1d59..17124d4 100644 --- a/src/FbTk/AutoReloadHelper.cc +++ b/src/FbTk/AutoReloadHelper.cc @@ -40,19 +40,19 @@ void AutoReloadHelper::checkReload() { } } -void AutoReloadHelper::setMainFile(std::string file) { - file = StringUtil::expandFilename(file); - if (file == m_main_file) +void AutoReloadHelper::setMainFile(const std::string& file) { + std::string expanded_file = StringUtil::expandFilename(file); + if (expanded_file == m_main_file) return; - m_main_file = file; + m_main_file = expanded_file; reload(); } -void AutoReloadHelper::addFile(std::string file) { +void AutoReloadHelper::addFile(const std::string& file) { if (file.empty()) return; - file = StringUtil::expandFilename(file); - m_timestamps[file] = FileUtil::getLastStatusChangeTimestamp(file.c_str()); + std::string expanded_file = StringUtil::expandFilename(file); + m_timestamps[expanded_file] = FileUtil::getLastStatusChangeTimestamp(expanded_file.c_str()); } void AutoReloadHelper::reload() { diff --git a/src/FbTk/AutoReloadHelper.hh b/src/FbTk/AutoReloadHelper.hh index 36be8f1..b337a4a 100644 --- a/src/FbTk/AutoReloadHelper.hh +++ b/src/FbTk/AutoReloadHelper.hh @@ -34,8 +34,8 @@ namespace FbTk { class AutoReloadHelper { public: - void setMainFile(std::string filename); - void addFile(std::string filename); + void setMainFile(const std::string& filename); + void addFile(const std::string& filename); void setReloadCmd(RefCount > cmd) { m_reload_cmd = cmd; } void checkReload(); diff --git a/src/FbTk/ImageControl.cc b/src/FbTk/ImageControl.cc index b9c3685..38114c8 100644 --- a/src/FbTk/ImageControl.cc +++ b/src/FbTk/ImageControl.cc @@ -495,7 +495,7 @@ void ImageControl::createColorTable() { for (int b = 0; b < m_colors_per_channel; b++, i++) { m_colors[i].red = (r * 0xffff) / (m_colors_per_channel - 1); m_colors[i].green = (g * 0xffff) / (m_colors_per_channel - 1); - m_colors[i].blue = (b * 0xffff) / (m_colors_per_channel - 1);; + m_colors[i].blue = (b * 0xffff) / (m_colors_per_channel - 1); m_colors[i].flags = DoRed|DoGreen|DoBlue; } } @@ -587,7 +587,7 @@ void ImageControl::createColorTable() { for (unsigned int i = 0; i < m_num_colors; i++) { m_colors[i].red = (i * 0xffff) / (m_colors_per_channel - 1); m_colors[i].green = (i * 0xffff) / (m_colors_per_channel - 1); - m_colors[i].blue = (i * 0xffff) / (m_colors_per_channel - 1);; + m_colors[i].blue = (i * 0xffff) / (m_colors_per_channel - 1); m_colors[i].flags = DoRed|DoGreen|DoBlue; if (! XAllocColor(disp, m_colormap, diff --git a/src/Keys.cc b/src/Keys.cc index ec1fde0..3b0c206 100644 --- a/src/Keys.cc +++ b/src/Keys.cc @@ -34,6 +34,7 @@ #include "FbTk/KeyUtil.hh" #include "FbTk/CommandParser.hh" #include "FbTk/I18n.hh" +#include "FbTk/AutoReloadHelper.hh" #ifdef HAVE_CONFIG_H #include "config.h" @@ -92,7 +93,6 @@ #include #include #include -#include #include using std::cerr; @@ -131,7 +131,7 @@ public: } // member variables - + int type; // KeyPress or ButtonPress unsigned int mod; unsigned int key; // key code or button number @@ -170,14 +170,15 @@ Keys::t_key::~t_key() { -Keys::Keys(): next_key(0) { - m_reloader.setReloadCmd(FbTk::RefCount >(new FbTk::SimpleCommand(*this, &Keys::reload))); +Keys::Keys(): next_key(0), m_reloader(new FbTk::AutoReloadHelper()) { + m_reloader->setReloadCmd(FbTk::RefCount >(new FbTk::SimpleCommand(*this, &Keys::reload))); } Keys::~Keys() { ungrabKeys(); ungrabButtons(); deleteTree(); + delete m_reloader; } /// Destroys the keytree @@ -570,8 +571,8 @@ void Keys::unregisterWindow(Window win) { */ void Keys::reconfigure() { m_filename = FbTk::StringUtil::expandFilename(Fluxbox::instance()->getKeysFilename()); - m_reloader.setMainFile(m_filename); - m_reloader.checkReload(); + m_reloader->setMainFile(m_filename); + m_reloader->checkReload(); } void Keys::keyMode(const string& keyMode) { diff --git a/src/Keys.hh b/src/Keys.hh index 0812761..03a15dd 100644 --- a/src/Keys.hh +++ b/src/Keys.hh @@ -23,7 +23,6 @@ #define KEYS_HH #include "FbTk/NotCopyable.hh" -#include "FbTk/AutoReloadHelper.hh" #include #include @@ -33,6 +32,7 @@ class WinClient; namespace FbTk { class EventHandler; + class AutoReloadHelper; } class Keys:private FbTk::NotCopyable { @@ -104,7 +104,7 @@ private: // member variables std::string m_filename; - FbTk::AutoReloadHelper m_reloader; + FbTk::AutoReloadHelper* m_reloader; t_key *m_keylist; keyspace_t m_map; diff --git a/src/Remember.cc b/src/Remember.cc index f76fe9b..76d2221 100644 --- a/src/Remember.cc +++ b/src/Remember.cc @@ -39,7 +39,8 @@ #include "FbTk/App.hh" #include "FbTk/stringstream.hh" #include "FbTk/Transparent.hh" - +#include "FbTk/AutoReloadHelper.hh" +#include "FbTk/RefCount.hh" #ifdef HAVE_CSTRING #include @@ -67,6 +68,160 @@ using std::ofstream; using std::hex; using std::dec; +/*------------------------------------------------------------------*\ +\*------------------------------------------------------------------*/ + +class Application { +public: + Application(bool grouped, ClientPattern *pat = 0); + void reset(); + void forgetWorkspace() { workspace_remember = false; } + void forgetHead() { head_remember = false; } + void forgetDimensions() { dimensions_remember = false; } + void forgetPosition() { position_remember = false; } + void forgetShadedstate() { shadedstate_remember = false; } + void forgetTabstate() { tabstate_remember = false; } + void forgetDecostate() { decostate_remember = false; } + void forgetFocusHiddenstate() { focushiddenstate_remember= false; } + void forgetIconHiddenstate() { iconhiddenstate_remember= false; } + void forgetStuckstate() { stuckstate_remember = false; } + void forgetJumpworkspace() { jumpworkspace_remember = false; } + void forgetLayer() { layer_remember = false; } + void forgetSaveOnClose() { save_on_close_remember = false; } + void forgetAlpha() { alpha_remember = false; } + void forgetMinimizedstate() { minimizedstate_remember = false; } + void forgetMaximizedstate() { maximizedstate_remember = false; } + void forgetFullscreenstate() { fullscreenstate_remember = false; } + + void rememberWorkspace(int ws) + { workspace = ws; workspace_remember = true; } + void rememberHead(int h) + { head = h; head_remember = true; } + void rememberDimensions(int width, int height) + { w = width; h = height; dimensions_remember = true; } + void rememberFocusHiddenstate(bool state) + { focushiddenstate= state; focushiddenstate_remember= true; } + void rememberIconHiddenstate(bool state) + { iconhiddenstate= state; iconhiddenstate_remember= true; } + void rememberPosition(int posx, int posy, unsigned char rfc= 0 ) + { x = posx; y = posy; refc = rfc; position_remember = true; } + void rememberShadedstate(bool state) + { shadedstate = state; shadedstate_remember = true; } + void rememberTabstate(bool state) + { tabstate = state; tabstate_remember = true; } + void rememberDecostate(unsigned int state) + { decostate = state; decostate_remember = true; } + void rememberStuckstate(bool state) + { stuckstate = state; stuckstate_remember = true; } + void rememberJumpworkspace(bool state) + { jumpworkspace = state; jumpworkspace_remember = true; } + void rememberLayer(int layernum) + { layer = layernum; layer_remember = true; } + void rememberSaveOnClose(bool state) + { save_on_close = state; save_on_close_remember = true; } + void rememberAlpha(int focused_a, int unfocused_a) + { focused_alpha = focused_a; unfocused_alpha = unfocused_a; alpha_remember = true; } + void rememberMinimizedstate(bool state) + { minimizedstate = state; minimizedstate_remember = true; } + void rememberMaximizedstate(int state) + { maximizedstate = state; maximizedstate_remember = true; } + void rememberFullscreenstate(bool state) + { fullscreenstate = state; fullscreenstate_remember = true; } + + bool workspace_remember; + unsigned int workspace; + + bool head_remember; + int head; + + bool dimensions_remember; + int w,h; // width, height + + bool position_remember; + int x,y; + unsigned char refc; // referenceCorner-> 0 - upperleft + // 1 - upperight + // 2 - lowerleft + // 3 - lowerright + + bool alpha_remember; + int focused_alpha; + int unfocused_alpha; + + bool shadedstate_remember; + bool shadedstate; + + bool tabstate_remember; + bool tabstate; + + bool decostate_remember; + unsigned int decostate; + + bool stuckstate_remember; + bool stuckstate; + + bool focushiddenstate_remember; + bool focushiddenstate; + + bool iconhiddenstate_remember; + bool iconhiddenstate; + + bool jumpworkspace_remember; + bool jumpworkspace; + + bool layer_remember; + int layer; + + bool save_on_close_remember; + bool save_on_close; + + bool minimizedstate_remember; + bool minimizedstate; + + bool maximizedstate_remember; + int maximizedstate; + + bool fullscreenstate_remember; + bool fullscreenstate; + + bool is_grouped; + FbTk::RefCount group_pattern; + +}; + + + + + + +Application::Application(bool grouped, ClientPattern *pat) + : is_grouped(grouped), group_pattern(pat) +{ + reset(); +} + +void Application::reset() { + decostate_remember = + dimensions_remember = + focushiddenstate_remember = + iconhiddenstate_remember = + jumpworkspace_remember = + layer_remember = + position_remember = + shadedstate_remember = + stuckstate_remember = + tabstate_remember = + workspace_remember = + head_remember = + alpha_remember = + minimizedstate_remember = + maximizedstate_remember = + fullscreenstate_remember = + save_on_close_remember = false; +} + +/*------------------------------------------------------------------*\ +\*------------------------------------------------------------------*/ namespace { @@ -245,116 +400,11 @@ bool handleStartupItem(const string &line, int offset) { return true; }; -}; // end anonymous namespace - - -Application::Application(bool grouped, ClientPattern *pat) - : is_grouped(grouped), group_pattern(pat) -{ - reset(); -} - -void Application::reset() { - decostate_remember = - dimensions_remember = - focushiddenstate_remember = - iconhiddenstate_remember = - jumpworkspace_remember = - layer_remember = - position_remember = - shadedstate_remember = - stuckstate_remember = - tabstate_remember = - workspace_remember = - head_remember = - alpha_remember = - minimizedstate_remember = - maximizedstate_remember = - fullscreenstate_remember = - save_on_close_remember = false; -} - -/************ - * Remember * - ************/ - -Remember *Remember::s_instance = 0; - -Remember::Remember(): - m_pats(new Patterns()) { - if (s_instance != 0) - throw string("Can not create more than one instance of Remember"); - - s_instance = this; - enableUpdate(); - - m_reloader.setReloadCmd(FbTk::RefCount >(new FbTk::SimpleCommand(*this, &Remember::reload))); - reconfigure(); -} - -Remember::~Remember() { - - // free our resources - - // the patterns free the "Application"s - // the client mapping shouldn't need cleaning - Patterns::iterator it; - set all_apps; // no duplicates - while (!m_pats->empty()) { - it = m_pats->begin(); - delete it->first; // ClientPattern - all_apps.insert(it->second); // Application, not necessarily unique - m_pats->erase(it); - } - - set::iterator ait = all_apps.begin(); // no duplicates - for (; ait != all_apps.end(); ++ait) { - delete (*ait); - } - - s_instance = 0; -} - -Application* Remember::find(WinClient &winclient) { - // if it is already associated with a application, return that one - // otherwise, check it against every pattern that we've got - Clients::iterator wc_it = m_clients.find(&winclient); - if (wc_it != m_clients.end()) - return wc_it->second; - else { - Patterns::iterator it = m_pats->begin(); - for (; it != m_pats->end(); it++) - if (it->first->match(winclient)) { - it->first->addMatch(); - m_clients[&winclient] = it->second; - return it->second; - } - } - // oh well, no matches - return 0; -} - -Application * Remember::add(WinClient &winclient) { - ClientPattern *p = new ClientPattern(); - Application *app = new Application(false); - // by default, we match against the WMClass of a window (instance and class strings) - string win_name = ::escapeRememberChars(p->getProperty(ClientPattern::NAME, winclient)); - string win_class = ::escapeRememberChars(p->getProperty(ClientPattern::CLASS, winclient)); - string win_role = ::escapeRememberChars(p->getProperty(ClientPattern::ROLE, winclient)); - - p->addTerm(win_name, ClientPattern::NAME); - p->addTerm(win_class, ClientPattern::CLASS); - if (!win_role.empty()) - p->addTerm(win_role, ClientPattern::ROLE); - p->addTerm(winclient.isTransient() ? "yes" : "no", ClientPattern::TRANSIENT); - m_clients[&winclient] = app; - p->addMatch(); - m_pats->push_back(make_pair(p, app)); - return app; -} -int Remember::parseApp(ifstream &file, Application &app, string *first_line) { +// returns number of lines read +// optionally can give a line to read before the first (lookahead line) +int parseApp(ifstream &file, Application &app, string *first_line = 0) { string line; _FB_USES_NLS; int row = 0; @@ -370,8 +420,10 @@ int Remember::parseApp(ifstream &file, Application &app, string *first_line) { FbTk::StringUtil::removeTrailingWhitespace(line); if (line.size() == 0 || line[0] == '#') continue; //the line is commented or blank + int parse_pos = 0, err = 0; string str_key, str_option, str_label; + err = FbTk::StringUtil::getStringBetween(str_key, line.c_str(), '[', ']'); @@ -398,44 +450,48 @@ int Remember::parseApp(ifstream &file, Application &app, string *first_line) { if (str_key.empty()) continue; //read next line - if (strcasecmp(str_key.c_str(), "Workspace") == 0) { + + str_key = FbTk::StringUtil::toLower(str_key); + + if (str_key == "workspace") { unsigned int w; if (getuint(str_label.c_str(), w)) app.rememberWorkspace(w); else had_error = true; - } else if (strcasecmp(str_key.c_str(), "Head") == 0) { + } else if (str_key == "head") { unsigned int h; if (getuint(str_label.c_str(), h)) app.rememberHead(h); else had_error = true; - } else if (strcasecmp(str_key.c_str(), "Layer") == 0) { + } else if (str_key == "layer") { int l = Layer::getNumFromString(str_label); had_error = (l == -1); if (!had_error) app.rememberLayer(l); - } else if (strcasecmp(str_key.c_str(), "Dimensions") == 0) { + } else if (str_key == "dimensions") { unsigned int h,w; if (sscanf(str_label.c_str(), "%u %u", &w, &h) == 2) app.rememberDimensions(w, h); else had_error = true; - } else if (strcasecmp(str_key.c_str(), "Position") == 0) { + } else if (str_key == "position") { unsigned int r= 0; unsigned int x= 0; unsigned int y= 0; // more info about the parameter // in ::rememberPosition + str_option == FbTk::StringUtil::toUpper(str_option); if ( str_option.length() ) { - if (strcasecmp(str_option.c_str(), "UPPERLEFT") == 0) r= POS_UPPERLEFT; - else if (strcasecmp(str_option.c_str(), "UPPERRIGHT") == 0) r= POS_UPPERRIGHT; - else if (strcasecmp(str_option.c_str(), "LOWERLEFT") == 0) r= POS_LOWERLEFT; - else if (strcasecmp(str_option.c_str(), "LOWERRIGHT") == 0) r= POS_LOWERRIGHT; - else if (strcasecmp(str_option.c_str(), "CENTER") == 0) r= POS_CENTER; - else if (strcasecmp(str_option.c_str(), "WINCENTER") == 0) r= POS_WINCENTER; + if (str_option == "UPPERLEFT") r= Remember::POS_UPPERLEFT; + else if (str_option == "UPPERRIGHT") r= Remember::POS_UPPERRIGHT; + else if (str_option == "LOWERLEFT") r= Remember::POS_LOWERLEFT; + else if (str_option == "LOWERRIGHT") r= Remember::POS_LOWERRIGHT; + else if (str_option == "CENTER") r= Remember::POS_CENTER; + else if (str_option == "WINCENTER") r= Remember::POS_WINCENTER; else if (!getuint(str_option.c_str(), r)) { had_error = 1; } @@ -445,24 +501,24 @@ int Remember::parseApp(ifstream &file, Application &app, string *first_line) { app.rememberPosition(x, y, r); else had_error = true; - } else if (strcasecmp(str_key.c_str(), "Shaded") == 0) { + } else if (str_key == "shaded") { app.rememberShadedstate((strcasecmp(str_label.c_str(), "yes") == 0)); - } else if (strcasecmp(str_key.c_str(), "Tab") == 0) { + } else if (str_key == "tab") { app.rememberTabstate((strcasecmp(str_label.c_str(), "yes") == 0)); - } else if (strcasecmp(str_key.c_str(), "FocusHidden") == 0) { + } else if (str_key == "focushidden") { app.rememberFocusHiddenstate((strcasecmp(str_label.c_str(), "yes") == 0)); - } else if (strcasecmp(str_key.c_str(), "IconHidden") == 0) { + } else if (str_key == "iconhidden") { app.rememberIconHiddenstate((strcasecmp(str_label.c_str(), "yes") == 0)); - } else if (strcasecmp(str_key.c_str(), "Hidden") == 0) { + } else if (str_key == "hidden") { app.rememberIconHiddenstate((strcasecmp(str_label.c_str(), "yes") == 0)); app.rememberFocusHiddenstate((strcasecmp(str_label.c_str(), "yes") == 0)); - } else if (strcasecmp(str_key.c_str(), "Deco") == 0) { + } else if (str_key == "deco") { int deco = FluxboxWindow::getDecoMaskFromString(str_label); if (deco == -1) had_error = 1; else app.rememberDecostate((unsigned int)deco); - } else if (strcasecmp(str_key.c_str(), "Alpha") == 0) { + } else if (str_key == "alpha") { int focused_a, unfocused_a; if (sscanf(str_label.c_str(), "%i %i", &focused_a, &unfocused_a) == 2) { @@ -486,11 +542,11 @@ int Remember::parseApp(ifstream &file, Application &app, string *first_line) { } else had_error = 1; - } else if (strcasecmp(str_key.c_str(), "Sticky") == 0) { + } else if (str_key == "sticky") { app.rememberStuckstate((strcasecmp(str_label.c_str(), "yes") == 0)); - } else if (strcasecmp(str_key.c_str(), "Minimized") == 0) { + } else if (str_key == "minimized") { app.rememberMinimizedstate((strcasecmp(str_label.c_str(), "yes") == 0)); - } else if (strcasecmp(str_key.c_str(), "Maximized") == 0) { + } else if (str_key == "maximized") { if (strcasecmp(str_label.c_str(), "yes") == 0) app.rememberMaximizedstate(FluxboxWindow::MAX_FULL); else if (strcasecmp(str_label.c_str(), "horz") == 0) @@ -499,13 +555,13 @@ int Remember::parseApp(ifstream &file, Application &app, string *first_line) { app.rememberMaximizedstate(FluxboxWindow::MAX_VERT); else app.rememberMaximizedstate(FluxboxWindow::MAX_NONE); - } else if (strcasecmp(str_key.c_str(), "Fullscreen") == 0) { + } else if (str_key == "fullscreen") { app.rememberFullscreenstate((strcasecmp(str_label.c_str(), "yes") == 0)); - } else if (strcasecmp(str_key.c_str(), "Jump") == 0) { + } else if (str_key == "jump") { app.rememberJumpworkspace((strcasecmp(str_label.c_str(), "yes") == 0)); - } else if (strcasecmp(str_key.c_str(), "Close") == 0) { + } else if (str_key == "close") { app.rememberSaveOnClose((strcasecmp(str_label.c_str(), "yes") == 0)); - } else if (strcasecmp(str_key.c_str(), "end") == 0) { + } else if (str_key == "end") { return row; } else { cerr << _FB_CONSOLETEXT(Remember, Unknown, "Unknown apps key", "apps entry type not known")<<" = " << str_key << endl; @@ -518,6 +574,8 @@ int Remember::parseApp(ifstream &file, Application &app, string *first_line) { return row; } + + /* This function is used to search for old instances of the same pattern (when reloading apps file). More than one pattern might match, but only @@ -526,20 +584,23 @@ int Remember::parseApp(ifstream &file, Application &app, string *first_line) { effectively moved into the new */ -Application *Remember::findMatchingPatterns(ClientPattern *pat, Patterns *patlist, bool is_group, ClientPattern *match_pat) { - Patterns::iterator it = patlist->begin(); - Patterns::iterator it_end = patlist->end(); +Application* findMatchingPatterns(ClientPattern *pat, Remember::Patterns *patlist, bool is_group, ClientPattern *match_pat = 0) { + + Remember::Patterns::iterator it = patlist->begin(); + Remember::Patterns::iterator it_end = patlist->end(); + for (; it != it_end; ++it) { if (*it->first == *pat && is_group == it->second->is_grouped && ((match_pat == 0 && *it->second->group_pattern == 0) || (match_pat && *match_pat == **it->second->group_pattern))) { + Application *ret = it->second; if (!is_group) return ret; // find the rest of the group and remove it from the list // rewind - Patterns::iterator tmpit = it; + Remember::Patterns::iterator tmpit = it; while (tmpit != patlist->begin()) { --tmpit; if (tmpit->second == ret) @@ -561,13 +622,100 @@ Application *Remember::findMatchingPatterns(ClientPattern *pat, Patterns *patlis return 0; } +}; // end anonymous namespace + +/*------------------------------------------------------------------*\ +\*------------------------------------------------------------------*/ + +Remember *Remember::s_instance = 0; + +Remember::Remember(): + m_pats(new Patterns()), + m_reloader(new FbTk::AutoReloadHelper()) { + + if (s_instance != 0) + throw string("Can not create more than one instance of Remember"); + + s_instance = this; + enableUpdate(); + + m_reloader->setReloadCmd(FbTk::RefCount >(new FbTk::SimpleCommand(*this, &Remember::reload))); + reconfigure(); +} + +Remember::~Remember() { + + // free our resources + + // the patterns free the "Application"s + // the client mapping shouldn't need cleaning + Patterns::iterator it; + set all_apps; // no duplicates + while (!m_pats->empty()) { + it = m_pats->begin(); + delete it->first; // ClientPattern + all_apps.insert(it->second); // Application, not necessarily unique + m_pats->erase(it); + } + + set::iterator ait = all_apps.begin(); // no duplicates + for (; ait != all_apps.end(); ++ait) { + delete (*ait); + } + + delete(m_reloader); + + s_instance = 0; +} + +Application* Remember::find(WinClient &winclient) { + // if it is already associated with a application, return that one + // otherwise, check it against every pattern that we've got + Clients::iterator wc_it = m_clients.find(&winclient); + if (wc_it != m_clients.end()) + return wc_it->second; + else { + Patterns::iterator it = m_pats->begin(); + for (; it != m_pats->end(); it++) + if (it->first->match(winclient)) { + it->first->addMatch(); + m_clients[&winclient] = it->second; + return it->second; + } + } + // oh well, no matches + return 0; +} + +Application * Remember::add(WinClient &winclient) { + ClientPattern *p = new ClientPattern(); + Application *app = new Application(false); + + // by default, we match against the WMClass of a window (instance and class strings) + string win_name = ::escapeRememberChars(p->getProperty(ClientPattern::NAME, winclient)); + string win_class = ::escapeRememberChars(p->getProperty(ClientPattern::CLASS, winclient)); + string win_role = ::escapeRememberChars(p->getProperty(ClientPattern::ROLE, winclient)); + + p->addTerm(win_name, ClientPattern::NAME); + p->addTerm(win_class, ClientPattern::CLASS); + if (!win_role.empty()) + p->addTerm(win_role, ClientPattern::ROLE); + p->addTerm(winclient.isTransient() ? "yes" : "no", ClientPattern::TRANSIENT); + m_clients[&winclient] = app; + p->addMatch(); + m_pats->push_back(make_pair(p, app)); + return app; +} + + + void Remember::reconfigure() { - m_reloader.setMainFile(Fluxbox::instance()->getAppsFilename()); + m_reloader->setMainFile(Fluxbox::instance()->getAppsFilename()); } void Remember::checkReload() { - m_reloader.checkReload(); + m_reloader->checkReload(); } void Remember::reload() { @@ -883,7 +1031,7 @@ void Remember::save() { } apps_file.close(); // update timestamp to avoid unnecessary reload - m_reloader.addFile(Fluxbox::instance()->getAppsFilename()); + m_reloader->addFile(Fluxbox::instance()->getAppsFilename()); } bool Remember::isRemembered(WinClient &winclient, Attribute attrib) { @@ -1234,6 +1382,15 @@ FluxboxWindow *Remember::findGroup(Application *app, BScreen &screen) { return 0; } +void Remember::updateDecoStateFromClient(WinClient& winclient) { + + Application* app= find(winclient); + + if ( app && isRemembered(winclient, REM_DECOSTATE)) { + winclient.fbwindow()->setDecorationMask(app->decostate); + } +} + void Remember::updateClientClose(WinClient &winclient) { checkReload(); // reload if it's changed Application *app = find(winclient); diff --git a/src/Remember.hh b/src/Remember.hh index 1f3ed7f..a401abb 100644 --- a/src/Remember.hh +++ b/src/Remember.hh @@ -29,135 +29,18 @@ #include "AtomHandler.hh" #include "ClientPattern.hh" -#include "FbTk/AutoReloadHelper.hh" -#include "FbTk/RefCount.hh" -#include #include #include -#include #include class FluxboxWindow; class BScreen; class WinClient; +class Application; -class Application { -public: - Application(bool grouped, ClientPattern *pat = 0); - void reset(); - void forgetWorkspace() { workspace_remember = false; } - void forgetHead() { head_remember = false; } - void forgetDimensions() { dimensions_remember = false; } - void forgetPosition() { position_remember = false; } - void forgetShadedstate() { shadedstate_remember = false; } - void forgetTabstate() { tabstate_remember = false; } - void forgetDecostate() { decostate_remember = false; } - void forgetFocusHiddenstate() { focushiddenstate_remember= false; } - void forgetIconHiddenstate() { iconhiddenstate_remember= false; } - void forgetStuckstate() { stuckstate_remember = false; } - void forgetJumpworkspace() { jumpworkspace_remember = false; } - void forgetLayer() { layer_remember = false; } - void forgetSaveOnClose() { save_on_close_remember = false; } - void forgetAlpha() { alpha_remember = false; } - void forgetMinimizedstate() { minimizedstate_remember = false; } - void forgetMaximizedstate() { maximizedstate_remember = false; } - void forgetFullscreenstate() { fullscreenstate_remember = false; } - - void rememberWorkspace(int ws) - { workspace = ws; workspace_remember = true; } - void rememberHead(int h) - { head = h; head_remember = true; } - void rememberDimensions(int width, int height) - { w = width; h = height; dimensions_remember = true; } - void rememberFocusHiddenstate(bool state) - { focushiddenstate= state; focushiddenstate_remember= true; } - void rememberIconHiddenstate(bool state) - { iconhiddenstate= state; iconhiddenstate_remember= true; } - void rememberPosition(int posx, int posy, unsigned char rfc= 0 ) - { x = posx; y = posy; refc = rfc; position_remember = true; } - void rememberShadedstate(bool state) - { shadedstate = state; shadedstate_remember = true; } - void rememberTabstate(bool state) - { tabstate = state; tabstate_remember = true; } - void rememberDecostate(unsigned int state) - { decostate = state; decostate_remember = true; } - void rememberStuckstate(bool state) - { stuckstate = state; stuckstate_remember = true; } - void rememberJumpworkspace(bool state) - { jumpworkspace = state; jumpworkspace_remember = true; } - void rememberLayer(int layernum) - { layer = layernum; layer_remember = true; } - void rememberSaveOnClose(bool state) - { save_on_close = state; save_on_close_remember = true; } - void rememberAlpha(int focused_a, int unfocused_a) - { focused_alpha = focused_a; unfocused_alpha = unfocused_a; alpha_remember = true; } - void rememberMinimizedstate(bool state) - { minimizedstate = state; minimizedstate_remember = true; } - void rememberMaximizedstate(int state) - { maximizedstate = state; maximizedstate_remember = true; } - void rememberFullscreenstate(bool state) - { fullscreenstate = state; fullscreenstate_remember = true; } - - bool workspace_remember; - unsigned int workspace; - - bool head_remember; - int head; - - bool dimensions_remember; - int w,h; // width, height - - bool position_remember; - int x,y; - unsigned char refc; // referenceCorner-> 0 - upperleft - // 1 - upperight - // 2 - lowerleft - // 3 - lowerright - - bool alpha_remember; - int focused_alpha; - int unfocused_alpha; - - bool shadedstate_remember; - bool shadedstate; - - bool tabstate_remember; - bool tabstate; - - bool decostate_remember; - unsigned int decostate; - - bool stuckstate_remember; - bool stuckstate; - - bool focushiddenstate_remember; - bool focushiddenstate; - - bool iconhiddenstate_remember; - bool iconhiddenstate; - - bool jumpworkspace_remember; - bool jumpworkspace; - - bool layer_remember; - int layer; - - bool save_on_close_remember; - bool save_on_close; - - bool minimizedstate_remember; - bool minimizedstate; - - bool maximizedstate_remember; - int maximizedstate; - - bool fullscreenstate_remember; - bool fullscreenstate; - - bool is_grouped; - FbTk::RefCount group_pattern; - +namespace FbTk { +class AutoReloadHelper; }; /** @@ -258,6 +141,8 @@ public: void updateLayer(FluxboxWindow &win) {} void updateFrameClose(FluxboxWindow &win) {} + void updateDecoStateFromClient(WinClient& client); + bool checkClientMessage(const XClientMessageEvent &ce, BScreen * screen, WinClient * const winclient) { return false; } // ignore this @@ -267,20 +152,13 @@ public: private: - // returns number of lines read - // optionally can give a line to read before the first (lookahead line) - int parseApp(std::ifstream &file, Application &app, std::string *first_line = 0); - - Application *findMatchingPatterns(ClientPattern *pat, Patterns *patlist, - bool is_group, ClientPattern *match_pat = 0); - std::auto_ptr m_pats; Clients m_clients; Startups m_startups; static Remember *s_instance; - FbTk::AutoReloadHelper m_reloader; + FbTk::AutoReloadHelper* m_reloader; }; #endif // REMEMBER_HH diff --git a/src/Slit.cc b/src/Slit.cc index 80dca0d..56e591e 100644 --- a/src/Slit.cc +++ b/src/Slit.cc @@ -1029,7 +1029,7 @@ void Slit::configureRequestEvent(XConfigureRequestEvent &event) { if ((*it)->window() == event.window) { if ((*it)->width() != ((unsigned) event.width) || (*it)->height() != ((unsigned) event.height)) { - (*it)->resize(event.width, event.height);; + (*it)->resize(event.width, event.height); reconf = true; //requires reconfiguration diff --git a/src/Window.cc b/src/Window.cc index 2f06603..0c5ae0f 100644 --- a/src/Window.cc +++ b/src/Window.cc @@ -1183,17 +1183,6 @@ void FluxboxWindow::updateMWMHintsFromClient(WinClient &client) { } } -void FluxboxWindow::updateRememberStateFromClient(WinClient &client) { -#ifdef REMEMBER - Remember* rem= const_cast(static_cast(Fluxbox::instance()->getAtomHandler("remember"))); - Application* app= 0; - if ( rem && (app= (const_cast(rem))->find(client)) ) { - if ( !m_toggled_decos && rem->isRemembered(client, Remember::REM_DECOSTATE) ) - setDecorationMask(app->decostate); - } -#endif // REMEMBER -} - void FluxboxWindow::updateFunctions() { if (!m_client) return; @@ -1828,7 +1817,7 @@ void FluxboxWindow::setIconic(bool val) { void FluxboxWindow::raise() { if (isIconic()) - return;; + return; #ifdef DEBUG cerr<<"FluxboxWindow("<getMWMHintsAtom()) { client.updateMWMHints(); updateMWMHintsFromClient(client); - updateRememberStateFromClient(client); + if (!m_toggled_decos) { + Remember::instance().updateDecoStateFromClient(client); + } applyDecorations(); // update decorations (if they changed) } break; @@ -2511,21 +2502,19 @@ void FluxboxWindow::configureRequestEvent(XConfigureRequestEvent &cr) { struct timeval now; gettimeofday(&now, NULL); + Remember& rinst = Remember::instance(); + if (now.tv_sec > m_creation_time + 1) m_creation_time = 0; - else if (Remember::instance().isRemembered(*client, - Remember::REM_MAXIMIZEDSTATE) || - Remember::instance().isRemembered(*client, - Remember::REM_FULLSCREENSTATE)) { + else if (rinst.isRemembered(*client, Remember::REM_MAXIMIZEDSTATE) || + rinst.isRemembered(*client, Remember::REM_FULLSCREENSTATE)) { cr.value_mask = cr.value_mask & ~(CWWidth | CWHeight); cr.value_mask = cr.value_mask & ~(CWX | CWY); } else { - if (Remember::instance().isRemembered(*client, - Remember::REM_DIMENSIONS)) + if (rinst.isRemembered(*client, Remember::REM_DIMENSIONS)) cr.value_mask = cr.value_mask & ~(CWWidth | CWHeight); - if (Remember::instance().isRemembered(*client, - Remember::REM_POSITION)) + if (rinst.isRemembered(*client, Remember::REM_POSITION)) cr.value_mask = cr.value_mask & ~(CWX | CWY); } } diff --git a/src/Window.hh b/src/Window.hh index e7d2270..8085622 100644 --- a/src/Window.hh +++ b/src/Window.hh @@ -528,7 +528,6 @@ private: bool getState(); void updateMWMHintsFromClient(WinClient &client); - void updateRememberStateFromClient(WinClient &client); void saveBlackboxAttribs(); void associateClientWindow(bool use_attrs = false, int x = 0, int y = 0, unsigned int width = 1, unsigned int height = 1, int gravity = ForgetGravity, unsigned int client_bw = 0); diff --git a/src/fluxbox.cc b/src/fluxbox.cc index d62e5ca..db337ad 100644 --- a/src/fluxbox.cc +++ b/src/fluxbox.cc @@ -1183,7 +1183,7 @@ AtomHandler* Fluxbox::getAtomHandler(const string &name) { return 0; } void Fluxbox::addAtomHandler(AtomHandler *atomh, const string &name) { - m_atomhandler[atomh]= name;; + m_atomhandler[atomh]= name; } void Fluxbox::removeAtomHandler(AtomHandler *atomh) { -- cgit v0.11.2