summaryrefslogtreecommitdiffstats
path: root/twin/lib/kdecoration_p.cpp
blob: 3561d63e04703bc0087a17d02099d0540a1c807b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*****************************************************************
This file is part of the KDE project.

Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>

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 IN THE SOFTWARE.
******************************************************************/

#include "kdecoration_p.h"

#include <kconfig.h>
#include <kglobalsettings.h>
#include <palette.h>
#include <tqapplication.h>
#include <assert.h>

KDecorationOptionsPrivate::KDecorationOptionsPrivate()
    {
    for(int i=0; i < NUM_COLORS*2; ++i)
        cg[i] = NULL;
    }

KDecorationOptionsPrivate::~KDecorationOptionsPrivate()
    {
    int i;
    for(i=0; i < NUM_COLORS*2; ++i)
        {
        if(cg[i])
            {
            delete cg[i];
            cg[i] = NULL;
            }
        }
    }

void KDecorationOptionsPrivate::defaultKWinSettings()
    {
    title_buttons_left = "MS";
    title_buttons_right = "HIAX";
    custom_button_positions = false;
    show_tooltips = true;
    border_size = BorderNormal;
    cached_border_size = BordersCount; // invalid
    move_resize_maximized_windows = true;
    OpMaxButtonRightClick = MaximizeOp;
    OpMaxButtonMiddleClick = VMaximizeOp;
    OpMaxButtonLeftClick = HMaximizeOp;
    }

