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"
|
2012-11-23 09:09:39 +00:00
|
|
|
#include "oxygenexceptionlist.h"
|
2009-09-16 06:09:31 +00:00
|
|
|
|
2012-11-26 18:06:26 +00:00
|
|
|
#include <KSharedConfig>
|
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>
|
|
|
|
|
2012-05-17 21:25:22 +00:00
|
|
|
KWIN_DECORATION(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 )
|
2012-11-23 09:09:39 +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 );
|
2012-11-23 09:09:39 +00:00
|
|
|
readConfig();
|
2010-05-02 18:34:08 +00:00
|
|
|
setInitialized( true );
|
2012-11-23 09:09:39 +00:00
|
|
|
return true;
|
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
|
|
|
//___________________________________________________
|
2012-11-23 09:09:39 +00:00
|
|
|
void Factory::readConfig()
|
2010-04-14 22:21:08 +00:00
|
|
|
{
|
2010-05-02 18:34:08 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
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();
|
|
|
|
|
2012-11-23 09:09:39 +00:00
|
|
|
// initialize default configuration and read
|
|
|
|
if( !_defaultConfiguration ) _defaultConfiguration = ConfigurationPtr(new Configuration());
|
|
|
|
_defaultConfiguration->setCurrentGroup( "Windeco" );
|
|
|
|
_defaultConfiguration->readConfig();
|
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
// create a config object
|
2012-11-26 18:06:26 +00:00
|
|
|
KSharedConfig::Ptr config( KSharedConfig::openConfig( "oxygenrc" ) );
|
2010-04-14 22:21:08 +00:00
|
|
|
|
2012-11-23 09:09:39 +00:00
|
|
|
// clear exceptions and read
|
|
|
|
ExceptionList exceptions;
|
|
|
|
exceptions.readConfig( config );
|
|
|
|
_exceptions = exceptions.get();
|
2010-04-14 22:21:08 +00:00
|
|
|
|
2011-02-23 10:14:21 +00:00
|
|
|
// read shadowCache configuration
|
2012-11-23 09:09:39 +00:00
|
|
|
_shadowCache.readConfig();
|
|
|
|
_shadowCache.setAnimationsDuration( _defaultConfiguration->shadowAnimationsDuration() );
|
2010-04-25 20:28:02 +00:00
|
|
|
|
2011-03-03 09:52:35 +00:00
|
|
|
// background pixmap
|
|
|
|
{
|
2012-11-26 18:06:26 +00:00
|
|
|
KConfigGroup group( config->group("Common") );
|
2011-03-03 09:52:35 +00:00
|
|
|
helper().setBackgroundPixmap( group.readEntry( "BackgroundPixmap", "" ) );
|
|
|
|
}
|
|
|
|
|
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:
|
2012-11-09 12:44:50 +00:00
|
|
|
case AbilityButtonApplicationMenu:
|
2010-05-02 18:34:08 +00:00
|
|
|
case AbilityButtonHelp:
|
|
|
|
case AbilityButtonMinimize:
|
|
|
|
case AbilityButtonMaximize:
|
|
|
|
case AbilityButtonClose:
|
|
|
|
case AbilityButtonOnAllDesktops:
|
|
|
|
case AbilityButtonAboveOthers:
|
|
|
|
case AbilityButtonBelowOthers:
|
|
|
|
case AbilityButtonSpacer:
|
|
|
|
case AbilityButtonShade:
|
|
|
|
|
|
|
|
// compositing
|
2012-11-23 09:09:39 +00:00
|
|
|
case AbilityProvidesShadow:
|
2011-05-01 09:52:22 +00:00
|
|
|
return true;
|
2010-05-02 18:34:08 +00:00
|
|
|
|
|
|
|
case AbilityUsesAlphaChannel:
|
2012-10-12 09:34:05 +00:00
|
|
|
case AbilityAnnounceAlphaChannel:
|
2010-05-02 18:34:08 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
// tabs
|
2012-01-12 06:42:55 +00:00
|
|
|
case AbilityTabbing:
|
2011-07-17 14:12:30 +00:00
|
|
|
return true;
|
2010-05-02 18:34:08 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
//____________________________________________________________________
|
2012-11-23 09:09:39 +00:00
|
|
|
Factory::ConfigurationPtr Factory::configuration( const Client& client )
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2012-11-23 09:09:39 +00:00
|
|
|
QString windowTitle;
|
|
|
|
QString className;
|
|
|
|
foreach( const ConfigurationPtr& configuration, _exceptions )
|
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
|
2012-11-23 09:09:39 +00:00
|
|
|
if( !configuration->enabled() ) continue;
|
|
|
|
|
|
|
|
// discard exceptions with empty exception pattern
|
|
|
|
if( configuration->exceptionPattern().isEmpty() ) continue;
|
2010-05-02 18:34:08 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
decide which value is to be compared
|
|
|
|
to the regular expression, based on exception type
|
|
|
|
*/
|
|
|
|
QString value;
|
2012-11-23 09:09:39 +00:00
|
|
|
switch( configuration->exceptionType() )
|
2010-05-02 18:34:08 +00:00
|
|
|
{
|
2012-11-23 09:09:39 +00:00
|
|
|
case Configuration::ExceptionWindowTitle:
|
2010-05-02 18:34:08 +00:00
|
|
|
{
|
2012-11-23 09:09:39 +00:00
|
|
|
value = windowTitle.isEmpty() ? (windowTitle = client.caption()):windowTitle;
|
2010-05-02 18:34:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-11-23 09:09:39 +00:00
|
|
|
default:
|
|
|
|
case Configuration::ExceptionWindowClassName:
|
2010-05-02 18:34:08 +00:00
|
|
|
{
|
2012-11-23 09:09:39 +00:00
|
|
|
if( className.isEmpty() )
|
2010-05-02 18:34:08 +00:00
|
|
|
{
|
|
|
|
// retrieve class name
|
|
|
|
KWindowInfo info( client.windowId(), 0, NET::WM2WindowClass );
|
2012-11-23 09:09:39 +00:00
|
|
|
QString window_className( info.windowClassName() );
|
2010-05-02 18:34:08 +00:00
|
|
|
QString window_class( info.windowClassClass() );
|
2012-11-23 09:09:39 +00:00
|
|
|
className = window_className + ' ' + window_class;
|
2010-05-02 18:34:08 +00:00
|
|
|
}
|
|
|
|
|
2012-11-23 09:09:39 +00:00
|
|
|
value = className;
|
2010-05-02 18:34:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-11-23 09:09:39 +00:00
|
|
|
// check matching
|
|
|
|
if( QRegExp( configuration->exceptionPattern() ).indexIn( value ) >= 0 )
|
|
|
|
{ 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
|
|
|
|
2012-11-23 09:09:39 +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
|
|
|
|
2012-11-23 09:09:39 +00:00
|
|
|
}
|