[Pkg-mozext-commits] [firetray] 42/399: * replace Components.utils.reportError() with ERROR() * prepare implementation of text icon * prepare support of other Mozilla apps (Seamonkey)

David Prévot taffit at alioth.debian.org
Tue Oct 29 18:23:10 UTC 2013


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch dfsg-clean
in repository firetray.

commit 74f9cf7da3f84d962bd609390d98fc95d3f27fdc
Author: foudfou <foudil.newbie+git at gmail.com>
Date:   Tue Sep 13 22:08:06 2011 +0200

    * replace Components.utils.reportError() with ERROR()
    * prepare implementation of text icon
    * prepare support of other Mozilla apps (Seamonkey)
---
 TODO                            |    2 +
 src/chrome.manifest             |    8 +-
 src/chrome/content/overlay.js   |   15 +++-
 src/chrome/skin/seamonkey32.png |  Bin 0 -> 2015 bytes
 src/install.rdf                 |   35 +++++++-
 src/modules/MoztHandler.jsm     |   12 +--
 src/modules/MoztIconLinux.jsm   |  168 ++++++++++++++++++++-------------------
 src/modules/ctypes-utils.jsm    |    2 +-
 src/modules/gdk.jsm             |   19 +++--
 src/modules/gobject.jsm         |    1 +
 testing/gtk_icon_example        |  Bin 68328 -> 0 bytes
 testing/gtk_icon_example.c      |  102 +++++++++++++++++++++++-
 testing/newmail.png             |    1 +
 13 files changed, 263 insertions(+), 102 deletions(-)

diff --git a/TODO b/TODO
index c56d9d0..c0f1b07 100644
--- a/TODO
+++ b/TODO
@@ -1,3 +1,5 @@
+* check why unreadMsgCount not well updated with seamonkey
+
 * make multi-platform. At least have js-ctypes library call dependant on OS detection. (best would be to have the OS-dependant modules loaded at startup) 
 
 * convert to a https://developer.mozilla.org/en/Extensions/Bootstrapped_extensions
diff --git a/src/chrome.manifest b/src/chrome.manifest
index 2a32496..cc535b6 100644
--- a/src/chrome.manifest
+++ b/src/chrome.manifest
@@ -5,7 +5,7 @@ resource	moztray			modules/
 
 overlay	chrome://browser/content/browser.xul	chrome://moztray/content/overlay.xul
 overlay	chrome://messenger/content/messenger.xul	chrome://moztray/content/overlay.xul
-overlay	chrome://songbird/content/xul/mainScriptsOverlay.xul	chrome://moztray/content/songOverlay.xul
-overlay	chrome://sunbird/content/calendar.xul	chrome://moztray/content/mailOverlay.xul
-overlay	chrome://navigator/content/navigator.xul	chrome://moztray/content/navigatorOverlay.xul
-overlay	chrome://chatzilla/content/chatzilla.xul	chrome://moztray/content/ircOverlay.xul
+overlay	chrome://songbird/content/xul/mainScriptsOverlay.xul	chrome://moztray/content/overlay.xul
+overlay	chrome://sunbird/content/calendar.xul	chrome://moztray/content/overlay.xul
+overlay	chrome://navigator/content/navigator.xul	chrome://moztray/content/overlay.xul
+overlay	chrome://chatzilla/content/chatzilla.xul	chrome://moztray/content/overlay.xul
diff --git a/src/chrome/content/overlay.js b/src/chrome/content/overlay.js
index d8d5cc2..4f8b22d 100644
--- a/src/chrome/content/overlay.js
+++ b/src/chrome/content/overlay.js
@@ -23,12 +23,16 @@ mozt.Main = {
       mozt.Utils.prefService.addObserver("", that, false);
     }
     catch (ex) {
-      Components.utils.reportError(ex);
+      ERROR(ex);
       return false;
     }
 
     let init = mozt.Handler.initialized || mozt.Handler.init();
 
