[MPlayer-cvslog] r33630 - in trunk/gui: interface.c mplayer/widgets.c mplayer/widgets.h wm/ws.c

ib subversion at mplayerhq.hu
Thu Jun 16 16:50:24 CEST 2011


Author: ib
Date: Thu Jun 16 16:50:24 2011
New Revision: 33630

Log:
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.

Modified:
   trunk/gui/interface.c
   trunk/gui/mplayer/widgets.c
   trunk/gui/mplayer/widgets.h
   trunk/gui/wm/ws.c

Modified: trunk/gui/interface.c
==============================================================================
--- trunk/gui/interface.c	Thu Jun 16 15:09:52 2011	(r33629)
+++ trunk/gui/interface.c	Thu Jun 16 16:50:24 2011	(r33630)
@@ -403,6 +403,7 @@ void guiDone(void)
     }
 
     appFreeStruct();
+    free(guiIcon.collection);
 
     if (gui_conf) {
         m_config_free(gui_conf);

Modified: trunk/gui/mplayer/widgets.c
==============================================================================
--- trunk/gui/mplayer/widgets.c	Thu Jun 16 15:09:52 2011	(r33629)
+++ trunk/gui/mplayer/widgets.c	Thu Jun 16 16:50:24 2011	(r33630)
@@ -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 @@ int gtkInitialized    = 0;
 
 #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 @@ void gtkInit(void)
 
     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);

Modified: trunk/gui/mplayer/widgets.h
==============================================================================
--- trunk/gui/mplayer/widgets.h	Thu Jun 16 15:09:52 2011	(r33629)
+++ trunk/gui/mplayer/widgets.h	Thu Jun 16 16:50:24 2011	(r33630)
@@ -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 @@ extern char *sbMPlayerPrefixDir;
 typedef struct {
     Pixmap normal;
     Pixmap normal_mask;
+    int collection_size;
+    CARD32 *collection;
 } guiIcon_t;
 
 extern guiIcon_t guiIcon;

Modified: trunk/gui/wm/ws.c
==============================================================================
--- trunk/gui/wm/ws.c	Thu Jun 16 15:09:52 2011	(r33629)
+++ trunk/gui/wm/ws.c	Thu Jun 16 16:50:24 2011	(r33630)
@@ -1554,4 +1554,9 @@ void wsSetIcon(Display *dsp, Window win,
     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);
+    }
 }


More information about the MPlayer-cvslog mailing list