00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include <netwm_def.h>
00014 #include <kconfig.h>
00015 #include <kinstance.h>
00016 #include <dcopclient.h>
00017
00018 struct SessionInfo
00019 {
00020 QCString sessionId;
00021 QCString windowRole;
00022 QCString wmCommand;
00023 QCString wmClientMachine;
00024 QCString resourceName;
00025 QCString resourceClass;
00026
00027 QRect geometry;
00028 QRect restore;
00029 QRect fsrestore;
00030 int maximized;
00031 int fullscreen;
00032 int desktop;
00033 bool minimized;
00034 bool onAllDesktops;
00035 bool shaded;
00036 bool keepAbove;
00037 bool keepBelow;
00038 bool skipTaskbar;
00039 bool skipPager;
00040 bool userNoBorder;
00041 NET::WindowType windowType;
00042 bool active;
00043 bool fake;
00044 };
00045
00046 QPtrList<SessionInfo> fakeSession;
00047
00048 static const char* const window_type_names[] =
00049 {
00050 "Unknown", "Normal" , "Desktop", "Dock", "Toolbar", "Menu", "Dialog",
00051 "Override", "TopMenu", "Utility", "Splash"
00052 };
00053
00054
00055 NET::WindowType txtToWindowType( const char* txt )
00056 {
00057 for( int i = NET::Unknown;
00058 i <= NET::Splash;
00059 ++i )
00060 if( qstrcmp( txt, window_type_names[ i + 1 ] ) == 0 )
00061 return static_cast< NET::WindowType >( i );
00062 return static_cast< NET::WindowType >( -2 );
00063 }
00064
00065 void loadFakeSessionInfo( KConfig* config )
00066 {
00067 fakeSession.clear();
00068 config->setGroup("FakeSession" );
00069 int count = config->readNumEntry( "count" );
00070 for ( int i = 1; i <= count; i++ )
00071 {
00072 QString n = QString::number(i);
00073 SessionInfo* info = new SessionInfo;
00074 fakeSession.append( info );
00075 info->windowRole = config->readEntry( QString("windowRole")+n ).latin1();
00076 info->resourceName = config->readEntry( QString("resourceName")+n ).latin1();
00077 info->resourceClass = config->readEntry( QString("resourceClass")+n ).lower().latin1();
00078 info->wmClientMachine = config->readEntry( QString("clientMachine")+n ).latin1();
00079 info->geometry = config->readRectEntry( QString("geometry")+n );
00080 info->restore = config->readRectEntry( QString("restore")+n );
00081 info->fsrestore = config->readRectEntry( QString("fsrestore")+n );
00082 info->maximized = config->readNumEntry( QString("maximize")+n, 0 );
00083 info->fullscreen = config->readNumEntry( QString("fullscreen")+n, 0 );
00084 info->desktop = config->readNumEntry( QString("desktop")+n, 0 );
00085 info->minimized = config->readBoolEntry( QString("iconified")+n, FALSE );
00086 info->onAllDesktops = config->readBoolEntry( QString("sticky")+n, FALSE );
00087 info->shaded = config->readBoolEntry( QString("shaded")+n, FALSE );
00088 info->keepAbove = config->readBoolEntry( QString("staysOnTop")+n, FALSE );
00089 info->keepBelow = config->readBoolEntry( QString("keepBelow")+n, FALSE );
00090 info->skipTaskbar = config->readBoolEntry( QString("skipTaskbar")+n, FALSE );
00091 info->skipPager = config->readBoolEntry( QString("skipPager")+n, FALSE );
00092 info->userNoBorder = config->readBoolEntry( QString("userNoBorder")+n, FALSE );
00093 info->windowType = txtToWindowType( config->readEntry( QString("windowType")+n ).latin1());
00094 info->active = false;
00095 info->fake = true;
00096 }
00097 config->deleteGroup( "FakeSession" );
00098 }
00099
00100 void writeRules( KConfig& cfg )
00101 {
00102 cfg.setGroup( "General" );
00103 int pos = cfg.readNumEntry( "count" );
00104 for ( SessionInfo* info = fakeSession.first(); info; info = fakeSession.next() )
00105 {
00106 if( info->resourceName.isEmpty() && info->resourceClass.isEmpty())
00107 continue;
00108 ++pos;
00109 cfg.setGroup( QString::number( pos ));
00110 cfg.writeEntry( "description", ( const char* ) ( info->resourceClass + " (KDE3.2)" ));
00111 cfg.writeEntry( "wmclass", ( const char* )( info->resourceName + ' ' + info->resourceClass ));
00112 cfg.writeEntry( "wmclasscomplete", true );
00113 cfg.writeEntry( "wmclassmatch", 1 );
00114 if( !info->windowRole.isEmpty())
00115 {
00116 cfg.writeEntry( "windowrole", ( const char* ) info->windowRole );
00117 cfg.writeEntry( "windowrolematch", 1 );
00118 }
00119 if( info->windowType == static_cast< NET::WindowType >( -2 ))
00120 ;
00121 if( info->windowType == NET::Unknown )
00122 cfg.writeEntry( "types", NET::NormalMask );
00123 else
00124 cfg.writeEntry( "types", 1 << info->windowType );
00125 cfg.writeEntry( "position", info->geometry.topLeft());
00126 cfg.writeEntry( "positionrule", 4 );
00127 cfg.writeEntry( "size", info->geometry.size());
00128 cfg.writeEntry( "sizerule", 4 );
00129 cfg.writeEntry( "maximizevert", info->maximized & NET::MaxVert );
00130 cfg.writeEntry( "maximizevertrule", 4 );
00131 cfg.writeEntry( "maximizehoriz", info->maximized & NET::MaxHoriz );
00132 cfg.writeEntry( "maximizehorizrule", 4 );
00133 cfg.writeEntry( "fullscreen", info->fullscreen );
00134 cfg.writeEntry( "fullscreenrule", 4 );
00135 cfg.writeEntry( "desktop", info->desktop );
00136 cfg.writeEntry( "desktoprule", 4 );
00137 cfg.writeEntry( "minimize", info->minimized );
00138 cfg.writeEntry( "minimizerule", 4 );
00139 cfg.writeEntry( "shade", info->shaded );
00140 cfg.writeEntry( "shaderule", 4 );
00141 cfg.writeEntry( "above", info->keepAbove );
00142 cfg.writeEntry( "aboverule", 4 );
00143 cfg.writeEntry( "below", info->keepBelow );
00144 cfg.writeEntry( "belowrule", 4 );
00145 cfg.writeEntry( "skiptaskbar", info->skipTaskbar );
00146 cfg.writeEntry( "skiptaskbarrule", 4 );
00147 cfg.writeEntry( "skippager", info->skipPager );
00148 cfg.writeEntry( "skippagerrule", 4 );
00149 cfg.writeEntry( "noborder", info->userNoBorder );
00150 cfg.writeEntry( "noborderrule", 4 );
00151 }
00152 cfg.setGroup( "General" );
00153 cfg.writeEntry( "count", pos );
00154 }
00155
00156 int main()
00157 {
00158 KInstance inst( "kwin_update_window_settings" );
00159 KConfig src_cfg( "kwinrc" );
00160 KConfig dest_cfg( "kwinrulesrc" );
00161 loadFakeSessionInfo( &src_cfg );
00162 writeRules( dest_cfg );
00163 src_cfg.sync();
00164 dest_cfg.sync();
00165 DCOPClient client;
00166 client.attach();
00167 client.send("kwin*", "", "reconfigure()", "");
00168 }