2004-05-28 13:51:11 +00:00
|
|
|
/*****************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2004 Lubos Lunak <l.lunak@kde.org>
|
|
|
|
|
|
|
|
You can Freely distribute this program under the GNU General Public
|
|
|
|
License. See the file "COPYING" for the exact licensing terms.
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
#include "rules.h"
|
|
|
|
|
|
|
|
#include <kconfig.h>
|
|
|
|
#include <qregexp.h>
|
2004-06-11 15:10:09 +00:00
|
|
|
#include <ktempfile.h>
|
|
|
|
#include <ksimpleconfig.h>
|
|
|
|
#include <qfile.h>
|
2004-05-28 13:51:11 +00:00
|
|
|
|
|
|
|
#include "client.h"
|
|
|
|
#include "workspace.h"
|
|
|
|
|
|
|
|
namespace KWinInternal
|
|
|
|
{
|
|
|
|
|
|
|
|
static WindowRules dummyRules; // dummy used to avoid NULL checks
|
|
|
|
|
|
|
|
WindowRules::WindowRules()
|
2004-06-11 15:10:09 +00:00
|
|
|
: temporary_state( 0 )
|
|
|
|
, wmclassregexp( false )
|
2004-05-28 13:54:20 +00:00
|
|
|
, wmclasscomplete( false )
|
2004-05-28 13:51:11 +00:00
|
|
|
, windowroleregexp( false )
|
|
|
|
, titleregexp( false )
|
|
|
|
, extraroleregexp( false )
|
2004-05-28 13:54:20 +00:00
|
|
|
, clientmachineregexp( false )
|
2004-05-31 14:04:49 +00:00
|
|
|
, types( NET::AllTypesMask )
|
2004-05-31 14:14:10 +00:00
|
|
|
, placementrule( DontCareRule )
|
2004-05-31 14:25:25 +00:00
|
|
|
, positionrule( DontCareRule )
|
|
|
|
, sizerule( DontCareRule )
|
2004-05-31 14:15:33 +00:00
|
|
|
, minsizerule( DontCareRule )
|
|
|
|
, maxsizerule( DontCareRule )
|
2004-05-28 13:51:11 +00:00
|
|
|
, desktoprule( DontCareRule )
|
2004-05-28 15:04:01 +00:00
|
|
|
, typerule( DontCareRule )
|
2004-06-03 14:09:45 +00:00
|
|
|
, maximizevertrule( DontCareRule )
|
|
|
|
, maximizehorizrule( DontCareRule )
|
|
|
|
, minimizerule( DontCareRule )
|
|
|
|
, shaderule( DontCareRule )
|
|
|
|
, skiptaskbarrule( DontCareRule )
|
|
|
|
, skippagerrule( DontCareRule )
|
2004-05-28 13:51:11 +00:00
|
|
|
, aboverule( DontCareRule )
|
|
|
|
, belowrule( DontCareRule )
|
2004-06-03 14:09:45 +00:00
|
|
|
, fullscreenrule( DontCareRule )
|
|
|
|
, noborderrule( DontCareRule )
|
2004-06-11 15:12:07 +00:00
|
|
|
, fsplevelrule( DontCareRule )
|
2004-06-09 08:30:06 +00:00
|
|
|
, acceptfocusrule( DontCareRule )
|
2004-06-09 08:33:53 +00:00
|
|
|
, moveresizemoderule( DontCareRule )
|
|
|
|
, closeablerule( DontCareRule )
|
2004-05-28 13:51:11 +00:00
|
|
|
{
|
|
|
|
}
|
2004-05-31 14:04:49 +00:00
|
|
|
|
2004-06-11 15:10:09 +00:00
|
|
|
WindowRules::WindowRules( const QString& str, bool temporary )
|
|
|
|
: temporary_state( temporary ? 2 : 0 )
|
|
|
|
{
|
|
|
|
KTempFile file;
|
|
|
|
QFile* f = file.file();
|
|
|
|
if( f != NULL )
|
|
|
|
{
|
|
|
|
QCString s = str.utf8();
|
|
|
|
f->writeBlock( s.data(), s.length());
|
|
|
|
}
|
|
|
|
file.close();
|
|
|
|
KSimpleConfig cfg( file.name());
|
|
|
|
readFromCfg( cfg );
|
|
|
|
file.unlink();
|
|
|
|
}
|
|
|
|
|
2004-05-31 14:31:52 +00:00
|
|
|
#define READ_MATCH_STRING( var, func ) \
|
|
|
|
var = cfg.readEntry( #var ) func; \
|
|
|
|
var##regexp = cfg.readBoolEntry( #var "regexp" );
|
|
|
|
|
|
|
|
#define READ_SET_RULE( var, type, func ) \
|
|
|
|
var = func ( cfg.read##type##Entry( #var )); \
|
|
|
|
var##rule = readRule( cfg, #var "rule" );
|
|
|
|
|
|
|
|
#define READ_SET_RULE_2( var, type, func, funcarg ) \
|
|
|
|
var = func ( cfg.read##type##Entry( #var ), funcarg ); \
|
|
|
|
var##rule = readRule( cfg, #var "rule" );
|
2004-06-09 08:29:35 +00:00
|
|
|
|
|
|
|
#define READ_FORCE_RULE( var, type, func ) \
|
|
|
|
var = func ( cfg.read##type##Entry( #var )); \
|
|
|
|
var##rule = readForceRule( cfg, #var "rule" );
|
|
|
|
|
2004-05-28 13:51:11 +00:00
|
|
|
WindowRules::WindowRules( KConfig& cfg )
|
2004-06-11 15:10:09 +00:00
|
|
|
: temporary_state( 0 )
|
|
|
|
{
|
|
|
|
readFromCfg( cfg );
|
|
|
|
}
|
|
|
|
|
2004-06-11 15:12:07 +00:00
|
|
|
static int limit0to4( int i ) { return QMAX( 0, QMIN( 4, i )); }
|
|
|
|
|
2004-06-11 15:10:09 +00:00
|
|
|
void WindowRules::readFromCfg( KConfig& cfg )
|
2004-05-28 13:51:11 +00:00
|
|
|
{
|
|
|
|
wmclass = cfg.readEntry( "wmclass" ).lower().latin1();
|
|
|
|
wmclassregexp = cfg.readBoolEntry( "wmclassregexp" );
|
2004-05-28 13:54:20 +00:00
|
|
|
wmclasscomplete = cfg.readBoolEntry( "wmclasscomplete" );
|
2004-05-31 14:31:52 +00:00
|
|
|
READ_MATCH_STRING( windowrole, .lower().latin1() );
|
|
|
|
READ_MATCH_STRING( title, );
|
|
|
|
READ_MATCH_STRING( extrarole, .lower().latin1() );
|
|
|
|
READ_MATCH_STRING( clientmachine, .lower().latin1() );
|
2004-05-31 14:04:49 +00:00
|
|
|
types = cfg.readUnsignedLongNumEntry( "types", NET::AllTypesMask );
|
2004-05-31 14:31:52 +00:00
|
|
|
READ_SET_RULE_2( placement,, Placement::policyFromString, false );
|
|
|
|
READ_SET_RULE( position, Point, );
|
|
|
|
READ_SET_RULE( size, Size, );
|
2004-05-31 14:25:25 +00:00
|
|
|
if( size.isEmpty())
|
|
|
|
sizerule = DontCareRule;
|
2004-05-31 14:31:52 +00:00
|
|
|
READ_SET_RULE( minsize, Size, );
|
2004-05-31 14:25:25 +00:00
|
|
|
if( !minsize.isValid())
|
|
|
|
minsizerule = DontCareRule;
|
2004-05-31 14:31:52 +00:00
|
|
|
READ_SET_RULE( maxsize, Size, );
|
2004-05-31 14:25:25 +00:00
|
|
|
if( maxsize.isEmpty())
|
|
|
|
maxsizerule = DontCareRule;
|
2004-05-31 14:31:52 +00:00
|
|
|
READ_SET_RULE( desktop, Num, );
|
2004-05-28 15:04:01 +00:00
|
|
|
type = readType( cfg, "type" );
|
|
|
|
typerule = type != NET::Unknown ? readForceRule( cfg, "typerule" ) : DontCareRule;
|
2004-06-03 14:09:45 +00:00
|
|
|
READ_SET_RULE( maximizevert, Bool, );
|
|
|
|
READ_SET_RULE( maximizehoriz, Bool, );
|
|
|
|
READ_SET_RULE( minimize, Bool, );
|
|
|
|
READ_SET_RULE( shade, Bool, );
|
|
|
|
READ_SET_RULE( skiptaskbar, Bool, );
|
|
|
|
READ_SET_RULE( skippager, Bool, );
|
2004-05-31 14:31:52 +00:00
|
|
|
READ_SET_RULE( above, Bool, );
|
|
|
|
READ_SET_RULE( below, Bool, );
|
2004-06-03 14:09:45 +00:00
|
|
|
READ_SET_RULE( fullscreen, Bool, );
|
|
|
|
READ_SET_RULE( noborder, Bool, );
|
2004-06-11 15:12:07 +00:00
|
|
|
READ_FORCE_RULE( fsplevel, Num, limit0to4 ); // fsp is 0-4
|
2004-06-09 08:30:06 +00:00
|
|
|
READ_FORCE_RULE( acceptfocus, Bool, );
|
2004-06-09 08:33:53 +00:00
|
|
|
READ_FORCE_RULE( moveresizemode, , Options::stringToMoveResizeMode );
|
|
|
|
READ_FORCE_RULE( closeable, Bool, );
|
2004-06-11 15:10:09 +00:00
|
|
|
kdDebug() << "READ RULE:" << wmclass << "/" << title << endl;
|
2004-05-28 13:51:11 +00:00
|
|
|
}
|
|
|
|
|
2004-05-31 14:31:52 +00:00
|
|
|
#undef READ_MATCH_STRING
|
|
|
|
#undef READ_SET_RULE
|
|
|
|
#undef READ_SET_RULE_2
|
2004-06-09 08:29:35 +00:00
|
|
|
#undef READ_FORCE_RULE
|
2004-05-31 14:31:52 +00:00
|
|
|
|
2004-05-28 13:51:11 +00:00
|
|
|
#define WRITE_MATCH_STRING( var, cast ) \
|
|
|
|
if( !var.isEmpty()) \
|
|
|
|
{ \
|
|
|
|
cfg.writeEntry( #var, cast var ); \
|
|
|
|
cfg.writeEntry( #var "regexp", var##regexp ); \
|
|
|
|
} \
|
|
|
|
else \
|
|
|
|
{ \
|
|
|
|
cfg.deleteEntry( #var ); \
|
|
|
|
cfg.deleteEntry( #var "regexp" ); \
|
|
|
|
}
|
|
|
|
|
2004-05-31 14:14:10 +00:00
|
|
|
#define WRITE_SET_RULE( var, func ) \
|
2004-05-28 13:51:11 +00:00
|
|
|
if( var##rule != DontCareRule ) \
|
|
|
|
{ \
|
2004-05-31 14:14:10 +00:00
|
|
|
cfg.writeEntry( #var, func ( var )); \
|
2004-05-28 13:51:11 +00:00
|
|
|
cfg.writeEntry( #var "rule", var##rule ); \
|
|
|
|
} \
|
|
|
|
else \
|
|
|
|
{ \
|
|
|
|
cfg.deleteEntry( #var ); \
|
|
|
|
cfg.deleteEntry( #var "rule" ); \
|
|
|
|
}
|
|
|
|
|
2004-05-31 14:04:49 +00:00
|
|
|
#define WRITE_WITH_DEFAULT( var, default ) \
|
|
|
|
if( var != default ) \
|
|
|
|
cfg.writeEntry( #var, var ); \
|
|
|
|
else \
|
|
|
|
cfg.deleteEntry( #var );
|
|
|
|
|
|
|
|
|
2004-05-28 13:51:11 +00:00
|
|
|
void WindowRules::write( KConfig& cfg ) const
|
|
|
|
{
|
|
|
|
// always write wmclass
|
|
|
|
cfg.writeEntry( "wmclass", ( const char* )wmclass );
|
|
|
|
cfg.writeEntry( "wmclassregexp", wmclassregexp );
|
2004-05-28 13:54:20 +00:00
|
|
|
cfg.writeEntry( "wmclasscomplete", wmclasscomplete );
|
2004-05-28 13:51:11 +00:00
|
|
|
WRITE_MATCH_STRING( windowrole, (const char*) );
|
|
|
|
WRITE_MATCH_STRING( title, );
|
|
|
|
WRITE_MATCH_STRING( extrarole, (const char*) );
|
2004-05-28 13:54:20 +00:00
|
|
|
WRITE_MATCH_STRING( clientmachine, (const char*) );
|
2004-05-31 14:04:49 +00:00
|
|
|
WRITE_WITH_DEFAULT( types, NET::AllTypesMask );
|
2004-05-31 14:14:10 +00:00
|
|
|
WRITE_SET_RULE( placement, Placement::policyToString );
|
2004-05-31 14:25:25 +00:00
|
|
|
WRITE_SET_RULE( position, );
|
|
|
|
WRITE_SET_RULE( size, );
|
2004-05-31 14:15:33 +00:00
|
|
|
WRITE_SET_RULE( minsize, );
|
|
|
|
WRITE_SET_RULE( maxsize, );
|
2004-05-31 14:14:10 +00:00
|
|
|
WRITE_SET_RULE( desktop, );
|
|
|
|
WRITE_SET_RULE( type, );
|
2004-06-03 14:09:45 +00:00
|
|
|
WRITE_SET_RULE( maximizevert, );
|
|
|
|
WRITE_SET_RULE( maximizehoriz, );
|
|
|
|
WRITE_SET_RULE( minimize, );
|
|
|
|
WRITE_SET_RULE( shade, );
|
|
|
|
WRITE_SET_RULE( skiptaskbar, );
|
|
|
|
WRITE_SET_RULE( skippager, );
|
2004-05-31 14:14:10 +00:00
|
|
|
WRITE_SET_RULE( above, );
|
|
|
|
WRITE_SET_RULE( below, );
|
2004-06-03 14:09:45 +00:00
|
|
|
WRITE_SET_RULE( fullscreen, );
|
|
|
|
WRITE_SET_RULE( noborder, );
|
2004-06-11 15:12:07 +00:00
|
|
|
WRITE_SET_RULE( fsplevel, );
|
2004-06-09 08:30:06 +00:00
|
|
|
WRITE_SET_RULE( acceptfocus, );
|
2004-06-09 08:33:53 +00:00
|
|
|
WRITE_SET_RULE( moveresizemode, Options::moveResizeModeToString );
|
|
|
|
WRITE_SET_RULE( closeable, );
|
2004-05-28 13:51:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#undef WRITE_MATCH_STRING
|
|
|
|
#undef WRITE_SET_RULE
|
2004-05-31 14:04:49 +00:00
|
|
|
#undef WRITE_WITH_DEFAULT
|
2004-05-28 13:51:11 +00:00
|
|
|
|
|
|
|
SettingRule WindowRules::readRule( KConfig& cfg, const QString& key )
|
|
|
|
{
|
|
|
|
int v = cfg.readNumEntry( key );
|
|
|
|
if( v >= DontCareRule && v <= LastRule )
|
|
|
|
return static_cast< SettingRule >( v );
|
|
|
|
return DontCareRule;
|
|
|
|
}
|
|
|
|
|
2004-05-28 15:04:01 +00:00
|
|
|
SettingRule WindowRules::readForceRule( KConfig& cfg, const QString& key )
|
2004-05-28 13:51:11 +00:00
|
|
|
{
|
2004-05-28 15:04:01 +00:00
|
|
|
int v = cfg.readNumEntry( key );
|
|
|
|
if( v == DontCareRule || v == ForceRule )
|
|
|
|
return static_cast< SettingRule >( v );
|
|
|
|
return DontCareRule;
|
|
|
|
}
|
|
|
|
|
|
|
|
NET::WindowType WindowRules::readType( KConfig& cfg, const QString& key )
|
|
|
|
{
|
|
|
|
int v = cfg.readNumEntry( key );
|
|
|
|
if( v >= NET::Normal && v <= NET::Splash )
|
|
|
|
return static_cast< NET::WindowType >( v );
|
|
|
|
return NET::Unknown;
|
2004-05-28 13:51:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool WindowRules::match( const Client* c ) const
|
|
|
|
{
|
2004-05-31 14:04:49 +00:00
|
|
|
if( types != NET::AllTypesMask )
|
|
|
|
{
|
2004-06-11 15:10:09 +00:00
|
|
|
NET::WindowType t = c->windowType( true ); // direct type
|
|
|
|
if( t == NET::Unknown )
|
|
|
|
t = NET::Normal; // NET::Unknown->NET::Normal is only here for matching
|
|
|
|
if( !NET::typeMatchesMask( t, types ))
|
2004-05-31 14:04:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
2004-05-28 13:51:11 +00:00
|
|
|
if( !wmclass.isEmpty())
|
|
|
|
{ // TODO optimize?
|
2004-05-28 13:54:20 +00:00
|
|
|
QCString cwmclass = wmclasscomplete
|
2004-06-10 12:34:20 +00:00
|
|
|
? c->resourceName() + ' ' + c->resourceClass() : c->resourceClass();
|
2004-06-11 15:10:09 +00:00
|
|
|
if( wmclassregexp && QRegExp( wmclass ).search( cwmclass ) == -1 )
|
2004-05-28 13:51:11 +00:00
|
|
|
return false;
|
2004-05-28 13:54:20 +00:00
|
|
|
if( !wmclassregexp && wmclass != cwmclass )
|
2004-05-28 13:51:11 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if( !windowrole.isEmpty())
|
|
|
|
{
|
2004-06-11 15:10:09 +00:00
|
|
|
if( windowroleregexp && QRegExp( windowrole ).search( c->windowRole()) == -1 )
|
2004-05-28 13:51:11 +00:00
|
|
|
return false;
|
|
|
|
if( !windowroleregexp && windowrole != c->windowRole())
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if( !title.isEmpty())
|
|
|
|
{
|
2004-06-11 15:10:09 +00:00
|
|
|
if( titleregexp && QRegExp( title ).search( c->caption( false )) == -1 )
|
2004-05-28 13:51:11 +00:00
|
|
|
return false;
|
|
|
|
if( !titleregexp && title != c->caption( false ))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// TODO extrarole
|
2004-05-28 13:54:20 +00:00
|
|
|
if( !clientmachine.isEmpty())
|
|
|
|
{
|
|
|
|
if( clientmachineregexp
|
2004-06-11 15:10:09 +00:00
|
|
|
&& QRegExp( clientmachine ).search( c->wmClientMachine( true )) == -1
|
|
|
|
&& QRegExp( clientmachine ).search( c->wmClientMachine( false )) == -1 )
|
2004-05-28 13:54:20 +00:00
|
|
|
return false;
|
|
|
|
if( !clientmachineregexp
|
|
|
|
&& clientmachine != c->wmClientMachine( true )
|
|
|
|
&& clientmachine != c->wmClientMachine( false ))
|
|
|
|
return false;
|
|
|
|
}
|
2004-05-28 13:51:11 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-05-28 15:04:01 +00:00
|
|
|
void WindowRules::update( Client* c )
|
|
|
|
{
|
|
|
|
// TODO check this setting is for this client ?
|
2004-05-31 14:25:25 +00:00
|
|
|
if( positionrule == RememberRule )
|
|
|
|
position = c->pos();
|
|
|
|
if( sizerule == RememberRule )
|
|
|
|
size = c->size();
|
2004-05-28 15:04:01 +00:00
|
|
|
if( desktoprule == RememberRule )
|
|
|
|
desktop = c->desktop();
|
2004-06-03 14:09:45 +00:00
|
|
|
if( maximizevertrule == RememberRule )
|
|
|
|
maximizevert = c->maximizeMode() & MaximizeVertical;
|
|
|
|
if( maximizehorizrule == RememberRule )
|
|
|
|
maximizehoriz = c->maximizeMode() & MaximizeHorizontal;
|
|
|
|
if( minimizerule == RememberRule )
|
|
|
|
minimize = c->isMinimized();
|
|
|
|
if( shaderule == RememberRule )
|
|
|
|
shade = c->shadeMode() != Client::ShadeNone;
|
|
|
|
if( skiptaskbarrule == RememberRule )
|
|
|
|
skiptaskbar = c->skipTaskbar();
|
|
|
|
if( skippagerrule == RememberRule )
|
|
|
|
skippager = c->skipPager();
|
2004-05-28 15:04:01 +00:00
|
|
|
if( aboverule == RememberRule )
|
|
|
|
above = c->keepAbove();
|
|
|
|
if( belowrule == RememberRule )
|
|
|
|
below = c->keepBelow();
|
2004-06-03 14:09:45 +00:00
|
|
|
if( fullscreenrule == RememberRule )
|
|
|
|
fullscreen = c->isFullScreen();
|
|
|
|
if( noborderrule == RememberRule )
|
|
|
|
noborder = c->isUserNoBorder();
|
2004-05-28 15:04:01 +00:00
|
|
|
}
|
|
|
|
|
2004-05-31 14:14:10 +00:00
|
|
|
Placement::Policy WindowRules::checkPlacement( Placement::Policy placement ) const
|
|
|
|
{
|
|
|
|
return checkForceRule( placementrule ) ? this->placement : placement;
|
|
|
|
}
|
|
|
|
|
2004-05-31 14:25:25 +00:00
|
|
|
// TODO at to porad jeste kontroluje min/max size , + udelat override pro min/max?
|
|
|
|
QRect WindowRules::checkGeometry( const QRect& rect, bool init ) const
|
|
|
|
{
|
|
|
|
return QRect( checkRule( positionrule, init ) ? this->position : rect.topLeft(),
|
|
|
|
checkRule( sizerule, init ) ? this->size : rect.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
QPoint WindowRules::checkPosition( const QPoint& pos, bool init ) const
|
|
|
|
{
|
|
|
|
return checkRule( positionrule, init ) ? this->position : pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize WindowRules::checkSize( const QSize& s, bool init ) const
|
|
|
|
{
|
|
|
|
return checkRule( sizerule, init ) ? this->size : s;
|
|
|
|
}
|
|
|
|
|
2004-05-31 14:15:33 +00:00
|
|
|
QSize WindowRules::checkMinSize( const QSize& s ) const
|
|
|
|
{
|
|
|
|
return checkForceRule( minsizerule ) ? this->minsize : s;
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize WindowRules::checkMaxSize( const QSize& s ) const
|
|
|
|
{
|
|
|
|
return checkForceRule( maxsizerule ) ? this->maxsize : s;
|
|
|
|
}
|
|
|
|
|
2004-05-28 13:51:11 +00:00
|
|
|
int WindowRules::checkDesktop( int req_desktop, bool init ) const
|
|
|
|
{
|
|
|
|
// TODO chaining?
|
2004-05-31 14:14:10 +00:00
|
|
|
return checkRule( desktoprule, init ) ? this->desktop : req_desktop;
|
2004-05-28 13:51:11 +00:00
|
|
|
}
|
|
|
|
|
2004-06-03 14:09:45 +00:00
|
|
|
NET::WindowType WindowRules::checkType( NET::WindowType req_type ) const
|
2004-05-28 13:51:11 +00:00
|
|
|
{
|
2004-06-03 14:09:45 +00:00
|
|
|
return checkForceRule( typerule ) ? this->type : req_type;
|
2004-05-28 13:51:11 +00:00
|
|
|
}
|
|
|
|
|
2004-06-03 14:09:45 +00:00
|
|
|
KDecorationDefines::MaximizeMode WindowRules::checkMaximize( MaximizeMode mode, bool init ) const
|
2004-05-28 13:51:11 +00:00
|
|
|
{
|
2004-06-03 14:09:45 +00:00
|
|
|
bool vert = checkRule( maximizevertrule, init ) ? this->maximizevert : bool( mode & MaximizeVertical );
|
|
|
|
bool horiz = checkRule( maximizehorizrule, init ) ? this->maximizehoriz : bool( mode & MaximizeHorizontal );
|
|
|
|
return static_cast< MaximizeMode >(( vert ? MaximizeVertical : 0 ) | ( horiz ? MaximizeHorizontal : 0 ));
|
2004-05-28 13:51:11 +00:00
|
|
|
}
|
2004-06-03 14:09:45 +00:00
|
|
|
|
|
|
|
bool WindowRules::checkMinimize( bool minimize, bool init ) const
|
2004-05-28 15:04:01 +00:00
|
|
|
{
|
2004-06-03 14:09:45 +00:00
|
|
|
return checkRule( minimizerule, init ) ? this->minimize : minimize;
|
|
|
|
}
|
|
|
|
|
|
|
|
Client::ShadeMode WindowRules::checkShade( Client::ShadeMode shade, bool init ) const
|
|
|
|
{
|
|
|
|
if( checkRule( shaderule, init ))
|
|
|
|
{
|
|
|
|
if( !this->shade )
|
|
|
|
return Client::ShadeNone;
|
|
|
|
if( this->shade && shade == Client::ShadeNone )
|
|
|
|
return Client::ShadeNormal;
|
|
|
|
}
|
|
|
|
return shade;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WindowRules::checkSkipTaskbar( bool skip, bool init ) const
|
|
|
|
{
|
|
|
|
return checkRule( skiptaskbarrule, init ) ? this->skiptaskbar : skip;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WindowRules::checkSkipPager( bool skip, bool init ) const
|
|
|
|
{
|
|
|
|
return checkRule( skippagerrule, init ) ? this->skippager : skip;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WindowRules::checkKeepAbove( bool above, bool init ) const
|
|
|
|
{
|
|
|
|
return checkRule( aboverule, init ) ? this->above : above;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WindowRules::checkKeepBelow( bool below, bool init ) const
|
|
|
|
{
|
|
|
|
return checkRule( belowrule, init ) ? this->below : below;
|
2004-05-28 15:04:01 +00:00
|
|
|
}
|
2004-05-28 13:51:11 +00:00
|
|
|
|
2004-06-03 14:09:45 +00:00
|
|
|
bool WindowRules::checkFullScreen( bool fs, bool init ) const
|
|
|
|
{
|
|
|
|
return checkRule( fullscreenrule, init ) ? this->fullscreen : fs;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WindowRules::checkNoBorder( bool noborder, bool init ) const
|
|
|
|
{
|
|
|
|
return checkRule( noborderrule, init ) ? this->noborder : noborder;
|
|
|
|
}
|
|
|
|
|
2004-06-09 08:29:35 +00:00
|
|
|
int WindowRules::checkFSP( int fsp ) const
|
|
|
|
{
|
2004-06-11 15:12:07 +00:00
|
|
|
return checkForceRule( fsplevelrule ) ? this->fsplevel : fsp;
|
2004-06-09 08:29:35 +00:00
|
|
|
}
|
2004-06-03 14:09:45 +00:00
|
|
|
|
2004-06-09 08:30:06 +00:00
|
|
|
bool WindowRules::checkAcceptFocus( bool focus ) const
|
|
|
|
{
|
|
|
|
return checkForceRule( acceptfocusrule ) ? this->acceptfocus : focus;
|
|
|
|
}
|
|
|
|
|
2004-06-09 08:33:53 +00:00
|
|
|
Options::MoveResizeMode WindowRules::checkMoveResizeMode( Options::MoveResizeMode mode ) const
|
|
|
|
{
|
|
|
|
return checkForceRule( moveresizemoderule ) ? this->moveresizemode : mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WindowRules::checkCloseable( bool closeable ) const
|
|
|
|
{
|
|
|
|
return checkForceRule( closeablerule ) ? this->closeable : closeable;
|
|
|
|
}
|
|
|
|
|
2004-06-11 15:10:09 +00:00
|
|
|
bool WindowRules::isTemporary() const
|
|
|
|
{
|
|
|
|
return temporary_state > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WindowRules::discardTemporary( bool force )
|
|
|
|
{
|
|
|
|
if( temporary_state == 0 ) // not temporary
|
|
|
|
return false;
|
|
|
|
if( force || --temporary_state == 0 ) // too old
|
|
|
|
{
|
|
|
|
kdDebug() << "DISCARD:" << wmclass << "/" << title << endl;
|
|
|
|
delete this;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-05-28 13:51:11 +00:00
|
|
|
// Client
|
|
|
|
|
2004-06-11 15:10:09 +00:00
|
|
|
void Client::setupWindowRules( bool ignore_temporary )
|
2004-05-28 13:51:11 +00:00
|
|
|
{
|
2004-06-11 15:10:09 +00:00
|
|
|
client_rules = workspace()->findWindowRules( this, ignore_temporary );
|
2004-05-28 15:04:01 +00:00
|
|
|
// check only after getting the rules, because there may be a rule forcing window type
|
|
|
|
if( isTopMenu()) // TODO cannot have restrictions
|
|
|
|
client_rules = &dummyRules;
|
2004-05-28 13:51:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Client::updateWindowRules()
|
|
|
|
{
|
|
|
|
client_rules->update( this );
|
|
|
|
}
|
|
|
|
|
2004-05-31 14:25:25 +00:00
|
|
|
void Client::finishWindowRules()
|
|
|
|
{
|
|
|
|
updateWindowRules();
|
|
|
|
client_rules = &dummyRules;
|
|
|
|
}
|
|
|
|
|
2004-05-28 13:51:11 +00:00
|
|
|
// Workspace
|
|
|
|
|
2004-06-11 15:10:09 +00:00
|
|
|
WindowRules* Workspace::findWindowRules( const Client* c, bool ignore_temporary )
|
2004-05-28 13:51:11 +00:00
|
|
|
{
|
|
|
|
for( QValueList< WindowRules* >::ConstIterator it = windowRules.begin();
|
|
|
|
it != windowRules.end();
|
|
|
|
++it )
|
|
|
|
{
|
2004-06-11 15:10:09 +00:00
|
|
|
if( ignore_temporary && (*it)->isTemporary())
|
|
|
|
continue;
|
|
|
|
// TODO chaining for wildcard matches
|
2004-05-28 13:51:11 +00:00
|
|
|
if( (*it)->match( c ))
|
|
|
|
{
|
|
|
|
kdDebug() << "RULE FOUND:" << c << endl;
|
2004-06-11 15:10:09 +00:00
|
|
|
WindowRules* ret = *it;
|
|
|
|
if( ret->isTemporary())
|
|
|
|
windowRules.remove( *it );
|
|
|
|
return ret;
|
2004-05-28 13:51:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
kdDebug() << "RULE DUMMY:" << c << endl;
|
|
|
|
return &dummyRules;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::editWindowRules( Client* c )
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::loadWindowRules()
|
|
|
|
{
|
|
|
|
while( !windowRules.isEmpty())
|
|
|
|
{
|
|
|
|
delete windowRules.front();
|
|
|
|
windowRules.pop_front();
|
|
|
|
}
|
|
|
|
KConfig cfg( "kwinrulesrc", true );
|
|
|
|
cfg.setGroup( "General" );
|
|
|
|
int count = cfg.readNumEntry( "count" );
|
|
|
|
kdDebug() << "RULES:" << count << endl;
|
|
|
|
for( int i = 1;
|
|
|
|
i <= count;
|
|
|
|
++i )
|
|
|
|
{
|
|
|
|
cfg.setGroup( QString::number( i ));
|
|
|
|
WindowRules* setting = new WindowRules( cfg );
|
|
|
|
windowRules.append( setting );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::writeWindowRules()
|
|
|
|
{
|
|
|
|
KConfig cfg( "kwinrulesrc" );
|
|
|
|
cfg.setGroup( "General" );
|
|
|
|
cfg.writeEntry( "count", windowRules.count());
|
|
|
|
int i = 1;
|
|
|
|
for( QValueList< WindowRules* >::ConstIterator it = windowRules.begin();
|
|
|
|
it != windowRules.end();
|
2004-06-11 15:10:09 +00:00
|
|
|
++it )
|
2004-05-28 13:51:11 +00:00
|
|
|
{
|
2004-06-11 15:10:09 +00:00
|
|
|
if( (*it)->isTemporary())
|
|
|
|
continue;
|
2004-05-28 13:51:11 +00:00
|
|
|
cfg.setGroup( QString::number( i ));
|
|
|
|
(*it)->write( cfg );
|
2004-06-11 15:10:09 +00:00
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::gotTemporaryRulesMessage( const QString& message )
|
|
|
|
{
|
|
|
|
bool was_temporary = false;
|
|
|
|
for( QValueList< WindowRules* >::ConstIterator it = windowRules.begin();
|
|
|
|
it != windowRules.end();
|
|
|
|
++it )
|
|
|
|
if( (*it)->isTemporary())
|
|
|
|
was_temporary = true;
|
|
|
|
WindowRules* rule = new WindowRules( message, true );
|
|
|
|
windowRules.prepend( rule ); // highest priority first
|
|
|
|
if( !was_temporary )
|
|
|
|
QTimer::singleShot( 60000, this, SLOT( cleanupTemporaryRules()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::cleanupTemporaryRules()
|
|
|
|
{
|
|
|
|
kdDebug() << "CLEANUP" << endl;
|
|
|
|
bool has_temporary = false;
|
|
|
|
for( QValueList< WindowRules* >::Iterator it = windowRules.begin();
|
|
|
|
it != windowRules.end();
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if( (*it)->discardTemporary( false ))
|
|
|
|
it = windowRules.remove( it );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( (*it)->isTemporary())
|
|
|
|
has_temporary = true;
|
|
|
|
++it;
|
|
|
|
}
|
2004-05-28 13:51:11 +00:00
|
|
|
}
|
2004-06-11 15:10:09 +00:00
|
|
|
if( has_temporary )
|
|
|
|
QTimer::singleShot( 60000, this, SLOT( cleanupTemporaryRules()));
|
2004-05-28 13:51:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|