From a0384cdd8aa148546d3e0d029d5e6e467bd05a0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Mon, 31 May 2004 14:04:49 +0000 Subject: [PATCH] KWin rules - matching on window type. svn path=/trunk/kdebase/kwin/; revision=316407 --- client.cpp | 38 +++++++++++++++++++------------------- client.h | 2 +- rules.cpp | 18 +++++++++++++++++- rules.h | 3 ++- 4 files changed, 39 insertions(+), 22 deletions(-) diff --git a/client.cpp b/client.cpp index cfdb37691b..3a79650819 100644 --- a/client.cpp +++ b/client.cpp @@ -1568,34 +1568,34 @@ bool Client::isSpecialWindow() const || isToolbar(); // TODO } -NET::WindowType Client::windowType( bool strict, int supported_types ) const +NET::WindowType Client::windowType( bool direct, int supported_types ) const { NET::WindowType wt = info->windowType( supported_types ); + if( direct ) + return wt; NET::WindowType wt2 = rules()->checkType( wt ); if( wt != wt2 ) { wt = wt2; info->setWindowType( wt ); // force hint change } - // TODO is this 'strict' really needed (and used?) - if( !strict ) - { // hacks here - if( wt == NET::Menu ) - { - // ugly hack to support the times when NET::Menu meant NET::TopMenu - // if it's as wide as the screen, not very high and has its upper-left - // corner a bit above the screen's upper-left cornet, it's a topmenu - if( x() == 0 && y() < 0 && y() > -10 && height() < 100 - && abs( width() - workspace()->clientArea( FullArea, this ).width()) < 10 ) - wt = NET::TopMenu; - } - const char* const oo_prefix = "openoffice.org"; // QCString has no startsWith() - // oo_prefix is lowercase, because resourceClass() is forced to be lowercase - if( qstrncmp( resourceClass(), oo_prefix, strlen( oo_prefix )) == 0 && wt == NET::Dialog ) - wt = NET::Normal; // see bug #66065 - if( wt == NET::Unknown ) // this is more or less suggested in NETWM spec - wt = isTransient() ? NET::Dialog : NET::Normal; + // hacks here + if( wt == NET::Menu ) + { + // ugly hack to support the times when NET::Menu meant NET::TopMenu + // if it's as wide as the screen, not very high and has its upper-left + // corner a bit above the screen's upper-left cornet, it's a topmenu + if( x() == 0 && y() < 0 && y() > -10 && height() < 100 + && abs( width() - workspace()->clientArea( FullArea, this ).width()) < 10 ) + wt = NET::TopMenu; } + // TODO change this to rule + const char* const oo_prefix = "openoffice.org"; // QCString has no startsWith() + // oo_prefix is lowercase, because resourceClass() is forced to be lowercase + if( qstrncmp( resourceClass(), oo_prefix, strlen( oo_prefix )) == 0 && wt == NET::Dialog ) + wt = NET::Normal; // see bug #66065 + if( wt == NET::Unknown ) // this is more or less suggested in NETWM spec + wt = isTransient() ? NET::Dialog : NET::Normal; return wt; } diff --git a/client.h b/client.h index cbabe167fe..fdc6655fd8 100644 --- a/client.h +++ b/client.h @@ -66,7 +66,7 @@ class Client : public QObject, public KDecorationDefines Group* group(); void checkGroup( Group* gr = NULL, bool force = false ); // prefer isXXX() instead - NET::WindowType windowType( bool strict = false, int supported_types = SUPPORTED_WINDOW_TYPES_MASK ) const; + NET::WindowType windowType( bool direct = false, int supported_types = SUPPORTED_WINDOW_TYPES_MASK ) const; const WindowRules* rules() const; QRect geometry() const; diff --git a/rules.cpp b/rules.cpp index a6f2ff7b3f..6fe0501009 100644 --- a/rules.cpp +++ b/rules.cpp @@ -28,13 +28,14 @@ WindowRules::WindowRules() , titleregexp( false ) , extraroleregexp( false ) , clientmachineregexp( false ) + , types( NET::AllTypesMask ) , desktoprule( DontCareRule ) , typerule( DontCareRule ) , aboverule( DontCareRule ) , belowrule( DontCareRule ) { } - + WindowRules::WindowRules( KConfig& cfg ) { wmclass = cfg.readEntry( "wmclass" ).lower().latin1(); @@ -48,6 +49,7 @@ WindowRules::WindowRules( KConfig& cfg ) extraroleregexp = cfg.readBoolEntry( "extraroleregexp" ); clientmachine = cfg.readEntry( "clientmachine" ).lower().latin1(); clientmachineregexp = cfg.readBoolEntry( "clientmachineregexp" ); + types = cfg.readUnsignedLongNumEntry( "types", NET::AllTypesMask ); desktop = cfg.readNumEntry( "desktop" ); desktoprule = readRule( cfg, "desktoprule" ); type = readType( cfg, "type" ); @@ -83,6 +85,13 @@ WindowRules::WindowRules( KConfig& cfg ) cfg.deleteEntry( #var "rule" ); \ } +#define WRITE_WITH_DEFAULT( var, default ) \ + if( var != default ) \ + cfg.writeEntry( #var, var ); \ + else \ + cfg.deleteEntry( #var ); + + void WindowRules::write( KConfig& cfg ) const { // always write wmclass @@ -93,6 +102,7 @@ void WindowRules::write( KConfig& cfg ) const WRITE_MATCH_STRING( title, ); WRITE_MATCH_STRING( extrarole, (const char*) ); WRITE_MATCH_STRING( clientmachine, (const char*) ); + WRITE_WITH_DEFAULT( types, NET::AllTypesMask ); WRITE_SET_RULE( desktop ); WRITE_SET_RULE( type ); WRITE_SET_RULE( above ); @@ -101,6 +111,7 @@ void WindowRules::write( KConfig& cfg ) const #undef WRITE_MATCH_STRING #undef WRITE_SET_RULE +#undef WRITE_WITH_DEFAULT SettingRule WindowRules::readRule( KConfig& cfg, const QString& key ) { @@ -128,6 +139,11 @@ NET::WindowType WindowRules::readType( KConfig& cfg, const QString& key ) bool WindowRules::match( const Client* c ) const { + if( types != NET::AllTypesMask ) + { + if( !NET::typeMatchesMask( c->windowType( true ), types )) // direct + return false; + } // TODO exactMatch() for regexp? if( !wmclass.isEmpty()) { // TODO optimize? diff --git a/rules.h b/rules.h index f4d564d807..b2d38dc259 100644 --- a/rules.h +++ b/rules.h @@ -59,9 +59,10 @@ class WindowRules bool extraroleregexp; QCString clientmachine; bool clientmachineregexp; + unsigned long types; // types for matching int desktop; SettingRule desktoprule; - NET::WindowType type; + NET::WindowType type; // type for setting SettingRule typerule; bool above; SettingRule aboverule;