diff options
author | Timothy Pearson <[email protected]> | 2012-01-22 01:02:36 -0600 |
---|---|---|
committer | Timothy Pearson <[email protected]> | 2012-01-22 01:02:36 -0600 |
commit | b81e43465b14836b17e4fe2dea91c78a2bdd29b3 (patch) | |
tree | 7815d61ce59a6ccb6e655ed44f5fea786f520985 /tdm/kfrontend/krootimage.cpp | |
parent | 7021f40c13f949b7cb5ded32d0241d648a43bf6c (diff) | |
download | tdebase-b81e43465b14836b17e4fe2dea91c78a2bdd29b3.tar.gz tdebase-b81e43465b14836b17e4fe2dea91c78a2bdd29b3.zip |
Part 2 of prior commit
Diffstat (limited to 'tdm/kfrontend/krootimage.cpp')
-rw-r--r-- | tdm/kfrontend/krootimage.cpp | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/tdm/kfrontend/krootimage.cpp b/tdm/kfrontend/krootimage.cpp new file mode 100644 index 000000000..b51367485 --- /dev/null +++ b/tdm/kfrontend/krootimage.cpp @@ -0,0 +1,140 @@ +/* + +Copyright (C) 1999 Matthias Hoelzer-Kluepfel <[email protected]> +Copyright (C) 2002,2004 Oswald Buddenhagen <[email protected]> + +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 <kcmdlineargs.h> +#include <ksimpleconfig.h> +#include <klocale.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 KCmdLineOptions options[] = { + { "+config", I18N_NOOP( "Name of the configuration file" ), 0 }, + KCmdLineLastOption +}; + +static Atom prop_root; +static bool properties_inited = false; + +MyApplication::MyApplication( const char *conf ) + : KApplication(), + renderer( 0, new KSimpleConfig( TQFile::decodeName( conf ) ) ) +{ + connect( &timer, TQT_SIGNAL(timeout()), TQT_SLOT(slotTimeout()) ); + connect( &renderer, TQT_SIGNAL(imageDone( int )), this, TQT_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(qt_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... + TQT_TQWIDGET(desktop())->setBackgroundPixmap( pm ); + TQT_TQWIDGET(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(qt_xdisplay(), qt_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[] ) +{ + KApplication::disableAutoDcopRegistration(); + + KLocale::setMainCatalogue( "kdesktop" ); + KCmdLineArgs::init( argc, argv, "krootimage", I18N_NOOP( "KRootImage" ), description, version ); + KCmdLineArgs::addCmdLineOptions( options ); + + KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); + if (!args->count()) + args->usage(); + MyApplication app( args->arg( 0 ) ); + args->clear(); + + app.exec(); + + app.flushX(); + + // Keep color resources after termination + XSetCloseDownMode( qt_xdisplay(), RetainTemporary ); + + return 0; +} + +#include "krootimage.moc" |