• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeui
 

tdeui

  • tdeui
krootpixmap.cpp
1/*
2 *
3 *
4 * This file is part of the KDE project, module tdeui.
5 * Copyright (C) 1999,2000 Geert Jansen <jansen@kde.org>
6 *
7 * You can Freely distribute this program under the GNU Library
8 * General Public License. See the file "COPYING.LIB" for the exact
9 * licensing terms.
10 */
11
12#include <tqwidget.h>
13#include <tqtimer.h>
14#include <tqrect.h>
15#include <tqimage.h>
16
17#include <tdeapplication.h>
18#include <kimageeffect.h>
19#include <kpixmapio.h>
20#include <twinmodule.h>
21#include <twin.h>
22#include <kdebug.h>
23#include <netwm.h>
24#include <dcopclient.h>
25#include <dcopref.h>
26
27#include <ksharedpixmap.h>
28#include <krootpixmap.h>
29
30
31static TQString wallpaperForDesktop(int desktop)
32{
33 return DCOPRef("kdesktop", "KBackgroundIface").call("currentWallpaper", desktop);
34}
35
36class KRootPixmapData
37{
38public:
39 TQWidget *toplevel;
40#ifdef TQ_WS_X11
41 KWinModule *twin;
42#endif
43};
44
45
46KRootPixmap::KRootPixmap( TQWidget *widget, const char *name )
47 : TQObject(widget, name ? name : "KRootPixmap" ), m_Desk(0), m_pWidget(widget)
48{
49 init();
50}
51
52KRootPixmap::KRootPixmap( TQWidget *widget, TQObject *parent, const char *name )
53 : TQObject( parent, name ? name : "KRootPixmap" ), m_Desk(0), m_pWidget(widget)
54{
55 init();
56}
57
58void KRootPixmap::init()
59{
60 d = new KRootPixmapData;
61 m_Fade = 0;
62 m_BlurRadius = 0;
63 m_BlurSigma = 0;
64 m_pPixmap = new TDESharedPixmap; //ordinary KPixmap on win32
65 m_pTimer = new TQTimer( this );
66 m_bInit = false;
67 m_bActive = false;
68 m_bCustomPaint = false;
69
70 connect(tdeApp, TQ_SIGNAL(backgroundChanged(int)), TQ_SLOT(slotBackgroundChanged(int)));
71 connect(m_pTimer, TQ_SIGNAL(timeout()), TQ_SLOT(repaint()));
72#ifdef TQ_WS_X11
73 connect(m_pPixmap, TQ_SIGNAL(done(bool)), TQ_SLOT(slotDone(bool)));
74
75 d->twin = new KWinModule( this );
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)));
78#endif
79
80 d->toplevel = m_pWidget->topLevelWidget();
81 d->toplevel->installEventFilter(this);
82 m_pWidget->installEventFilter(this);
83}
84
85KRootPixmap::~KRootPixmap()
86{
87 delete m_pPixmap;
88 delete d;
89}
90
91
92int KRootPixmap::currentDesktop() const
93{
94#ifdef TQ_WS_X11
95 NETRootInfo rinfo( tqt_xdisplay(), NET::CurrentDesktop );
96 rinfo.activate();
97 return rinfo.currentDesktop();
98#else
99 //OK?
100 return TQApplication::desktop()->screenNumber(m_pWidget);
101#endif
102}
103
104
105void KRootPixmap::start()
106{
107 if (m_bActive)
108 return;
109
110 m_bActive = true;
111 if ( !isAvailable() )
112 {
113 // We will get a KIPC message when the shared pixmap is available.
114 enableExports();
115 return;
116 }
117 if (m_bInit)
118 repaint(true);
119}
120
121
122void KRootPixmap::stop()
123{
124 m_bActive = false;
125 m_pTimer->stop();
126}
127
128
129void KRootPixmap::setFadeEffect(double fade, const TQColor &color)
130{
131 if (fade < 0)
132 m_Fade = 0;
133 else if (fade > 1)
134 m_Fade = 1;
135 else
136 m_Fade = fade;
137 m_FadeColor = color;
138
139 if ( m_bActive && m_bInit ) repaint(true);
140}
141
142void KRootPixmap::setBlurEffect(double radius, double sigma)
143{
144 m_BlurRadius = radius;
145 m_BlurSigma = sigma;
146}
147
148bool KRootPixmap::eventFilter(TQObject *, TQEvent *event)
149{
150 // Initialise after the first show or paint event on the managed widget.
151 if (!m_bInit && ((event->type() == TQEvent::Show) || (event->type() == TQEvent::Paint)))
152 {
153 m_bInit = true;
154 m_Desk = currentDesktop();
155 }
156
157 if (!m_bActive)
158 return false;
159
160 switch (event->type())
161 {
162 case TQEvent::Resize:
163 case TQEvent::Move:
164 m_pTimer->start(100, true);
165 break;
166
167 case TQEvent::Paint:
168 m_pTimer->start(0, true);
169 break;
170
171 case TQEvent::Reparent:
172 d->toplevel->removeEventFilter(this);
173 d->toplevel = m_pWidget->topLevelWidget();
174 d->toplevel->installEventFilter(this);
175 break;
176
177 default:
178 break;
179 }
180
181 return false; // always continue processing
182}
183
184void KRootPixmap::desktopChanged(int desktop)
185{
186 if (wallpaperForDesktop(m_Desk) == wallpaperForDesktop(desktop) &&
187 !wallpaperForDesktop(m_Desk).isNull())
188 return;
189
190#ifdef TQ_WS_X11
191 if (KWin::windowInfo(m_pWidget->topLevelWidget()->winId()).desktop() == NET::OnAllDesktops &&
192 pixmapName(m_Desk) != pixmapName(desktop))
193#endif
194 repaint(true);
195}
196
197void KRootPixmap::desktopChanged( WId window, unsigned int properties )
198{
199#ifdef TQ_WS_X11
200 if( !(properties & NET::WMDesktop) ||
201 (window != m_pWidget->topLevelWidget()->winId()))
202 return;
203#endif
204
205 kdDebug() << k_funcinfo << endl;
206 repaint(true);
207}
208
209void KRootPixmap::repaint()
210{
211 repaint(false);
212}
213
214
215void KRootPixmap::repaint(bool force)
216{
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)))
220 return;
221
222 // Due to northwest bit gravity, we don't need to do anything if the
223 // bottom right corner of the widget is moved inward.
224 // That said, konsole clears the background when it is resized, so
225 // we have to reset the background pixmap.
226 if ((p1 == m_Rect.topLeft()) && (m_pWidget->width() < m_Rect.width()) &&
227 (m_pWidget->height() < m_Rect.height())
228 )
229 {
230 m_Rect = TQRect(p1, p2);
231 updateBackground( m_pPixmap );
232 return;
233 }
234 m_Rect = TQRect(p1, p2);
235#ifdef TQ_WS_X11
236 m_Desk = KWin::windowInfo(m_pWidget->topLevelWidget()->winId()).desktop();
237 if ((m_Desk == NET::OnAllDesktops) || (m_Desk == 0)) {
238 m_Desk = currentDesktop();
239 }
240
241 // TDESharedPixmap will correctly generate a tile for us.
242 m_pPixmap->loadFromShared(pixmapName(m_Desk), m_Rect);
243#else
244 m_Desk = currentDesktop();
245 // !x11 note: tile is not generated!
246 // TODO: pixmapName() is a nonsense now!
247 m_pPixmap->load( pixmapName(m_Desk) );
248 if (!m_pPixmap->isNull()) {
249 m_pPixmap->resize( m_Rect.size() );
250 slotDone(true);
251 }
252#endif
253}
254
255bool KRootPixmap::isAvailable() const
256{
257#ifdef TQ_WS_X11
258 return m_pPixmap->isAvailable(pixmapName(m_Desk));
259#else
260 return m_pPixmap->isNull();
261#endif
262}
263
264TQString KRootPixmap::pixmapName(int desk) {
265 TQString pattern = TQString("DESKTOP%1");
266#ifdef TQ_WS_X11
267 int screen_number = DefaultScreen(tqt_xdisplay());
268 if (screen_number) {
269 pattern = TQString("SCREEN%1-DESKTOP").arg(screen_number) + "%1";
270 }
271#endif
272 return pattern.arg( desk );
273}
274
275
276void KRootPixmap::enableExports()
277{
278#ifdef TQ_WS_X11
279 kdDebug(270) << k_lineinfo << "activating background exports.\n";
280 DCOPClient *client = tdeApp->dcopClient();
281 if (!client->isAttached())
282 client->attach();
283 TQByteArray data;
284 TQDataStream args( data, IO_WriteOnly );
285 args << 1;
286
287 TQCString appname( "kdesktop" );
288 int screen_number = DefaultScreen(tqt_xdisplay());
289 if ( screen_number )
290 appname.sprintf("kdesktop-screen-%d", screen_number );
291
292 client->send( appname, "KBackgroundIface", "setExport(int)", data );
293#endif
294}
295
296
297void KRootPixmap::slotDone(bool success)
298{
299 if (!success)
300 {
301 kdWarning(270) << k_lineinfo << "loading of desktop background failed.\n";
302 return;
303 }
304
305 // We need to test active as the pixmap might become available
306 // after the widget has been destroyed.
307 if ( m_bActive )
308 updateBackground( m_pPixmap );
309}
310
311void KRootPixmap::updateBackground( TDESharedPixmap *spm )
312{
313 TQPixmap pm = *spm;
314
315 if (m_Fade > 1e-6)
316 {
317 KPixmapIO io;
318 TQImage img = io.convertToImage(pm);
319 img = KImageEffect::fade(img, m_Fade, m_FadeColor);
320 pm = io.convertToPixmap(img);
321 }
322
323 if ((m_BlurRadius > 1e-6) || (m_BlurSigma > 1e-6))
324 {
325 KPixmapIO io;
326 TQImage img = io.convertToImage(pm);
327 img = KImageEffect::blur(img, m_BlurRadius, m_BlurSigma);
328 pm = io.convertToPixmap(img);
329 }
330
331 if ( !m_bCustomPaint )
332 m_pWidget->setBackgroundPixmap( pm );
333 else {
334 emit backgroundUpdated( pm );
335 }
336}
337
338
339void KRootPixmap::slotBackgroundChanged(int desk)
340{
341 if (!m_bInit || !m_bActive)
342 return;
343
344 if (desk == m_Desk)
345 repaint(true);
346}
347
348#include "krootpixmap.moc"
DCOPClient
DCOPClient::attach
bool attach()
DCOPClient::send
bool send(const TQCString &remApp, const TQCString &remObj, const TQCString &remFun, const TQByteArray &data)
DCOPClient::isAttached
bool isAttached() const
DCOPRef
DCOPRef::call
DCOPReply call(const TQCString &fun)
KImageEffect::fade
static TQImage & fade(TQImage &image, float val, const TQColor &color)
KImageEffect::blur
static TQImage blur(TQImage &src, double radius, double sigma)
KPixmapIO
Fast TQImage to/from TQPixmap conversion.
Definition: kpixmapio.h:88
KPixmapIO::convertToPixmap
TQPixmap convertToPixmap(const TQImage &image)
Convert an image to a pixmap.
Definition: kpixmapio.cpp:184
KPixmapIO::convertToImage
TQImage convertToImage(const TQPixmap &pixmap)
Convert a pixmap to an image.
Definition: kpixmapio.cpp:202
KRootPixmap::start
virtual void start()
Starts background handling.
Definition: krootpixmap.cpp:105
KRootPixmap::updateBackground
virtual void updateBackground(TDESharedPixmap *)
Called when the pixmap has been updated.
Definition: krootpixmap.cpp:311
KRootPixmap::eventFilter
virtual bool eventFilter(TQObject *, TQEvent *)
Reimplemented to filter the events from the target widget and track its movements.
Definition: krootpixmap.cpp:148
KRootPixmap::color
const TQColor & color() const
Definition: krootpixmap.h:106
KRootPixmap::setFadeEffect
void setFadeEffect(double opacity, const TQColor &color)
Sets the fade effect.
Definition: krootpixmap.cpp:129
KRootPixmap::stop
virtual void stop()
Stops background handling.
Definition: krootpixmap.cpp:122
KRootPixmap::enableExports
void enableExports()
Asks KDesktop to export the desktop background as a TDESharedPixmap.
Definition: krootpixmap.cpp:276
KRootPixmap::backgroundUpdated
void backgroundUpdated(const TQPixmap &pm)
Emitted when the background needs updating and custom painting (see setCustomPainting(bool) ) is enab...
KRootPixmap::setBlurEffect
void setBlurEffect(double radius, double sigma)
Sets the blue effect.
Definition: krootpixmap.cpp:142
KRootPixmap::repaint
void repaint()
Repaints the widget background.
Definition: krootpixmap.cpp:209
KRootPixmap::currentDesktop
int currentDesktop() const
Returns the number of the current desktop.
Definition: krootpixmap.cpp:92
KRootPixmap::isAvailable
bool isAvailable() const
Checks if pseudo-transparency is available.
Definition: krootpixmap.cpp:255
KRootPixmap::~KRootPixmap
virtual ~KRootPixmap()
Destructs the object.
Definition: krootpixmap.cpp:85
KRootPixmap::KRootPixmap
KRootPixmap(TQWidget *target, const char *name=0)
Constructs a KRootPixmap.
Definition: krootpixmap.cpp:46
KRootPixmap::pixmapName
static TQString pixmapName(int desk)
Returns the name of the shared pixmap (only needed for low level access)
Definition: krootpixmap.cpp:264
KWinModule
KWin::windowInfo
static WindowInfo windowInfo(WId win, unsigned long properties=0, unsigned long properties2=0)
kdWarning
kdbgstream kdWarning(int area=0)
endl
kndbgstream & endl(kndbgstream &s)
kdDebug
kdbgstream kdDebug(int area=0)

tdeui

Skip menu "tdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.9.4
This website is maintained by Timothy Pearson.