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
}
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;
}

View file

@ -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;

View file

@ -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?

View file

@ -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;