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
|
/*
Copyright (C) 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
Copyright (C) 2002,2004 Oswald Buddenhagen <ossi@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include <tdecmdlineargs.h>
#include <ksimpleconfig.h>
#include <tdelocale.h>
#include <tqfile.h>
#include "krootimage.h"
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <stdlib.h>
static const char description[] =
I18N_NOOP( "Fancy desktop background for tdm" );
static const char version[] = "v2.0";
static TDECmdLineOptions options[] = {
{ "+config", I18N_NOOP( "Name of the configuration file" ), 0 },
TDECmdLineLastOption
};
static Atom prop_root;
static bool properties_inited = false;
MyApplication::MyApplication( const char *conf )
: TDEApplication(),
renderer( 0, new KSimpleConfig( TQFile::decodeName( conf ) ) )
{
connect( &timer, TQ_SIGNAL(timeout()), TQ_SLOT(slotTimeout()) );
connect( &renderer, TQ_SIGNAL(imageDone( int )), this, TQ_SLOT(renderDone()) );
renderer.enableTiling( true ); // optimize
renderer.changeWallpaper(); // cannot do it when we're killed, so do it now
timer.start( 60000 );
renderer.start();
if( !properties_inited ) {
prop_root = XInternAtom(tqt_xdisplay(), "_XROOTPMAP_ID", False);
properties_inited = true;
}
}
void
MyApplication::renderDone()
{
// Get the newly drawn pixmap...
TQPixmap pm = renderer.pixmap();
// ...set it to the desktop widget...
desktop()->setBackgroundPixmap( pm );
desktop()->repaint( true );
// ...and export it via Esetroot-style so that composition managers can use it!
Pixmap bgPm = pm.handle(); // fetch the actual X handle to it
XChangeProperty(tqt_xdisplay(), tqt_xrootwin(), prop_root, XA_PIXMAP, 32, PropModeReplace, (unsigned char *) &bgPm, 1);
renderer.saveCacheFile();
renderer.cleanup();
for (unsigned i=0; i<renderer.numRenderers(); ++i)
{
KBackgroundRenderer * r = renderer.renderer(i);
if (r->backgroundMode() == KBackgroundSettings::Program ||
(r->multiWallpaperMode() != KBackgroundSettings::NoMulti &&
r->multiWallpaperMode() != KBackgroundSettings::NoMultiRandom)) {
return;
}
}
}
void
MyApplication::slotTimeout()
{
bool change = false;
if (renderer.needProgramUpdate()) {
renderer.programUpdate();
change = true;
}
if (renderer.needWallpaperChange()) {
renderer.changeWallpaper();
change = true;
}
if (change)
renderer.start();
}
int
main( int argc, char *argv[] )
{
TDEApplication::disableAutoDcopRegistration();
TDELocale::setMainCatalogue( "kdesktop" );
TDECmdLineArgs::init( argc, argv, "krootimage", I18N_NOOP( "KRootImage" ), description, version );
TDECmdLineArgs::addCmdLineOptions( options );
TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
if (!args->count())
args->usage();
MyApplication app( args->arg( 0 ) );
args->clear();
app.exec();
app.flushX();
// Keep color resources after termination
XSetCloseDownMode( tqt_xdisplay(), RetainTemporary );
return 0;
}
#include "krootimage.moc"
|