Bug 67713 - The playing icon in systray isn't transparent
Summary: The playing icon in systray isn't transparent
Status: RESOLVED FIXED
Alias: None
Product: juk
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: Scott Wheeler
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-11-09 22:53 UTC by Teemu Rytilahti
Modified: 2004-03-15 20:25 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
JuK Paused systray icon (1.25 KB, image/png)
2003-12-19 03:51 UTC, Michael Pyne
Details
JuK Playing systray icon (1.27 KB, image/png)
2003-12-19 03:51 UTC, Michael Pyne
Details
Patch to load icons for the system tray instead of creating them. (668 bytes, patch)
2003-12-19 03:54 UTC, Michael Pyne
Details
Template for JuK systray icons (GIMP 1.3) (2.20 KB, image/x-xcf-gimp)
2003-12-19 04:04 UTC, Michael Pyne
Details
Better patch to implement transparent system tray icons (3.23 KB, patch)
2003-12-20 06:13 UTC, Michael Pyne
Details
JuK's system tray with my transparent systray patch (1.54 KB, image/png)
2003-12-20 06:18 UTC, Michael Pyne
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Teemu Rytilahti 2003-11-09 22:53:27 UTC
Version:           1.96 (2.0 Beta 2) (using KDE 3.1.93 (CVS >= 20031028), compiled sources)
Compiler:          gcc version 3.2.3 (Debian)
OS:          Linux (i686) release 2.6.0-test9

Well, I don't know if this is a bug or a wishlist, but the playing icon in systray isn't transparent.. When the panel has different color than grey, it looks pretty ugly..

So please, could you fix this for kde 3.2?
Comment 1 Scott Wheeler 2003-11-14 03:03:04 UTC
After looking into the problem and the issues around it, this probably won't be fixed in the 3.2 timeframe.  It would require changes in both kdelibs and kdebase.  I'll try to come up with a patch before then, but I don't expect that it would be accepted any sooner than 3.3.
Comment 2 Stephan Kulow 2003-11-14 11:48:15 UTC
why do you need patches to kdelibs and kdebase to make a systray icon transparent? It works for anything else - including the mega complex kmoon :)
Comment 3 Scott Wheeler 2003-11-14 11:52:45 UTC
JuK currently does a blend of the current status and a semi-transparent application icon to indicate the status.  However to generate this properly the KSystemTray needs to have an accurate way to get the background of the widget.  There's actually some X magic in the system tray applet to set the background of the QXEmbed widget used there to the background of the Kicker.  To get a background pixmap into KSystemTray it would probably need to be passed over DCOP between the applet and the kdelibs class and then the blend could be done in JuK.  
Comment 4 Stephan Kulow 2003-11-14 13:23:19 UTC
Subject: Re:  The playing icon in systray isn't transparent

On Friday 14 November 2003 11:52, Scott Wheeler wrote:
> To get a background pixmap into KSystemTray it would probably 
> need to be passed over DCOP between the applet and the kdelibs 
> class and then the blend could be done in JuK.  
> 
You just need to set a correct alpha mask on your widget.

Greetings, Stephan

Comment 5 Scott Wheeler 2003-11-14 14:27:01 UTC
Nope -- tried that last night before my reply.  That works for part of the background, but the semi-transparency of the icon still looks really bad.
Comment 6 Dan Leinir Turthra Jensen 2003-11-20 15:52:37 UTC
On this note, I have often been a little annoyed as to the fact that the taskbar icon isn't themed (I know, I've made this point in other applications too, but I find it important ;) ). Maybe the simplest fix would be simply to use the JuK application icon, as opposed to one found in the program folder? I am not, however, certain how you would actually do it practically, as my only experience with C++ as of yet is KStyle programming ;).
Comment 7 Scott Wheeler 2003-11-20 16:16:00 UTC
Uhm, there is only on JuK application icon -- there's not a separate one for the system tray icon.
Comment 8 Tom Gilligan 2003-12-12 09:42:47 UTC
For 3.2 would it be possible to just have the current status icon by itself (ie not blended) and have the JuK icon when it is stopped?
Comment 9 Michael Pyne 2003-12-19 03:51:14 UTC
Created attachment 3769 [details]
JuK Paused systray icon

Sample icon for JuK while paused.
Comment 10 Michael Pyne 2003-12-19 03:51:51 UTC
Created attachment 3770 [details]
JuK Playing systray icon

Sample icon for JuK while it is playing.
Comment 11 Michael Pyne 2003-12-19 03:54:59 UTC
Created attachment 3771 [details]
Patch to load icons for the system tray instead of creating them.

This patch changes systemtray.cpp to load PNGs for the Playing and Paused
systray icons, rather than dynamically creating them.  Although creating them
dynamically would be better in case more states are created in the future,
current kdelibs makes that infeasible.	I will also attach the GIMP template I
used to create the icons.  Although I have attempted to make the icons resemble
the current generated ones when possible, it is still possible to detect a
difference.
Comment 12 Michael Pyne 2003-12-19 03:57:03 UTC
Forgot to comment on my last patch, it depends on adding the two .png's that I've created to the list of icons to install.  I'm still working on the changes to make that happen.
Comment 13 Michael Pyne 2003-12-19 04:04:18 UTC
Created attachment 3772 [details]
Template for JuK systray icons (GIMP 1.3)

