From b2755bcaa70027e9f9d14e2ddf221e3fd9df139f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20L=C3=BCbking?= Date: Sun, 27 Sep 2015 21:15:35 +0200 Subject: [PATCH] re-evaluate rules on title change If a rule minus the title match matches, the captionChanged signal is bound to re-evaluate the rules for that client, ie. the tracking overhead only exists for those clients where title matching is relevant and costs rematching all rules when such client changes its title (yes, the partial matching rules could be stored for faster re-check, but that would make the patch bigger and is probably not worth it; just some string comparisms) additional tracking of wm_class or wm_role (what is iirc a netwm violation anyway) would require to monitor the resp. property for changes (not done atm.) BUG: 220227 FIXED-IN: 5.5 REVIEW: 125427 --- client.cpp | 6 ++++++ client.h | 1 + rules.cpp | 10 ++++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/client.cpp b/client.cpp index dbadafee98..248831747d 100644 --- a/client.cpp +++ b/client.cpp @@ -1520,6 +1520,12 @@ void Client::updateCaption() setCaption(cap_normal, true); } +void Client::evaluateWindowRules() +{ + setupWindowRules(true); + applyWindowRules(); +} + void Client::fetchIconicName() { QString s; diff --git a/client.h b/client.h index 4fbaa5ffbc..f22e6908f4 100644 --- a/client.h +++ b/client.h @@ -410,6 +410,7 @@ public: public Q_SLOTS: void closeWindow() override; void updateCaption(); + void evaluateWindowRules(); private Q_SLOTS: void shadeHover(); diff --git a/rules.cpp b/rules.cpp index 7ab6fa724d..fe449e6427 100644 --- a/rules.cpp +++ b/rules.cpp @@ -449,10 +449,15 @@ bool Rules::match(const Client* c) const return false; if (!matchRole(c->windowRole())) return false; - if (!matchTitle(c->caption(false))) - return false; if (!matchClientMachine(c->clientMachine()->hostName(), c->clientMachine()->isLocal())) return false; + if (titlematch != UnimportantMatch) // track title changes to rematch rules + QObject::connect(c, &Client::captionChanged, c, &Client::evaluateWindowRules, + // QueuedConnection, because title may change before + // the client is ready (could segfault!) + static_cast(Qt::QueuedConnection|Qt::UniqueConnection)); + if (!matchTitle(c->caption(false))) + return false; return true; } @@ -862,6 +867,7 @@ CHECK_FORCE_RULE(DisableGlobalShortcuts, bool) void Client::setupWindowRules(bool ignore_temporary) { + disconnect(this, &Client::captionChanged, this, &Client::evaluateWindowRules); client_rules = RuleBook::self()->find(this, ignore_temporary); // check only after getting the rules, because there may be a rule forcing window type }