17#include <tdeapplication.h>
18#include <kimageeffect.h>
20#include <twinmodule.h>
24#include <dcopclient.h>
27#include <ksharedpixmap.h>
28#include <krootpixmap.h>
31static TQString wallpaperForDesktop(
int desktop)
33 return DCOPRef(
"kdesktop",
"KBackgroundIface").
call(
"currentWallpaper", desktop);
47 : TQObject(widget, name ? name :
"KRootPixmap" ), m_Desk(0), m_pWidget(widget)
53 : TQObject( parent, name ? name :
"KRootPixmap" ), m_Desk(0), m_pWidget(widget)
58void KRootPixmap::init()
60 d =
new KRootPixmapData;
64 m_pPixmap =
new TDESharedPixmap;
65 m_pTimer =
new TQTimer(
this );
68 m_bCustomPaint =
false;
70 connect(tdeApp, TQ_SIGNAL(backgroundChanged(
int)), TQ_SLOT(slotBackgroundChanged(
int)));
71 connect(m_pTimer, TQ_SIGNAL(timeout()), TQ_SLOT(
repaint()));
73 connect(m_pPixmap, TQ_SIGNAL(done(
bool)), TQ_SLOT(slotDone(
bool)));
76 connect(d->twin, TQ_SIGNAL(windowChanged(WId,
unsigned int)), TQ_SLOT(desktopChanged(WId,
unsigned int)));
77 connect(d->twin, TQ_SIGNAL(currentDesktopChanged(
int)), TQ_SLOT(desktopChanged(
int)));
80 d->toplevel = m_pWidget->topLevelWidget();
81 d->toplevel->installEventFilter(
this);
82 m_pWidget->installEventFilter(
this);
95 NETRootInfo rinfo( tqt_xdisplay(), NET::CurrentDesktop );
97 return rinfo.currentDesktop();
100 return TQApplication::desktop()->screenNumber(m_pWidget);
139 if ( m_bActive && m_bInit )
repaint(
true);
144 m_BlurRadius = radius;
151 if (!m_bInit && ((event->type() == TQEvent::Show) || (event->type() == TQEvent::Paint)))
160 switch (event->type())
162 case TQEvent::Resize:
164 m_pTimer->start(100,
true);
168 m_pTimer->start(0,
true);
171 case TQEvent::Reparent:
172 d->toplevel->removeEventFilter(
this);
173 d->toplevel = m_pWidget->topLevelWidget();
174 d->toplevel->installEventFilter(
this);
184void KRootPixmap::desktopChanged(
int desktop)
186 if (wallpaperForDesktop(m_Desk) == wallpaperForDesktop(desktop) &&
187 !wallpaperForDesktop(m_Desk).isNull())
191 if (
KWin::windowInfo(m_pWidget->topLevelWidget()->winId()).desktop() == NET::OnAllDesktops &&
197void KRootPixmap::desktopChanged( WId window,
unsigned int properties )
200 if( !(properties & NET::WMDesktop) ||
201 (window != m_pWidget->topLevelWidget()->winId()))
217 TQPoint p1 = m_pWidget->mapToGlobal(m_pWidget->rect().topLeft());
218 TQPoint p2 = m_pWidget->mapToGlobal(m_pWidget->rect().bottomRight());
219 if (!force && (m_Rect == TQRect(p1, p2)))
226 if ((p1 == m_Rect.topLeft()) && (m_pWidget->width() < m_Rect.width()) &&
227 (m_pWidget->height() < m_Rect.height())
230 m_Rect = TQRect(p1, p2);
234 m_Rect = TQRect(p1, p2);
237 if ((m_Desk == NET::OnAllDesktops) || (m_Desk == 0)) {
242 m_pPixmap->loadFromShared(
pixmapName(m_Desk), m_Rect);
248 if (!m_pPixmap->isNull()) {
249 m_pPixmap->resize( m_Rect.size() );
258 return m_pPixmap->isAvailable(
pixmapName(m_Desk));
260 return m_pPixmap->isNull();
265 TQString pattern = TQString(
"DESKTOP%1");
267 int screen_number = DefaultScreen(tqt_xdisplay());
269 pattern = TQString(
"SCREEN%1-DESKTOP").arg(screen_number) +
"%1";
272 return pattern.arg( desk );
279 kdDebug(270) << k_lineinfo <<
"activating background exports.\n";
284 TQDataStream args( data, IO_WriteOnly );
287 TQCString appname(
"kdesktop" );
288 int screen_number = DefaultScreen(tqt_xdisplay());
290 appname.sprintf(
"kdesktop-screen-%d", screen_number );
292 client->
send( appname,
"KBackgroundIface",
"setExport(int)", data );
297void KRootPixmap::slotDone(
bool success)
301 kdWarning(270) << k_lineinfo <<
"loading of desktop background failed.\n";
323 if ((m_BlurRadius > 1e-6) || (m_BlurSigma > 1e-6))
331 if ( !m_bCustomPaint )
332 m_pWidget->setBackgroundPixmap( pm );
339void KRootPixmap::slotBackgroundChanged(
int desk)
341 if (!m_bInit || !m_bActive)
348#include "krootpixmap.moc"
bool send(const TQCString &remApp, const TQCString &remObj, const TQCString &remFun, const TQByteArray &data)
DCOPReply call(const TQCString &fun)
static TQImage & fade(TQImage &image, float val, const TQColor &color)
static TQImage blur(TQImage &src, double radius, double sigma)
Fast TQImage to/from TQPixmap conversion.
TQPixmap convertToPixmap(const TQImage &image)
Convert an image to a pixmap.
TQImage convertToImage(const TQPixmap &pixmap)
Convert a pixmap to an image.
virtual void start()
Starts background handling.
virtual void updateBackground(TDESharedPixmap *)
Called when the pixmap has been updated.
virtual bool eventFilter(TQObject *, TQEvent *)
Reimplemented to filter the events from the target widget and track its movements.
const TQColor & color() const
void setFadeEffect(double opacity, const TQColor &color)
Sets the fade effect.
virtual void stop()
Stops background handling.
void enableExports()
Asks KDesktop to export the desktop background as a TDESharedPixmap.
void backgroundUpdated(const TQPixmap &pm)
Emitted when the background needs updating and custom painting (see setCustomPainting(bool) ) is enab...
void setBlurEffect(double radius, double sigma)
Sets the blue effect.
void repaint()
Repaints the widget background.
int currentDesktop() const
Returns the number of the current desktop.
bool isAvailable() const
Checks if pseudo-transparency is available.
virtual ~KRootPixmap()
Destructs the object.
KRootPixmap(TQWidget *target, const char *name=0)
Constructs a KRootPixmap.
static TQString pixmapName(int desk)
Returns the name of the shared pixmap (only needed for low level access)
static WindowInfo windowInfo(WId win, unsigned long properties=0, unsigned long properties2=0)
kdbgstream kdWarning(int area=0)
kndbgstream & endl(kndbgstream &s)
kdbgstream kdDebug(int area=0)