changeset 33542:107084241b00

Add support for _NET_WM_ICON This property will allow the window manager to select from differently sized icons. It is a preparation for this feature to come.
author ib
date Thu, 16 Jun 2011 14:50:24 +0000
parents 729826b857cf
children 10f9498fada1
files gui/interface.c gui/mplayer/widgets.c gui/mplayer/widgets.h gui/wm/ws.c
diffstat 4 files changed, 37 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/gui/interface.c	Thu Jun 16 13:09:52 2011 +0000
+++ b/gui/interface.c	Thu Jun 16 14:50:24 2011 +0000
@@ -403,6 +403,7 @@
     }
 
     appFreeStruct();
+    free(guiIcon.collection);
 
     if (gui_conf) {
         m_config_free(gui_conf);
--- a/gui/mplayer/widgets.c	Thu Jun 16 13:09:52 2011 +0000
+++ b/gui/mplayer/widgets.c	Thu Jun 16 14:50:24 2011 +0000
@@ -35,6 +35,7 @@
 #include "config.h"
 #include "help_mp.h"
 #include "mp_msg.h"
+#include "libavutil/intreadwrite.h"
 #include "libvo/x11_common.h"
 
 #include "widgets.h"
@@ -66,16 +67,21 @@
 
 #include "pixmaps/mplayer.xpm"
 
+#define THRESHOLD 128   // transparency values equal to or above this will become
+                        // opaque, all values below this will become transparent
+
 // --- init & close gtk
 
 guiIcon_t guiIcon;
 
 void gtkInit(void)
 {
-    int argc = 0;
+    int argc = 0, i;
     char *arg[3], **argv = arg;
+    GdkPixbuf *pixbuf;
     GdkPixmap *gdkIcon;
     GdkBitmap *gdkIconMask;
+    guchar *data;
 
     mp_msg(MSGT_GPLAYER, MSGL_V, "GTK init.\n");
 
@@ -92,7 +98,27 @@
 
     gtk_init(&argc, &argv);
 
-    gdkIcon = gdk_pixmap_colormap_create_from_xpm_d(NULL, gdk_colormap_get_system(), &gdkIconMask, NULL, (gchar **)mplayer_xpm);
+    pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)mplayer_xpm);
+
+    gdk_pixbuf_render_pixmap_and_mask_for_colormap(pixbuf, gdk_colormap_get_system(), &gdkIcon, &gdkIconMask, THRESHOLD);
+
+    if (gdk_pixbuf_get_colorspace(pixbuf) == GDK_COLORSPACE_RGB &&
+        gdk_pixbuf_get_n_channels(pixbuf) == 4 &&
+        gdk_pixbuf_get_bits_per_sample(pixbuf) == 8) {
+        guiIcon.collection_size = 2 + gdk_pixbuf_get_width(pixbuf) * gdk_pixbuf_get_height(pixbuf);
+
+        guiIcon.collection = malloc(guiIcon.collection_size * sizeof(*guiIcon.collection));
+
+        if (guiIcon.collection) {
+            guiIcon.collection[0] = gdk_pixbuf_get_width(pixbuf);
+            guiIcon.collection[1] = gdk_pixbuf_get_height(pixbuf);
+
+            data = gdk_pixbuf_get_pixels(pixbuf);
+
+            for (i = 2; i < guiIcon.collection_size; data += 4, i++)
+                guiIcon.collection[i] = (data[3] << 24) | AV_RB24(data);  // RGBA -> ARGB
+        }
+    }
 
     // start up GTK which realizes the pixmaps
     gtk_main_iteration_do(FALSE);
--- a/gui/mplayer/widgets.h	Thu Jun 16 13:09:52 2011 +0000
+++ b/gui/mplayer/widgets.h	Thu Jun 16 14:50:24 2011 +0000
@@ -24,6 +24,7 @@
 #include <gdk/gdkkeysyms.h>
 #include <gtk/gtk.h>
 #include <X11/Xlib.h>
+#include <X11/Xproto.h>
 
 #include "config.h"
 #include "osdep/shmem.h"
@@ -56,6 +57,8 @@
 typedef struct {
     Pixmap normal;
     Pixmap normal_mask;
+    int collection_size;
+    CARD32 *collection;
 } guiIcon_t;
 
 extern guiIcon_t guiIcon;
--- a/gui/wm/ws.c	Thu Jun 16 13:09:52 2011 +0000
+++ b/gui/wm/ws.c	Thu Jun 16 14:50:24 2011 +0000
@@ -1554,4 +1554,9 @@
     data[1]  = icon->normal_mask;
 
     XChangeProperty(dsp, win, iconatom, iconatom, 32, PropModeReplace, (unsigned char *)data, 2);
+
+    if (icon->collection) {
+        iconatom = XInternAtom(dsp, "_NET_WM_ICON", False);
+        XChangeProperty(dsp, win, iconatom, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)icon->collection, icon->collection_size);
+    }
 }