+    // update unread messages count
+    if (mozt.Handler._inMailApp)
+      mozt.Messaging.updateUnreadMsgCount();
+
     // prevent window closing.
     let that = this;
     window.addEventListener('close', that.onClose, true);
@@ -84,3 +88,12 @@ window.addEventListener(
     removeEventListener('unload', arguments.callee, true);
     mozt.Main.onQuit(); },
   false);
+
+// // TEST - can we catch minimize event ?
+// window.addEventListener(
+//   'DOMAttrModified', function (e) { // focus
+//     removeEventListener('deactivate', arguments.callee, true);
+//     WARN("Got deactivated: "+e.originalTarget.windowState); // Ci.nsIDOMChromeWindow.STATE_MINIMIZED|STATE_NORMAL
+//     WARN("attrName: "+e.attrName);
+//   },
+//   false);
diff --git a/src/chrome/skin/seamonkey32.png b/src/chrome/skin/seamonkey32.png
new file mode 100644
index 0000000..644bed1
Binary files /dev/null and b/src/chrome/skin/seamonkey32.png differ
diff --git a/src/install.rdf b/src/install.rdf
index 9ae9e69..d688e21 100644
--- a/src/install.rdf
+++ b/src/install.rdf
@@ -4,7 +4,7 @@
     <em:id>moztray at foudil.fr</em:id>
     <em:unpack>true</em:unpack> <!-- needed for embedded icons -->
     <em:type>2</em:type>
-    <em:name>Mozilla Tray</em:name>
+    <em:name>MozTray</em:name>
     <em:version>0.1.0</em:version>
     <em:creator>Foudil BRÉTEL</em:creator>
     <em:contributor>Hua Luo, Francesco Solero (Firetray original authors)</em:contributor>
@@ -31,5 +31,38 @@
       </Description>
     </em:targetApplication>
 
+
+    <em:targetApplication>      <!-- Songbird -->
+      <Description>
+        <em:id>songbird at songbirdnest.com</em:id>
+        <em:minVersion>0.8</em:minVersion>
+        <em:maxVersion>1.8.0</em:maxVersion>
+      </Description>
+    </em:targetApplication>
+
+    <em:targetApplication>      <!-- SeaMonkey -->
+      <Description>
+        <em:id>{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}</em:id>
+        <em:minVersion>2.0a1</em:minVersion>
+        <em:maxVersion>2.4.*   </em:maxVersion>
+      </Description>
+    </em:targetApplication>
+
+    <em:targetApplication>      <!-- Sunbird -->
+      <Description>
+        <em:id>{718e30fb-e89b-41dd-9da7-e25a45638b28}</em:id>
+        <em:minVersion>1.0b1</em:minVersion>
+        <em:maxVersion>1.0pre</em:maxVersion>
+      </Description>
+    </em:targetApplication>
+
+    <em:targetApplication>      <!-- ChatZilla -->
+      <Description>
+        <em:id>{59c81df5-4b7a-477b-912d-4e0fdf64e5f2}</em:id>
+        <em:minVersion>0.8</em:minVersion>
+        <em:maxVersion>0.9.*</em:maxVersion>
+      </Description>
+    </em:targetApplication>
+
   </Description>
 </RDF>
diff --git a/src/modules/MoztHandler.jsm b/src/modules/MoztHandler.jsm
index c741feb..4a0d14b 100644
--- a/src/modules/MoztHandler.jsm
+++ b/src/modules/MoztHandler.jsm
@@ -43,8 +43,7 @@ mozt.Handler = {
         .QueryInterface(Ci.nsIInterfaceRequestor);
     } catch (ex) {
       // ignore no-interface exception
-      LOG(ex);
-      Components.utils.reportError(ex);
+      ERROR(ex);
       return null;
     }
 
