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"
|
|
|
|
|
2004-06-18 08:57:42 +00:00
|
|
|
#include <fixx11h.h>
|
2004-05-28 13:51:11 +00:00
|
|
|
#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
|
|
|
|
2004-06-21 16:25:24 +00:00
|
|
|
#ifndef KCMRULES
|
2004-05-28 13:51:11 +00:00
|
|
|
#include "client.h"
|
|
|
|
#include "workspace.h"
|
2004-06-21 16:25:24 +00:00
|
|
|
#endif
|
2004-05-28 13:51:11 +00:00
|
|
|
|
|
|
|
namespace KWinInternal
|
|
|
|
{
|
|
|
|
|
2004-06-18 08:57:42 +00:00
|
|
|
Rules::Rules()
|
2004-06-11 15:10:09 +00:00
|
|
|
: temporary_state( 0 )
|
2004-06-25 11:28:17 +00:00
|
|
|
, wmclassmatch( UnimportantMatch )
|
|
|
|
, wmclasscomplete( UnimportantMatch )
|
|
|
|
, windowrolematch( UnimportantMatch )
|
|
|
|
, titlematch( UnimportantMatch )
|
|
|
|
, extrarolematch( UnimportantMatch )
|
|
|
|
, clientmachinematch( UnimportantMatch )
|
2004-05-31 14:04:49 +00:00
|
|
|
, types( NET::AllTypesMask )
|
2004-06-18 08:57:42 +00:00
|
|
|
, placementrule( UnusedForceRule )
|
|
|
|
, positionrule( UnusedSetRule )
|
|
|
|
, sizerule( UnusedSetRule )
|
|
|
|
, minsizerule( UnusedForceRule )
|
|
|
|
, maxsizerule( UnusedForceRule )
|
2005-01-15 17:07:48 +00:00
|
|
|
, opacityactiverule( UnusedForceRule )
|
|
|
|
, opacityinactiverule( UnusedForceRule )
|
2004-06-21 12:38:40 +00:00
|
|
|
, ignorepositionrule( UnusedForceRule )
|
2004-06-18 08:57:42 +00:00
|
|
|
, desktoprule( UnusedSetRule )
|
|
|
|
, typerule( UnusedForceRule )
|
|
|
|
, maximizevertrule( UnusedSetRule )
|
|
|
|
, maximizehorizrule( UnusedSetRule )
|
|
|
|
, minimizerule( UnusedSetRule )
|
|
|
|
, shaderule( UnusedSetRule )
|
|
|
|
, skiptaskbarrule( UnusedSetRule )
|
|
|
|
, skippagerrule( UnusedSetRule )
|
|
|
|
, aboverule( UnusedSetRule )
|
|
|
|
, belowrule( UnusedSetRule )
|
|
|
|
, fullscreenrule( UnusedSetRule )
|
|
|
|
, noborderrule( UnusedSetRule )
|
|
|
|
, fsplevelrule( UnusedForceRule )
|
|
|
|
, acceptfocusrule( UnusedForceRule )
|
|
|
|
, moveresizemoderule( UnusedForceRule )
|
|
|
|
, closeablerule( UnusedForceRule )
|
2005-01-17 15:53:14 +00:00
|
|
|
, strictgeometryrule( UnusedForceRule )
|
|
|
|
, shortcutrule( UnusedSetRule )
|
2005-08-02 13:25:20 +00:00
|
|
|
, disableglobalshortcutsrule( UnusedForceRule )
|
2004-06-18 08:57:42 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Rules::Rules( const QString& str, bool temporary )
|
2004-06-11 15:10:09 +00:00
|
|
|
: temporary_state( temporary ? 2 : 0 )
|
|
|
|
{
|
|
|
|
KTempFile file;
|
|
|
|
QFile* f = file.file();
|
|
|
|
if( f != NULL )
|
|
|
|
{
|
2005-07-28 14:59:42 +00:00
|
|
|
QByteArray s = str.utf8();
|
2004-06-11 15:10:09 +00:00
|
|
|
f->writeBlock( s.data(), s.length());
|
|
|
|
}
|
|
|
|
file.close();
|
|
|
|
KSimpleConfig cfg( file.name());
|
|
|
|
readFromCfg( cfg );
|
2004-06-21 16:25:24 +00:00
|
|
|
if( description.isEmpty())
|
|
|
|
description = "temporary";
|
2004-06-11 15:10:09 +00:00
|
|
|
file.unlink();
|
|
|
|
}
|
|
|
|
|
2004-05-31 14:31:52 +00:00
|
|
|
#define READ_MATCH_STRING( var, func ) \
|
|
|
|
var = cfg.readEntry( #var ) func; \
|
2005-07-28 14:59:42 +00:00
|
|
|
var##match = (StringMatch) QMAX( FirstStringMatch, \
|
|
|
|
QMIN( LastStringMatch, static_cast< StringMatch >( cfg.readNumEntry( #var "match" ))));
|
2004-05-31 14:31:52 +00:00
|
|
|
|
|
|
|
#define READ_SET_RULE( var, type, func ) \
|
|
|
|
var = func ( cfg.read##type##Entry( #var )); \
|
2004-06-18 08:57:42 +00:00
|
|
|
var##rule = readSetRule( cfg, #var "rule" );
|
2004-05-31 14:31:52 +00:00
|
|
|
|
2004-06-11 15:12:43 +00:00
|
|
|
#define READ_SET_RULE_DEF( var, type, func, def ) \
|
|
|
|
var = func ( cfg.read##type##Entry( #var, def )); \
|
2004-06-18 08:57:42 +00:00
|
|
|
var##rule = readSetRule( cfg, #var "rule" );
|
2004-06-11 15:12:43 +00:00
|
|
|
|
2004-05-31 14:31:52 +00:00
|
|
|
#define READ_SET_RULE_2( var, type, func, funcarg ) \
|
|
|
|
var = func ( cfg.read##type##Entry( #var ), funcarg ); \
|
2004-06-18 08:57:42 +00:00
|
|
|
var##rule = readSetRule( 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-06-18 08:57:42 +00:00
|
|
|
#define READ_FORCE_RULE_2( var, type, func, funcarg ) \
|
|
|
|
var = func ( cfg.read##type##Entry( #var ), funcarg ); \
|
|
|
|
var##rule = readForceRule( cfg, #var "rule" );
|
|
|
|
|
|
|
|
|
|
|
|
Rules::Rules( 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-18 08:57:42 +00:00
|
|
|
void Rules::readFromCfg( KConfig& cfg )
|
2004-05-28 13:51:11 +00:00
|
|
|
{
|
2004-06-21 16:25:24 +00:00
|
|
|
description = cfg.readEntry( "description" );
|
2004-06-25 11:28:17 +00:00
|
|
|
READ_MATCH_STRING( wmclass, .lower().latin1() );
|
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-06-18 08:57:42 +00:00
|
|
|
READ_FORCE_RULE_2( placement,, Placement::policyFromString, false );
|
2004-06-11 15:12:43 +00:00
|
|
|
READ_SET_RULE_DEF( position, Point,, &invalidPoint );
|
2004-05-31 14:31:52 +00:00
|
|
|
READ_SET_RULE( size, Size, );
|
2004-06-18 22:06:04 +00:00
|
|
|
if( size.isEmpty() && sizerule != ( SetRule )Remember)
|
2004-06-18 08:57:42 +00:00
|
|
|
sizerule = UnusedSetRule;
|
|
|
|
READ_FORCE_RULE( minsize, Size, );
|
2004-05-31 14:25:25 +00:00
|
|
|
if( !minsize.isValid())
|
2004-06-28 13:47:33 +00:00
|
|
|
minsize = QSize( 1, 1 );
|
2004-06-18 08:57:42 +00:00
|
|
|
READ_FORCE_RULE( maxsize, Size, );
|
2004-05-31 14:25:25 +00:00
|
|
|
if( maxsize.isEmpty())
|
2004-06-28 13:47:33 +00:00
|
|
|
maxsize = QSize( 32767, 32767 );
|
2005-01-15 17:07:48 +00:00
|
|
|
READ_FORCE_RULE( opacityactive, Num, );
|
|
|
|
if( opacityactive < 0 || opacityactive > 100 )
|
|
|
|
opacityactive = 100;
|
|
|
|
READ_FORCE_RULE( opacityinactive, Num, );
|
|
|
|
if( opacityinactive < 0 || opacityinactive > 100 )
|
|
|
|
opacityinactive = 100;
|
2004-06-21 12:38:40 +00:00
|
|
|
READ_FORCE_RULE( ignoreposition, Bool, );
|
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" );
|
2004-06-18 08:57:42 +00:00
|
|
|
typerule = type != NET::Unknown ? readForceRule( cfg, "typerule" ) : UnusedForceRule;
|
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, );
|
2005-01-17 13:35:48 +00:00
|
|
|
READ_FORCE_RULE( strictgeometry, Bool, );
|
2005-01-17 15:53:14 +00:00
|
|
|
READ_SET_RULE( shortcut, , );
|
2005-08-02 13:25:20 +00:00
|
|
|
READ_FORCE_RULE( disableglobalshortcuts, Bool, );
|
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-06-18 08:57:42 +00:00
|
|
|
#undef READ_FORCE_RULE_2
|
2004-05-31 14:31:52 +00:00
|
|
|
|
2004-06-25 11:28:17 +00:00
|
|
|
#define WRITE_MATCH_STRING( var, cast, force ) \
|
|
|
|
if( !var.isEmpty() || force ) \
|
2004-05-28 13:51:11 +00:00
|
|
|
{ \
|
|
|
|
cfg.writeEntry( #var, cast var ); \
|
2004-06-25 11:28:17 +00:00
|
|
|
cfg.writeEntry( #var "match", var##match ); \
|
2004-05-28 13:51:11 +00:00
|
|
|
} \
|
|
|
|
else \
|
|
|
|
{ \
|
|
|
|
cfg.deleteEntry( #var ); \
|
2004-06-25 11:28:17 +00:00
|
|
|
cfg.deleteEntry( #var "match" ); \
|
2004-05-28 13:51:11 +00:00
|
|
|
}
|
|
|
|
|
2004-05-31 14:14:10 +00:00
|
|
|
#define WRITE_SET_RULE( var, func ) \
|
2004-06-18 08:57:42 +00:00
|
|
|
if( var##rule != UnusedSetRule ) \
|
|
|
|
{ \
|
|
|
|
cfg.writeEntry( #var, func ( var )); \
|
|
|
|
cfg.writeEntry( #var "rule", var##rule ); \
|
|
|
|
} \
|
|
|
|
else \
|
|
|
|
{ \
|
|
|
|
cfg.deleteEntry( #var ); \
|
|
|
|
cfg.deleteEntry( #var "rule" ); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define WRITE_FORCE_RULE( var, func ) \
|
|
|
|
if( var##rule != UnusedForceRule ) \
|
2004-05-28 13:51:11 +00:00
|
|
|
{ \
|
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-06-18 08:57:42 +00:00
|
|
|
void Rules::write( KConfig& cfg ) const
|
2004-05-28 13:51:11 +00:00
|
|
|
{
|
2004-06-21 16:25:24 +00:00
|
|
|
cfg.writeEntry( "description", description );
|
2004-05-28 13:51:11 +00:00
|
|
|
// always write wmclass
|
2004-06-25 11:28:17 +00:00
|
|
|
WRITE_MATCH_STRING( wmclass, (const char*), true );
|
2004-05-28 13:54:20 +00:00
|
|
|
cfg.writeEntry( "wmclasscomplete", wmclasscomplete );
|
2004-06-25 11:28:17 +00:00
|
|
|
WRITE_MATCH_STRING( windowrole, (const char*), false );
|
|
|
|
WRITE_MATCH_STRING( title,, false );
|
|
|
|
WRITE_MATCH_STRING( extrarole, (const char*), false );
|
|
|
|
WRITE_MATCH_STRING( clientmachine, (const char*), false );
|
2004-05-31 14:04:49 +00:00
|
|
|
WRITE_WITH_DEFAULT( types, NET::AllTypesMask );
|
2004-06-18 08:57:42 +00:00
|
|
|
WRITE_FORCE_RULE( placement, Placement::policyToString );
|
2004-05-31 14:25:25 +00:00
|
|
|
WRITE_SET_RULE( position, );
|
|
|
|
WRITE_SET_RULE( size, );
|
2004-06-18 08:57:42 +00:00
|
|
|
WRITE_FORCE_RULE( minsize, );
|
|
|
|
WRITE_FORCE_RULE( maxsize, );
|
2005-01-15 17:07:48 +00:00
|
|
|
WRITE_FORCE_RULE( opacityactive, );
|
|
|
|
WRITE_FORCE_RULE( opacityinactive, );
|
2004-06-21 12:38:40 +00:00
|
|
|
WRITE_FORCE_RULE( ignoreposition, );
|
2004-05-31 14:14:10 +00:00
|
|
|
WRITE_SET_RULE( desktop, );
|
2004-06-18 08:57:42 +00:00
|
|
|
WRITE_FORCE_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-18 08:57:42 +00:00
|
|
|
WRITE_FORCE_RULE( fsplevel, );
|
|
|
|
WRITE_FORCE_RULE( acceptfocus, );
|
|
|
|
WRITE_FORCE_RULE( moveresizemode, Options::moveResizeModeToString );
|
|
|
|
WRITE_FORCE_RULE( closeable, );
|
2005-01-17 13:35:48 +00:00
|
|
|
WRITE_FORCE_RULE( strictgeometry, );
|
2005-01-17 15:53:14 +00:00
|
|
|
WRITE_SET_RULE( shortcut, );
|
2005-08-02 13:25:20 +00:00
|
|
|
WRITE_FORCE_RULE( disableglobalshortcuts, );
|
2004-05-28 13:51:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#undef WRITE_MATCH_STRING
|
|
|
|
#undef WRITE_SET_RULE
|
2004-06-18 08:57:42 +00:00
|
|
|
#undef WRITE_FORCE_RULE
|
2004-05-31 14:04:49 +00:00
|
|
|
#undef WRITE_WITH_DEFAULT
|
2004-05-28 13:51:11 +00:00
|
|
|
|
2004-07-29 17:08:25 +00:00
|
|
|
// returns true if it doesn't affect anything
|
|
|
|
bool Rules::isEmpty() const
|
|
|
|
{
|
|
|
|
return( placementrule == UnusedForceRule
|
|
|
|
&& positionrule == UnusedSetRule
|
|
|
|
&& sizerule == UnusedSetRule
|
|
|
|
&& minsizerule == UnusedForceRule
|
|
|
|
&& maxsizerule == UnusedForceRule
|
2005-01-15 17:07:48 +00:00
|
|
|
&& opacityactiverule == UnusedForceRule
|
|
|
|
&& opacityinactiverule == UnusedForceRule
|
2004-07-29 17:08:25 +00:00
|
|
|
&& ignorepositionrule == UnusedForceRule
|
|
|
|
&& desktoprule == UnusedSetRule
|
|
|
|
&& typerule == UnusedForceRule
|
|
|
|
&& maximizevertrule == UnusedSetRule
|
|
|
|
&& maximizehorizrule == UnusedSetRule
|
|
|
|
&& minimizerule == UnusedSetRule
|
|
|
|
&& shaderule == UnusedSetRule
|
|
|
|
&& skiptaskbarrule == UnusedSetRule
|
|
|
|
&& skippagerrule == UnusedSetRule
|
|
|
|
&& aboverule == UnusedSetRule
|
|
|
|
&& belowrule == UnusedSetRule
|
|
|
|
&& fullscreenrule == UnusedSetRule
|
|
|
|
&& noborderrule == UnusedSetRule
|
|
|
|
&& fsplevelrule == UnusedForceRule
|
|
|
|
&& acceptfocusrule == UnusedForceRule
|
|
|
|
&& moveresizemoderule == UnusedForceRule
|
2005-01-17 13:35:48 +00:00
|
|
|
&& closeablerule == UnusedForceRule
|
2005-01-17 15:53:14 +00:00
|
|
|
&& strictgeometryrule == UnusedForceRule
|
2005-08-02 13:25:20 +00:00
|
|
|
&& shortcutrule == UnusedSetRule
|
|
|
|
&& disableglobalshortcutsrule == UnusedForceRule );
|
2004-07-29 17:08:25 +00:00
|
|
|
}
|
|
|
|
|
2004-06-18 08:57:42 +00:00
|
|
|
Rules::SetRule Rules::readSetRule( KConfig& cfg, const QString& key )
|
2004-05-28 13:51:11 +00:00
|
|
|
{
|
|
|
|
int v = cfg.readNumEntry( key );
|
2005-06-07 15:31:15 +00:00
|
|
|
if( v >= DontAffect && v <= ForceTemporarily )
|
2004-06-18 08:57:42 +00:00
|
|
|
return static_cast< SetRule >( v );
|
|
|
|
return UnusedSetRule;
|
2004-05-28 13:51:11 +00:00
|
|
|
}
|
|
|
|
|
2004-06-18 08:57:42 +00:00
|
|
|
Rules::ForceRule Rules::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 );
|
2005-06-07 15:31:15 +00:00
|
|
|
if( v == DontAffect || v == Force || v == ForceTemporarily )
|
2004-06-18 08:57:42 +00:00
|
|
|
return static_cast< ForceRule >( v );
|
|
|
|
return UnusedForceRule;
|
2004-05-28 15:04:01 +00:00
|
|
|
}
|
|
|
|
|
2004-06-18 08:57:42 +00:00
|
|
|
NET::WindowType Rules::readType( KConfig& cfg, const QString& key )
|
2004-05-28 15:04:01 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2004-07-29 17:08:25 +00:00
|
|
|
bool Rules::matchType( NET::WindowType match_type ) const
|
2004-05-28 13:51:11 +00:00
|
|
|
{
|
2004-05-31 14:04:49 +00:00
|
|
|
if( types != NET::AllTypesMask )
|
|
|
|
{
|
2004-07-29 17:08:25 +00:00
|
|
|
if( match_type == NET::Unknown )
|
|
|
|
match_type = NET::Normal; // NET::Unknown->NET::Normal is only here for matching
|
|
|
|
if( !NET::typeMatchesMask( match_type, types ))
|
2004-05-31 14:04:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
2004-07-29 17:08:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-07-28 14:59:42 +00:00
|
|
|
bool Rules::matchWMClass( const QByteArray& match_class, const QByteArray& match_name ) const
|
2004-07-29 17:08:25 +00:00
|
|
|
{
|
2004-06-25 11:28:17 +00:00
|
|
|
if( wmclassmatch != UnimportantMatch )
|
2004-05-28 13:51:11 +00:00
|
|
|
{ // TODO optimize?
|
2005-07-28 14:59:42 +00:00
|
|
|
QByteArray cwmclass = wmclasscomplete
|
2004-07-29 17:08:25 +00:00
|
|
|
? match_name + ' ' + match_class : match_class;
|
2004-06-25 11:28:17 +00:00
|
|
|
if( wmclassmatch == RegExpMatch && QRegExp( wmclass ).search( cwmclass ) == -1 )
|
2004-05-28 13:51:11 +00:00
|
|
|
return false;
|
2004-06-25 11:28:17 +00:00
|
|
|
if( wmclassmatch == ExactMatch && wmclass != cwmclass )
|
|
|
|
return false;
|
|
|
|
if( wmclassmatch == SubstringMatch && !cwmclass.contains( wmclass ))
|
2004-05-28 13:51:11 +00:00
|
|
|
return false;
|
|
|
|
}
|
2004-07-29 17:08:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-07-28 14:59:42 +00:00
|
|
|
bool Rules::matchRole( const QByteArray& match_role ) const
|
2004-07-29 17:08:25 +00:00
|
|
|
{
|
2004-06-25 11:28:17 +00:00
|
|
|
if( windowrolematch != UnimportantMatch )
|
2004-05-28 13:51:11 +00:00
|
|
|
{
|
2004-07-29 17:08:25 +00:00
|
|
|
if( windowrolematch == RegExpMatch && QRegExp( windowrole ).search( match_role ) == -1 )
|
2004-06-25 11:28:17 +00:00
|
|
|
return false;
|
2004-07-29 17:08:25 +00:00
|
|
|
if( windowrolematch == ExactMatch && windowrole != match_role )
|
2004-05-28 13:51:11 +00:00
|
|
|
return false;
|
2004-07-29 17:08:25 +00:00
|
|
|
if( windowrolematch == SubstringMatch && !match_role.contains( windowrole ))
|
2004-05-28 13:51:11 +00:00
|
|
|
return false;
|
|
|
|
}
|
2004-07-29 17:08:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Rules::matchTitle( const QString& match_title ) const
|
|
|
|
{
|
2004-06-25 11:28:17 +00:00
|
|
|
if( titlematch != UnimportantMatch )
|
2004-05-28 13:51:11 +00:00
|
|
|
{
|
2004-07-29 17:08:25 +00:00
|
|
|
if( titlematch == RegExpMatch && QRegExp( title ).search( match_title ) == -1 )
|
2004-05-28 13:51:11 +00:00
|
|
|
return false;
|
2004-07-29 17:08:25 +00:00
|
|
|
if( titlematch == ExactMatch && title != match_title )
|
2004-06-25 11:28:17 +00:00
|
|
|
return false;
|
2004-07-29 17:08:25 +00:00
|
|
|
if( titlematch == SubstringMatch && !match_title.contains( title ))
|
2004-05-28 13:51:11 +00:00
|
|
|
return false;
|
|
|
|
}
|
2004-07-29 17:08:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-07-28 14:59:42 +00:00
|
|
|
bool Rules::matchClientMachine( const QByteArray& match_machine ) const
|
2004-07-29 17:08:25 +00:00
|
|
|
{
|
2004-06-25 11:28:17 +00:00
|
|
|
if( clientmachinematch != UnimportantMatch )
|
2004-05-28 13:54:20 +00:00
|
|
|
{
|
2004-07-29 17:08:25 +00:00
|
|
|
// if it's localhost, check also "localhost" before checking hostname
|
|
|
|
if( match_machine != "localhost" && isLocalMachine( match_machine )
|
|
|
|
&& matchClientMachine( "localhost" ))
|
|
|
|
return true;
|
2004-06-25 11:28:17 +00:00
|
|
|
if( clientmachinematch == RegExpMatch
|
2004-07-29 17:08:25 +00:00
|
|
|
&& QRegExp( clientmachine ).search( match_machine ) == -1 )
|
2004-05-28 13:54:20 +00:00
|
|
|
return false;
|
2004-06-25 11:28:17 +00:00
|
|
|
if( clientmachinematch == ExactMatch
|
2004-07-29 17:08:25 +00:00
|
|
|
&& clientmachine != match_machine )
|
2004-05-28 13:54:20 +00:00
|
|
|
return false;
|
2004-06-25 11:28:17 +00:00
|
|
|
if( clientmachinematch == SubstringMatch
|
2004-07-29 17:08:25 +00:00
|
|
|
&& !match_machine.contains( clientmachine ))
|
2004-06-25 11:28:17 +00:00
|
|
|
return false;
|
2004-05-28 13:54:20 +00:00
|
|
|
}
|
2004-05-28 13:51:11 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-07-29 17:08:25 +00:00
|
|
|
#ifndef KCMRULES
|
|
|
|
bool Rules::match( const Client* c ) const
|
|
|
|
{
|
|
|
|
if( !matchType( c->windowType( true )))
|
|
|
|
return false;
|
|
|
|
if( !matchWMClass( c->resourceClass(), c->resourceName()))
|
|
|
|
return false;
|
|
|
|
if( !matchRole( c->windowRole()))
|
|
|
|
return false;
|
|
|
|
if( !matchTitle( c->caption( false )))
|
|
|
|
return false;
|
|
|
|
// TODO extrarole
|
|
|
|
if( !matchClientMachine( c->wmClientMachine( false )))
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-06-18 08:57:42 +00:00
|
|
|
bool Rules::update( Client* c )
|
2004-05-28 15:04:01 +00:00
|
|
|
{
|
|
|
|
// TODO check this setting is for this client ?
|
2004-06-11 15:12:29 +00:00
|
|
|
bool updated = false;
|
2004-06-18 22:06:04 +00:00
|
|
|
if( positionrule == ( SetRule )Remember)
|
2004-06-11 15:12:29 +00:00
|
|
|
{
|
2004-08-04 14:57:06 +00:00
|
|
|
if( !c->isFullScreen())
|
|
|
|
{
|
|
|
|
QPoint new_pos = position;
|
|
|
|
// don't use the position in the direction which is maximized
|
|
|
|
if(( c->maximizeMode() & MaximizeHorizontal ) == 0 )
|
|
|
|
new_pos.setX( c->pos().x());
|
|
|
|
if(( c->maximizeMode() & MaximizeVertical ) == 0 )
|
|
|
|
new_pos.setY( c->pos().y());
|
|
|
|
updated = updated || position != new_pos;
|
|
|
|
position = new_pos;
|
|
|
|
}
|
2004-06-11 15:12:29 +00:00
|
|
|
}
|
2004-06-18 22:06:04 +00:00
|
|
|
if( sizerule == ( SetRule )Remember)
|
2004-06-11 15:12:29 +00:00
|
|
|
{
|
2004-08-04 14:57:06 +00:00
|
|
|
if( !c->isFullScreen())
|
|
|
|
{
|
|
|
|
QSize new_size = size;
|
|
|
|
// don't use the position in the direction which is maximized
|
|
|
|
if(( c->maximizeMode() & MaximizeHorizontal ) == 0 )
|
|
|
|
new_size.setWidth( c->size().width());
|
|
|
|
if(( c->maximizeMode() & MaximizeVertical ) == 0 )
|
|
|
|
new_size.setHeight( c->size().height());
|
|
|
|
updated = updated || size != new_size;
|
|
|
|
size = new_size;
|
|
|
|
}
|
2004-06-11 15:12:29 +00:00
|
|
|
}
|
2004-06-18 22:06:04 +00:00
|
|
|
if( desktoprule == ( SetRule )Remember)
|
2004-06-11 15:12:29 +00:00
|
|
|
{
|
|
|
|
updated = updated || desktop != c->desktop();
|
2004-05-28 15:04:01 +00:00
|
|
|
desktop = c->desktop();
|
2004-06-11 15:12:29 +00:00
|
|
|
}
|
2004-06-18 22:06:04 +00:00
|
|
|
if( maximizevertrule == ( SetRule )Remember)
|
2004-06-11 15:12:29 +00:00
|
|
|
{
|
|
|
|
updated = updated || maximizevert != bool( c->maximizeMode() & MaximizeVertical );
|
2004-06-03 14:09:45 +00:00
|
|
|
maximizevert = c->maximizeMode() & MaximizeVertical;
|
2004-06-11 15:12:29 +00:00
|
|
|
}
|
2004-06-18 22:06:04 +00:00
|
|
|
if( maximizehorizrule == ( SetRule )Remember)
|
2004-06-11 15:12:29 +00:00
|
|
|
{
|
|
|
|
updated = updated || maximizehoriz != bool( c->maximizeMode() & MaximizeHorizontal );
|
2004-06-03 14:09:45 +00:00
|
|
|
maximizehoriz = c->maximizeMode() & MaximizeHorizontal;
|
2004-06-11 15:12:29 +00:00
|
|
|
}
|
2004-06-18 22:06:04 +00:00
|
|
|
if( minimizerule == ( SetRule )Remember)
|
2004-06-11 15:12:29 +00:00
|
|
|
{
|
|
|
|
updated = updated || minimize != c->isMinimized();
|
2004-06-03 14:09:45 +00:00
|
|
|
minimize = c->isMinimized();
|
2004-06-11 15:12:29 +00:00
|
|
|
}
|
2004-06-18 22:06:04 +00:00
|
|
|
if( shaderule == ( SetRule )Remember)
|
2004-06-11 15:12:29 +00:00
|
|
|
{
|
2004-06-18 08:57:42 +00:00
|
|
|
updated = updated || ( shade != ( c->shadeMode() != ShadeNone ));
|
|
|
|
shade = c->shadeMode() != ShadeNone;
|
2004-06-11 15:12:29 +00:00
|
|
|
}
|
2004-06-18 22:06:04 +00:00
|
|
|
if( skiptaskbarrule == ( SetRule )Remember)
|
2004-06-11 15:12:29 +00:00
|
|
|
{
|
|
|
|
updated = updated || skiptaskbar != c->skipTaskbar();
|
2004-06-03 14:09:45 +00:00
|
|
|
skiptaskbar = c->skipTaskbar();
|
2004-06-11 15:12:29 +00:00
|
|
|
}
|
2004-06-18 22:06:04 +00:00
|
|
|
if( skippagerrule == ( SetRule )Remember)
|
2004-06-11 15:12:29 +00:00
|
|
|
{
|
|
|
|
updated = updated || skippager != c->skipPager();
|
2004-06-03 14:09:45 +00:00
|
|
|
skippager = c->skipPager();
|
2004-06-11 15:12:29 +00:00
|
|
|
}
|
2004-06-18 22:06:04 +00:00
|
|
|
if( aboverule == ( SetRule )Remember)
|
2004-06-11 15:12:29 +00:00
|
|
|
{
|
|
|
|
updated = updated || above != c->keepAbove();
|
2004-05-28 15:04:01 +00:00
|
|
|
above = c->keepAbove();
|
2004-06-11 15:12:29 +00:00
|
|
|
}
|
2004-06-18 22:06:04 +00:00
|
|
|
if( belowrule == ( SetRule )Remember)
|
2004-06-11 15:12:29 +00:00
|
|
|
{
|
|
|
|
updated = updated || below != c->keepBelow();
|
2004-05-28 15:04:01 +00:00
|
|
|
below = c->keepBelow();
|
2004-06-11 15:12:29 +00:00
|
|
|
}
|
2004-06-18 22:06:04 +00:00
|
|
|
if( fullscreenrule == ( SetRule )Remember)
|
2004-06-11 15:12:29 +00:00
|
|
|
{
|
|
|
|
updated = updated || fullscreen != c->isFullScreen();
|
2004-06-03 14:09:45 +00:00
|
|
|
fullscreen = c->isFullScreen();
|
2004-06-11 15:12:29 +00:00
|
|
|
}
|
2004-06-18 22:06:04 +00:00
|
|
|
if( noborderrule == ( SetRule )Remember)
|
2004-06-11 15:12:29 +00:00
|
|
|
{
|
|
|
|
updated = updated || noborder != c->isUserNoBorder();
|
2004-06-03 14:09:45 +00:00
|
|
|
noborder = c->isUserNoBorder();
|
2004-06-11 15:12:29 +00:00
|
|
|
}
|
2005-01-15 17:07:48 +00:00
|
|
|
if (opacityactiverule == ( ForceRule )Force)
|
|
|
|
{
|
|
|
|
updated = updated || (uint) (opacityactive/100.0*0xffffffff) != c->ruleOpacityActive();
|
|
|
|
opacityactive = (uint)(((double)c->ruleOpacityActive())/0xffffffff*100);
|
|
|
|
}
|
|
|
|
if (opacityinactiverule == ( ForceRule )Force)
|
|
|
|
{
|
|
|
|
updated = updated || (uint) (opacityinactive/100.0*0xffffffff) != c->ruleOpacityInactive();
|
|
|
|
opacityinactive = (uint)(((double)c->ruleOpacityInactive())/0xffffffff*100);
|
|
|
|
}
|
2004-06-18 08:57:42 +00:00
|
|
|
return updated;
|
2004-05-28 15:04:01 +00:00
|
|
|
}
|
|
|
|
|
2004-06-18 08:57:42 +00:00
|
|
|
#define APPLY_RULE( var, name, type ) \
|
|
|
|
bool Rules::apply##name( type& arg, bool init ) const \
|
|
|
|
{ \
|
|
|
|
if( checkSetRule( var##rule, init )) \
|
|
|
|
arg = this->var; \
|
|
|
|
return checkSetStop( var##rule ); \
|
2004-05-31 14:14:10 +00:00
|
|
|
}
|
|
|
|
|
2004-06-18 08:57:42 +00:00
|
|
|
#define APPLY_FORCE_RULE( var, name, type ) \
|
|
|
|
bool Rules::apply##name( type& arg ) const \
|
|
|
|
{ \
|
|
|
|
if( checkForceRule( var##rule )) \
|
|
|
|
arg = this->var; \
|
|
|
|
return checkForceStop( var##rule ); \
|
2004-05-31 14:25:25 +00:00
|
|
|
}
|
|
|
|
|
2004-06-18 08:57:42 +00:00
|
|
|
APPLY_FORCE_RULE( placement, Placement, Placement::Policy )
|
2004-05-31 14:25:25 +00:00
|
|
|
|
2004-06-18 08:57:42 +00:00
|
|
|
bool Rules::applyGeometry( QRect& rect, bool init ) const
|
2004-05-31 14:25:25 +00:00
|
|
|
{
|
2004-06-18 08:57:42 +00:00
|
|
|
QPoint p = rect.topLeft();
|
|
|
|
QSize s = rect.size();
|
|
|
|
bool ret = false; // no short-circuiting
|
|
|
|
if( applyPosition( p, init ))
|
|
|
|
{
|
|
|
|
rect.moveTopLeft( p );
|
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
if( applySize( s, init ))
|
|
|
|
{
|
|
|
|
rect.setSize( s );
|
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
return ret;
|
2004-05-31 14:25:25 +00:00
|
|
|
}
|
|
|
|
|
2004-06-18 08:57:42 +00:00
|
|
|
bool Rules::applyPosition( QPoint& pos, bool init ) const
|
2004-05-31 14:15:33 +00:00
|
|
|
{
|
2004-06-23 17:34:36 +00:00
|
|
|
if( this->position != invalidPoint && checkSetRule( positionrule, init ))
|
2004-06-18 08:57:42 +00:00
|
|
|
pos = this->position;
|
|
|
|
return checkSetStop( positionrule );
|
2004-05-31 14:15:33 +00:00
|
|
|
}
|
|
|
|
|
2004-06-18 08:57:42 +00:00
|
|
|
bool Rules::applySize( QSize& s, bool init ) const
|
2004-05-31 14:15:33 +00:00
|
|
|
{
|
2004-06-23 17:34:36 +00:00
|
|
|
if( this->size.isValid() && checkSetRule( sizerule, init ))
|
2004-06-18 08:57:42 +00:00
|
|
|
s = this->size;
|
|
|
|
return checkSetStop( sizerule );
|
2004-05-31 14:15:33 +00:00
|
|
|
}
|
|
|
|
|
2004-06-18 08:57:42 +00:00
|
|
|
APPLY_FORCE_RULE( minsize, MinSize, QSize )
|
|
|
|
APPLY_FORCE_RULE( maxsize, MaxSize, QSize )
|
2005-01-15 17:07:48 +00:00
|
|
|
APPLY_FORCE_RULE( opacityactive, OpacityActive, int )
|
|
|
|
APPLY_FORCE_RULE( opacityinactive, OpacityInactive, int )
|
2004-06-21 12:38:40 +00:00
|
|
|
APPLY_FORCE_RULE( ignoreposition, IgnorePosition, bool )
|
2005-08-08 14:27:03 +00:00
|
|
|
|
|
|
|
// the cfg. entry needs to stay named the say for backwards compatibility
|
|
|
|
bool Rules::applyIgnoreGeometry( bool& ignore ) const
|
|
|
|
{
|
|
|
|
return applyIgnorePosition( ignore );
|
|
|
|
}
|
|
|
|
|
2004-06-18 08:57:42 +00:00
|
|
|
APPLY_RULE( desktop, Desktop, int )
|
|
|
|
APPLY_FORCE_RULE( type, Type, NET::WindowType )
|
2004-05-28 13:51:11 +00:00
|
|
|
|
2004-06-18 08:57:42 +00:00
|
|
|
bool Rules::applyMaximizeHoriz( MaximizeMode& mode, bool init ) const
|
2004-05-28 13:51:11 +00:00
|
|
|
{
|
2004-06-18 08:57:42 +00:00
|
|
|
if( checkSetRule( maximizehorizrule, init ))
|
|
|
|
mode = static_cast< MaximizeMode >(( maximizehoriz ? MaximizeHorizontal : 0 ) | ( mode & MaximizeVertical ));
|
|
|
|
return checkSetStop( maximizehorizrule );
|
2004-05-28 13:51:11 +00:00
|
|
|
}
|
|
|
|
|
2004-06-18 08:57:42 +00:00
|
|
|
bool Rules::applyMaximizeVert( MaximizeMode& mode, bool init ) const
|
2004-05-28 13:51:11 +00:00
|
|
|
{
|
2004-06-18 08:57:42 +00:00
|
|
|
if( checkSetRule( maximizevertrule, init ))
|
|
|
|
mode = static_cast< MaximizeMode >(( maximizevert ? MaximizeVertical : 0 ) | ( mode & MaximizeHorizontal ));
|
|
|
|
return checkSetStop( maximizevertrule );
|
2004-05-28 13:51:11 +00:00
|
|
|
}
|
2004-06-03 14:09:45 +00:00
|
|
|
|
2004-06-18 08:57:42 +00:00
|
|
|
APPLY_RULE( minimize, Minimize, bool )
|
2004-06-03 14:09:45 +00:00
|
|
|
|
2004-06-18 08:57:42 +00:00
|
|
|
bool Rules::applyShade( ShadeMode& sh, bool init ) const
|
2004-06-03 14:09:45 +00:00
|
|
|
{
|
2004-06-18 08:57:42 +00:00
|
|
|
if( checkSetRule( shaderule, init ))
|
2004-06-03 14:09:45 +00:00
|
|
|
{
|
|
|
|
if( !this->shade )
|
2004-06-18 08:57:42 +00:00
|
|
|
sh = ShadeNone;
|
|
|
|
if( this->shade && sh == ShadeNone )
|
|
|
|
sh = ShadeNormal;
|
2004-06-03 14:09:45 +00:00
|
|
|
}
|
2004-06-18 08:57:42 +00:00
|
|
|
return checkSetStop( shaderule );
|
2004-06-03 14:09:45 +00:00
|
|
|
}
|
|
|
|
|
2004-06-18 08:57:42 +00:00
|
|
|
APPLY_RULE( skiptaskbar, SkipTaskbar, bool )
|
|
|
|
APPLY_RULE( skippager, SkipPager, bool )
|
|
|
|
APPLY_RULE( above, KeepAbove, bool )
|
|
|
|
APPLY_RULE( below, KeepBelow, bool )
|
|
|
|
APPLY_RULE( fullscreen, FullScreen, bool )
|
|
|
|
APPLY_RULE( noborder, NoBorder, bool )
|
|
|
|
APPLY_FORCE_RULE( fsplevel, FSP, int )
|
|
|
|
APPLY_FORCE_RULE( acceptfocus, AcceptFocus, bool )
|
|
|
|
APPLY_FORCE_RULE( moveresizemode, MoveResizeMode, Options::MoveResizeMode )
|
|
|
|
APPLY_FORCE_RULE( closeable, Closeable, bool )
|
2005-01-17 13:35:48 +00:00
|
|
|
APPLY_FORCE_RULE( strictgeometry, StrictGeometry, bool )
|
2005-01-17 15:53:14 +00:00
|
|
|
APPLY_RULE( shortcut, Shortcut, QString )
|
2005-08-02 13:25:20 +00:00
|
|
|
APPLY_FORCE_RULE( disableglobalshortcuts, DisableGlobalShortcuts, bool )
|
|
|
|
|
2004-06-03 14:09:45 +00:00
|
|
|
|
2004-06-18 08:57:42 +00:00
|
|
|
#undef APPLY_RULE
|
|
|
|
#undef APPLY_FORCE_RULE
|
2004-06-03 14:09:45 +00:00
|
|
|
|
2004-06-18 08:57:42 +00:00
|
|
|
bool Rules::isTemporary() const
|
2004-06-03 14:09:45 +00:00
|
|
|
{
|
2004-06-18 08:57:42 +00:00
|
|
|
return temporary_state > 0;
|
2004-06-03 14:09:45 +00:00
|
|
|
}
|
|
|
|
|
2004-06-18 08:57:42 +00:00
|
|
|
bool Rules::discardTemporary( bool force )
|
2004-06-03 14:09:45 +00:00
|
|
|
{
|
2004-06-18 08:57:42 +00:00
|
|
|
if( temporary_state == 0 ) // not temporary
|
|
|
|
return false;
|
|
|
|
if( force || --temporary_state == 0 ) // too old
|
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2004-05-28 15:04:01 +00:00
|
|
|
}
|
2005-06-07 15:31:15 +00:00
|
|
|
|
|
|
|
#define DISCARD_USED_SET_RULE( var ) \
|
|
|
|
do { \
|
|
|
|
if( var##rule == ( SetRule ) ApplyNow || ( withdrawn && var##rule == ( SetRule ) ForceTemporarily )) \
|
|
|
|
var##rule = UnusedSetRule; \
|
|
|
|
} while( false )
|
|
|
|
#define DISCARD_USED_FORCE_RULE( var ) \
|
|
|
|
do { \
|
|
|
|
if( withdrawn && var##rule == ( ForceRule ) ForceTemporarily ) \
|
|
|
|
var##rule = UnusedForceRule; \
|
|
|
|
} while( false )
|
|
|
|
|
|
|
|
void Rules::discardUsed( bool withdrawn )
|
|
|
|
{
|
|
|
|
DISCARD_USED_FORCE_RULE( placement );
|
|
|
|
DISCARD_USED_SET_RULE( position );
|
|
|
|
DISCARD_USED_SET_RULE( size );
|
|
|
|
DISCARD_USED_FORCE_RULE( minsize );
|
|
|
|
DISCARD_USED_FORCE_RULE( maxsize );
|
|
|
|
DISCARD_USED_FORCE_RULE( opacityactive );
|
|
|
|
DISCARD_USED_FORCE_RULE( opacityinactive );
|
|
|
|
DISCARD_USED_FORCE_RULE( ignoreposition );
|
|
|
|
DISCARD_USED_SET_RULE( desktop );
|
|
|
|
DISCARD_USED_FORCE_RULE( type );
|
|
|
|
DISCARD_USED_SET_RULE( maximizevert );
|
|
|
|
DISCARD_USED_SET_RULE( maximizehoriz );
|
|
|
|
DISCARD_USED_SET_RULE( minimize );
|
|
|
|
DISCARD_USED_SET_RULE( shade );
|
|
|
|
DISCARD_USED_SET_RULE( skiptaskbar );
|
|
|
|
DISCARD_USED_SET_RULE( skippager );
|
|
|
|
DISCARD_USED_SET_RULE( above );
|
|
|
|
DISCARD_USED_SET_RULE( below );
|
|
|
|
DISCARD_USED_SET_RULE( fullscreen );
|
|
|
|
DISCARD_USED_SET_RULE( noborder );
|
|
|
|
DISCARD_USED_FORCE_RULE( fsplevel );
|
|
|
|
DISCARD_USED_FORCE_RULE( acceptfocus );
|
|
|
|
DISCARD_USED_FORCE_RULE( moveresizemode );
|
|
|
|
DISCARD_USED_FORCE_RULE( closeable );
|
|
|
|
DISCARD_USED_FORCE_RULE( strictgeometry );
|
|
|
|
DISCARD_USED_SET_RULE( shortcut );
|
2005-08-02 13:25:20 +00:00
|
|
|
DISCARD_USED_FORCE_RULE( disableglobalshortcuts );
|
2005-06-07 15:31:15 +00:00
|
|
|
}
|
|
|
|
#undef DISCARD_USED_SET_RULE
|
|
|
|
#undef DISCARD_USED_FORCE_RULE
|
|
|
|
|
2004-06-21 16:25:24 +00:00
|
|
|
#endif
|
2004-05-28 13:51:11 +00:00
|
|
|
|
2004-06-18 08:57:42 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
kdbgstream& operator<<( kdbgstream& stream, const Rules* r )
|
2004-06-03 14:09:45 +00:00
|
|
|
{
|
2004-09-24 13:30:25 +00:00
|
|
|
return stream << "[" << r->description << ":" << r->wmclass << "]" ;
|
2004-06-03 14:09:45 +00:00
|
|
|
}
|
2004-06-18 08:57:42 +00:00
|
|
|
#endif
|
2004-06-03 14:09:45 +00:00
|
|
|
|
2004-06-21 16:25:24 +00:00
|
|
|
#ifndef KCMRULES
|
2004-06-18 08:57:42 +00:00
|
|
|
void WindowRules::discardTemporary()
|
2004-06-03 14:09:45 +00:00
|
|
|
{
|
2005-07-28 14:59:42 +00:00
|
|
|
QVector< Rules* >::Iterator it2 = rules.begin();
|
|
|
|
for( QVector< Rules* >::Iterator it = rules.begin();
|
2004-06-18 08:57:42 +00:00
|
|
|
it != rules.end();
|
|
|
|
)
|
|
|
|
{
|
2004-10-01 13:34:57 +00:00
|
|
|
if( (*it)->discardTemporary( true ))
|
2004-06-18 08:57:42 +00:00
|
|
|
++it;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*it2++ = *it++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rules.erase( it2, rules.end());
|
2004-06-03 14:09:45 +00:00
|
|
|
}
|
|
|
|
|
2004-06-18 08:57:42 +00:00
|
|
|
void WindowRules::update( Client* c )
|
2004-06-09 08:29:35 +00:00
|
|
|
{
|
2004-06-18 08:57:42 +00:00
|
|
|
bool updated = false;
|
2005-07-28 14:59:42 +00:00
|
|
|
for( QVector< Rules* >::ConstIterator it = rules.begin();
|
2004-06-18 08:57:42 +00:00
|
|
|
it != rules.end();
|
|
|
|
++it )
|
|
|
|
if( (*it)->update( c )) // no short-circuiting here
|
|
|
|
updated = true;
|
|
|
|
if( updated )
|
|
|
|
Workspace::self()->rulesUpdated();
|
2004-06-09 08:29:35 +00:00
|
|
|
}
|
2004-06-03 14:09:45 +00:00
|
|
|
|
2004-06-18 08:57:42 +00:00
|
|
|
#define CHECK_RULE( rule, type ) \
|
|
|
|
type WindowRules::check##rule( type arg, bool init ) const \
|
|
|
|
{ \
|
|
|
|
if( rules.count() == 0 ) \
|
|
|
|
return arg; \
|
|
|
|
type ret = arg; \
|
2005-07-28 14:59:42 +00:00
|
|
|
for( QVector< Rules* >::ConstIterator it = rules.begin(); \
|
2004-06-18 08:57:42 +00:00
|
|
|
it != rules.end(); \
|
|
|
|
++it ) \
|
|
|
|
{ \
|
|
|
|
if( (*it)->apply##rule( ret, init )) \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
return ret; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CHECK_FORCE_RULE( rule, type ) \
|
|
|
|
type WindowRules::check##rule( type arg ) const \
|
|
|
|
{ \
|
|
|
|
if( rules.count() == 0 ) \
|
|
|
|
return arg; \
|
|
|
|
type ret = arg; \
|
2005-07-28 14:59:42 +00:00
|
|
|
for( QVector< Rules* >::ConstIterator it = rules.begin(); \
|
2004-06-18 08:57:42 +00:00
|
|
|
it != rules.end(); \
|
|
|
|
++it ) \
|
|
|
|
{ \
|
|
|
|
if( (*it)->apply##rule( ret )) \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
return ret; \
|
2004-06-09 08:30:06 +00:00
|
|
|
}
|
|
|
|
|
2004-06-18 08:57:42 +00:00
|
|
|
CHECK_FORCE_RULE( Placement, Placement::Policy )
|
2004-06-09 08:33:53 +00:00
|
|
|
|
2004-06-18 08:57:42 +00:00
|
|
|
QRect WindowRules::checkGeometry( QRect rect, bool init ) const
|
2004-06-09 08:33:53 +00:00
|
|
|
{
|
2004-06-18 08:57:42 +00:00
|
|
|
return QRect( checkPosition( rect.topLeft(), init ), checkSize( rect.size(), init ));
|
2004-06-09 08:33:53 +00:00
|
|
|
}
|
|
|
|
|
2004-06-18 08:57:42 +00:00
|
|
|
CHECK_RULE( Position, QPoint )
|
|
|
|
CHECK_RULE( Size, QSize )
|
|
|
|
CHECK_FORCE_RULE( MinSize, QSize )
|
|
|
|
CHECK_FORCE_RULE( MaxSize, QSize )
|
2005-01-15 17:07:48 +00:00
|
|
|
CHECK_FORCE_RULE( OpacityActive, int )
|
|
|
|
CHECK_FORCE_RULE( OpacityInactive, int )
|
2004-06-21 12:38:40 +00:00
|
|
|
CHECK_FORCE_RULE( IgnorePosition, bool )
|
2005-08-08 14:27:03 +00:00
|
|
|
|
|
|
|
bool WindowRules::checkIgnoreGeometry( bool ignore ) const
|
|
|
|
{
|
|
|
|
return checkIgnorePosition( ignore );
|
|
|
|
}
|
|
|
|
|
2004-06-18 08:57:42 +00:00
|
|
|
CHECK_RULE( Desktop, int )
|
|
|
|
CHECK_FORCE_RULE( Type, NET::WindowType )
|
|
|
|
CHECK_RULE( MaximizeVert, KDecorationDefines::MaximizeMode )
|
|
|
|
CHECK_RULE( MaximizeHoriz, KDecorationDefines::MaximizeMode )
|
2004-06-11 15:10:09 +00:00
|
|
|
|
2004-06-18 08:57:42 +00:00
|
|
|
KDecorationDefines::MaximizeMode WindowRules::checkMaximize( MaximizeMode mode, bool init ) const
|
2004-06-11 15:10:09 +00:00
|
|
|
{
|
2004-06-18 08:57:42 +00:00
|
|
|
bool vert = checkMaximizeVert( mode, init ) & MaximizeVertical;
|
|
|
|
bool horiz = checkMaximizeHoriz( mode, init ) & MaximizeHorizontal;
|
|
|
|
return static_cast< MaximizeMode >(( vert ? MaximizeVertical : 0 ) | ( horiz ? MaximizeHorizontal : 0 ));
|
2004-06-11 15:10:09 +00:00
|
|
|
}
|
|
|
|
|
2004-06-18 08:57:42 +00:00
|
|
|
CHECK_RULE( Minimize, bool )
|
|
|
|
CHECK_RULE( Shade, ShadeMode )
|
|
|
|
CHECK_RULE( SkipTaskbar, bool )
|
|
|
|
CHECK_RULE( SkipPager, bool )
|
|
|
|
CHECK_RULE( KeepAbove, bool )
|
|
|
|
CHECK_RULE( KeepBelow, bool )
|
|
|
|
CHECK_RULE( FullScreen, bool )
|
|
|
|
CHECK_RULE( NoBorder, bool )
|
|
|
|
CHECK_FORCE_RULE( FSP, int )
|
|
|
|
CHECK_FORCE_RULE( AcceptFocus, bool )
|
|
|
|
CHECK_FORCE_RULE( MoveResizeMode, Options::MoveResizeMode )
|
|
|
|
CHECK_FORCE_RULE( Closeable, bool )
|
2005-01-17 13:35:48 +00:00
|
|
|
CHECK_FORCE_RULE( StrictGeometry, bool )
|
2005-01-17 15:53:14 +00:00
|
|
|
CHECK_RULE( Shortcut, QString )
|
2005-08-02 13:25:20 +00:00
|
|
|
CHECK_FORCE_RULE( DisableGlobalShortcuts, bool )
|
2004-06-18 08:57:42 +00:00
|
|
|
|
|
|
|
#undef CHECK_RULE
|
|
|
|
#undef CHECK_FORCE_RULE
|
|
|
|
|
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
|
2004-06-18 08:57:42 +00:00
|
|
|
client_rules = WindowRules();
|
2005-06-07 15:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Applies Force, ForceTemporarily and ApplyNow rules
|
|
|
|
// Used e.g. after the rules have been modified using the kcm.
|
|
|
|
void Client::applyWindowRules()
|
|
|
|
{
|
2005-01-15 17:07:48 +00:00
|
|
|
checkAndSetInitialRuledOpacity();
|
2005-06-07 15:31:15 +00:00
|
|
|
// apply force rules
|
|
|
|
// Placement - does need explicit update, just like some others below
|
|
|
|
// Geometry : setGeometry() doesn't check rules
|
2005-06-08 18:07:27 +00:00
|
|
|
QRect orig_geom = QRect( pos(), sizeForClientSize( clientSize())); // handle shading
|
|
|
|
QRect geom = client_rules.checkGeometry( orig_geom );
|
|
|
|
if( geom != orig_geom )
|
2005-06-07 15:31:15 +00:00
|
|
|
setGeometry( geom );
|
|
|
|
// MinSize, MaxSize handled by Geometry
|
|
|
|
// IgnorePosition
|
|
|
|
setDesktop( desktop());
|
|
|
|
// Type
|
|
|
|
maximize( maximizeMode());
|
|
|
|
// Minimize : functions don't check, and there are two functions
|
|
|
|
if( client_rules.checkMinimize( isMinimized()))
|
|
|
|
minimize();
|
|
|
|
else
|
|
|
|
unminimize();
|
|
|
|
setShade( shadeMode());
|
|
|
|
setSkipTaskbar( skipTaskbar(), true );
|
|
|
|
setSkipPager( skipPager());
|
|
|
|
setKeepAbove( keepAbove());
|
|
|
|
setKeepBelow( keepBelow());
|
|
|
|
setFullScreen( isFullScreen(), true );
|
|
|
|
setUserNoBorder( isUserNoBorder());
|
|
|
|
// FSP
|
|
|
|
// AcceptFocus :
|
|
|
|
if( workspace()->mostRecentlyActivatedClient() == this
|
|
|
|
&& !client_rules.checkAcceptFocus( true ))
|
|
|
|
workspace()->activateNextClient( this );
|
|
|
|
// MoveResizeMode
|
|
|
|
// Closeable
|
2005-06-14 15:35:44 +00:00
|
|
|
QSize s = adjustedSize();
|
2005-06-07 15:31:15 +00:00
|
|
|
if( s != size())
|
|
|
|
resizeWithChecks( s );
|
2005-08-02 13:25:20 +00:00
|
|
|
// StrictGeometry
|
2005-06-07 15:31:15 +00:00
|
|
|
setShortcut( rules()->checkShortcut( shortcut().toString()));
|
2005-08-02 13:25:20 +00:00
|
|
|
// see also Client::setActive()
|
|
|
|
if( isActive())
|
|
|
|
workspace()->disableGlobalShortcutsForClient( rules()->checkDisableGlobalShortcuts( false ));
|
2005-06-07 15:31:15 +00:00
|
|
|
}
|
2004-10-15 14:29:47 +00:00
|
|
|
|
2004-05-28 13:51:11 +00:00
|
|
|
void Client::updateWindowRules()
|
|
|
|
{
|
2004-07-20 14:35:33 +00:00
|
|
|
if( !isManaged()) // not fully setup yet
|
|
|
|
return;
|
2004-06-18 08:57:42 +00:00
|
|
|
client_rules.update( this );
|
2004-05-28 13:51:11 +00:00
|
|
|
}
|
|
|
|
|
2004-05-31 14:25:25 +00:00
|
|
|
void Client::finishWindowRules()
|
|
|
|
{
|
|
|
|
updateWindowRules();
|
2004-06-18 08:57:42 +00:00
|
|
|
client_rules = WindowRules();
|
2004-05-31 14:25:25 +00:00
|
|
|
}
|
2005-01-15 17:07:48 +00:00
|
|
|
|
|
|
|
void Client::checkAndSetInitialRuledOpacity()
|
|
|
|
//apply kwin-rules for window-translucency upon hitting apply or starting to manage client
|
|
|
|
{
|
|
|
|
int tmp;
|
|
|
|
|
|
|
|
//active translucency
|
|
|
|
tmp = -1;
|
|
|
|
tmp = rules()->checkOpacityActive(tmp);
|
|
|
|
if( tmp != -1 ) //rule did apply and returns valid value
|
|
|
|
{
|
|
|
|
rule_opacity_active = (uint)((tmp/100.0)*0xffffffff);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rule_opacity_active = 0;
|
|
|
|
|
|
|
|
//inactive translucency
|
|
|
|
tmp = -1;
|
|
|
|
tmp = rules()->checkOpacityInactive(tmp);
|
|
|
|
if( tmp != -1 ) //rule did apply and returns valid value
|
|
|
|
{
|
|
|
|
rule_opacity_inactive = (uint)((tmp/100.0)*0xffffffff);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rule_opacity_inactive = 0;
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( isDock() )
|
|
|
|
//workaround for docks, as they don't have active/inactive settings and don't aut, therefore we take only the active one...
|
|
|
|
{
|
|
|
|
uint tmp = rule_opacity_active ? rule_opacity_active : options->dockOpacity;
|
|
|
|
setOpacity(tmp < 0xFFFFFFFF && (rule_opacity_active || options->translucentDocks), tmp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
updateOpacity();
|
|
|
|
}
|
2004-05-31 14:25:25 +00:00
|
|
|
|
2004-05-28 13:51:11 +00:00
|
|
|
// Workspace
|
|
|
|
|
2004-06-18 08:57:42 +00:00
|
|
|
WindowRules Workspace::findWindowRules( const Client* c, bool ignore_temporary )
|
2004-05-28 13:51:11 +00:00
|
|
|
{
|
2005-07-28 14:59:42 +00:00
|
|
|
QVector< Rules* > ret;
|
|
|
|
for( QList< Rules* >::Iterator it = rules.begin();
|
2004-06-18 08:57:42 +00:00
|
|
|
it != rules.end();
|
|
|
|
)
|
2004-05-28 13:51:11 +00:00
|
|
|
{
|
2004-06-11 15:10:09 +00:00
|
|
|
if( ignore_temporary && (*it)->isTemporary())
|
2004-06-18 08:57:42 +00:00
|
|
|
{
|
|
|
|
++it;
|
2004-06-11 15:10:09 +00:00
|
|
|
continue;
|
2004-06-18 08:57:42 +00:00
|
|
|
}
|
2004-05-28 13:51:11 +00:00
|
|
|
if( (*it)->match( c ))
|
|
|
|
{
|
2004-06-18 08:57:42 +00:00
|
|
|
Rules* rule = *it;
|
2004-07-28 06:59:16 +00:00
|
|
|
kdDebug( 1212 ) << "Rule found:" << rule << ":" << c << endl;
|
2004-06-18 08:57:42 +00:00
|
|
|
if( rule->isTemporary())
|
|
|
|
it = rules.remove( it );
|
|
|
|
else
|
|
|
|
++it;
|
|
|
|
ret.append( rule );
|
|
|
|
continue;
|
2004-05-28 13:51:11 +00:00
|
|
|
}
|
2004-06-18 08:57:42 +00:00
|
|
|
++it;
|
2004-05-28 13:51:11 +00:00
|
|
|
}
|
2004-06-18 08:57:42 +00:00
|
|
|
return WindowRules( ret );
|
2004-05-28 13:51:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::editWindowRules( Client* c )
|
|
|
|
{
|
2005-06-07 12:08:23 +00:00
|
|
|
writeWindowRules();
|
2004-07-29 17:08:25 +00:00
|
|
|
KApplication::kdeinitExec( "kwin_rules_dialog", QStringList() << "--wid" << QString::number( c->window()));
|
2004-05-28 13:51:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::loadWindowRules()
|
|
|
|
{
|
2004-06-18 08:57:42 +00:00
|
|
|
while( !rules.isEmpty())
|
2004-05-28 13:51:11 +00:00
|
|
|
{
|
2004-06-18 08:57:42 +00:00
|
|
|
delete rules.front();
|
|
|
|
rules.pop_front();
|
2004-05-28 13:51:11 +00:00
|
|
|
}
|
|
|
|
KConfig cfg( "kwinrulesrc", true );
|
|
|
|
cfg.setGroup( "General" );
|
|
|
|
int count = cfg.readNumEntry( "count" );
|
|
|
|
for( int i = 1;
|
|
|
|
i <= count;
|
|
|
|
++i )
|
|
|
|
{
|
|
|
|
cfg.setGroup( QString::number( i ));
|
2004-06-18 08:57:42 +00:00
|
|
|
Rules* rule = new Rules( cfg );
|
|
|
|
rules.append( rule );
|
2004-05-28 13:51:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::writeWindowRules()
|
|
|
|
{
|
2005-06-07 12:08:23 +00:00
|
|
|
rulesUpdatedTimer.stop();
|
2004-05-28 13:51:11 +00:00
|
|
|
KConfig cfg( "kwinrulesrc" );
|
|
|
|
cfg.setGroup( "General" );
|
2004-06-18 08:57:42 +00:00
|
|
|
cfg.writeEntry( "count", rules.count());
|
2004-05-28 13:51:11 +00:00
|
|
|
int i = 1;
|
2005-07-28 14:59:42 +00:00
|
|
|
for( QList< Rules* >::ConstIterator it = rules.begin();
|
2004-06-18 08:57:42 +00:00
|
|
|
it != rules.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;
|
2005-07-28 14:59:42 +00:00
|
|
|
for( QList< Rules* >::ConstIterator it = rules.begin();
|
2004-06-18 08:57:42 +00:00
|
|
|
it != rules.end();
|
2004-06-11 15:10:09 +00:00
|
|
|
++it )
|
|
|
|
if( (*it)->isTemporary())
|
|
|
|
was_temporary = true;
|
2004-06-18 08:57:42 +00:00
|
|
|
Rules* rule = new Rules( message, true );
|
|
|
|
rules.prepend( rule ); // highest priority first
|
2004-06-11 15:10:09 +00:00
|
|
|
if( !was_temporary )
|
|
|
|
QTimer::singleShot( 60000, this, SLOT( cleanupTemporaryRules()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::cleanupTemporaryRules()
|
|
|
|
{
|
|
|
|
bool has_temporary = false;
|
2005-07-28 14:59:42 +00:00
|
|
|
for( QList< Rules* >::Iterator it = rules.begin();
|
2004-06-18 08:57:42 +00:00
|
|
|
it != rules.end();
|
2004-06-11 15:10:09 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
if( (*it)->discardTemporary( false ))
|
2004-06-18 08:57:42 +00:00
|
|
|
it = rules.remove( it );
|
2004-06-11 15:10:09 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2005-06-07 15:31:15 +00:00
|
|
|
void Workspace::discardUsedWindowRules( Client* c, bool withdrawn )
|
|
|
|
{
|
2005-07-28 14:59:42 +00:00
|
|
|
for( QList< Rules* >::Iterator it = rules.begin();
|
2005-06-07 15:31:15 +00:00
|
|
|
it != rules.end();
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if( c->rules()->contains( *it ))
|
|
|
|
{
|
|
|
|
(*it)->discardUsed( withdrawn );
|
|
|
|
if( (*it)->isEmpty())
|
|
|
|
{
|
|
|
|
c->removeRule( *it );
|
|
|
|
Rules* r = *it;
|
|
|
|
it = rules.remove( it );
|
|
|
|
delete r;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
rulesUpdated();
|
|
|
|
}
|
|
|
|
|
2004-06-11 15:12:29 +00:00
|
|
|
void Workspace::rulesUpdated()
|
|
|
|
{
|
|
|
|
rulesUpdatedTimer.start( 1000, true );
|
|
|
|
}
|
|
|
|
|
2004-06-21 16:25:24 +00:00
|
|
|
#endif
|
|
|
|
|
2004-05-28 13:51:11 +00:00
|
|
|
} // namespace
|