You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
259 lines
6.3 KiB
259 lines
6.3 KiB
4 years ago
|
/*
|
||
15 years ago
|
*
|
||
|
* $Id: krootpixmap.cpp,v 1.20 2003/06/01 01:49:31 hadacek Exp $
|
||
|
*
|
||
13 years ago
|
* This file is part of the KDE project, module tdeui.
|
||
15 years ago
|
* Copyright (C) 1999,2000 Geert Jansen <jansen@kde.org>
|
||
|
*
|
||
|
* You can Freely distribute this program under the GNU Library
|
||
|
* General Public License. See the file "COPYING.LIB" for the exact
|
||
|
* licensing terms.
|
||
|
*/
|
||
|
|
||
|
/* Modified by Sascha Hlusiak */
|
||
10 years ago
|
/* Further modified 11/18/2014 by Timothy Pearson <kb9vqf@pearsoncomputing.net> */
|
||
15 years ago
|
|
||
14 years ago
|
#include <tqwidget.h>
|
||
|
#include <tqtimer.h>
|
||
|
#include <tqrect.h>
|
||
|
#include <tqimage.h>
|
||
15 years ago
|
|
||
14 years ago
|
#ifndef TQ_WS_TQWS //FIXME
|
||
12 years ago
|
#include <tdeapplication.h>
|
||
15 years ago
|
#include <kimageeffect.h>
|
||
|
#include <kpixmapio.h>
|
||
10 years ago
|
#include <netwm.h>
|
||
10 years ago
|
#include <twin.h>
|
||
15 years ago
|
#include <kdebug.h>
|
||
|
#include <netwm.h>
|
||
|
#include <dcopclient.h>
|
||
10 years ago
|
#include <dcopref.h>
|
||
14 years ago
|
#include <tqpainter.h>
|
||
15 years ago
|
|
||
|
#include <ksharedpixmap.h>
|
||
|
#include "myrootpixmap.h"
|
||
|
|
||
10 years ago
|
static TQString wallpaperForDesktop(int desktop)
|
||
|
{
|
||
|
return DCOPRef("kdesktop", "KBackgroundIface").call("currentWallpaper", desktop);
|
||
|
}
|
||
15 years ago
|
|
||
10 years ago
|
DesktopWallpaperWatcher::DesktopWallpaperWatcher() : TQWidget(), m_old_current_desktop(-1)
|
||
|
{
|
||
|
kapp->installX11EventFilter( this );
|
||
|
(void ) kapp->desktop(); //trigger desktop widget creation to select root window events
|
||
|
}
|
||
|
|
||
|
DesktopWallpaperWatcher::~DesktopWallpaperWatcher()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
bool DesktopWallpaperWatcher::x11Event( XEvent * ev )
|
||
|
{
|
||
|
if ( ev->xany.window == tqt_xrootwin() ) {
|
||
|
NETRootInfo rinfo( tqt_xdisplay(), NET::CurrentDesktop );
|
||
|
rinfo.activate();
|
||
|
|
||
|
if ( rinfo.currentDesktop() != m_old_current_desktop ) {
|
||
|
emit currentDesktopChanged( rinfo.currentDesktop() );
|
||
|
}
|
||
|
|
||
|
m_old_current_desktop = rinfo.currentDesktop();
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
10 years ago
|
class KMyRootPixmapData
|
||
|
{
|
||
|
public:
|
||
|
#ifdef Q_WS_X11
|
||
10 years ago
|
DesktopWallpaperWatcher *twin;
|
||
10 years ago
|
#endif
|
||
|
};
|
||
15 years ago
|
|
||
14 years ago
|
KMyRootPixmap::KMyRootPixmap( TQWidget * widget, const char *name )
|
||
|
: TQObject(widget, name ? name : "KMyRootPixmap" )
|
||
15 years ago
|
{
|
||
|
init();
|
||
|
}
|
||
|
|
||
13 years ago
|
KMyRootPixmap::KMyRootPixmap( TQWidget *, TQObject *parent, const char *name )
|
||
|
: TQObject( parent, name ? name : "KMyRootPixmap" )
|
||
15 years ago
|
{
|
||
|
init();
|
||
|
}
|
||
|
|
||
|
void KMyRootPixmap::init()
|
||
|
{
|
||
10 years ago
|
d = new KMyRootPixmapData;
|
||
15 years ago
|
// m_Fade = 0;
|
||
12 years ago
|
m_pPixmap = new TDESharedPixmap;
|
||
14 years ago
|
// m_pTimer = new TQTimer( this );
|
||
15 years ago
|
m_bInit = false;
|
||
|
m_bActive = false;
|
||
|
m_Desk=-1;
|
||
|
// m_bCustomPaint = false;
|
||
|
|
||
14 years ago
|
// connect(kapp, TQT_SIGNAL(backgroundChanged(int)), TQT_SLOT(slotBackgroundChanged(int)));
|
||
|
connect(m_pPixmap, TQT_SIGNAL(done(bool)), TQT_SLOT(slotDone(bool)));
|
||
13 years ago
|
// connect(m_pTimer, TQT_SIGNAL(timeout()), TQT_SLOT(repaint()));
|
||
15 years ago
|
|
||
10 years ago
|
#ifdef Q_WS_X11
|
||
10 years ago
|
d->twin = new DesktopWallpaperWatcher();
|
||
10 years ago
|
connect(d->twin, TQT_SIGNAL(currentDesktopChanged(int)), TQT_SLOT(desktopChanged(int)));
|
||
|
#endif
|
||
|
|
||
13 years ago
|
// d->toplevel = m_pWidget->topLevelWidget();
|
||
15 years ago
|
// d->toplevel->installEventFilter(this);
|
||
|
}
|
||
|
|
||
|
KMyRootPixmap::~KMyRootPixmap()
|
||
|
{
|
||
|
delete m_pPixmap;
|
||
10 years ago
|
delete d;
|
||
|
}
|
||
|
|
||
|
void KMyRootPixmap::desktopChanged(int desktop)
|
||
|
{
|
||
|
if (wallpaperForDesktop(m_Desk) == wallpaperForDesktop(desktop) &&
|
||
|
!wallpaperForDesktop(m_Desk).isNull())
|
||
|
return;
|
||
|
|
||
|
// #ifdef Q_WS_X11
|
||
|
// if (KWin::windowInfo(m_pWidget->topLevelWidget()->winId()).desktop() == NET::OnAllDesktops &&
|
||
|
// pixmapName(m_Desk) != pixmapName(desktop))
|
||
|
// #endif
|
||
|
repaint(true);
|
||
15 years ago
|
}
|
||
|
|
||
|
int KMyRootPixmap::currentDesktop() const
|
||
|
{
|
||
13 years ago
|
NETRootInfo rinfo( tqt_xdisplay(), NET::CurrentDesktop );
|
||
15 years ago
|
rinfo.activate();
|
||
|
return rinfo.currentDesktop();
|
||
|
}
|
||
|
|
||
|
void KMyRootPixmap::start()
|
||
|
{
|
||
|
if (m_bActive)
|
||
|
return;
|
||
|
|
||
|
m_bActive = true;
|
||
|
enableExports();
|
||
|
return;
|
||
|
// if (m_bInit)
|
||
13 years ago
|
// repaint(true);
|
||
15 years ago
|
}
|
||
|
|
||
|
void KMyRootPixmap::stop()
|
||
|
{
|
||
|
m_bActive = false;
|
||
|
// m_pTimer->stop();
|
||
|
}
|
||
|
|
||
|
|
||
13 years ago
|
void KMyRootPixmap::repaint()
|
||
15 years ago
|
{
|
||
13 years ago
|
repaint(false);
|
||
15 years ago
|
}
|
||
|
|
||
13 years ago
|
void KMyRootPixmap::repaint(bool force)
|
||
15 years ago
|
{
|
||
13 years ago
|
// printf("KMyRootPixmap::repaint(%s)\n",force?"true":"false");
|
||
15 years ago
|
if ((!force) && (m_Desk==currentDesktop()))return;
|
||
|
|
||
|
m_Desk = currentDesktop();
|
||
|
|
||
|
if (!isAvailable())
|
||
|
{
|
||
|
emit backgroundUpdated(NULL);
|
||
|
}else{
|
||
12 years ago
|
// TDESharedPixmap will correctly generate a tile for us.
|
||
15 years ago
|
m_pPixmap->loadFromShared(pixmapName(m_Desk));
|
||
|
updateBackground( m_pPixmap );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
bool KMyRootPixmap::isAvailable()
|
||
|
{
|
||
|
return m_pPixmap->isAvailable(pixmapName(m_Desk));
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString KMyRootPixmap::pixmapName(int desk)
|
||
15 years ago
|
{
|
||
14 years ago
|
TQString pattern = TQString("DESKTOP%1");
|
||
13 years ago
|
int screen_number = DefaultScreen(tqt_xdisplay());
|
||
15 years ago
|
if (screen_number) {
|
||
13 years ago
|
pattern = TQString("SCREEN%1-DESKTOP").arg(screen_number) + "%1";
|
||
15 years ago
|
}
|
||
13 years ago
|
return pattern.arg( desk );
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
|
void KMyRootPixmap::enableExports()
|
||
|
{
|
||
|
// kdDebug(270) << k_lineinfo << "activating background exports.\n";
|
||
|
DCOPClient *client = kapp->dcopClient();
|
||
|
if (!client->isAttached())
|
||
|
client->attach();
|
||
14 years ago
|
TQByteArray data;
|
||
|
TQDataStream args( data, IO_WriteOnly );
|
||
15 years ago
|
args << 1;
|
||
|
|
||
14 years ago
|
TQCString appname( "kdesktop" );
|
||
13 years ago
|
int screen_number = DefaultScreen(tqt_xdisplay());
|
||
15 years ago
|
if ( screen_number )
|
||
|
appname.sprintf("kdesktop-screen-%d", screen_number );
|
||
|
|
||
|
client->send( appname, "KBackgroundIface", "setExport(int)", data );
|
||
|
}
|
||
|
|
||
|
|
||
|
void KMyRootPixmap::slotDone(bool success)
|
||
|
{
|
||
|
if (!success)
|
||
|
{
|
||
|
// kdWarning(270) << k_lineinfo << "loading of desktop background failed.\n";
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
// We need to test active as the pixmap might become available
|
||
|
// after the widget has been destroyed.
|
||
|
if ( m_bActive )
|
||
|
updateBackground( m_pPixmap );
|
||
|
}
|
||
|
|
||
12 years ago
|
void KMyRootPixmap::updateBackground( TDESharedPixmap *spm )
|
||
15 years ago
|
{
|
||
|
// printf("KMyRootPixmap::updateBackground(%p)\n",spm);
|
||
14 years ago
|
TQPixmap *px=spm;
|
||
15 years ago
|
if (px->isNull() || px->width()==0 || px->height()==0)
|
||
|
{ // This is NOT an image, something went wrong, update to plain
|
||
|
emit backgroundUpdated(NULL);
|
||
|
return;
|
||
|
}
|
||
|
KPixmapIO io;
|
||
14 years ago
|
TQSize desktopsize(TQApplication::desktop()->width(),TQApplication::desktop()->height());
|
||
15 years ago
|
|
||
|
if (px->rect().size()==desktopsize)
|
||
|
{ // Image has already the right dimension, make a quick update
|
||
14 years ago
|
TQImage img = io.convertToImage(*spm);
|
||
15 years ago
|
emit backgroundUpdated(&img);
|
||
|
return;
|
||
|
}else{ // we need to create a tiled pixmap and then the image to update
|
||
14 years ago
|
TQPixmap pix(desktopsize,spm->TQPixmap::depth());
|
||
|
TQPainter pufferPainter(&pix);
|
||
15 years ago
|
|
||
|
pufferPainter.drawTiledPixmap(pix.rect(),*spm);
|
||
|
|
||
|
pufferPainter.end();
|
||
|
|
||
14 years ago
|
TQImage img=io.convertToImage(pix);
|
||
15 years ago
|
emit backgroundUpdated(&img);
|
||
|
}
|
||
|
}
|
||
|
|
||
10 years ago
|
#include "myrootpixmap.moc"
|
||
15 years ago
|
#endif
|