@@ -53,7 +52,7 @@ mozt.Handler = {
     else if (winType == "XUL")
     winOut = winInterface.getInterface(Ci.nsIXULWindow);
     else {
-      Components.utils.reportError("MOZTRAY: unknown winType '" + winType + "'");
+      ERROR("MOZTRAY: unknown winType '" + winType + "'");
       return null;
     }
 
@@ -161,7 +160,7 @@ mozt.Handler = {
         .getService(Ci.nsIAppStartup);
       appStartup.quit(Components.interfaces.nsIAppStartup.eAttemptQuit);
     } catch (x) {
-      Components.utils.reportError(x);
+      ERROR(x);
       return;
     }
   },
@@ -174,16 +173,18 @@ mozt.Handler = {
     let xulVer = Services.appinfo.platformVersion; // Services.vc.compare(xulVer,"2.0a")>=0
     LOG("OS=" + runtimeOS + ", XULrunner=" + xulVer);
     if (runtimeOS != "Linux") {
-      Components.utils.reportError("MOZTRAY: only Linux platform supported at this time. Moztray not loaded");
+      ERROR("MOZTRAY: only Linux platform supported at this time. Moztray not loaded");
       return false;
     }
     Cu.import("resource://moztray/MoztIconLinux.jsm");
+    LOG('MoztIconLinux imported');
 
     // init all handled windows
     this._updateHandledDOMWindows();
 
     // instanciate tray icon
     mozt.IconLinux.init();
+    LOG('IconLinux initialized');
 
     // check if in mail app
     var mozAppId = Services.appinfo.ID;
@@ -200,6 +201,7 @@ mozt.Handler = {
       // init unread messages count
       mozt.Messaging.updateUnreadMsgCount();
     }
+    LOG('inMailApp: '+this._inMailApp);
 
     this.initialized = true;
     return true;
diff --git a/src/modules/MoztIconLinux.jsm b/src/modules/MoztIconLinux.jsm
index 912fe2f..7d08b25 100644
--- a/src/modules/MoztIconLinux.jsm
+++ b/src/modules/MoztIconLinux.jsm
@@ -78,12 +78,8 @@ mozt.IconLinux = {
                                   mozt_iconActivateCb, null);
 
 
-      // TEST
-      let special_icon =
-        gdk.gdk_pixbuf_new_from_file("newmail.png" , null); // gerror ignored
-
     } catch (x) {
-      Components.utils.reportError(x);
+      ERROR(x);
       return false;
     }
 
@@ -133,88 +129,98 @@ mozt.IconLinux = {
     this.setTooltip(this.appName);
   },
 
+  // SetIconText(GtkStatusIcon *tray_icon, const char *text, const char *color) {
   setText: function() {
-    // special_icon=gdk_pixbuf_new_from_file(gchar *filename , GError **error) newmail.xpm
-    // GdkPixbuf *edit=DrawText (special_icon, (gchar *)text, color);
-    // gtk_status_icon_set_from_pixbuf(GTK_STATUS_ICON(this->systray_icon), GDK_PIXBUF(edit));
-  }
 
-  // GdkPixbuf *DrawText (GdkPixbuf *base, gchar *text, const gchar *colorstr)
-  // {
-  //   if(!base || !text) return NULL;
-  //   GdkPixbuf *dest=gdk_pixbuf_copy(base); //copy the icon content as background
-  //   int w=gdk_pixbuf_get_width(base);
-  //   int h=gdk_pixbuf_get_height(base);
-  //   if(hasPrintedChars(text)) {
-  //     //get the text rendered on a new pixbuf with alpha channel
-  //     GdkPixbuf *textbuf=renderTextWithAlpha(w, h, text, colorstr);
-  //     //merge the rendered text on top
-  //     gdk_pixbuf_composite (textbuf,dest,0,0,w,h,0,0,1,1,GDK_INTERP_NEAREST,255);
-  //     g_object_unref(textbuf);
-  //   }
-  //   return dest;
+  // // build background from image
+  // GdkPixbuf* special_icon = gdk_pixbuf_new_from_file("newmail.png", NULL); // GError **error);
+  // GdkPixbuf *dest = gdk_pixbuf_copy(special_icon);
+  // int w=gdk_pixbuf_get_width(special_icon);
+  // int h=gdk_pixbuf_get_height(special_icon);
+
+  // // prepare colors/alpha
+  // GdkColormap* cmap=gdk_screen_get_system_colormap(gdk_screen_get_default());
+  // int screen_depth=24;
+  // GdkVisual* visual = gdk_colormap_get_visual(cmap);
+  // screen_depth = visual->depth;
+  // GdkColor fore = { 0, 0, 0, 0 };
+  // GdkColor alpha  = { 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF};
+  // gdk_color_parse  (color, &fore) )
+  // if(fore.red==alpha.red && fore.green==alpha.green && fore.blue==alpha.blue) {
+  //   alpha.red=0; //make sure alpha is different from fore
   // }
