From 03bdeb94b0cd1fc13e7795c5dd4218c0d16737a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Thu, 3 Jun 2004 14:09:45 +0000 Subject: [PATCH] KWin rules setting maximizevert, maximizehoriz, minimize, shade, skiptaskbar, skippager, fullscreen, noborder. svn path=/trunk/kdebase/kwin/; revision=317377 --- client.cpp | 6 +++ geometry.cpp | 9 ++++- manage.cpp | 38 +++++++++---------- rules.cpp | 105 ++++++++++++++++++++++++++++++++++++++++++++++----- rules.h | 28 +++++++++++++- 5 files changed, 154 insertions(+), 32 deletions(-) diff --git a/client.cpp b/client.cpp index 79e325e783..053502ab9a 100644 --- a/client.cpp +++ b/client.cpp @@ -400,6 +400,7 @@ void Client::setUserNoBorder( bool set ) { if( !userCanSetNoBorder()) return; + set = rules()->checkNoBorder( set ); if( user_noborder == set ) return; user_noborder = set; @@ -687,6 +688,7 @@ void Client::setShade( ShadeMode mode ) { if( !isShadeable()) return; + mode = rules()->checkShade( mode ); if( shade_mode == mode ) return; bool was_shade = isShade(); @@ -1053,7 +1055,10 @@ void Client::processKillerExited() void Client::setSkipTaskbar( bool b, bool from_outside ) { if( from_outside ) + { + b = rules()->checkSkipTaskbar( b ); original_skip_taskbar = b; + } if ( b == skipTaskbar() ) return; skip_taskbar = b; @@ -1062,6 +1067,7 @@ void Client::setSkipTaskbar( bool b, bool from_outside ) void Client::setSkipPager( bool b ) { + b = rules()->checkSkipPager( b ); if ( b == skipPager() ) return; skip_pager = b; diff --git a/geometry.cpp b/geometry.cpp index 1cb512b8d3..ed8d5e6a5f 100644 --- a/geometry.cpp +++ b/geometry.cpp @@ -1665,8 +1665,6 @@ void Client::changeMaximize( bool vertical, bool horizontal, bool adjust ) if( !isMaximizable()) return; - ++block_geometry; // TODO GeometryBlocker class? - if( isShade()) // SELI SHADE setShade( ShadeNone ); @@ -1679,6 +1677,12 @@ void Client::changeMaximize( bool vertical, bool horizontal, bool adjust ) if( horizontal ) max_mode = MaximizeMode( max_mode ^ MaximizeHorizontal ); } + + max_mode = rules()->checkMaximize( max_mode ); + if( !adjust && max_mode == old_mode ) + return; + + ++block_geometry; // TODO GeometryBlocker class? // maximing one way and unmaximizing the other way shouldn't happen Q_ASSERT( !( vertical && horizontal ) @@ -1846,6 +1850,7 @@ void Client::setFullScreen( bool set, bool user ) return; if( user && !userCanSetFullScreen()) return; + set = rules()->checkFullScreen( set ); setShade( ShadeNone ); bool was_fs = isFullScreen(); if( !was_fs ) diff --git a/manage.cpp b/manage.cpp index 0405cffff3..31fb19c98f 100644 --- a/manage.cpp +++ b/manage.cpp @@ -145,6 +145,10 @@ bool Client::manage( Window w, bool isMapped ) setUserNoBorder( true ); } + init_minimize = rules()->checkMinimize( init_minimize, !isMapped ); + if( rules()->checkNoBorder( false, !isMapped )) + setUserNoBorder( true ); + // initial desktop placement if ( info->desktop() ) desk = info->desktop(); // window had the initial desktop property! @@ -269,9 +273,9 @@ bool Client::manage( Window w, bool isMapped ) updateDecoration( false ); // also gravitates // TODO is CentralGravity right here, when resizing is done after gravitating? - plainResize( rules()->checkSize( sizeForClientSize( geom.size()), true )); + plainResize( rules()->checkSize( sizeForClientSize( geom.size()), !isMapped )); - QPoint forced_pos = rules()->checkPosition( invalidPoint, true ); + QPoint forced_pos = rules()->checkPosition( invalidPoint, !isMapped ); if( forced_pos != invalidPoint ) { move( forced_pos ); @@ -370,31 +374,27 @@ bool Client::manage( Window w, bool isMapped ) // done after checking that the window isn't larger than the workarea, so that // the restore geometry from the checks above takes precedence, and window // isn't restored larger than the workarea - if ( (info->state() & NET::Max) == NET::Max ) - maximize( Client::MaximizeFull ); - else if ( info->state() & NET::MaxVert ) - maximize( Client::MaximizeVertical ); - else if ( info->state() & NET::MaxHoriz ) - maximize( Client::MaximizeHorizontal ); + MaximizeMode maxmode = static_cast< MaximizeMode > + ((( info->state() & NET::MaxVert ) ? MaximizeVertical : 0 ) + | (( info->state() & NET::MaxHoriz ) ? MaximizeHorizontal : 0 )); + MaximizeMode forced_maxmode = rules()->checkMaximize( maxmode, !isMapped ); + // either hints were set to maximize, or is forced to maximize, + // or is forced to non-maximize and hints were set to maximize + if( forced_maxmode != MaximizeRestore || maxmode != MaximizeRestore ) + maximize( forced_maxmode ); // read other initial states - if( info->state() & NET::Shaded ) - setShade( ShadeNormal ); + setShade( rules()->checkShade( info->state() & NET::Shaded ? ShadeNormal : ShadeNone, !isMapped )); setKeepAbove( rules()->checkKeepAbove( info->state() & NET::KeepAbove, !isMapped )); setKeepBelow( rules()->checkKeepBelow( info->state() & NET::KeepBelow, !isMapped )); - if( info->state() & NET::SkipTaskbar ) - setSkipTaskbar( true, true ); - if( info->state() & NET::SkipPager ) - setSkipPager( true ); + setSkipTaskbar( rules()->checkSkipTaskbar( info->state() & NET::SkipTaskbar, !isMapped ), true ); + setSkipPager( rules()->checkSkipPager( info->state() & NET::SkipPager, !isMapped )); if( info->state() & NET::DemandsAttention ) demandAttention(); if( info->state() & NET::Modal ) setModal( true ); - if( fullscreen_mode != FullScreenHack ) - { - if(( info->state() & NET::FullScreen ) != 0 && isFullScreenable()) - setFullScreen( true, false ); - } + if( fullscreen_mode != FullScreenHack && isFullScreenable()) + setFullScreen( rules()->checkFullScreen( info->state() & NET::FullScreen, !isMapped ), false ); } updateAllowedActions( true ); diff --git a/rules.cpp b/rules.cpp index abbe08c48c..e027920632 100644 --- a/rules.cpp +++ b/rules.cpp @@ -36,8 +36,16 @@ WindowRules::WindowRules() , maxsizerule( DontCareRule ) , desktoprule( DontCareRule ) , typerule( DontCareRule ) + , maximizevertrule( DontCareRule ) + , maximizehorizrule( DontCareRule ) + , minimizerule( DontCareRule ) + , shaderule( DontCareRule ) + , skiptaskbarrule( DontCareRule ) + , skippagerrule( DontCareRule ) , aboverule( DontCareRule ) , belowrule( DontCareRule ) + , fullscreenrule( DontCareRule ) + , noborderrule( DontCareRule ) { } @@ -77,8 +85,16 @@ WindowRules::WindowRules( KConfig& cfg ) READ_SET_RULE( desktop, Num, ); type = readType( cfg, "type" ); typerule = type != NET::Unknown ? readForceRule( cfg, "typerule" ) : DontCareRule; + 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, ); READ_SET_RULE( above, Bool, ); READ_SET_RULE( below, Bool, ); + READ_SET_RULE( fullscreen, Bool, ); + READ_SET_RULE( noborder, Bool, ); kdDebug() << "READ RULE:" << wmclass << endl; } @@ -135,8 +151,16 @@ void WindowRules::write( KConfig& cfg ) const WRITE_SET_RULE( maxsize, ); WRITE_SET_RULE( desktop, ); WRITE_SET_RULE( type, ); + WRITE_SET_RULE( maximizevert, ); + WRITE_SET_RULE( maximizehoriz, ); + WRITE_SET_RULE( minimize, ); + WRITE_SET_RULE( shade, ); + WRITE_SET_RULE( skiptaskbar, ); + WRITE_SET_RULE( skippager, ); WRITE_SET_RULE( above, ); WRITE_SET_RULE( below, ); + WRITE_SET_RULE( fullscreen, ); + WRITE_SET_RULE( noborder, ); } #undef WRITE_MATCH_STRING @@ -222,10 +246,26 @@ void WindowRules::update( Client* c ) size = c->size(); if( desktoprule == RememberRule ) desktop = c->desktop(); + if( maximizevertrule == RememberRule ) + maximizevert = c->maximizeMode() & MaximizeVertical; + if( maximizehorizrule == RememberRule ) + maximizehoriz = c->maximizeMode() & MaximizeHorizontal; + if( minimizerule == RememberRule ) + minimize = c->isMinimized(); + if( shaderule == RememberRule ) + shade = c->shadeMode() != Client::ShadeNone; + if( skiptaskbarrule == RememberRule ) + skiptaskbar = c->skipTaskbar(); + if( skippagerrule == RememberRule ) + skippager = c->skipPager(); if( aboverule == RememberRule ) above = c->keepAbove(); if( belowrule == RememberRule ) below = c->keepBelow(); + if( fullscreenrule == RememberRule ) + fullscreen = c->isFullScreen(); + if( noborderrule == RememberRule ) + noborder = c->isUserNoBorder(); } Placement::Policy WindowRules::checkPlacement( Placement::Policy placement ) const @@ -266,21 +306,66 @@ int WindowRules::checkDesktop( int req_desktop, bool init ) const return checkRule( desktoprule, init ) ? this->desktop : req_desktop; } -bool WindowRules::checkKeepAbove( bool req_above, bool init ) const - { - return checkRule( aboverule, init ) ? this->above : req_above; - } - -bool WindowRules::checkKeepBelow( bool req_below, bool init ) const - { - return checkRule( belowrule, init ) ? this->below : req_below; - } - NET::WindowType WindowRules::checkType( NET::WindowType req_type ) const { return checkForceRule( typerule ) ? this->type : req_type; } +KDecorationDefines::MaximizeMode WindowRules::checkMaximize( MaximizeMode mode, bool init ) const + { + bool vert = checkRule( maximizevertrule, init ) ? this->maximizevert : bool( mode & MaximizeVertical ); + bool horiz = checkRule( maximizehorizrule, init ) ? this->maximizehoriz : bool( mode & MaximizeHorizontal ); + return static_cast< MaximizeMode >(( vert ? MaximizeVertical : 0 ) | ( horiz ? MaximizeHorizontal : 0 )); + } + +bool WindowRules::checkMinimize( bool minimize, bool init ) const + { + return checkRule( minimizerule, init ) ? this->minimize : minimize; + } + +Client::ShadeMode WindowRules::checkShade( Client::ShadeMode shade, bool init ) const + { + if( checkRule( shaderule, init )) + { + if( !this->shade ) + return Client::ShadeNone; + if( this->shade && shade == Client::ShadeNone ) + return Client::ShadeNormal; + } + return shade; + } + +bool WindowRules::checkSkipTaskbar( bool skip, bool init ) const + { + return checkRule( skiptaskbarrule, init ) ? this->skiptaskbar : skip; + } + +bool WindowRules::checkSkipPager( bool skip, bool init ) const + { + return checkRule( skippagerrule, init ) ? this->skippager : skip; + } + +bool WindowRules::checkKeepAbove( bool above, bool init ) const + { + return checkRule( aboverule, init ) ? this->above : above; + } + +bool WindowRules::checkKeepBelow( bool below, bool init ) const + { + return checkRule( belowrule, init ) ? this->below : below; + } + +bool WindowRules::checkFullScreen( bool fs, bool init ) const + { + return checkRule( fullscreenrule, init ) ? this->fullscreen : fs; + } + +bool WindowRules::checkNoBorder( bool noborder, bool init ) const + { + return checkRule( noborderrule, init ) ? this->noborder : noborder; + } + + // Client void Client::setupWindowRules() diff --git a/rules.h b/rules.h index 206beb8e81..babaf96c02 100644 --- a/rules.h +++ b/rules.h @@ -16,6 +16,8 @@ License. See the file "COPYING" for the exact licensing terms. #include #include "placement.h" +#include "lib/kdecoration.h" +#include "client.h" class KConfig; @@ -34,6 +36,7 @@ enum SettingRule }; class WindowRules + : public KDecorationDefines { public: WindowRules(); @@ -50,8 +53,15 @@ class WindowRules QSize checkMaxSize( const QSize& s ) const; int checkDesktop( int desktop, bool init = false ) const; NET::WindowType checkType( NET::WindowType type ) const; + MaximizeMode checkMaximize( MaximizeMode mode, bool init = false ) const; + bool checkMinimize( bool minimized, bool init = false ) const; + Client::ShadeMode checkShade( Client::ShadeMode shade, bool init = false ) const; + bool checkSkipTaskbar( bool skip, bool init = false ) const; + bool checkSkipPager( bool skip, bool init = false ) const; bool checkKeepAbove( bool above, bool init = false ) const; - bool checkKeepBelow( bool above, bool init = false ) const; + bool checkKeepBelow( bool below, bool init = false ) const; + bool checkFullScreen( bool fs, bool init = false ) const; + bool checkNoBorder( bool noborder, bool init = false ) const; private: static SettingRule readRule( KConfig&, const QString& key ); static SettingRule readForceRule( KConfig&, const QString& key ); @@ -84,10 +94,26 @@ class WindowRules SettingRule desktoprule; NET::WindowType type; // type for setting SettingRule typerule; + bool maximizevert; + SettingRule maximizevertrule; + bool maximizehoriz; + SettingRule maximizehorizrule; + bool minimize; + SettingRule minimizerule; + bool shade; + SettingRule shaderule; + bool skiptaskbar; + SettingRule skiptaskbarrule; + bool skippager; + SettingRule skippagerrule; bool above; SettingRule aboverule; bool below; SettingRule belowrule; + bool fullscreen; + SettingRule fullscreenrule; + bool noborder; + SettingRule noborderrule; }; inline