2009-08-22 08:24:06 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2009-08-24 16:17:15 +00:00
|
|
|
// nitrogen.cpp
|
2009-08-22 08:24:06 +00:00
|
|
|
// -------------------
|
2009-09-09 00:55:55 +00:00
|
|
|
//
|
2009-08-24 16:17:15 +00:00
|
|
|
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
|
2009-08-25 04:15:13 +00:00
|
|
|
// Copyright (c) 2006, 2007 Riccardo Iaconelli <riccardo@kde.org>
|
2009-08-22 08:24:06 +00:00
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
// of this software and associated documentation files (the "Software"), to
|
|
|
|
// deal in the Software without restriction, including without limitation the
|
|
|
|
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
|
// sell copies of the Software, and to permit persons to whom the Software is
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
2009-09-09 00:55:55 +00:00
|
|
|
// IN THE SOFTWARE.
|
2009-08-22 08:24:06 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-08-24 16:17:15 +00:00
|
|
|
#include <cassert>
|
2009-09-06 23:32:41 +00:00
|
|
|
#include <kdebug.h>
|
2009-08-22 08:24:06 +00:00
|
|
|
#include <kconfiggroup.h>
|
|
|
|
#include <kdeversion.h>
|
|
|
|
#include <kwindowinfo.h>
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QPainter>
|
|
|
|
|
|
|
|
#include "nitrogen.h"
|
|
|
|
#include "nitrogen.moc"
|
|
|
|
#include "nitrogenclient.h"
|
|
|
|
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
KDE_EXPORT KDecorationFactory* create_factory()
|
|
|
|
{ return new Nitrogen::NitrogenFactory(); }
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace Nitrogen
|
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// referenced from definition in Nitrogendclient.cpp
|
2009-09-09 00:55:55 +00:00
|
|
|
OxygenHelper *nitrogenHelper();
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// initialize static members
|
|
|
|
bool NitrogenFactory::initialized_ = false;
|
|
|
|
NitrogenConfiguration NitrogenFactory::defaultConfiguration_;
|
2009-09-14 19:21:39 +00:00
|
|
|
NitrogenShadowConfiguration NitrogenFactory::activeShadowConfiguration_ = NitrogenShadowConfiguration( QPalette::Active );
|
|
|
|
NitrogenShadowConfiguration NitrogenFactory::inactiveShadowConfiguration_ = NitrogenShadowConfiguration( QPalette::Inactive );
|
2009-08-22 08:24:06 +00:00
|
|
|
NitrogenExceptionList NitrogenFactory::exceptions_;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//___________________________________________________
|
|
|
|
NitrogenFactory::NitrogenFactory()
|
|
|
|
{
|
|
|
|
readConfig();
|
|
|
|
setInitialized( true );
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//___________________________________________________
|
2009-09-09 00:55:55 +00:00
|
|
|
NitrogenFactory::~NitrogenFactory()
|
2009-08-22 08:24:06 +00:00
|
|
|
{ setInitialized( false ); }
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//___________________________________________________
|
|
|
|
KDecoration* NitrogenFactory::createDecoration(KDecorationBridge* bridge )
|
2009-09-09 00:55:55 +00:00
|
|
|
{
|
2009-08-22 08:24:06 +00:00
|
|
|
NitrogenClient* client( new NitrogenClient( bridge, this ) );
|
|
|
|
connect( this, SIGNAL( configurationChanged() ), client, SLOT( resetConfiguration() ) );
|
2009-09-09 00:55:55 +00:00
|
|
|
return client->decoration();
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//___________________________________________________
|
|
|
|
bool NitrogenFactory::reset(unsigned long changed)
|
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-06 23:32:41 +00:00
|
|
|
kDebug( 1212 ) << endl;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// read in the configuration
|
|
|
|
setInitialized( false );
|
|
|
|
bool configuration_changed = readConfig();
|
|
|
|
setInitialized( true );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
|
|
|
if( configuration_changed || (changed & (SettingDecoration | SettingButtons | SettingBorder)) )
|
|
|
|
{
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
emit configurationChanged();
|
2009-09-09 00:55:55 +00:00
|
|
|
return true;
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
} else {
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
emit configurationChanged();
|
|
|
|
resetDecorations(changed);
|
|
|
|
return false;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//___________________________________________________
|
|
|
|
bool NitrogenFactory::readConfig()
|
|
|
|
{
|
|
|
|
|
2009-09-06 23:32:41 +00:00
|
|
|
kDebug( 1212 ) << endl;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-14 19:21:39 +00:00
|
|
|
bool changed( false );
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// create a config object
|
2009-09-15 06:25:06 +00:00
|
|
|
KConfig config("oxygenrc");
|
2009-08-22 08:24:06 +00:00
|
|
|
KConfigGroup group( config.group("Windeco") );
|
|
|
|
NitrogenConfiguration configuration( group );
|
2009-09-14 19:21:39 +00:00
|
|
|
if( !( configuration == defaultConfiguration() ) )
|
|
|
|
{
|
|
|
|
setDefaultConfiguration( configuration );
|
|
|
|
changed = true;
|
|
|
|
}
|
2009-08-22 08:24:06 +00:00
|
|
|
|
|
|
|
// read exceptionsreadConfig
|
|
|
|
NitrogenExceptionList exceptions( config );
|
2009-09-09 00:55:55 +00:00
|
|
|
if( !( exceptions == exceptions_ ) )
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
exceptions_ = exceptions;
|
2009-08-22 08:24:06 +00:00
|
|
|
changed = true;
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-14 19:21:39 +00:00
|
|
|
// read shadow configurations
|
|
|
|
NitrogenShadowConfiguration activeShadowConfiguration( QPalette::Active, config.group( "ActiveShadow" ) );
|
|
|
|
if( !( activeShadowConfiguration == activeShadowConfiguration_ ) )
|
|
|
|
{
|
|
|
|
activeShadowConfiguration_ = activeShadowConfiguration;
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// read shadow configurations
|
|
|
|
NitrogenShadowConfiguration inactiveShadowConfiguration( QPalette::Inactive, config.group( "InactiveShadow" ) );
|
|
|
|
if( !( inactiveShadowConfiguration == inactiveShadowConfiguration_ ) )
|
|
|
|
{
|
|
|
|
inactiveShadowConfiguration_ = inactiveShadowConfiguration;
|
|
|
|
changed = true;
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
|
|
|
if( changed )
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
nitrogenHelper()->invalidateCaches();
|
|
|
|
return true;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
} else return false;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//_________________________________________________________________
|
|
|
|
bool NitrogenFactory::supports( Ability ability ) const
|
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
switch( ability )
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// announce
|
|
|
|
case AbilityAnnounceButtons:
|
|
|
|
case AbilityAnnounceColors:
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// buttons
|
|
|
|
case AbilityButtonMenu:
|
|
|
|
case AbilityButtonHelp:
|
|
|
|
case AbilityButtonMinimize:
|
|
|
|
case AbilityButtonMaximize:
|
|
|
|
case AbilityButtonClose:
|
|
|
|
case AbilityButtonOnAllDesktops:
|
|
|
|
case AbilityButtonAboveOthers:
|
|
|
|
case AbilityButtonBelowOthers:
|
|
|
|
case AbilityButtonSpacer:
|
|
|
|
case AbilityButtonShade:
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// // colors
|
|
|
|
// case AbilityColorTitleBack:
|
|
|
|
// case AbilityColorTitleFore:
|
|
|
|
// case AbilityColorFrame:
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// compositing
|
|
|
|
case AbilityProvidesShadow: // TODO: UI option to use default shadows instead
|
|
|
|
case AbilityUsesAlphaChannel:
|
2009-08-31 00:58:10 +00:00
|
|
|
return true;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// no colors supported at this time
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//____________________________________________________________________
|
|
|
|
NitrogenConfiguration NitrogenFactory::configuration( const NitrogenClient& client )
|
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
QString window_title;
|
|
|
|
QString class_name;
|
2009-08-24 06:27:49 +00:00
|
|
|
for( NitrogenExceptionList::const_iterator iter = exceptions_.constBegin(); iter != exceptions_.constEnd(); iter++ )
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// discard disabled exceptions
|
|
|
|
if( !iter->enabled() ) continue;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
|
|
|
/*
|
2009-08-22 08:24:06 +00:00
|
|
|
decide which value is to be compared
|
|
|
|
to the regular expression, based on exception type
|
|
|
|
*/
|
|
|
|
QString value;
|
|
|
|
switch( iter->type() )
|
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
case NitrogenException::WindowTitle:
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
|
|
|
value = window_title.isEmpty() ? (window_title = client.caption()):window_title;
|
|
|
|
break;
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
case NitrogenException::WindowClassName:
|
|
|
|
{
|
|
|
|
if( class_name.isEmpty() )
|
|
|
|
{
|
|
|
|
// retrieve class name
|
|
|
|
KWindowInfo info( client.windowId(), 0, NET::WM2WindowClass );
|
|
|
|
QString window_class_name( info.windowClassName() );
|
|
|
|
QString window_class( info.windowClassClass() );
|
|
|
|
class_name = window_class_name + " " + window_class;
|
2009-09-09 00:55:55 +00:00
|
|
|
}
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
value = class_name;
|
|
|
|
break;
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
default: assert( false );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
if( iter->regExp().indexIn( value ) < 0 ) continue;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
NitrogenConfiguration configuration( defaultConfiguration() );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// propagate all features found in mask to the output configuration
|
|
|
|
if( iter->mask() & NitrogenException::FrameBorder ) configuration.setFrameBorder( iter->frameBorder() );
|
|
|
|
if( iter->mask() & NitrogenException::BlendColor ) configuration.setBlendColor( iter->blendColor() );
|
|
|
|
if( iter->mask() & NitrogenException::DrawSeparator ) configuration.setDrawSeparator( iter->drawSeparator() );
|
2009-09-04 19:04:14 +00:00
|
|
|
if( iter->mask() & NitrogenException::TitleOutline ) configuration.setDrawTitleOutline( iter->drawTitleOutline() );
|
2009-09-02 02:15:53 +00:00
|
|
|
if( iter->mask() & NitrogenException::SizeGripMode ) configuration.setSizeGripMode( iter->sizeGripMode() );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
return configuration;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
return defaultConfiguration();
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
} //namespace Nitrogen
|