[Pkg-mozext-commits] [firetray] 39/399: begin implementation for text icon
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 d31f9278301686a20b061832194a8066127ef0a1
Author: foudfou <foudil.newbie+git at gmail.com>
Date: Fri Sep 9 22:14:40 2011 +0200
begin implementation for text icon
---
README.md | 2 +-
src/chrome/content/overlay.js | 8 ++-
src/chrome/skin/newmail.png | Bin 0 -> 1413 bytes
src/modules/LibGLib.jsm | 28 ++++++++++
src/modules/LibGObject.jsm | 6 ++-
src/modules/LibGdkWindow.jsm | 113 ++++++++++++++++++++++++++++++++++++-----
src/modules/MoztIconLinux.jsm | 87 +++++++++++++++++++++++++++++++
7 files changed, 224 insertions(+), 20 deletions(-)
diff --git a/README.md b/README.md
index 97b6b32..fed1334 100644
--- a/README.md
+++ b/README.md
@@ -20,7 +20,7 @@ References
* Mike Conley's
[Unity-Thunderbird integration](http://mozillalabs.com/messaging/messaging-menu/
"Unity-Thunderbird integration")
- * discontinued [Mozilla New Mail Icon (Biff)](http://moztraybiff.mozdev.org/)
+ * discontinued [Mozilla New Mail Icon (Biff)](https://addons.mozilla.org/fr/thunderbird/addon/new-mail-icon/)
* [Alltray](http://alltray.trausch.us/ "alltray") launches any applications
into tray
diff --git a/src/chrome/content/overlay.js b/src/chrome/content/overlay.js
index c9a1119..d8d5cc2 100644
--- a/src/chrome/content/overlay.js
+++ b/src/chrome/content/overlay.js
@@ -44,11 +44,9 @@ mozt.Main = {
let that = this;
mozt.Utils.prefService.removeObserver("", that);
LOG('Moztray UNLOADED !');
- /*
- * NOTE: don't mozt.Handler.initialized=false here, otherwise after a
- * window close, a new window will create a new handler (and hence, a new
- * tray icon)
- */
+ /* NOTE: don't mozt.Handler.initialized=false here, otherwise after a
+ window close, a new window will create a new handler (and hence, a new
+ tray icon) */
},
// TODO: prevent preceding warning about closing multiple tabs
diff --git a/src/chrome/skin/newmail.png b/src/chrome/skin/newmail.png
new file mode 100644
index 0000000..d35237f
Binary files /dev/null and b/src/chrome/skin/newmail.png differ
diff --git a/src/modules/LibGLib.jsm b/src/modules/LibGLib.jsm
new file mode 100644
index 0000000..d1eab4a
--- /dev/null
+++ b/src/modules/LibGLib.jsm
@@ -0,0 +1,28 @@
+/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+var EXPORTED_SYMBOLS = ["LibGLib"];
+
+const LIB_GLIB = "libglib-2.0.so.0";
+
+const Cu = Components.utils;
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+
+Cu.import("resource://gre/modules/ctypes.jsm");
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+XPCOMUtils.defineLazyGetter(this, "libglib", function() {
+ var libglib = ctypes.open(LIB_GLIB);
+ if (!libglib)
+ throw "libglib is unavailable";
+ return libglib;
+});
+
+XPCOMUtils.defineLazyGetter(this, "GError", function() {
+ return ctypes.StructType("GError");
+});
+
+
+var LibGLib = {
+ GError: GError
+}
diff --git a/src/modules/LibGObject.jsm b/src/modules/LibGObject.jsm
index 106cf3a..3279f7c 100644
--- a/src/modules/LibGObject.jsm
+++ b/src/modules/LibGObject.jsm
@@ -72,7 +72,11 @@ XPCOMUtils.defineLazyGetter(this, "guint", function() {
});
XPCOMUtils.defineLazyGetter(this, "guint32", function() {
- return ctypes.unsigned_int;
+ return ctypes.uint32_t;
+});
+
+XPCOMUtils.defineLazyGetter(this, "guint16", function() {
+ return ctypes.uint16_t;
});
XPCOMUtils.defineLazyGetter(this, "gint", function() {
diff --git a/src/modules/LibGdkWindow.jsm b/src/modules/LibGdkWindow.jsm
index 167c292..43a63f6 100644
--- a/src/modules/LibGdkWindow.jsm
+++ b/src/modules/LibGdkWindow.jsm
@@ -47,6 +47,7 @@ const Ci = Components.interfaces;
Cu.import("resource://gre/modules/ctypes.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+Cu.import("resource://moztray/LibGLib.jsm");
Cu.import("resource://moztray/LibGObject.jsm");
XPCOMUtils.defineLazyGetter(this, "libgdkwindow", function() {
@@ -57,6 +58,9 @@ XPCOMUtils.defineLazyGetter(this, "libgdkwindow", function() {
return libgdkwindow;
});
+
+// Structures
+
XPCOMUtils.defineLazyGetter(this, "GdkWindow", function() {
return ctypes.StructType("GdkWindow");
});
@@ -104,6 +108,32 @@ XPCOMUtils.defineLazyGetter(this, "GdkWindowAttributes", function() {
{ "type_hint": LibGObject.gint }]);
});
+XPCOMUtils.defineLazyGetter(this, "GdkPixbuf", function() {
+ return ctypes.StructType("GdkPixbuf");
+});
+
+XPCOMUtils.defineLazyGetter(this, "GdkColor", function() {
+ return ctypes.StructType("GdkColor");
+ GdkColor.define([
+ { pixel: LibGObject.guint32 },
+ { red: LibGObject.guint16 },
+ { green: LibGObject.guint16 },
+ { blue: LibGObject.guint16 }
+ ]);
+});
+
+XPCOMUtils.defineLazyGetter(this, "GdkColormap", function() {
+ return ctypes.StructType("GdkColormap");
+ GdkColormap.define([
+ { size: ctypes.gint },
+ { colors: GdkColor.ptr }
+ ]);
+ return GdkColormap;
+});
+
+
+// Functions
+
XPCOMUtils.defineLazyGetter(this, "gdk_window_new", function() {
var gdk_window_new =
libgdkwindow.declare("gdk_window_new",
@@ -112,10 +142,8 @@ XPCOMUtils.defineLazyGetter(this, "gdk_window_new", function() {
GdkWindow.ptr,
GdkWindowAttributes.ptr,
LibGObject.gint);
-
if (!gdk_window_new)
throw "gdk_window_new is unavailable";
-
return gdk_window_new;
});
@@ -125,10 +153,8 @@ XPCOMUtils.defineLazyGetter(this, "gdk_window_destroy", function() {
ctypes.default_abi,
ctypes.void_t,
GdkWindow.ptr);
-
if (!gdk_window_destroy)
throw "gdk_window_destroy is unavailable";
-
return gdk_window_destroy;
});
@@ -139,10 +165,8 @@ XPCOMUtils.defineLazyGetter(this, "gdk_x11_window_set_user_time", function() {
ctypes.void_t,
GdkWindow.ptr,
LibGObject.guint32);
-
if (!gdk_x11_window_set_user_time)
throw "gdk_x11_window_set_user_time is unavailable";
-
return gdk_x11_window_set_user_time;
});
@@ -152,10 +176,8 @@ XPCOMUtils.defineLazyGetter(this, "gdk_window_hide", function() {
ctypes.default_abi,
ctypes.void_t,
GdkWindow.ptr);
-
if (!gdk_window_hide)
throw "gdk_window_hide is unavailable";
-
return gdk_window_hide;
});
@@ -166,10 +188,8 @@ XPCOMUtils.defineLazyGetter(this, "GdkScreen", function() {
XPCOMUtils.defineLazyGetter(this, "gdk_screen_get_default", function() {
var gdk_screen_get_default =
libgdkwindow.declare("gdk_screen_get_default", ctypes.default_abi, GdkScreen.ptr);
-
if (!gdk_screen_get_default)
throw "gdk_screen_get_default is unavailable";
-
return gdk_screen_get_default;
});
@@ -178,14 +198,75 @@ XPCOMUtils.defineLazyGetter(this, "gdk_screen_get_toplevel_windows", function()
"gdk_screen_get_toplevel_windows", ctypes.default_abi, LibGObject.GList.ptr,
GdkScreen.ptr
);
-
if (!gdk_screen_get_toplevel_windows)
throw "gdk_screen_get_toplevel_windows is unavailable";
-
return gdk_screen_get_toplevel_windows;
});
+XPCOMUtils.defineLazyGetter(this, "gdk_pixbuf_new_from_file", function() {
+ var gdk_pixbuf_new_from_file = libgdkwindow.declare(
+ "gdk_pixbuf_new_from_file", ctypes.default_abi, GdkPixbuf.ptr,
+ LibGObject.gchar.ptr, LibGLib.GError.ptr.ptr
+ );
+ if (!gdk_pixbuf_new_from_file)
+ throw "gdk_pixbuf_new_from_file is unavailable";
+ return gdk_pixbuf_new_from_file;
+});
+
+XPCOMUtils.defineLazyGetter(this, "gdk_pixbuf_copy", function() {
+ var gdk_pixbuf_copy = libgdkwindow.declare(
+ "gdk_pixbuf_copy", ctypes.default_abi, GdkPixbuf.ptr,
+ GdkPixbuf.ptr
+ );
+ if (!gdk_pixbuf_copy)
+ throw "gdk_pixbuf_copy is unavailable";
+ return gdk_pixbuf_copy;
+});
+
+XPCOMUtils.defineLazyGetter(this, "gdk_pixbuf_get_width", function() {
+ var gdk_pixbuf_get_width = libgdkwindow.declare(
+ "gdk_pixbuf_get_width", ctypes.default_abi, ctypes.int,
+ GdkPixbuf.ptr
+ );
+ if (!gdk_pixbuf_get_width)
+ throw "gdk_pixbuf_get_width is unavailable";
+ return gdk_pixbuf_get_width;
+});
+
+XPCOMUtils.defineLazyGetter(this, "gdk_pixbuf_get_height", function() {
+ var gdk_pixbuf_get_height = libgdkwindow.declare(
+ "gdk_pixbuf_get_height", ctypes.default_abi, ctypes.int,
+ GdkPixbuf.ptr
+ );
+ if (!gdk_pixbuf_get_height)
+ throw "gdk_pixbuf_get_height is unavailable";
+ return gdk_pixbuf_get_height;
+});
+
+XPCOMUtils.defineLazyGetter(this, "gdk_pixbuf_composite", function() {
+ var gdk_pixbuf_composite = libgdkwindow.declare(
+ "gdk_pixbuf_composite", ctypes.default_abi, ctypes.void_t,
+ GdkPixbuf.ptr, GdkPixbuf.ptr, ctypes.int, ctypes.int, ctypes.int, ctypes.int,
+ ctypes.double, ctypes.double, ctypes.double, ctypes.double,
+ ctypes.int, ctypes.int
+ );
+ if (!gdk_pixbuf_composite)
+ throw "gdk_pixbuf_composite is unavailable";
+ return gdk_pixbuf_composite;
+});
+
+XPCOMUtils.defineLazyGetter(this, "gdk_screen_get_system_colormap", function() {
+ var gdk_screen_get_system_colormap = libgdkwindow.declare(
+ "gdk_screen_get_system_colormap", ctypes.default_abi, GdkColormap.ptr,
+ GdkScreen.ptr
+ );
+ if (!gdk_screen_get_system_colormap)
+ throw "gdk_screen_get_system_colormap is unavailable";
+ return gdk_screen_get_system_colormap;
+});
+
var LibGdkWindow = {
+ GDK_INTERP_NEAREST: 1, // GdkInterpType
GdkWindow: GdkWindow,
GdkWindowAttributes: GdkWindowAttributes,
GdkScreen: GdkScreen,
@@ -194,5 +275,11 @@ var LibGdkWindow = {
GdkWindowDestroy: gdk_window_destroy,
GdkWindowHide: gdk_window_hide,
GdkScreenGetDefault: gdk_screen_get_default,
- GdkScreenGetToplevelWindows: gdk_screen_get_toplevel_windows
+ GdkScreenGetToplevelWindows: gdk_screen_get_toplevel_windows,
+ gdk_pixbuf_new_from_file: gdk_pixbuf_new_from_file,
+ gdk_pixbuf_copy: gdk_pixbuf_copy,
+ gdk_pixbuf_get_width: gdk_pixbuf_get_width,
+ gdk_pixbuf_get_height: gdk_pixbuf_get_height,
+ gdk_pixbuf_composite: gdk_pixbuf_composite,
+ gdk_screen_get_system_colormap: gdk_screen_get_system_colormap,
}
diff --git a/src/modules/MoztIconLinux.jsm b/src/modules/MoztIconLinux.jsm
index ac39221..eb877a4 100644
--- a/src/modules/MoztIconLinux.jsm
+++ b/src/modules/MoztIconLinux.jsm
@@ -9,6 +9,7 @@ const Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/ctypes.jsm");
Cu.import("resource://moztray/LibGObject.jsm");
+Cu.import("resource://moztray/LibGdkWindow.jsm");
Cu.import("resource://moztray/LibGtkStatusIcon.jsm");
Cu.import("resource://moztray/commons.js");
@@ -76,6 +77,11 @@ mozt.IconLinux = {
LibGObject.g_signal_connect(this.trayIcon, "activate",
mozt_iconActivateCb, null);
+
+ // TEST
+ let special_icon =
+ LibGdkWindow.gdk_pixbuf_new_from_file("newmail.png" , null); // gerror ignored
+
} catch (x) {
Components.utils.reportError(x);
return false;
@@ -118,6 +124,87 @@ mozt.IconLinux = {
if (!this.appName)
throw "application name not initialized";
this.setTooltip(this.appName);
+ },
+
+ 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;
+ // }
+
+ // GdkPixbuf *renderTextWithAlpha(int w, int h, gchar *text, const gchar *colorstr)
+ // {
+ // GdkColormap* cmap=gdk_screen_get_system_colormap(gdk_screen_get_default())
+ // int screen_depth=24;
+ // if(cmap) screen_depth=cmap->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);
+ // 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;
+ // }
+
}; // mozt.IconLinux
--
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