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
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-05-02 18:38:05 +00:00
|
|
|
#include "oxygenfactory.h"
|
|
|
|
#include "oxygenfactory.moc"
|
2009-09-16 06:09:31 +00:00
|
|
|
#include "oxygenclient.h"
|
|
|
|
|
2009-08-24 16:17:15 +00:00
|
|
|
#include <cassert>
|
2009-09-17 22:40:06 +00:00
|
|
|
#include <KConfigGroup>
|
2009-09-26 04:23:27 +00:00
|
|
|
#include <KDebug>
|
|
|
|
#include <KGlobal>
|
2009-09-17 22:40:06 +00:00
|
|
|
#include <KWindowInfo>
|
2009-08-22 08:24:06 +00:00
|
|
|
#include <kdeversion.h>
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
{
|
2010-05-02 18:34:08 +00:00
|
|
|
KDE_EXPORT KDecorationFactory* create_factory()
|
|
|
|
{ return new Oxygen::Factory(); }
|
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
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//___________________________________________________
|
|
|
|
Factory::Factory():
|
2011-02-24 16:37:04 +00:00
|
|
|
_initialized( false ),
|
|
|
|
_helper( "oxygenDeco" ),
|
|
|
|
_shadowCache( _helper )
|
2009-09-09 00:55:55 +00:00
|
|
|
{
|
2010-05-02 18:34:08 +00:00
|
|
|
readConfig();
|
|
|
|
setInitialized( true );
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//___________________________________________________
|
|
|
|
Factory::~Factory()
|
|
|
|
{ setInitialized( false ); }
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//___________________________________________________
|
|
|
|
KDecoration* Factory::createDecoration(KDecorationBridge* bridge )
|
|
|
|
{ return (new Client( bridge, this ))->decoration(); }
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//___________________________________________________
|
|
|
|
bool Factory::reset(unsigned long changed)
|
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-08-28 23:45:14 +00:00
|
|
|
if( changed & SettingColors )
|
2010-09-08 21:07:14 +00:00
|
|
|
{ shadowCache().invalidateCaches(); }
|
2010-08-28 23:45:14 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
// read in the configuration
|
|
|
|
setInitialized( false );
|
2011-02-24 16:37:04 +00:00
|
|
|
bool _configurationchanged = readConfig();
|
2010-05-02 18:34:08 +00:00
|
|
|
setInitialized( true );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2011-02-24 16:37:04 +00:00
|
|
|
if( _configurationchanged || (changed & (SettingDecoration | SettingButtons | SettingBorder)) )
|
2010-05-02 18:34:08 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-08-28 23:45:14 +00:00
|
|
|
// returning true triggers all decorations to be re-created
|
2010-05-02 18:34:08 +00:00
|
|
|
return true;
|
2009-08-22 08:24:06 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
} else {
|
2009-09-14 19:21:39 +00:00
|
|
|
|
2010-08-28 23:45:14 +00:00
|
|
|
// no need to re-create the decorations
|
|
|
|
// trigger repaint only
|
2010-05-02 18:34:08 +00:00
|
|
|
resetDecorations(changed);
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
2009-11-24 00:36:01 +00:00
|
|
|
|
2009-09-14 19:21:39 +00:00
|
|
|
}
|
2009-08-22 08:24:06 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//___________________________________________________
|
|
|
|
bool Factory::readConfig()
|
2010-04-14 22:21:08 +00:00
|
|
|
{
|
2010-05-02 18:34:08 +00:00
|
|
|
|
|
|
|
bool changed( false );
|
|
|
|
|
|
|
|
/*
|
|
|
|
always reload helper
|
|
|
|
this is needed to properly handle
|
|
|
|
color contrast settings changed
|
|
|
|
*/
|
2010-09-08 21:07:14 +00:00
|
|
|
helper().invalidateCaches();
|
2010-05-02 18:34:08 +00:00
|
|
|
helper().reloadConfig();
|
|
|
|
|
|
|
|
// create a config object
|
|
|
|
KConfig config("oxygenrc");
|
|
|
|
KConfigGroup group( config.group("Windeco") );
|
|
|
|
Configuration configuration( group );
|
|
|
|
if( !( configuration == defaultConfiguration() ) )
|
2010-04-14 22:21:08 +00:00
|
|
|
{
|
2010-05-02 18:34:08 +00:00
|
|
|
setDefaultConfiguration( configuration );
|
|
|
|
changed = true;
|
2010-04-14 22:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
// read exceptionsreadConfig
|
|
|
|
ExceptionList exceptions( config );
|
2011-02-24 16:37:04 +00:00
|
|
|
if( !( exceptions == _exceptions ) )
|
2010-04-14 22:21:08 +00:00
|
|
|
{
|
2011-02-24 16:37:04 +00:00
|
|
|
_exceptions = exceptions;
|
2010-05-02 18:34:08 +00:00
|
|
|
changed = true;
|
2010-04-14 22:21:08 +00:00
|
|
|
}
|
|
|
|
|
2011-02-23 10:14:21 +00:00
|
|
|
// read shadowCache configuration
|
2011-02-23 10:21:46 +00:00
|
|
|
changed |= shadowCache().readConfig( config );
|
2010-04-25 20:28:02 +00:00
|
|
|
|
2011-03-03 09:52:35 +00:00
|
|
|
// background pixmap
|
|
|
|
{
|
|
|
|
KConfigGroup group( config.group("Common") );
|
|
|
|
helper().setBackgroundPixmap( group.readEntry( "BackgroundPixmap", "" ) );
|
|
|
|
}
|
|
|
|
|
2010-08-28 23:45:14 +00:00
|
|
|
return changed;
|
2009-09-14 19:21:39 +00:00
|
|
|
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//_________________________________________________________________
|
|
|
|
bool Factory::supports( Ability ability ) const
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2010-05-02 18:34:08 +00:00
|
|
|
switch( ability )
|
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
// announce
|
|
|
|
case AbilityAnnounceButtons:
|
|
|
|
case AbilityAnnounceColors:
|
|
|
|
|
|
|
|
// buttons
|
|
|
|
case AbilityButtonMenu:
|
|
|
|
case AbilityButtonHelp:
|
|
|
|
case AbilityButtonMinimize:
|
|
|
|
case AbilityButtonMaximize:
|
|
|
|
case AbilityButtonClose:
|
|
|
|
case AbilityButtonOnAllDesktops:
|
|
|
|
case AbilityButtonAboveOthers:
|
|
|
|
case AbilityButtonBelowOthers:
|
|
|
|
case AbilityButtonSpacer:
|
|
|
|
case AbilityButtonShade:
|
|
|
|
|
|
|
|
// // colors
|
|
|
|
// case AbilityColorTitleBack:
|
|
|
|
// case AbilityColorTitleFore:
|
|
|
|
// case AbilityColorFrame:
|
|
|
|
|
|
|
|
// compositing
|
|
|
|
case AbilityProvidesShadow: // TODO: UI option to use default shadows instead
|
2011-05-01 09:52:22 +00:00
|
|
|
return true;
|
2010-05-02 18:34:08 +00:00
|
|
|
|
|
|
|
case AbilityUsesAlphaChannel:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// tabs
|
|
|
|
case AbilityClientGrouping:
|
|
|
|
return defaultConfiguration().tabsEnabled();
|
|
|
|
|
|
|
|
// no colors supported at this time
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//____________________________________________________________________
|
|
|
|
Configuration Factory::configuration( const Client& client )
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
QString window_title;
|
|
|
|
QString class_name;
|
2011-02-24 16:37:04 +00:00
|
|
|
for( ExceptionList::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
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
// discard disabled exceptions
|
|
|
|
if( !iter->enabled() ) continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
decide which value is to be compared
|
|
|
|
to the regular expression, based on exception type
|
|
|
|
*/
|
|
|
|
QString value;
|
|
|
|
switch( iter->type() )
|
|
|
|
{
|
|
|
|
case Exception::WindowTitle:
|
|
|
|
{
|
|
|
|
value = window_title.isEmpty() ? (window_title = client.caption()):window_title;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Exception::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;
|
|
|
|
}
|
|
|
|
|
|
|
|
value = class_name;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default: assert( false );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if( iter->regExp().indexIn( value ) < 0 ) continue;
|
|
|
|
|
|
|
|
Configuration configuration( defaultConfiguration() );
|
2010-11-11 16:38:44 +00:00
|
|
|
configuration.readException( *iter );
|
2010-05-02 18:34:08 +00:00
|
|
|
return configuration;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +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
|