From 8b5f039f10e51f972dbed0a4d75fc569bde4b9a8 Mon Sep 17 00:00:00 2001 From: rathnor Date: Fri, 30 Jan 2004 11:06:25 +0000 Subject: slitlist fixing up --- ChangeLog | 5 +++++ src/Slit.cc | 31 ++++++++++++++++++++++--------- src/Xutil.cc | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/Xutil.hh | 6 +++++- 4 files changed, 87 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 02cdd7c..589df47 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ (Format: Year/Month/Day) Changes for 0.9.9: +*04/01/30: + * Tidy up a few slitlist things (Simon) + - expand ~, trim spaces, allow comments, use WM_CLASS instead of NAME + - should make it use regexp like remember sometime + Slit.cc Xutil.hh/cc *04/01/23: * Fix a few window frame issues when changing styles (Simon) - particularly a "void" area of the window diff --git a/src/Slit.cc b/src/Slit.cc index 5d596ef..2c2574e 100644 --- a/src/Slit.cc +++ b/src/Slit.cc @@ -22,7 +22,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Slit.cc,v 1.87 2004/01/10 02:58:21 fluxgen Exp $ +// $Id: Slit.cc,v 1.88 2004/01/30 11:06:25 rathnor Exp $ #include "Slit.hh" @@ -57,6 +57,7 @@ #include "SlitClient.hh" #include "Xutil.hh" #include "FbAtoms.hh" +#include "FbTk/StringUtil.hh" #include #include @@ -415,7 +416,7 @@ void Slit::addClient(Window w) { // Look for slot in client list by name SlitClient *client = 0; std::string match_name; - match_name = Xutil::getWMName(w); + match_name = Xutil::getWMClassName(w); SlitClients::iterator it = m_client_list.begin(); SlitClients::iterator it_end = m_client_list.end(); bool found_match = false; @@ -1123,22 +1124,34 @@ void Slit::toggleHidden() { } void Slit::loadClientList(const char *filename) { - if (filename == 0) + if (filename == 0 || filename[0] == '\0') return; - m_filename = filename; // save filename so we can save client list later + // save filename so we can save client list later + m_filename = FbTk::StringUtil::expandFilename(filename); struct stat buf; - if (!stat(filename, &buf)) { + if (stat(filename, &buf) != 0) { std::ifstream file(filename); std::string name; while (! file.eof()) { name = ""; std::getline(file, name); // get the entire line - if (name.size() > 0) { // don't add client unless we have a valid line - SlitClient *client = new SlitClient(name.c_str()); - m_client_list.push_back(client); - } + if (name.size() <= 0) + continue; + + // remove whitespaces from start and end + FbTk::StringUtil::removeFirstWhitespace(name); + + // the cleaned string could still be a comment, or blank + if ( name.size() <= 0 || name[0] == '#' || name[0] == '!' ) + continue; + + // trailing whitespace won't affect the above test + FbTk::StringUtil::removeTrailingWhitespace(name); + + SlitClient *client = new SlitClient(name.c_str()); + m_client_list.push_back(client); } } } diff --git a/src/Xutil.cc b/src/Xutil.cc index a5a6c59..e36080a 100644 --- a/src/Xutil.cc +++ b/src/Xutil.cc @@ -20,7 +20,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Xutil.cc,v 1.3 2004/01/11 16:04:39 fluxgen Exp $ +// $Id: Xutil.cc,v 1.4 2004/01/30 11:06:25 rathnor Exp $ #include "Xutil.hh" @@ -30,6 +30,8 @@ #include #include #include +#include +using namespace std; namespace Xutil { @@ -79,5 +81,57 @@ std::string getWMName(Window window) { return name; } + +// The name of this particular instance +std::string getWMClassName(Window win) { + XClassHint ch; + std::string instance_name; + + if (XGetClassHint(FbTk::App::instance()->display(), win, &ch) == 0) { +#ifdef DEBUG + cerr<<"Xutil: Failed to read class hint!"<(ch.res_name); + XFree(ch.res_name); + ch.res_name = 0; + } else + instance_name = ""; + } + + return instance_name; + +} + +// the name of the general class of the app +std::string getWMClassClass(Window win) { + XClassHint ch; + std::string class_name; + + if (XGetClassHint(FbTk::App::instance()->display(), win, &ch) == 0) { +#ifdef DEBUG + cerr<<"Xutil: Failed to read class hint!"<(ch.res_class); + XFree(ch.res_class); + ch.res_class = 0; + } else + class_name = ""; + } + + return class_name; +} + }; // end namespace Xutil diff --git a/src/Xutil.hh b/src/Xutil.hh index cbb7f78..43796db 100644 --- a/src/Xutil.hh +++ b/src/Xutil.hh @@ -20,7 +20,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Xutil.hh,v 1.2 2004/01/11 16:04:39 fluxgen Exp $ +// $Id: Xutil.hh,v 1.3 2004/01/30 11:06:25 rathnor Exp $ #ifndef XUTIL_HH #define XUTIL_HH @@ -33,6 +33,10 @@ namespace Xutil { std::string getWMName(Window window); +std::string getWMClassName(Window win); +std::string getWMClassClass(Window win); + + }; // end namespace Xutil #endif // XUTIL_HH -- cgit v0.11.2