Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 40175 Details for
Bug 65001
Patch to add icon drawing support to fbpanel's pager plugin
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
The patch to add icons to the pager plugin for fbpanel
pager_icons.patch (text/plain), 7.72 KB, created by
Dave Foster
on 2004-09-22 11:32:29 UTC
(
hide
)
Description:
The patch to add icons to the pager plugin for fbpanel
Filename:
MIME Type:
Creator:
Dave Foster
Created:
2004-09-22 11:32:29 UTC
Size:
7.72 KB
patch
obsolete
>--- old/fbpanel-3.8/pager.c 2004-04-21 17:43:15.000000000 -0400 >+++ fbpanel-3.8/pager.c 2004-09-22 17:53:54.719330848 -0400 >@@ -29,13 +29,15 @@ > #include <X11/xpm.h> > > #include <gdk-pixbuf/gdk-pixbuf.h> >+#include <gdk/gdk.h> > > #include "panel.h" > #include "misc.h" > #include "plugin.h" >+#include "icon.xpm" > > >-//#define DEBUG >+#define DEBUG > #include "dbg.h" > > /* managed window: all related info that wm holds about its managed windows */ >@@ -50,6 +52,9 @@ > net_wm_state nws; > net_wm_window_type nwwt; > guint focused:1; >+ >+ /* daf: added to try and get icons */ >+ GdkPixbuf *pixbuf; > } task; > > typedef struct _desk desk; >@@ -316,6 +321,189 @@ > } > > /***************************************************************** >+ * Stuff to grab icons from windows - ripped from taskbar.c * >+ *****************************************************************/ >+ >+static GdkColormap* >+get_cmap (GdkPixmap *pixmap) >+{ >+ GdkColormap *cmap; >+ >+ cmap = gdk_drawable_get_colormap (pixmap); >+ if (cmap) >+ g_object_ref (G_OBJECT (cmap)); >+ >+ if (cmap == NULL) >+ { >+ if (gdk_drawable_get_depth (pixmap) == 1) >+ { >+ /* try null cmap */ >+ cmap = NULL; >+ } >+ else >+ { >+ /* Try system cmap */ >+ GdkScreen *screen = gdk_drawable_get_screen (GDK_DRAWABLE (pixmap)); >+ cmap = gdk_screen_get_system_colormap (screen); >+ g_object_ref (G_OBJECT (cmap)); >+ } >+ } >+ >+ /* Be sure we aren't going to blow up due to visual mismatch */ >+ if (cmap && >+ (gdk_colormap_get_visual (cmap)->depth != >+ gdk_drawable_get_depth (pixmap))) >+ cmap = NULL; >+ >+ return cmap; >+} >+ >+static GdkPixbuf* >+_wnck_gdk_pixbuf_get_from_pixmap (GdkPixbuf *dest, >+ Pixmap xpixmap, >+ int src_x, >+ int src_y, >+ int dest_x, >+ int dest_y, >+ int width, >+ int height) >+{ >+ GdkDrawable *drawable; >+ GdkPixbuf *retval; >+ GdkColormap *cmap; >+ >+ retval = NULL; >+ >+ drawable = gdk_xid_table_lookup (xpixmap); >+ >+ if (drawable) >+ g_object_ref (G_OBJECT (drawable)); >+ else >+ drawable = gdk_pixmap_foreign_new (xpixmap); >+ >+ cmap = get_cmap (drawable); >+ >+ /* GDK is supposed to do this but doesn't in GTK 2.0.2, >+ * fixed in 2.0.3 >+ */ >+ if (width < 0) >+ gdk_drawable_get_size (drawable, &width, NULL); >+ if (height < 0) >+ gdk_drawable_get_size (drawable, NULL, &height); >+ >+ retval = gdk_pixbuf_get_from_drawable (dest, >+ drawable, >+ cmap, >+ src_x, src_y, >+ dest_x, dest_y, >+ width, height); >+ >+ if (cmap) >+ g_object_unref (G_OBJECT (cmap)); >+ g_object_unref (G_OBJECT (drawable)); >+ >+ return retval; >+} >+ >+static GdkPixbuf* >+apply_mask (GdkPixbuf *pixbuf, >+ GdkPixbuf *mask) >+{ >+ int w, h; >+ int i, j; >+ GdkPixbuf *with_alpha; >+ guchar *src; >+ guchar *dest; >+ int src_stride; >+ int dest_stride; >+ >+ w = MIN (gdk_pixbuf_get_width (mask), gdk_pixbuf_get_width (pixbuf)); >+ h = MIN (gdk_pixbuf_get_height (mask), gdk_pixbuf_get_height (pixbuf)); >+ >+ with_alpha = gdk_pixbuf_add_alpha (pixbuf, FALSE, 0, 0, 0); >+ >+ dest = gdk_pixbuf_get_pixels (with_alpha); >+ src = gdk_pixbuf_get_pixels (mask); >+ >+ dest_stride = gdk_pixbuf_get_rowstride (with_alpha); >+ src_stride = gdk_pixbuf_get_rowstride (mask); >+ >+ i = 0; >+ while (i < h) >+ { >+ j = 0; >+ while (j < w) >+ { >+ guchar *s = src + i * src_stride + j * 3; >+ guchar *d = dest + i * dest_stride + j * 4; >+ >+ /* s[0] == s[1] == s[2], they are 255 if the bit was set, 0 >+ * otherwise >+ */ >+ if (s[0] == 0) >+ d[3] = 0; /* transparent */ >+ else >+ d[3] = 255; /* opaque */ >+ >+ ++j; >+ } >+ >+ ++i; >+ } >+ >+ return with_alpha; >+} >+ >+static GdkPixbuf * >+get_wm_icon(Window tkwin, int iw, int ih) >+{ >+ XWMHints *hints; >+ Pixmap xpixmap = None, xmask = None; >+ Window win; >+ unsigned int w, h, d; >+ GdkPixbuf *ret, *masked, *pixmap, *mask = NULL; >+ >+ ENTER; >+ hints = (XWMHints *) get_xaproperty (tkwin, XA_WM_HINTS, XA_WM_HINTS, 0); >+ if (!hints) >+ RET(NULL); >+ >+ if ((hints->flags & IconPixmapHint)) >+ xpixmap = hints->icon_pixmap; >+ if ((hints->flags & IconMaskHint)) >+ xmask = hints->icon_mask; >+ >+ XFree (hints); >+ if (xpixmap == None) >+ RET(NULL); >+ >+ XGetGeometry (GDK_DISPLAY(), xpixmap, &win, &d, &d, &w, &h, &d, &d); >+ DBG("tkwin=%x icon pixmap w=%d h=%d\n", tkwin, w, h); >+ pixmap = _wnck_gdk_pixbuf_get_from_pixmap (NULL, xpixmap, 0, 0, 0, 0, w, h); >+ if (!pixmap) >+ RET(NULL); >+ if (xmask != None) { >+ XGetGeometry (GDK_DISPLAY(), xmask, &win, &d, &d, &w, &h, &d, &d); >+ mask = _wnck_gdk_pixbuf_get_from_pixmap (NULL, xmask, 0, 0, 0, 0, w, h); >+ >+ if (mask) { >+ masked = apply_mask (pixmap, mask); >+ g_object_unref (G_OBJECT (pixmap)); >+ g_object_unref (G_OBJECT (mask)); >+ pixmap = masked; >+ } >+ } >+ if (!pixmap) >+ RET(NULL); >+ ret = gdk_pixbuf_scale_simple (pixmap, iw, ih, GDK_INTERP_TILES); >+ g_object_unref(pixmap); >+ >+ RET(ret); >+} >+ >+ >+ >+/***************************************************************** > * Netwm/WM Interclient Communication * > *****************************************************************/ > >@@ -384,6 +572,10 @@ > get_net_wm_window_type(t->win, &t->nwwt); > get_sizepos(t); > XSelectInput (GDK_DISPLAY(), t->win, PropertyChangeMask | StructureNotifyMask); >+ >+ /* daf: grab icon */ >+ t->pixbuf = get_wm_icon(t->win, p->dw, p->dh); >+ > g_hash_table_insert(p->htable, &t->win, t); > desk_set_dirty(p, t); > } >@@ -531,18 +723,62 @@ > if (!d->dirty || !d->pix) > continue; > widget = GTK_WIDGET(d->da); >- gdk_draw_rectangle (d->pix, >+ // >+ // draw internal rectangle >+ // >+ gdk_draw_rectangle (d->pix, > (pg->focusedtask == t) ? > widget->style->bg_gc[GTK_STATE_SELECTED] : > widget->style->bg_gc[GTK_STATE_NORMAL], > TRUE, > x+1, y+1, w-1, h-1); >- gdk_draw_rectangle (d->pix, >+ >+ // >+ // draw border >+ // >+ gdk_draw_rectangle (d->pix, > (pg->focusedtask == t) ? > widget->style->fg_gc[GTK_STATE_SELECTED] : > widget->style->fg_gc[GTK_STATE_NORMAL], > FALSE, > x, y, w, h); >+ >+ /* daf: scale+draw icon here */ >+ if ( t->pixbuf != NULL && w>=10 && h>=10) { >+ >+ // determine how much to scale >+ int scale = 16; >+ int smallest = h; >+ if ( w < smallest ) >+ smallest = w; >+ if ( smallest < 18 ) >+ scale = smallest - 2; >+ if ( scale % 2 != 0 ) >+ scale++; >+ >+ // scale it >+ GdkPixbuf* scaled = gdk_pixbuf_scale_simple( t->pixbuf, >+ scale,scale, >+ GDK_INTERP_BILINEAR); >+ >+ // position >+ int pixx = x+((w/2)-(scale/2))+1; >+ int pixy = y+((h/2)-(scale/2))+1; >+ >+ // draw it >+ gdk_draw_pixbuf(d->pix, >+ NULL, >+ scaled, >+ 0,0, >+ pixx,pixy, >+ -1,-1, >+ GDK_RGB_DITHER_NONE, >+ 0,0); >+ >+ // free it >+ gdk_pixbuf_unref(scaled); >+ } >+ > } while ((t->desktop > pg->desknum) && ++i < pg->desknum); > } >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 65001
: 40175