1
/********************************************************************
2
KWin - the KDE window manager
3
This file is part of the KDE project.
5
Copyright (C) 2004 Lubos Lunak <l.lunak@kde.org>
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program. If not, see <http://www.gnu.org/licenses/>.
19
*********************************************************************/
21
// updates per-window settings from KDE3.2 to KDE3.3
23
#include <netwm_def.h>
25
#include <kconfiggroup.h>
26
#include <kcomponentdata.h>
30
#include <QtDBus/QtDBus>
34
QByteArray windowRole;
36
QByteArray wmClientMachine;
37
QByteArray resourceName;
38
QByteArray resourceClass;
54
bool active; // means 'was active in the saved session', not used otherwise
55
bool fake; // fake session, i.e. 'save window settings', not SM restored
56
NET::WindowType windowType;
59
QList<SessionInfo*> fakeSession;
61
static const char* const window_type_names[] =
63
"Unknown", "Normal" , "Desktop", "Dock", "Toolbar", "Menu", "Dialog",
64
"Override", "TopMenu", "Utility", "Splash"
66
// change also the two functions below when adding new entries
68
NET::WindowType txtToWindowType( const char* txt )
70
for( int i = NET::Unknown;
73
if( qstrcmp( txt, window_type_names[ i + 1 ] ) == 0 ) // +1
74
return static_cast< NET::WindowType >( i );
75
return static_cast< NET::WindowType >( -2 ); // undefined
78
void loadFakeSessionInfo( KConfig* config )
81
KConfigGroup fakeGroup(config, "FakeSession");
82
int count = fakeGroup.readEntry( "count",0 );
83
for ( int i = 1; i <= count; i++ )
85
QString n = QString::number(i);
86
SessionInfo* info = new SessionInfo;
87
fakeSession.append( info );
88
info->windowRole = fakeGroup.readEntry( QString("windowRole")+n, QString() ).toLatin1();
89
info->resourceName = fakeGroup.readEntry( QString("resourceName")+n, QString() ).toLatin1();
90
info->resourceClass = fakeGroup.readEntry( QString("resourceClass")+n, QString() ).toLower().toLatin1();
91
info->wmClientMachine = fakeGroup.readEntry( QString("clientMachine")+n, QString() ).toLatin1();
92
info->geometry = fakeGroup.readEntry( QString("geometry")+n, QRect() );
93
info->restore = fakeGroup.readEntry( QString("restore")+n, QRect() );
94
info->fsrestore = fakeGroup.readEntry( QString("fsrestore")+n, QRect() );
95
info->maximized = fakeGroup.readEntry( QString("maximize")+n, 0 );
96
info->fullscreen = fakeGroup.readEntry( QString("fullscreen")+n, 0 );
97
info->desktop = fakeGroup.readEntry( QString("desktop")+n, 0 );
98
info->minimized = fakeGroup.readEntry( QString("iconified")+n, false );
99
info->onAllDesktops = fakeGroup.readEntry( QString("sticky")+n, false );
100
info->shaded = fakeGroup.readEntry( QString("shaded")+n, false );
101
info->keepAbove = fakeGroup.readEntry( QString("staysOnTop")+n, false );
102
info->keepBelow = fakeGroup.readEntry( QString("keepBelow")+n, false );
103
info->skipTaskbar = fakeGroup.readEntry( QString("skipTaskbar")+n, false );
104
info->skipPager = fakeGroup.readEntry( QString("skipPager")+n, false );
105
info->userNoBorder = fakeGroup.readEntry( QString("userNoBorder")+n, false );
106
info->windowType = txtToWindowType( fakeGroup.readEntry( QString("windowType")+n, QString() ).toLatin1());
107
info->active = false;
110
config->deleteGroup( "FakeSession" );
113
void writeRules( KConfig& cfg )
115
KConfigGroup cg(&cfg, "General");
116
int pos = cg.readEntry( "count",0 );
118
QList<SessionInfo*>::iterator it;
119
for ( it = fakeSession.begin(); it != fakeSession.end(); ++it)
121
if( (*it)->resourceName.isEmpty() && (*it)->resourceClass.isEmpty())
124
KConfigGroup groupCfg(&cfg, QString::number( pos ));
125
groupCfg.writeEntry( "description", ( const char* ) ( (*it)->resourceClass + " (KDE3.2)" ));
126
groupCfg.writeEntry( "wmclass", ( const char* )( (*it)->resourceName + ' ' + (*it)->resourceClass ));
127
groupCfg.writeEntry( "wmclasscomplete", true );
128
groupCfg.writeEntry( "wmclassmatch", 1 ); // 1 == exact match
129
if( !(*it)->windowRole.isEmpty())
131
groupCfg.writeEntry( "windowrole", ( const char* ) (*it)->windowRole );
132
groupCfg.writeEntry( "windowrolematch", 1 );
134
if( (*it)->windowType == static_cast< NET::WindowType >( -2 )) // undefined
136
if( (*it)->windowType == NET::Unknown )
137
groupCfg.writeEntry( "types", (int)NET::NormalMask );
139
groupCfg.writeEntry( "types", 1 << (*it)->windowType );
140
groupCfg.writeEntry( "position", (*it)->geometry.topLeft());
141
groupCfg.writeEntry( "positionrule", 4 ); // 4 == remember
142
groupCfg.writeEntry( "size", (*it)->geometry.size());
143
groupCfg.writeEntry( "sizerule", 4 );
144
groupCfg.writeEntry( "maximizevert", (*it)->maximized & NET::MaxVert );
145
groupCfg.writeEntry( "maximizevertrule", 4 );
146
groupCfg.writeEntry( "maximizehoriz", (*it)->maximized & NET::MaxHoriz );
147
groupCfg.writeEntry( "maximizehorizrule", 4 );
148
groupCfg.writeEntry( "fullscreen", (*it)->fullscreen );
149
groupCfg.writeEntry( "fullscreenrule", 4 );
150
groupCfg.writeEntry( "desktop", (*it)->desktop );
151
groupCfg.writeEntry( "desktoprule", 4 );
152
groupCfg.writeEntry( "minimize", (*it)->minimized );
153
groupCfg.writeEntry( "minimizerule", 4 );
154
groupCfg.writeEntry( "shade", (*it)->shaded );
155
groupCfg.writeEntry( "shaderule", 4 );
156
groupCfg.writeEntry( "above", (*it)->keepAbove );
157
groupCfg.writeEntry( "aboverule", 4 );
158
groupCfg.writeEntry( "below", (*it)->keepBelow );
159
groupCfg.writeEntry( "belowrule", 4 );
160
groupCfg.writeEntry( "skiptaskbar", (*it)->skipTaskbar );
161
groupCfg.writeEntry( "skiptaskbarrule", 4 );
162
groupCfg.writeEntry( "skippager", (*it)->skipPager );
163
groupCfg.writeEntry( "skippagerrule", 4 );
164
groupCfg.writeEntry( "noborder", (*it)->userNoBorder );
165
groupCfg.writeEntry( "noborderrule", 4 );
167
cg.writeEntry( "count", pos );
172
KComponentData inst( "kwin_update_window_settings" );
173
KConfig src_cfg( "kwinrc" );
174
KConfig dest_cfg( "kwinrulesrc" );
175
loadFakeSessionInfo( &src_cfg );
176
writeRules( dest_cfg );
179
// Send signal to all kwin instances
180
QDBusMessage message =
181
QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig");
182
QDBusConnection::sessionBus().send(message);