-
-  // GdkPixbuf *renderTextWithAlpha(int w, int h, gchar *text, const gchar *colorstr)
+  // gdk_colormap_alloc_color (cmap, &fore, TRUE, TRUE);
+  // gdk_colormap_alloc_color (cmap, &alpha, TRUE, TRUE);
+
+  // // build pixmap with rectangle
+  // GdkPixmap *pm = gdk_pixmap_new (NULL, w, h, screen_depth);
+  // GdkGC *gc = gdk_gc_new (pm); // graphic context. DEPRECATED ?
+  // gdk_gc_set_foreground(gc,&alpha);
+  // /* gdk_draw_rectangle(pm,gc,TRUE, 0, 0, w ,h ); */
+  // cairo_t *cr;
+  // cr = gdk_cairo_create(pm);
+  // cairo_rectangle(cr, 0, 0, w, h);
+  // /* void                cairo_rectangle                     (cairo_t *cr, */
+  // /*                                                          double x, */
+  // /*                                                          double y, */
+  // /*                                                          double width, */
+  // /*                                                          double height); */
+  // cairo_set_source_rgb(cr, 1, 1, 1); /* TODO: consider cairo_set_source_rgba (notice the ending "a" for alpha) */
+  // cairo_fill(cr);
+  // cairo_destroy(cr);
+
+  // // build text
+  // GtkWidget *scratch = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+  // PangoLayout *layout = gtk_widget_create_pango_layout(scratch, NULL);
+  // gtk_widget_destroy(scratch);
+  // PangoFontDescription *fnt = pango_font_description_from_string("Sans 18");
+  // pango_font_description_set_weight (fnt,PANGO_WEIGHT_SEMIBOLD);
+  // pango_layout_set_spacing            (layout,0);
+  // pango_layout_set_font_description   (layout, fnt);
+  // pango_layout_set_text (layout, (gchar *)text,-1);
+  // int tw=0;
+  // int th=0;
+  // int sz;
+  // int border=4;
+  // pango_layout_get_pixel_size(layout, &tw, &th);
+  // while( (tw>w - border || th > h - border)) //fit text to the icon by decreasing font size
   // {
