1
//////////////////////////////////////////////////////////////////////////////
5
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
6
// Copyright (c) 2006, 2007 Riccardo Iaconelli <riccardo@kde.org>
8
// Permission is hereby granted, free of charge, to any person obtaining a copy
9
// of this software and associated documentation files (the "Software"), to
10
// deal in the Software without restriction, including without limitation the
11
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12
// sell copies of the Software, and to permit persons to whom the Software is
13
// furnished to do so, subject to the following conditions:
15
// The above copyright notice and this permission notice shall be included in
16
// all copies or substantial portions of the Software.
18
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25
//////////////////////////////////////////////////////////////////////////////
27
#include "oxygenfactory.h"
28
#include "oxygenfactory.moc"
29
#include "oxygenclient.h"
32
#include <KConfigGroup>
35
#include <KWindowInfo>
36
#include <kdeversion.h>
40
KDE_EXPORT KDecorationFactory* create_factory()
41
{ return new Oxygen::Factory(); }
47
//___________________________________________________
49
_initialized( false ),
50
_helper( "oxygenDeco" ),
51
_shadowCache( _helper )
54
setInitialized( true );
57
//___________________________________________________
59
{ setInitialized( false ); }
61
//___________________________________________________
62
KDecoration* Factory::createDecoration(KDecorationBridge* bridge )
63
{ return (new Client( bridge, this ))->decoration(); }
65
//___________________________________________________
66
bool Factory::reset(unsigned long changed)
69
if( changed & SettingColors )
70
{ shadowCache().invalidateCaches(); }
72
// read in the configuration
73
setInitialized( false );
74
bool _configurationchanged = readConfig();
75
setInitialized( true );
77
if( _configurationchanged || (changed & (SettingDecoration | SettingButtons | SettingBorder)) )
80
// returning true triggers all decorations to be re-created
85
// no need to re-create the decorations
86
// trigger repaint only
87
resetDecorations(changed);
94
//___________________________________________________
95
bool Factory::readConfig()
98
bool changed( false );
102
this is needed to properly handle
103
color contrast settings changed
105
helper().invalidateCaches();
106
helper().reloadConfig();
108
// create a config object
109
KConfig config("oxygenrc");
110
KConfigGroup group( config.group("Windeco") );
111
Configuration configuration( group );
112
if( !( configuration == defaultConfiguration() ) )
114
setDefaultConfiguration( configuration );
118
// read exceptionsreadConfig
119
ExceptionList exceptions( config );
120
if( !( exceptions == _exceptions ) )
122
_exceptions = exceptions;
126
// read shadowCache configuration
127
changed |= shadowCache().readConfig( config );
131
KConfigGroup group( config.group("Common") );
132
helper().setBackgroundPixmap( group.readEntry( "BackgroundPixmap", "" ) );
139
//_________________________________________________________________
140
bool Factory::supports( Ability ability ) const
146
case AbilityAnnounceButtons:
147
case AbilityAnnounceColors:
150
case AbilityButtonMenu:
151
case AbilityButtonHelp:
152
case AbilityButtonMinimize:
153
case AbilityButtonMaximize:
154
case AbilityButtonClose:
155
case AbilityButtonOnAllDesktops:
156
case AbilityButtonAboveOthers:
157
case AbilityButtonBelowOthers:
158
case AbilityButtonSpacer:
159
case AbilityButtonShade:
162
// case AbilityColorTitleBack:
163
// case AbilityColorTitleFore:
164
// case AbilityColorFrame:
167
case AbilityProvidesShadow: // TODO: UI option to use default shadows instead
170
case AbilityUsesAlphaChannel:
174
case AbilityClientGrouping:
175
return defaultConfiguration().tabsEnabled();
177
// no colors supported at this time
185
//____________________________________________________________________
186
Configuration Factory::configuration( const Client& client )
189
QString window_title;
191
for( ExceptionList::const_iterator iter = _exceptions.constBegin(); iter != _exceptions.constEnd(); ++iter )
194
// discard disabled exceptions
195
if( !iter->enabled() ) continue;
198
decide which value is to be compared
199
to the regular expression, based on exception type
202
switch( iter->type() )
204
case Exception::WindowTitle:
206
value = window_title.isEmpty() ? (window_title = client.caption()):window_title;
210
case Exception::WindowClassName:
212
if( class_name.isEmpty() )
214
// retrieve class name
215
KWindowInfo info( client.windowId(), 0, NET::WM2WindowClass );
216
QString window_class_name( info.windowClassName() );
217
QString window_class( info.windowClassClass() );
218
class_name = window_class_name + ' ' + window_class;
225
default: assert( false );
229
if( iter->regExp().indexIn( value ) < 0 ) continue;
231
Configuration configuration( defaultConfiguration() );
232
configuration.readException( *iter );
233
return configuration;
237
return defaultConfiguration();