KWin rules - matching on window type.

svn path=/trunk/kdebase/kwin/; revision=316407
This commit is contained in:
Luboš Luňák 2004-05-31 14:04:49 +00:00
parent 2b027203b1
commit a0384cdd8a
4 changed files with 39 additions and 22 deletions

View file

@ -1568,34 +1568,34 @@ bool Client::isSpecialWindow() const
|| isToolbar(); // TODO || 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 ); NET::WindowType wt = info->windowType( supported_types );
if( direct )
return wt;
NET::WindowType wt2 = rules()->checkType( wt ); NET::WindowType wt2 = rules()->checkType( wt );
if( wt != wt2 ) if( wt != wt2 )
{ {
wt = wt2; wt = wt2;
info->setWindowType( wt ); // force hint change info->setWindowType( wt ); // force hint change
} }
// TODO is this 'strict' really needed (and used?) // hacks here
if( !strict ) if( wt == NET::Menu )
{ // 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
// ugly hack to support the times when NET::Menu meant NET::TopMenu // corner a bit above the screen's upper-left cornet, it's a topmenu
// if it's as wide as the screen, not very high and has its upper-left if( x() == 0 && y() < 0 && y() > -10 && height() < 100
// corner a bit above the screen's upper-left cornet, it's a topmenu && abs( width() - workspace()->clientArea( FullArea, this ).width()) < 10 )
if( x() == 0 && y() < 0 && y() > -10 && height() < 100 wt = NET::TopMenu;
&& 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;
} }
// 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; return wt;
} }

View file

@ -66,7 +66,7 @@ class Client : public QObject, public KDecorationDefines
Group* group(); Group* group();
void checkGroup( Group* gr = NULL, bool force = false ); void checkGroup( Group* gr = NULL, bool force = false );
// prefer isXXX() instead // 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; const WindowRules* rules() const;
QRect geometry() const; QRect geometry() const;

View file

@ -28,13 +28,14 @@ WindowRules::WindowRules()
, titleregexp( false ) , titleregexp( false )
, extraroleregexp( false ) , extraroleregexp( false )
, clientmachineregexp( false ) , clientmachineregexp( false )
, types( NET::AllTypesMask )
, desktoprule( DontCareRule ) , desktoprule( DontCareRule )
, typerule( DontCareRule ) , typerule( DontCareRule )
, aboverule( DontCareRule ) , aboverule( DontCareRule )
, belowrule( DontCareRule ) , belowrule( DontCareRule )
{ {
} }
WindowRules::WindowRules( KConfig& cfg ) WindowRules::WindowRules( KConfig& cfg )
{ {
wmclass = cfg.readEntry( "wmclass" ).lower().latin1(); wmclass = cfg.readEntry( "wmclass" ).lower().latin1();
@ -48,6 +49,7 @@ WindowRules::WindowRules( KConfig& cfg )
extraroleregexp = cfg.readBoolEntry( "extraroleregexp" ); extraroleregexp = cfg.readBoolEntry( "extraroleregexp" );
clientmachine = cfg.readEntry( "clientmachine" ).lower().latin1(); clientmachine = cfg.readEntry( "clientmachine" ).lower().latin1();
clientmachineregexp = cfg.readBoolEntry( "clientmachineregexp" ); clientmachineregexp = cfg.readBoolEntry( "clientmachineregexp" );
types = cfg.readUnsignedLongNumEntry( "types", NET::AllTypesMask );
desktop = cfg.readNumEntry( "desktop" ); desktop = cfg.readNumEntry( "desktop" );
desktoprule = readRule( cfg, "desktoprule" ); desktoprule = readRule( cfg, "desktoprule" );
type = readType( cfg, "type" ); type = readType( cfg, "type" );
@ -83,6 +85,13 @@ WindowRules::WindowRules( KConfig& cfg )
cfg.deleteEntry( #var "rule" ); \ 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 void WindowRules::write( KConfig& cfg ) const
{ {
// always write wmclass // always write wmclass
@ -93,6 +102,7 @@ void WindowRules::write( KConfig& cfg ) const
WRITE_MATCH_STRING( title, ); WRITE_MATCH_STRING( title, );
WRITE_MATCH_STRING( extrarole, (const char*) ); WRITE_MATCH_STRING( extrarole, (const char*) );
WRITE_MATCH_STRING( clientmachine, (const char*) ); WRITE_MATCH_STRING( clientmachine, (const char*) );
WRITE_WITH_DEFAULT( types, NET::AllTypesMask );
WRITE_SET_RULE( desktop ); WRITE_SET_RULE( desktop );
WRITE_SET_RULE( type ); WRITE_SET_RULE( type );
WRITE_SET_RULE( above ); WRITE_SET_RULE( above );
@ -101,6 +111,7 @@ void WindowRules::write( KConfig& cfg ) const
#undef WRITE_MATCH_STRING #undef WRITE_MATCH_STRING
#undef WRITE_SET_RULE #undef WRITE_SET_RULE
#undef WRITE_WITH_DEFAULT
SettingRule WindowRules::readRule( KConfig& cfg, const QString& key ) 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 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? // TODO exactMatch() for regexp?
if( !wmclass.isEmpty()) if( !wmclass.isEmpty())
{ // TODO optimize? { // TODO optimize?

View file

@ -59,9 +59,10 @@ class WindowRules
bool extraroleregexp; bool extraroleregexp;
QCString clientmachine; QCString clientmachine;
bool clientmachineregexp; bool clientmachineregexp;
unsigned long types; // types for matching
int desktop; int desktop;
SettingRule desktoprule; SettingRule desktoprule;
NET::WindowType type; NET::WindowType type; // type for setting
SettingRule typerule; SettingRule typerule;
bool above; bool above;
SettingRule aboverule; SettingRule aboverule;