-  //   GdkColormap* cmap=gdk_screen_get_system_colormap(gdk_screen_get_default())
-  //   int screen_depth=24;
-  //   if(cmap)
-  //     GdkVisual* visual = gdk_colormap_get_visual(cmap);
-  //   screen_depth=visual->depth;
-  //   GdkColor fore = { 0, 0, 0, 0 };
-  //   GdkColor alpha  = { 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF};
-  //   if(  gdk_color_parse  (colorstr, &fore) ) DEBUGSTR("COLOR OK")
-  //   else DEBUGSTR("COLOR ERROR")
-  //   if(fore.red==alpha.red && fore.green==alpha.green && fore.blue==alpha.blue)
-	//     alpha.red=0; //make sure alpha is different from fore
-  //   gdk_colormap_alloc_color (cmap, &fore,true,true);
-  //   gdk_colormap_alloc_color (cmap, &alpha,true,true);
-
-  //   GdkPixmap *pm = gdk_pixmap_new (NULL, w, h, screen_depth);
-  //   GdkGC *gc = gdk_gc_new (pm);
-  //   gdk_gc_set_foreground(gc,&alpha);
-  //   gdk_draw_rectangle(pm,gc,true, 0, 0, w ,h );
-  //   GtkWidget *scratch = gtk_window_new (GTK_WINDOW_TOPLEVEL);
-  //   gtk_widget_realize (scratch);
-  //   PangoLayout *layout = gtk_widget_create_pango_layout (scratch, NULL);
-  //   gtk_widget_destroy (scratch);
-  //   PangoFontDescription *fnt = pango_font_description_from_string("Sans 18");
-  //   pango_font_description_set_weight (fnt,PANGO_WEIGHT_SEMIBOLD);
-  //   pango_layout_set_spacing            (layout,0);
+  //   sz=pango_font_description_get_size (fnt);
+  //   if(sz<MIN_FONT_SIZE) {
+  //     sz=MIN_FONT_SIZE;
+  //     break;
+  //   }
+  //   sz-=PANGO_SCALE;
+  //   pango_font_description_set_size (fnt,sz);
   //   pango_layout_set_font_description   (layout, fnt);
-  //   pango_layout_set_text (layout, text,-1);
-  //   int tw=0;
-  //   int th=0;
-  //   int sz;
-  //   int border=4;
   //   pango_layout_get_pixel_size(layout, &tw, &th);
-  //   while( (tw>w - border || th > h - border)) //fit text to the icon by decreasing font size
-  //   {
-  //     sz=pango_font_description_get_size (fnt);
-  //     if(sz<MIN_FONT_SIZE) {
-  //       sz=MIN_FONT_SIZE;
-  //       break;
-  //     }
-  //     sz-=PANGO_SCALE;
-  //     pango_font_description_set_size (fnt,sz);
-  //     pango_layout_set_font_description   (layout, fnt);
-  //     pango_layout_get_pixel_size(layout, &tw, &th);
-  //   }
-  //   //centers the text
-  //   int px, py;
-  //   px=(w-tw)/2;
-  //   py=(h-th)/2;
-  //   //paints the text
-  //   gdk_draw_layout_with_colors (pm, gc, px, py, layout, &fore,NULL);
-  //   GdkPixbuf *buf = gdk_pixbuf_get_from_drawable (NULL, pm, NULL, 0, 0, 0, 0, w, h);
-  //   g_object_unref (pm);
-  //   GdkPixbuf *alpha_buf = gdk_pixbuf_add_alpha  (buf, TRUE, (guchar)alpha.red, (guchar)alpha.green, (guchar)alpha.blue);
-  //   g_object_unref (buf);
-  //   g_object_unref (layout);
-  //   pango_font_description_free (fnt);
-  //   g_object_unref (gc);
-  //   return alpha_buf;
   // }
+  // // center text
+  // int px, py;
+  // px=(w-tw)/2;
+  // py=(h-th)/2;
+
+  // // draw text on pixmap
+  // gdk_draw_layout_with_colors (pm, gc, px, py, layout, &fore, NULL);
+
+  // GdkPixbuf *buf = gdk_pixbuf_get_from_drawable (NULL, pm, NULL, 0, 0, 0, 0, w, h);
+  // g_object_unref (pm);
+  // GdkPixbuf *alpha_buf = gdk_pixbuf_add_alpha  (buf, TRUE, (guchar)alpha.red, (guchar)alpha.green, (guchar)alpha.blue);
+
+  // // cleaning
+  // g_object_unref (buf);
+  // g_object_unref (layout);
+  // pango_font_description_free (fnt);
+  // g_object_unref (gc);
+
+
+  // //merge the rendered text on top
+  // gdk_pixbuf_composite (alpha_buf,dest,0,0,w,h,0,0,1,1,GDK_INTERP_NEAREST,255);
+  // g_object_unref(alpha_buf);
+
+
+  // gtk_status_icon_set_from_pixbuf(GTK_STATUS_ICON(tray_icon), GDK_PIXBUF(dest));
+
+  }
 
 }; // mozt.IconLinux
