add apps file matching on role. Includes new textProperty property on FbWindow.
@@ -1,5 +1,10 @@
(Format: Year/Month/Day) Changes for 0.9.10: +*04/04/28: + * Add apps file matching on WM_WINDOW_ROLE (Simon) + - use "role=string". Particularly useful for gaim windows + [app] (role=buddy_list) ... + ClientPattern.hh/cc FbWindow.hh/cc *04/04/27: * Fix up several toolbar theme items and alignments (Simon) - big improvement in look/compatibility of older styles
@@ -20,12 +20,13 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: ClientPattern.cc,v 1.6 2003/12/17 01:19:39 fluxgen Exp $ +// $Id: ClientPattern.cc,v 1.7 2004/04/28 13:04:06 rathnor Exp $ #include "ClientPattern.hh" #include "RegExp.hh" #include "StringUtil.hh" #include "WinClient.hh" +#include "FbTk/App.hh" // use GNU extensions #ifndef _GNU_SOURCE@@ -110,6 +111,8 @@ } else if (strcasecmp(memstr.c_str(), "class") == 0) {
prop = CLASS; } else if (strcasecmp(memstr.c_str(), "title") == 0) { prop = TITLE; + } else if (strcasecmp(memstr.c_str(), "role") == 0) { + prop = ROLE; } else { had_error = pos + match.find_first_of('(') + 1; break;@@ -186,6 +189,8 @@ break;
case TITLE: pat.append("title="); break; + case ROLE: + pat.append("role="); } pat.append((*it)->orig);@@ -245,6 +250,10 @@ return client.getWMClassClass();
break; case NAME: return client.getWMClassName(); + break; + case ROLE: + Atom wm_role = XInternAtom(FbTk::App::instance()->display(), "WM_WINDOW_ROLE", False); + return client.textProperty(wm_role); break; } return client.getWMClassName();
@@ -21,7 +21,7 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: ClientPattern.hh,v 1.2 2003/06/13 12:02:00 fluxgen Exp $ +// $Id: ClientPattern.hh,v 1.3 2004/04/28 13:04:06 rathnor Exp $ #ifndef CLIENTPATTERN_HH #define CLIENTPATTERN_HH@@ -53,7 +53,7 @@
/// @return a string representation of this pattern std::string toString() const; - enum WinProperty { TITLE, CLASS, NAME }; + enum WinProperty { TITLE, CLASS, NAME, ROLE }; /// Does this client match this pattern? bool match(const WinClient &win) const;
@@ -19,7 +19,7 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: FbWindow.cc,v 1.31 2004/01/21 20:07:41 fluxgen Exp $ +// $Id: FbWindow.cc,v 1.32 2004/04/28 13:04:06 rathnor Exp $ #include "FbWindow.hh"@@ -32,6 +32,7 @@ #ifdef HAVE_CONFIG_H
#include "config.h" #endif // HAVE_CONFIG_H +#include <X11/Xutil.h> #include <X11/Xatom.h> #include <cassert>@@ -340,6 +341,33 @@ void FbWindow::reparent(const FbWindow &parent, int x, int y) {
XReparentWindow(s_display, window(), parent.window(), x, y); m_parent = &parent; updateGeometry(); +} + +std::string FbWindow::textProperty(Atom property) const { + XTextProperty text_prop; + char ** stringlist; + int count; + std::string ret; + + if (XGetTextProperty(s_display, window(), &text_prop, property) == 0) + return ""; + + if (text_prop.value == 0 || text_prop.nitems == 0) + return ""; + + if (text_prop.encoding != XA_STRING) { + // still returns a "StringList" despite the different name + if (XmbTextPropertyToTextList(s_display, &text_prop, &stringlist, &count) == 0 || count == 0) + return ""; + } else { + if (XTextPropertyToStringList(&text_prop, &stringlist, &count) == 0 || count == 0) + return ""; + + } + + ret = stringlist[0]; + XFreeStringList(stringlist); + return ret; } bool FbWindow::property(Atom property,
@@ -19,7 +19,7 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: FbWindow.hh,v 1.28 2004/01/21 20:22:26 fluxgen Exp $ +// $Id: FbWindow.hh,v 1.29 2004/04/28 13:04:06 rathnor Exp $ #ifndef FBTK_FBWINDOW_HH #define FBTK_FBWINDOW_HH@@ -28,7 +28,7 @@ #include "FbDrawable.hh"
#include <X11/Xlib.h> #include <memory> - +#include <string> namespace FbTk {@@ -134,6 +134,8 @@ int format,
int mode, unsigned char *data, int nelements); + + std::string textProperty(Atom property) const; /// @return parent FbWindow const FbWindow *parent() const { return m_parent; }