I used this template to create the two PNGs I've attached.  I simply resized
the playing and paused icons to 16x16, and cut-and-pasted them into the Overlay
layer.	GIMP automatically centered on the paste operation, so no further
tweaking was needed.
Comment 14 Michael Pyne 2003-12-20 06:13:47 UTC
Created attachment 3791 [details]
Better patch to implement transparent system tray icons

This patch is much improved from the one I submitted yesterday.  It apparently
*IS* possible to overlay the icons and still maintain transparency, but it
involves an intermediate step using QImages instead of QPixmaps.

I also had to create a function to copy one QImage into another, as I couldn't
find an existing one.  I would imagine that the function is slow, but since
it's only called twice, I think it's OK.

This patch also allows a change in the icon theme for people who don't like
Crystal for whatever reason.  This also makes all of my GIMPery completely
unnecessary. :)

I think that this patch fixes this bug.
Comment 15 Michael Pyne 2003-12-20 06:18:55 UTC
Created attachment 3792 [details]
JuK's system tray with my transparent systray patch

I've taken a screenshot of the results of my patch to systemtray.cpp.  Now it's
time to change that damn kicker background back! ;-)
Comment 16 Scott Wheeler 2004-01-12 02:27:34 UTC
Subject: kdemultimedia/juk

CVS commit by wheeler: 

Patch from Michal Pyne to fix system tray icon transparency when blending
a status icon with the JuK icon.

CCMAIL:67713-done@bugs.kde.org
CCMAIL:pynm0001@comcast.net


  M +62 -14    systemtray.cpp   1.28


--- kdemultimedia/juk/systemtray.cpp  #1.27:1.28
@@ -31,4 +31,6 @@
 #include "jukIface.h"
 
+static bool copyImage(QImage &dest, QImage &src, int x, int y);
+
 ////////////////////////////////////////////////////////////////////////////////
 // public methods
@@ -130,5 +132,7 @@ void SystemTray::createPopup(const QStri
         m_popup->setView(box);
 
-        // We don't want an autodelete popup.  There are times when it will need to be hidden before the timeout.
+        // We don't want an autodelete popup.  There are times when it will need
+        // to be hidden before the timeout.
+
         m_popup->setAutoDelete(false);
         m_popup->show();
@@ -144,21 +148,19 @@ QPixmap SystemTray::createPixmap(const Q
     QPixmap fgPix = SmallIcon(pixName);
 
-    // Make this pretty close to invisible.  I'm certain there's a cleaner way to
-    // do this, but I am exceedingly lazy.
-    KIconEffect::semiTransparent(bgPix);
-    KIconEffect::semiTransparent(bgPix);
-
-    QPainter p(&buffer);
-    p.drawPixmap(0, 0, bgPix);
+    QImage bgImage = bgPix.convertToImage(); // Probably 22x22
+    QImage fgImage = fgPix.convertToImage(); // Should be 16x16
 
-    p.drawPixmap((buffer.width() - fgPix.width()) / 2,
-        (buffer.height() - fgPix.height()) / 2, fgPix);
+    KIconEffect::semiTransparent (bgImage);
+    KIconEffect::semiTransparent (bgImage);
+    copyImage(bgImage, fgImage, (bgImage.width() - fgImage.width()) / 2,
+              (bgImage.height() - fgImage.height()) / 2);
 
-    return buffer;
+    bgImage.setAlphaBuffer (true);
+    bgPix.convertFromImage (bgImage);
+    return bgPix;
 }
 
 void SystemTray::setToolTip(const QString &tip)
 {
-    // if(!QToolTip::textFor(this).isNull())
     QToolTip::remove(this);
 
@@ -200,4 +202,50 @@ void SystemTray::wheelEvent(QWheelEvent 
 }
 
+/*
+ * This function copies the entirety of src into dest, starting in
+ * dest at x and y.  This function exists because I was unable to find
+ * a function like it in either QImage or kdefx
+ */
+
+static bool copyImage(QImage &dest, QImage &src, int x, int y)
+{
+    if(dest.depth() != src.depth())
+        return false;   
+    if((x + src.width()) >= dest.width())
+        return false;
+    if((y + src.height()) >= dest.height())
+        return false;
+    
+    // We want to use KIconEffect::overlay to do this, since it handles
+    // alpha, but the images need to be the same size.  We can handle that.
+
+    QImage large_src(dest);
+
+    // It would perhaps be better to create large_src based on a size, but
+    // this is the easiest way to make a new image with the same depth, size,
+    // etc.
+
+    large_src.detach();
+        
+    // However, we do have to specifically ensure that setAlphaBuffer is set
+    // to false
+
+    large_src.setAlphaBuffer (false);
+    large_src.fill(0); // All transparent pixels
+    large_src.setAlphaBuffer (true);
+    
+    int w = src.width();
+    int h = src.height();
+    for(int dx = 0; dx < w; dx++)
+        for(int dy = 0; dy < h; dy++)
+            large_src.setPixel(dx + x, dy + y, src.pixel(dx, dy));
+    
+    // Apply effect to image
+
+    KIconEffect::overlay (dest, large_src);
+    
+    return true;
+}
+
 #include "systemtray.moc"
 


Comment 17 Sebastien 2004-03-15 20:25:15 UTC
It still do not work for my KDE 3.2.0 (kdf 0.5).