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>
|
2006-05-11 08:04:23 +00:00
|
|
|
#include <QRegExp>
|
2006-10-01 17:24:38 +00:00
|
|
|
#include <ktemporaryfile.h>
|
2006-05-11 08:04:23 +00:00
|
|
|
#include <QFile>
|
2005-10-22 10:44:47 +00:00
|
|
|
#include <ktoolinvocation.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 )
|
|
|
|
{
|
2006-10-01 17:24:38 +00:00
|
|
|
KTemporaryFile file;
|
|
|
|
if( file.open() )
|
2004-06-11 15:10:09 +00:00
|
|
|
{
|
2005-09-24 12:26:22 +00:00
|
|
|
QByteArray s = str.toUtf8();
|
2006-10-01 17:24:38 +00:00
|
|
|
file.write( s.data(), s.length());
|
2004-06-11 15:10:09 +00:00
|
|
|
}
|
2006-10-01 17:24:38 +00:00
|
|
|
file.flush();
|
2007-02-20 07:00:30 +00:00
|
|
|
KConfig cfg( file.fileName(), KConfig::OnlyLocal);
|
|
|
|
readFromCfg( cfg.group( QString() ) );
|
2004-06-21 16:25:24 +00:00
|
|
|
if( description.isEmpty())
|
|
|
|
description = "temporary";
|
2004-06-11 15:10:09 +00:00
|
|
|
}
|
|
|
|
|
2004-05-31 14:31:52 +00:00
|
|
|
#define READ_MATCH_STRING( var, func ) \
|
|
|
|
var = cfg.readEntry( #var ) func; \
|
2006-02-17 21:54:55 +00:00
|
|
|
var##match = (StringMatch) qMax( FirstStringMatch, \
|
|
|
|
qMin( LastStringMatch, static_cast< StringMatch >( cfg.readEntry( #var "match",0 ))));
|
2007-02-20 07:00:30 +00:00
|
|
|
|
2006-01-21 19:36:31 +00:00
|
|
|
#define READ_SET_RULE( var, func, def ) \
|
|
|
|
var = func ( cfg.readEntry( #var, def)); \
|
2004-06-18 08:57:42 +00:00
|
|
|
var##rule = readSetRule( cfg, #var "rule" );
|
2006-01-21 19:36:31 +00:00
|
|
|
|
|
|
|
#define READ_SET_RULE_DEF( var , func, def ) \
|
|
|
|
var = func ( cfg.readEntry( #var, def )); \
|
2004-06-18 08:57:42 +00:00
|
|
|
var##rule = readSetRule( cfg, #var "rule" );
|
2007-02-20 07:00:30 +00:00
|
|
|
|
2006-01-21 19:36:31 +00:00
|
|
|
#define READ_FORCE_RULE( var, func, def) \
|
|
|
|
var = func ( cfg.readEntry( #var, def)); \
|
2004-06-09 08:29:35 +00:00
|
|
|
var##rule = readForceRule( cfg, #var "rule" );
|
|
|
|
|
2006-01-21 19:36:31 +00:00
|
|
|
#define READ_FORCE_RULE2( var, def, func, funcarg ) \
|
|
|
|
var = func ( cfg.readEntry( #var, def),funcarg ); \
|
2004-06-18 08:57:42 +00:00
|
|
|
var##rule = readForceRule( cfg, #var "rule" );
|
|
|
|
|
|
|
|
|
2006-01-21 19:36:31 +00:00
|
|
|
|
2007-02-20 07:00:30 +00:00
|
|
|
Rules::Rules( const KConfigGroup& cfg )
|
2004-06-11 15:10:09 +00:00
|
|
|
: temporary_state( 0 )
|
|
|
|
{
|
|
|
|
readFromCfg( cfg );
|
|
|
|
}
|
|
|
|
|
2006-02-17 21:54:55 +00:00
|
|
|
static int limit0to4( int i ) { return qMax( 0, qMin( 4, i )); }
|
2004-06-11 15:12:07 +00:00
|
|
|
|
2007-02-20 07:00:30 +00:00
|
|
|
void Rules::readFromCfg( const KConfigGroup& cfg )
|
2004-05-28 13:51:11 +00:00
|
|
|
{
|
2004-06-21 16:25:24 +00:00
|
|
|
description = cfg.readEntry( "description" );
|
2006-04-12 15:13:31 +00:00
|
|
|
READ_MATCH_STRING( wmclass, .toLower().toLatin1() );
|
2007-02-10 09:12:35 +00:00
|
|
|
wmclasscomplete = cfg.readEntry( "wmclasscomplete" , false);
|
2006-04-12 15:13:31 +00:00
|
|
|
READ_MATCH_STRING( windowrole, .toLower().toLatin1() );
|
2004-05-31 14:31:52 +00:00
|
|
|
READ_MATCH_STRING( title, );
|
2006-04-12 15:13:31 +00:00
|
|
|
READ_MATCH_STRING( extrarole, .toLower().toLatin1() );
|
|
|
|
READ_MATCH_STRING( clientmachine, .toLower().toLatin1() );
|
2006-04-26 16:13:08 +00:00
|
|
|
types = cfg.readEntry( "types", uint(NET::AllTypesMask) );
|
2006-01-21 19:36:31 +00:00
|
|
|
READ_FORCE_RULE2( placement,QString(), Placement::policyFromString,false );
|
|
|
|
READ_SET_RULE_DEF( position, , invalidPoint );
|
|
|
|
READ_SET_RULE( size,, QSize());
|
2004-06-18 22:06:04 +00:00
|
|
|
if( size.isEmpty() && sizerule != ( SetRule )Remember)
|
2004-06-18 08:57:42 +00:00
|
|
|
sizerule = UnusedSetRule;
|
2006-01-21 19:36:31 +00:00
|
|
|
READ_FORCE_RULE( minsize,, QSize());
|
2004-05-31 14:25:25 +00:00
|
|
|
if( !minsize.isValid())
|
2004-06-28 13:47:33 +00:00
|
|
|
minsize = QSize( 1, 1 );
|
2006-01-21 19:36:31 +00:00
|
|
|
READ_FORCE_RULE( maxsize, , QSize());
|
2004-05-31 14:25:25 +00:00
|
|
|
if( maxsize.isEmpty())
|
2004-06-28 13:47:33 +00:00
|
|
|
maxsize = QSize( 32767, 32767 );
|
2006-01-21 19:36:31 +00:00
|
|
|
READ_FORCE_RULE( opacityactive, , 0);
|
2005-01-15 17:07:48 +00:00
|
|
|
if( opacityactive < 0 || opacityactive > 100 )
|
|
|
|
opacityactive = 100;
|
2006-01-21 19:36:31 +00:00
|
|
|
READ_FORCE_RULE( opacityinactive,, 0);
|
2005-01-15 17:07:48 +00:00
|
|
|
if( opacityinactive < 0 || opacityinactive > 100 )
|
|
|
|
opacityinactive = 100;
|
2006-01-21 19:36:31 +00:00
|
|
|
READ_FORCE_RULE( ignoreposition,, false);
|
|
|
|
READ_SET_RULE( desktop,,0 );
|
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;
|
2006-01-21 19:36:31 +00:00
|
|
|
READ_SET_RULE( maximizevert,, false);
|
|
|
|
READ_SET_RULE( maximizehoriz,, false);
|
|
|
|
READ_SET_RULE( minimize,, false);
|
|
|
|
READ_SET_RULE( shade,, false);
|
|
|
|
READ_SET_RULE( skiptaskbar,, false);
|
|
|
|
READ_SET_RULE( skippager,, false);
|
|
|
|
READ_SET_RULE( above,, false);
|
|
|
|
READ_SET_RULE( below,, false);
|
|
|
|
READ_SET_RULE( fullscreen,, false);
|
|
|
|
READ_SET_RULE( noborder,,false );
|
|
|
|
READ_FORCE_RULE( fsplevel,limit0to4,0 ); // fsp is 0-4
|
|
|
|
READ_FORCE_RULE( acceptfocus, , false);
|
|
|
|
READ_FORCE_RULE( moveresizemode,Options::stringToMoveResizeMode, QString());
|
|
|
|
READ_FORCE_RULE( closeable, , false);
|
|
|
|
READ_FORCE_RULE( strictgeometry, , false);
|
|
|
|
READ_SET_RULE( shortcut, ,QString() );
|
|
|
|
READ_FORCE_RULE( disableglobalshortcuts, , false);
|
2004-05-28 13:51:11 +00:00
|
|
|
}
|
|
|
|
|
2004-05-31 14:31:52 +00:00
|
|
|
#undef READ_MATCH_STRING
|
|
|
|
#undef READ_SET_RULE
|
2004-06-09 08:29:35 +00:00
|
|
|
#undef READ_FORCE_RULE
|
2006-01-21 19:36:31 +00:00
|
|
|
#undef READ_FORCE_RULE2
|
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 ); \
|
2006-01-10 11:51:06 +00:00
|
|
|
cfg.writeEntry( #var "match", (int)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 )); \
|
2006-01-10 11:51:06 +00:00
|
|
|
cfg.writeEntry( #var "rule", (int)var##rule ); \
|
2004-06-18 08:57:42 +00:00
|
|
|
} \
|
|
|
|
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 )); \
|
2006-01-10 11:51:06 +00:00
|
|
|
cfg.writeEntry( #var "rule", (int)var##rule ); \
|
2004-05-28 13:51:11 +00:00
|
|
|
} \
|
|
|
|
else \
|
|
|
|
{ \
|
|
|
|
cfg.deleteEntry( #var ); \
|
|
|
|
cfg.deleteEntry( #var "rule" ); \
|
|
|
|
}
|
|
|
|
|
2007-02-20 07:00:30 +00:00
|
|
|
void Rules::write( KConfigGroup& 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 );
|
2006-04-26 16:13:08 +00:00
|
|
|
if (types != NET::AllTypesMask)
|
|
|
|
cfg.writeEntry("types", uint(types));
|
|
|
|
else
|
|
|
|
cfg.deleteEntry("types");
|
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, );
|
2006-01-10 11:51:06 +00:00
|
|
|
WRITE_FORCE_RULE( type, int );
|
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
|
|
|
}
|
2007-02-20 07:00:30 +00:00
|
|
|
|
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-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
|
|
|
}
|
|
|
|
|
2007-02-20 07:00:30 +00:00
|
|
|
Rules::SetRule Rules::readSetRule( const KConfigGroup& cfg, const QString& key )
|
2004-05-28 13:51:11 +00:00
|
|
|
{
|
2006-01-21 19:36:31 +00:00
|
|
|
int v = cfg.readEntry( key,0 );
|
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
|
|
|
}
|
|
|
|
|
2007-02-20 07:00:30 +00:00
|
|
|
Rules::ForceRule Rules::readForceRule( const KConfigGroup& cfg, const QString& key )
|
2004-05-28 13:51:11 +00:00
|
|
|
{
|
2006-01-21 19:36:31 +00:00
|
|
|
int v = cfg.readEntry( key,0 );
|
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
|
|
|
}
|
|
|
|
|
2007-02-20 07:00:30 +00:00
|
|
|
NET::WindowType Rules::readType( const KConfigGroup& cfg, const QString& key )
|
2004-05-28 15:04:01 +00:00
|
|
|
{
|
2006-01-21 19:36:31 +00:00
|
|
|
int v = cfg.readEntry( key,0 );
|
2004-05-28 15:04:01 +00:00
|
|
|
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;
|
|
|
|
}
|
2007-02-20 07:00:30 +00:00
|
|
|
|
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;
|
2006-04-11 17:12:05 +00:00
|
|
|
if( wmclassmatch == RegExpMatch && QRegExp( wmclass ).indexIn( 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;
|
|
|
|
}
|
2007-02-20 07:00:30 +00:00
|
|
|
|
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
|
|
|
{
|
2006-04-11 17:12:05 +00:00
|
|
|
if( windowrolematch == RegExpMatch && QRegExp( windowrole ).indexIn( 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;
|
|
|
|
}
|
2007-02-20 07:00:30 +00:00
|
|
|
|
2004-07-29 17:08:25 +00:00
|
|
|
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
|
|
|
{
|
2006-04-11 17:12:05 +00:00
|
|
|
if( titlematch == RegExpMatch && QRegExp( title ).indexIn( 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
|
2006-04-11 17:12:05 +00:00
|
|
|
&& QRegExp( clientmachine ).indexIn( 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)
|
|
|
|
{
|
2006-07-04 23:30:05 +00:00
|
|
|
// TODO
|
2005-01-15 17:07:48 +00:00
|
|
|
}
|
|
|
|
if (opacityinactiverule == ( ForceRule )Force)
|
|
|
|
{
|
2006-07-04 23:30:05 +00:00
|
|
|
// TODO
|
2005-01-15 17:07:48 +00:00
|
|
|
}
|
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
|
|
|
}
|
2007-02-20 07:00:30 +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
|
2007-02-20 07:00:30 +00:00
|
|
|
// Used e.g. after the rules have been modified using the kcm.
|
2005-06-07 15:31:15 +00:00
|
|
|
void Client::applyWindowRules()
|
|
|
|
{
|
|
|
|
// 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
|
|
|
}
|
2007-02-20 07:00:30 +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;
|
2006-02-06 14:47:18 +00:00
|
|
|
kDebug( 1212 ) << "Rule found:" << rule << ":" << c << endl;
|
2004-06-18 08:57:42 +00:00
|
|
|
if( rule->isTemporary())
|
2006-04-11 17:12:05 +00:00
|
|
|
it = rules.erase( it );
|
2004-06-18 08:57:42 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2005-08-16 17:46:42 +00:00
|
|
|
void Workspace::editWindowRules( Client* c, bool whole_app )
|
2004-05-28 13:51:11 +00:00
|
|
|
{
|
2005-06-07 12:08:23 +00:00
|
|
|
writeWindowRules();
|
2005-08-16 17:46:42 +00:00
|
|
|
QStringList args;
|
|
|
|
args << "--wid" << QString::number( c->window());
|
|
|
|
if( whole_app )
|
|
|
|
args << "--whole-app";
|
2005-10-22 10:44:47 +00:00
|
|
|
KToolInvocation::kdeinitExec( "kwin_rules_dialog", args );
|
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
|
|
|
}
|
2007-02-20 07:00:30 +00:00
|
|
|
KConfig cfg( "kwinrulesrc" );
|
|
|
|
int count = cfg.group("General").readEntry( "count",0 );
|
2004-05-28 13:51:11 +00:00
|
|
|
for( int i = 1;
|
|
|
|
i <= count;
|
|
|
|
++i )
|
|
|
|
{
|
2007-02-20 07:00:30 +00:00
|
|
|
KConfigGroup cg( &cfg, QString::number( i ));
|
|
|
|
Rules* rule = new Rules( cg );
|
|
|
|
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" );
|
2006-02-06 20:44:10 +00:00
|
|
|
QStringList groups = cfg.groupList();
|
|
|
|
for( QStringList::ConstIterator it = groups.begin();
|
|
|
|
it != groups.end();
|
|
|
|
++it )
|
|
|
|
cfg.deleteGroup( *it );
|
2007-02-20 07:00:30 +00:00
|
|
|
cfg.group("General").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;
|
2007-02-20 07:00:30 +00:00
|
|
|
KConfigGroup cg( &cfg, QString::number( i ));
|
|
|
|
(*it)->write( cg );
|
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 ))
|
2006-04-11 17:12:05 +00:00
|
|
|
it = rules.erase( 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-11-01 14:17:11 +00:00
|
|
|
bool updated = false;
|
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 ))
|
|
|
|
{
|
2005-11-01 14:17:11 +00:00
|
|
|
updated = true;
|
2005-06-07 15:31:15 +00:00
|
|
|
(*it)->discardUsed( withdrawn );
|
|
|
|
if( (*it)->isEmpty())
|
|
|
|
{
|
|
|
|
c->removeRule( *it );
|
|
|
|
Rules* r = *it;
|
2006-04-11 17:12:05 +00:00
|
|
|
it = rules.erase( it );
|
2005-06-07 15:31:15 +00:00
|
|
|
delete r;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++it;
|
|
|
|
}
|
2005-11-01 14:17:11 +00:00
|
|
|
if( updated )
|
|
|
|
rulesUpdated();
|
2005-06-07 15:31:15 +00:00
|
|
|
}
|
|
|
|
|
2004-06-11 15:12:29 +00:00
|
|
|
void Workspace::rulesUpdated()
|
|
|
|
{
|
2006-04-11 17:12:05 +00:00
|
|
|
rulesUpdatedTimer.setSingleShot( true );
|
|
|
|
rulesUpdatedTimer.start( 1000 );
|
2004-06-11 15:12:29 +00:00
|
|
|
}
|
|
|
|
|
2004-06-21 16:25:24 +00:00
|
|
|
#endif
|
|
|
|
|
2004-05-28 13:51:11 +00:00
|
|
|
} // namespace
|