unsigned long KDecorationOptionsPrivate::updateKWinSettings( KConfig* config )
    {
    unsigned long changed = 0;
    TQString old_group = config->group();
    config->setGroup( "WM" );

// SettingColors
    TQColor old_colors[NUM_COLORS*2];
    for( int i = 0;
         i < NUM_COLORS*2;
         ++i )
        old_colors[ i ] = colors[ i ];
        
    TQPalette pal = TQApplication::palette();
    // normal colors
    colors[ColorFrame] = pal.active().background();
    colors[ColorFrame] = config->readColorEntry("frame", &colors[ColorFrame]);
    colors[ColorHandle] = colors[ColorFrame];
    colors[ColorHandle] = config->readColorEntry("handle", &colors[ColorHandle]);

    // full button configuration (background, blend, and foreground
    if(TQPixmap::defaultDepth() > 8)
        colors[ColorButtonBg] = colors[ColorFrame].light(130);
    else
        colors[ColorButtonBg] = colors[ColorFrame];
    colors[ColorButtonBg] = config->readColorEntry("activeTitleBtnBg",
                                              &colors[ColorFrame]);
    colors[ColorTitleBar] = pal.active().highlight();
    colors[ColorTitleBar] = config->readColorEntry("activeBackground",
                                              &colors[ColorTitleBar]);
    if(TQPixmap::defaultDepth() > 8)
        colors[ColorTitleBlend] = colors[ ColorTitleBar ].dark(110);
    else
        colors[ColorTitleBlend] = colors[ ColorTitleBar ];
    colors[ColorTitleBlend] = config->readColorEntry("activeBlend",
                                                &colors[ColorTitleBlend]);

    colors[ColorFont] = pal.active().highlightedText();
    colors[ColorFont] = config->readColorEntry("activeForeground", &colors[ColorFont]);

    // inactive
    colors[ColorFrame+NUM_COLORS] = config->readColorEntry("inactiveFrame",
                                                      &colors[ColorFrame]);
    colors[ColorTitleBar+NUM_COLORS] = colors[ColorFrame];
    colors[ColorTitleBar+NUM_COLORS] = config->
        readColorEntry("inactiveBackground", &colors[ColorTitleBar+NUM_COLORS]);

    if(TQPixmap::defaultDepth() > 8)
        colors[ColorTitleBlend+NUM_COLORS] = colors[ ColorTitleBar+NUM_COLORS ].dark(110);
    else
        colors[ColorTitleBlend+NUM_COLORS] = colors[ ColorTitleBar+NUM_COLORS ];
    colors[ColorTitleBlend+NUM_COLORS] =
        config->readColorEntry("inactiveBlend", &colors[ColorTitleBlend+NUM_COLORS]);

    // full button configuration
    if(TQPixmap::defaultDepth() > 8)
        colors[ColorButtonBg+NUM_COLORS] = colors[ColorFrame+NUM_COLORS].light(130);
    else
        colors[ColorButtonBg+NUM_COLORS] = colors[ColorFrame+NUM_COLORS];
    colors[ColorButtonBg+NUM_COLORS] =
        config->readColorEntry("inactiveTitleBtnBg",
                               &colors[ColorButtonBg]);

    colors[ColorHandle+NUM_COLORS] =
        config->readColorEntry("inactiveHandle", &colors[ColorHandle]);

    colors[ColorFont+NUM_COLORS] = colors[ColorFrame].dark();
    colors[ColorFont+NUM_COLORS] = config->readColorEntry("inactiveForeground",
                                                     &colors[ColorFont+NUM_COLORS]);

    for( int i = 0;
         i < NUM_COLORS*2;
         ++i )
        if( old_colors[ i ] != colors[ i ] )
            changed |= SettingColors;

// SettingFont
    TQFont old_activeFont = activeFont;
    TQFont old_inactiveFont = inactiveFont;
    TQFont old_activeFontSmall = activeFontSmall;
    TQFont old_inactiveFontSmall = inactiveFontSmall;

    TQFont activeFontGuess = KGlobalSettings::windowTitleFont();

    activeFont = config->readFontEntry("activeFont", &activeFontGuess);
    inactiveFont = config->readFontEntry("inactiveFont", &activeFont);

    activeFontSmall = activeFont;
    activeFontSmall.setPointSize(activeFont.pointSize() - 2);
    activeFontSmall = config->readFontEntry("activeFontSmall", &activeFontSmall);
    inactiveFontSmall = config->readFontEntry("inactiveFontSmall", &activeFontSmall);

    if( old_activeFont != activeFont
        || old_inactiveFont != inactiveFont
        || old_activeFontSmall != activeFontSmall
        || old_inactiveFontSmall != inactiveFontSmall )
        changed |= SettingFont;

    config->setGroup( "Style" );
// SettingsButtons        
    TQString old_title_buttons_left = title_buttons_left;
    TQString old_title_buttons_right = title_buttons_right;
    bool old_custom_button_positions = custom_button_positions;
    custom_button_positions = config->readBoolEntry("CustomButtonPositions", false);
    if (custom_button_positions)
        {
        title_buttons_left  = config->readEntry("ButtonsOnLeft", "MS");
        title_buttons_right = config->readEntry("ButtonsOnRight", "HIAX");
        }
    else
        {
        title_buttons_left  = "MS";
        title_buttons_right = "HIAX";
        }
    if( old_custom_button_positions != custom_button_positions
        || ( custom_button_positions &&
                ( old_title_buttons_left != title_buttons_left
                || old_title_buttons_right != title_buttons_right )))
        changed |= SettingButtons;

// SettingTooltips
    bool old_show_tooltips = show_tooltips;
    show_tooltips = config->readBoolEntry("ShowToolTips", true);
    if( old_show_tooltips != show_tooltips )
        changed |= SettingTooltips;

// SettingBorder

    BorderSize old_border_size = border_size;
    int border_size_num = config->readNumEntry( "BorderSize", BorderNormal );
    if( border_size_num >= 0 && border_size_num < BordersCount )
        border_size = static_cast< BorderSize >( border_size_num );
    else
        border_size = BorderNormal;
    if( old_border_size != border_size )
        changed |= SettingBorder;
    cached_border_size = BordersCount; // invalid

    config->setGroup( "Windows" );
    bool old_move_resize_maximized_windows = move_resize_maximized_windows;
    move_resize_maximized_windows = config->readBoolEntry( "MoveResizeMaximizedWindows", false );
    if( old_move_resize_maximized_windows != move_resize_maximized_windows )
        changed |= SettingBorder;

// destroy cached values
    int i;
    for(i=0; i < NUM_COLORS*2; ++i)
        {
        if(cg[i])
            {
            delete cg[i];
            cg[i] = NULL;
            }
        }

    config->setGroup( old_group );

    return changed;
    }

KDecorationDefines::BorderSize KDecorationOptionsPrivate::findPreferredBorderSize( BorderSize size,
    TQValueList< BorderSize > sizes ) const
    {
    for( TQValueList< BorderSize >::ConstIterator it = sizes.begin();
         it != sizes.end();
         ++it )
        if( size <= *it ) // size is either a supported size, or *it is the closest larger supported
            return *it;
    return sizes.last(); // size is larger than all supported ones, return largest
    }