diff --git a/src/modules/ctypes-utils.jsm b/src/modules/ctypes-utils.jsm
index 73c9321..2f12f45 100644
--- a/src/modules/ctypes-utils.jsm
+++ b/src/modules/ctypes-utils.jsm
@@ -41,7 +41,7 @@ const Cu = Components.utils;
 Cu.import("resource://gre/modules/ctypes.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
-var EXPORTED_SYMBOLS  = [ "ctypes_library" ];
+var EXPORTED_SYMBOLS  = [ "ctypes_library", "ERROR" ];
 
 ["LOG", "WARN", "ERROR"].forEach(function(aName) {
   this.__defineGetter__(aName, function() {
diff --git a/src/modules/gdk.jsm b/src/modules/gdk.jsm
index 34feb4c..7a45c3b 100644
--- a/src/modules/gdk.jsm
+++ b/src/modules/gdk.jsm
@@ -55,10 +55,10 @@ function gdk_defines(lib) {
   this.GDK_INTERP_NEAREST = 1, // GdkInterpType
 
   this.GdkWindow = ctypes.StructType("GdkWindow");
-  this.GdkByteOrder = ctype.StructType("GdkByteOrder");
-  this.GdkVisualType = ctype.StructType("GdkVisualType");
+  this.GdkByteOrder = ctypes.int; // enum
+  this.GdkVisualType = ctypes.int; // enum
   this.GdkVisual = ctypes.StructType("GdkVisual", [
-    { "parent_instance": gobject.GObject },
+    { "parent_instance": ctypes.void_t.ptr }, // gobject.GObject }, // FIXME !!
     { "type": this.GdkVisualType },
     { "depth": gobject.gint },
     { "byte": this.GdkByteOrder },
@@ -103,9 +103,13 @@ function gdk_defines(lib) {
     { "wmclass_name": gobject.gchar },
     { "wmclass_class": gobject.gchar },
     { "override_redirect": gobject.gboolean },
-    { "type_hint": gobject.gint }]);
+    { "type_hint": gobject.gint }
+  ]);
   this.GdkPixbuf = ctypes.StructType("GdkPixbuf");
   this.GdkScreen = ctypes.StructType("GdkScreen");
+  this.GdkPixmap = ctypes.StructType("GdkPixmap");
+  this.GdkDrawable = ctypes.StructType("GdkDrawable");
+  this.GdkGC = ctypes.StructType("GdkGC");
 
   lib.lazy_bind("gdk_window_new", this.GdkWindow.ptr, this.GdkWindow.ptr, this.GdkWindowAttributes.ptr, gobject.gint);
   lib.lazy_bind("gdk_window_destroy", ctypes.void_t, this.GdkWindow.ptr);
@@ -121,10 +125,11 @@ function gdk_defines(lib) {
   lib.lazy_bind("gdk_screen_get_system_colormap", this.GdkColormap.ptr, this.GdkScreen.ptr);
   lib.lazy_bind("gdk_colormap_get_visual", this.GdkVisual.ptr, this.GdkColormap.ptr);
   lib.lazy_bind("gdk_color_parse", gobject.gboolean, gobject.gchar.ptr, this.GdkColor.ptr);
-
   lib.lazy_bind("gdk_colormap_alloc_color", gobject.gboolean, this.GdkColormap.ptr, this.GdkColor.ptr, gobject.gboolean, gobject.gboolean);
-// gdk_pixmap_new
-// gdk_gc_new
+  lib.lazy_bind("gdk_pixmap_new", this.GdkPixmap.ptr, this.GdkDrawable.ptr, gobject.gint, gobject.gint, gobject.gint);
+  lib.lazy_bind("gdk_gc_new", this.GdkGC.ptr, this.GdkDrawable.ptr);
+  lib.lazy_bind("gdk_gc_set_foreground", ctypes.void_t, this.GdkGC.ptr, this.GdkColor.ptr);
+  lib.lazy_bind("gdk_draw_rectangle", ctypes.void_t, this.GdkDrawable.ptr, this.GdkGC.ptr, gobject.gboolean, gobject.gint, gobject.gint, gobject.gint, gobject.gint);
 
 }
 
diff --git a/src/modules/gobject.jsm b/src/modules/gobject.jsm
index 25f7d11..05e1864 100644
--- a/src/modules/gobject.jsm
+++ b/src/modules/gobject.jsm
@@ -50,6 +50,7 @@ Cu.import("resource://gre/modules/ctypes.jsm");
 Cu.import("resource://moztray/ctypes-utils.jsm");
 
 function gobject_defines(lib) {
+  this.GObject = ctypes.StructType("GObject");
   this.gpointer = ctypes.voidptr_t;
   this.gulong = ctypes.unsigned_long;
   this.guint = ctypes.unsigned_int;
diff --git a/testing/gtk_icon_example b/testing/gtk_icon_example
deleted file mode 100755
index 91ecccf..0000000
Binary files a/testing/gtk_icon_example and /dev/null differ
diff --git a/testing/gtk_icon_example.c b/testing/gtk_icon_example.c
index 0255d1a..478c6ab 100644
--- a/testing/gtk_icon_example.c
+++ b/testing/gtk_icon_example.c
@@ -3,6 +3,8 @@
 #include <gtk/gtk.h>
 #include "firefox.xpm"
 
+#define MIN_FONT_SIZE 4
+
 void tray_icon_on_click(GtkStatusIcon *status_icon, 
                         gpointer user_data)
 {
@@ -61,11 +63,104 @@ static void winShowHide(GtkMenuItem *item, gpointer window)
   /* GdkWindowState ws = gdk_window_get_state((GdkWindow*)tl_window); */
   /* printf("GdkWindowState: %d", ws); */
 
-  gdk_window_hide(window->window);
+  /* gdk_window_hide(window->window); */
   /* gtk_widget_show(GTK_WIDGET(window)); */
-  /* gtk_widget_hide(GTK_WIDGET(window)); */
+  gtk_widget_hide(GTK_WIDGET(window));
+}
+
+SetIconText(GtkStatusIcon *tray_icon, const char *text, const char *color) {
+
+  // build background from image
+  GdkPixbuf* special_icon = gdk_pixbuf_new_from_file("newmail.png", NULL); // GError **error);
+  GdkPixbuf *dest = gdk_pixbuf_copy(special_icon);
+  int w=gdk_pixbuf_get_width(special_icon);
+  int h=gdk_pixbuf_get_height(special_icon);
+
+  // prepare colors/alpha
+  GdkColormap* cmap=gdk_screen_get_system_colormap(gdk_screen_get_default());
+  int screen_depth=24;
+  GdkVisual* visual = gdk_colormap_get_visual(cmap);
+  screen_depth = visual->depth;
+  GdkColor fore = { 0, 0, 0, 0 };
+  GdkColor alpha  = { 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF};
+  gdk_color_parse  (color, &fore) )
+  if(fore.red==alpha.red && fore.green==alpha.green && fore.blue==alpha.blue) {
+    alpha.red=0; //make sure alpha is different from fore
+  }
+  gdk_colormap_alloc_color (cmap, &fore, TRUE, TRUE);
+  gdk_colormap_alloc_color (cmap, &alpha, TRUE, TRUE);
+
+  // build pixmap with rectangle
+  GdkPixmap *pm = gdk_pixmap_new (NULL, w, h, screen_depth);
+  GdkGC *gc = gdk_gc_new (pm); // graphic context. DEPRECATED ?
+  gdk_gc_set_foreground(gc,&alpha);
+  /* gdk_draw_rectangle(pm,gc,TRUE, 0, 0, w ,h ); */
+  cairo_t *cr;
+  cr = gdk_cairo_create(pm);
+  cairo_rectangle(cr, 0, 0, w, h);
+  /* void                cairo_rectangle                     (cairo_t *cr, */
+  /*                                                          double x, */
+  /*                                                          double y, */
+  /*                                                          double width, */
+  /*                                                          double height); */
+  cairo_set_source_rgb(cr, 1, 1, 1); /* TODO: consider cairo_set_source_rgba (notice the ending "a" for alpha) */
+  cairo_fill(cr);
+  cairo_destroy(cr);
+
+  // build text
+  GtkWidget *scratch = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+  PangoLayout *layout = gtk_widget_create_pango_layout(scratch, NULL);
+  gtk_widget_destroy(scratch);
+  PangoFontDescription *fnt = pango_font_description_from_string("Sans 18");
+  pango_font_description_set_weight (fnt,PANGO_WEIGHT_SEMIBOLD);
+  pango_layout_set_spacing            (layout,0);
+  pango_layout_set_font_description   (layout, fnt);
+  pango_layout_set_text (layout, (gchar *)text,-1);
+  int tw=0;
+  int th=0;
+  int sz;
+  int border=4;
+  pango_layout_get_pixel_size(layout, &tw, &th);
+  while( (tw>w - border || th > h - border)) //fit text to the icon by decreasing font size
+  {
+    sz=pango_font_description_get_size (fnt);
+    if(sz<MIN_FONT_SIZE) {
+      sz=MIN_FONT_SIZE;
+      break;
+    }
+    sz-=PANGO_SCALE;
+    pango_font_description_set_size (fnt,sz);
+    pango_layout_set_font_description   (layout, fnt);
+    pango_layout_get_pixel_size(layout, &tw, &th);
+  }
+  // center text
+  int px, py;
+  px=(w-tw)/2;
+  py=(h-th)/2;
+
+  // draw text on pixmap
+  gdk_draw_layout_with_colors (pm, gc, px, py, layout, &fore,NULL);
+
+  GdkPixbuf *buf = gdk_pixbuf_get_from_drawable (NULL, pm, NULL, 0, 0, 0, 0, w, h);
+  g_object_unref (pm);
+  GdkPixbuf *alpha_buf = gdk_pixbuf_add_alpha  (buf, TRUE, (guchar)alpha.red, (guchar)alpha.green, (guchar)alpha.blue);
+
+  // cleaning
+  g_object_unref (buf);
+  g_object_unref (layout);
+  pango_font_description_free (fnt);
+  g_object_unref (gc);
+
+
+  //merge the rendered text on top
+  gdk_pixbuf_composite (alpha_buf,dest,0,0,w,h,0,0,1,1,GDK_INTERP_NEAREST,255);
+  g_object_unref(alpha_buf);
+
+
+  gtk_status_icon_set_from_pixbuf(GTK_STATUS_ICON(tray_icon), GDK_PIXBUF(dest));
 }
 
+
 int main(int argc, char **argv) {
         GtkStatusIcon *tray_icon;
 
@@ -84,6 +179,9 @@ int main(int argc, char **argv) {
 
     gtk_widget_show_all (window);
 
+    /* TESTING */
+    SetIconText(tray_icon,"F", "#000000");
+
         gtk_main();
 
         return 0;
diff --git a/testing/newmail.png b/testing/newmail.png
new file mode 120000
index 0000000..5253edf
--- /dev/null
+++ b/testing/newmail.png
@@ -0,0 +1 @@
+../src/chrome/skin/newmail.png
\ No newline at end of file

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/firetray.git



More information about the Pkg-mozext-commits mailing list