~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kwin/clients/oxygen/oxygenfactory.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//////////////////////////////////////////////////////////////////////////////
 
2
// oxygen.cpp
 
3
// -------------------
 
4
//
 
5
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
 
6
// Copyright (c) 2006, 2007 Riccardo Iaconelli <riccardo@kde.org>
 
7
//
 
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:
 
14
//
 
15
// The above copyright notice and this permission notice shall be included in
 
16
// all copies or substantial portions of the Software.
 
17
//
 
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
 
24
// IN THE SOFTWARE.
 
25
//////////////////////////////////////////////////////////////////////////////
 
26
 
 
27
#include "oxygenfactory.h"
 
28
#include "oxygenfactory.moc"
 
29
#include "oxygenclient.h"
 
30
 
 
31
#include <cassert>
 
32
#include <KConfigGroup>
 
33
#include <KDebug>
 
34
#include <KGlobal>
 
35
#include <KWindowInfo>
 
36
#include <kdeversion.h>
 
37
 
 
38
extern "C"
 
39
{
 
40
    KDE_EXPORT KDecorationFactory* create_factory()
 
41
    { return new Oxygen::Factory(); }
 
42
}
 
43
 
 
44
namespace Oxygen
 
45
{
 
46
 
 
47
    //___________________________________________________
 
48
    Factory::Factory():
 
49
        _initialized( false ),
 
50
        _helper( "oxygenDeco" ),
 
51
        _shadowCache( _helper )
 
52
    {
 
53
        readConfig();
 
54
        setInitialized( true );
 
55
    }
 
56
 
 
57
    //___________________________________________________
 
58
    Factory::~Factory()
 
59
    { setInitialized( false ); }
 
60
 
 
61
    //___________________________________________________
 
62
    KDecoration* Factory::createDecoration(KDecorationBridge* bridge )
 
63
    { return (new Client( bridge, this ))->decoration(); }
 
64
 
 
65
    //___________________________________________________
 
66
    bool Factory::reset(unsigned long changed)
 
67
    {
 
68
 
 
69
        if( changed & SettingColors )
 
70
        { shadowCache().invalidateCaches(); }
 
71
 
 
72
        // read in the configuration
 
73
        setInitialized( false );
 
74
        bool _configurationchanged = readConfig();
 
75
        setInitialized( true );
 
76
 
 
77
        if( _configurationchanged || (changed & (SettingDecoration | SettingButtons | SettingBorder)) )
 
78
        {
 
79
 
 
80
            // returning true triggers all decorations to be re-created
 
81
            return true;
 
82
 
 
83
        } else {
 
84
 
 
85
            // no need to re-create the decorations
 
86
            // trigger repaint only
 
87
            resetDecorations(changed);
 
88
            return false;
 
89
 
 
90
        }
 
91
 
 
92
    }
 
93
 
 
94
    //___________________________________________________
 
95
    bool Factory::readConfig()
 
96
    {
 
97
 
 
98
        bool changed( false );
 
99
 
 
100
        /*
 
101
        always reload helper
 
102
        this is needed to properly handle
 
103
        color contrast settings changed
 
104
        */
 
105
        helper().invalidateCaches();
 
106
        helper().reloadConfig();
 
107
 
 
108
        // create a config object
 
109
        KConfig config("oxygenrc");
 
110
        KConfigGroup group( config.group("Windeco") );
 
111
        Configuration configuration( group );
 
112
        if( !( configuration == defaultConfiguration() ) )
 
113
        {
 
114
            setDefaultConfiguration( configuration );
 
115
            changed = true;
 
116
        }
 
117
 
 
118
        // read exceptionsreadConfig
 
119
        ExceptionList exceptions( config );
 
120
        if( !( exceptions == _exceptions ) )
 
121
        {
 
122
            _exceptions = exceptions;
 
123
            changed = true;
 
124
        }
 
125
 
 
126
        // read shadowCache configuration
 
127
        changed |= shadowCache().readConfig( config );
 
128
 
 
129
        // background pixmap
 
130
        {
 
131
            KConfigGroup group( config.group("Common") );
 
132
            helper().setBackgroundPixmap( group.readEntry( "BackgroundPixmap", "" ) );
 
133
        }
 
134
 
 
135
        return changed;
 
136
 
 
137
    }
 
138
 
 
139
    //_________________________________________________________________
 
140
    bool Factory::supports( Ability ability ) const
 
141
    {
 
142
        switch( ability )
 
143
        {
 
144
 
 
145
            // announce
 
146
            case AbilityAnnounceButtons:
 
147
            case AbilityAnnounceColors:
 
148
 
 
149
            // buttons
 
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:
 
160
 
 
161
            //       // colors
 
162
            //       case AbilityColorTitleBack:
 
163
            //       case AbilityColorTitleFore:
 
164
            //       case AbilityColorFrame:
 
165
 
 
166
            // compositing
 
167
            case AbilityProvidesShadow: // TODO: UI option to use default shadows instead
 
168
            return true;
 
169
 
 
170
            case AbilityUsesAlphaChannel:
 
171
            return true;
 
172
 
 
173
            // tabs
 
174
            case AbilityClientGrouping:
 
175
            return defaultConfiguration().tabsEnabled();
 
176
 
 
177
            // no colors supported at this time
 
178
            default:
 
179
            return false;
 
180
        };
 
181
    }
 
182
 
 
183
 
 
184
 
 
185
    //____________________________________________________________________
 
186
    Configuration Factory::configuration( const Client& client )
 
187
    {
 
188
 
 
189
        QString window_title;
 
190
        QString class_name;
 
191
        for( ExceptionList::const_iterator iter = _exceptions.constBegin(); iter != _exceptions.constEnd(); ++iter )
 
192
        {
 
193
 
 
194
            // discard disabled exceptions
 
195
            if( !iter->enabled() ) continue;
 
196
 
 
197
            /*
 
198
            decide which value is to be compared
 
199
            to the regular expression, based on exception type
 
200
            */
 
201
            QString value;
 
202
            switch( iter->type() )
 
203
            {
 
204
                case Exception::WindowTitle:
 
205
                {
 
206
                    value = window_title.isEmpty() ? (window_title = client.caption()):window_title;
 
207
                    break;
 
208
                }
 
209
 
 
210
                case Exception::WindowClassName:
 
211
                {
 
212
                    if( class_name.isEmpty() )
 
213
                    {
 
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;
 
219
                    }
 
220
 
 
221
                    value = class_name;
 
222
                    break;
 
223
                }
 
224
 
 
225
                default: assert( false );
 
226
 
 
227
            }
 
228
 
 
229
            if( iter->regExp().indexIn( value ) < 0 ) continue;
 
230
 
 
231
            Configuration configuration( defaultConfiguration() );
 
232
            configuration.readException( *iter );
 
233
            return configuration;
 
234
 
 
235
        }
 
236
 
 
237
        return defaultConfiguration();
 
238
 
 
239
    }
 
240
 
 
241
} //namespace Oxygen