2009-08-22 08:24:06 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2009-09-15 07:12:54 +00:00
|
|
|
// oxygen.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-09-16 06:09:31 +00:00
|
|
|
#include "oxygen.h"
|
|
|
|
#include "oxygen.moc"
|
|
|
|
#include "oxygenclient.h"
|
2009-09-17 22:40:06 +00:00
|
|
|
#include "oxygenshadowcache.h"
|
2009-09-16 06:09:31 +00:00
|
|
|
|
2009-08-24 16:17:15 +00:00
|
|
|
#include <cassert>
|
2009-09-17 22:40:06 +00:00
|
|
|
#include <KDebug>
|
|
|
|
#include <KConfigGroup>
|
|
|
|
#include <KWindowInfo>
|
2009-08-22 08:24:06 +00:00
|
|
|
#include <kdeversion.h>
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
KDE_EXPORT KDecorationFactory* create_factory()
|
2009-09-15 07:12:54 +00:00
|
|
|
{ return new Oxygen::OxygenFactory(); }
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
|
|
|
|
2009-09-15 07:12:54 +00:00
|
|
|
namespace Oxygen
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-15 07:12:54 +00:00
|
|
|
// referenced from definition in Oxygendclient.cpp
|
|
|
|
OxygenHelper *oxygenHelper();
|
2009-09-17 22:40:06 +00:00
|
|
|
OxygenShadowCache *oxygenShadowCache();
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// initialize static members
|
2009-09-15 07:12:54 +00:00
|
|
|
bool OxygenFactory::initialized_ = false;
|
|
|
|
OxygenConfiguration OxygenFactory::defaultConfiguration_;
|
|
|
|
OxygenExceptionList OxygenFactory::exceptions_;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//___________________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
OxygenFactory::OxygenFactory()
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
|
|
|
readConfig();
|
|
|
|
setInitialized( true );
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//___________________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
OxygenFactory::~OxygenFactory()
|
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
|
|
|
//___________________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
KDecoration* OxygenFactory::createDecoration(KDecorationBridge* bridge )
|
2009-09-09 00:55:55 +00:00
|
|
|
{
|
2009-09-15 07:12:54 +00:00
|
|
|
OxygenClient* client( new OxygenClient( bridge, this ) );
|
2009-08-22 08:24:06 +00:00
|
|
|
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
|
|
|
//___________________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
bool OxygenFactory::reset(unsigned long changed)
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
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
|
|
|
|
2009-09-17 22:40:06 +00:00
|
|
|
emit configurationChanged();
|
2009-09-09 00:55:55 +00:00
|
|
|
if( configuration_changed || (changed & (SettingDecoration | SettingButtons | SettingBorder)) )
|
|
|
|
{
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
} else {
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-19 20:32:23 +00:00
|
|
|
if( changed & SettingColors ) oxygenShadowCache()->invalidateCaches();
|
2009-08-22 08:24:06 +00:00
|
|
|
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
|
|
|
//___________________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
bool OxygenFactory::readConfig()
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
|
|
|
|
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") );
|
2009-09-15 07:12:54 +00:00
|
|
|
OxygenConfiguration 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
|
2009-09-15 07:12:54 +00:00
|
|
|
OxygenExceptionList 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
|
2009-09-15 07:12:54 +00:00
|
|
|
OxygenShadowConfiguration activeShadowConfiguration( QPalette::Active, config.group( "ActiveShadow" ) );
|
2009-09-17 22:40:06 +00:00
|
|
|
if( oxygenShadowCache()->shadowConfigurationChanged( activeShadowConfiguration ) )
|
2009-09-14 19:21:39 +00:00
|
|
|
{
|
2009-09-17 22:40:06 +00:00
|
|
|
oxygenShadowCache()->setShadowConfiguration( activeShadowConfiguration );
|
2009-09-14 19:21:39 +00:00
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// read shadow configurations
|
2009-09-15 07:12:54 +00:00
|
|
|
OxygenShadowConfiguration inactiveShadowConfiguration( QPalette::Inactive, config.group( "InactiveShadow" ) );
|
2009-09-17 22:40:06 +00:00
|
|
|
if( oxygenShadowCache()->shadowConfigurationChanged( inactiveShadowConfiguration ) )
|
2009-09-14 19:21:39 +00:00
|
|
|
{
|
2009-09-17 22:40:06 +00:00
|
|
|
oxygenShadowCache()->setShadowConfiguration( inactiveShadowConfiguration );
|
2009-09-14 19:21:39 +00:00
|
|
|
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-09-17 22:40:06 +00:00
|
|
|
oxygenShadowCache()->invalidateCaches();
|
2009-09-15 07:12:54 +00:00
|
|
|
oxygenHelper()->invalidateCaches();
|
2009-08-22 08:24:06 +00:00
|
|
|
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
|
|
|
//_________________________________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
bool OxygenFactory::supports( Ability ability ) const
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
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
|
|
|
//____________________________________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
OxygenConfiguration OxygenFactory::configuration( const OxygenClient& client )
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
QString window_title;
|
|
|
|
QString class_name;
|
2009-09-16 06:09:31 +00:00
|
|
|
for( OxygenExceptionList::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-15 07:12:54 +00:00
|
|
|
case OxygenException::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-09-15 07:12:54 +00:00
|
|
|
case OxygenException::WindowClassName:
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
|
|
|
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() );
|
2009-09-16 06:09:31 +00:00
|
|
|
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-09-15 07:12:54 +00:00
|
|
|
OxygenConfiguration 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
|
2009-09-15 07:12:54 +00:00
|
|
|
if( iter->mask() & OxygenException::FrameBorder ) configuration.setFrameBorder( iter->frameBorder() );
|
|
|
|
if( iter->mask() & OxygenException::BlendColor ) configuration.setBlendColor( iter->blendColor() );
|
|
|
|
if( iter->mask() & OxygenException::DrawSeparator ) configuration.setDrawSeparator( iter->drawSeparator() );
|
|
|
|
if( iter->mask() & OxygenException::TitleOutline ) configuration.setDrawTitleOutline( iter->drawTitleOutline() );
|
|
|
|
if( iter->mask() & OxygenException::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-09-15 07:12:54 +00:00
|
|
|
} //namespace Oxygen
|