[Pkg-mozext-commits] [firetray] 40/399: convert lib declarations to use ctypes-utils.jsm (Chris Coulson)

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 6737a670e5be2c9d85b0f3817a074dc73737611a
Author: foudfou <foudil.newbie+git at gmail.com>
Date:   Sat Sep 10 01:03:35 2011 +0200

    convert lib declarations to use ctypes-utils.jsm (Chris Coulson)
    
    grabbed from Mike Conley's messagingmenu extension
---
 src/modules/LibGLib.jsm          |   28 ----
 src/modules/LibGObject.jsm       |  238 -------------------------------
 src/modules/LibGdkWindow.jsm     |  285 --------------------------------------
 src/modules/LibGtkStatusIcon.jsm |  226 ------------------------------
 src/modules/MoztHandler.jsm      |   15 +-
 src/modules/MoztIconLinux.jsm    |   48 +++----
 src/modules/ctypes-utils.jsm     |  120 ++++++++++++++++
 src/modules/gdk.jsm              |  109 +++++++++++++++
 src/modules/glib.jsm             |   21 +++
 src/modules/gobject.jsm          |   92 ++++++++++++
 src/modules/gtk.jsm              |   85 ++++++++++++
 11 files changed, 459 insertions(+), 808 deletions(-)

diff --git a/src/modules/LibGLib.jsm b/src/modules/LibGLib.jsm
deleted file mode 100644
index d1eab4a..0000000
--- a/src/modules/LibGLib.jsm
+++ /dev/null
@@ -1,28 +0,0 @@
-/* -*- 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
deleted file mode 100644
index 3279f7c..0000000
--- a/src/modules/LibGObject.jsm
+++ /dev/null
@@ -1,238 +0,0 @@
-/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- *	 Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- * 
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is messagingmenu-extension
- *
- * The Initial Developer of the Original Code is
- * Mozilla Messaging, Ltd.
- * Portions created by the Initial Developer are Copyright (C) 2010
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *    Mike Conley <mconley at mozillamessaging.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- * 
- * ***** END LICENSE BLOCK ***** */
-
-var EXPORTED_SYMBOLS = ["LibGObject"];
-
-const LIB_GOBJECT = "libgobject-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, "libgobject", function() {
-  var libgobject = ctypes.open(LIB_GOBJECT);
-  if (!libgobject)
-    throw "libgobject is unavailable";
-
-  return libgobject;
-});
-
-XPCOMUtils.defineLazyGetter(this, "GCallback", function() {
-  return ctypes.void_t.ptr;
-});
-
-XPCOMUtils.defineLazyGetter(this, "gpointer", function() {
-  return ctypes.void_t.ptr;
-});
-
-XPCOMUtils.defineLazyGetter(this, "gulong", function() {
-  return ctypes.unsigned_long;
-});
-
-XPCOMUtils.defineLazyGetter(this, "guint", function() {
-  return ctypes.unsigned_int;
-});
-
-XPCOMUtils.defineLazyGetter(this, "guint32", function() {
-  return ctypes.uint32_t;
-});
-
-XPCOMUtils.defineLazyGetter(this, "guint16", function() {
-  return ctypes.uint16_t;
-});
-
-XPCOMUtils.defineLazyGetter(this, "gint", function() {
-  return ctypes.int;
-});
-
-XPCOMUtils.defineLazyGetter(this, "gchar", function() {
-  return ctypes.unsigned_char;
-});
-
-XPCOMUtils.defineLazyGetter(this, "gboolean", function() {
-  return gint;
-});
-
-XPCOMUtils.defineLazyGetter(this, "gfloat", function() {
-  return ctypes.float;
-});
-
-XPCOMUtils.defineLazyGetter(this, "GConnectFlags", function() {
-  return guint;
-});
-
-XPCOMUtils.defineLazyGetter(this, "GClosureNotify", function() {
-  return gpointer;
-});
-
-XPCOMUtils.defineLazyGetter(this, "GCallback_t", function() {
-  var GCallback_t =
-    ctypes.FunctionType(ctypes.default_abi,
-                        ctypes.void_t,
-                        [gpointer,
-                         guint,
-                         gpointer]).ptr;
-  if (!GCallback_t)
-    throw "GCallback_t is unavailable";
-
-  return GCallback_t;
-});
-
-XPCOMUtils.defineLazyGetter(this, "g_signal_connect_data", function() {
-  var g_signal_connect_data =
-    libgobject.declare("g_signal_connect_data",
-                   ctypes.default_abi,
-                   gulong,
-                   gpointer,    // instance
-                   gchar.ptr,   // detailed_signal
-                   GCallback,   // handler
-                   gpointer,    // data 
-                   GClosureNotify, // NULL
-                   GConnectFlags); // 0
-
-  if (!g_signal_connect_data)
-    throw "g_signal_connect_data is unavailable";
-
-  return g_signal_connect_data;
-});
-
-XPCOMUtils.defineLazyGetter(this, "g_object_unref", function() {
-  var g_object_unref =
-    libgobject.declare("g_object_unref",
-                   ctypes.default_abi,
-                   ctypes.void_t,
-                   gpointer);
-
-  if (!g_object_unref)
-    throw "g_object_unref is unavailable";
-
-  return g_object_unref;
-});
-
-
-XPCOMUtils.defineLazyGetter(this, "GFunc", function() {
-  return ctypes.void_t.ptr;
-});
-
-// intended for g_list_foreach.
-/* NOTE: if we needed more/different args, we'd need to implement another
-   FunctionType */
-XPCOMUtils.defineLazyGetter(this, "GFunc_t", function() {
-  var GFunc_t = ctypes.FunctionType(
-    ctypes.default_abi, ctypes.void_t,
-    [gpointer, gpointer]
-  ).ptr;
-  if (!GFunc_t)
-    throw "GFunc_t is unavailable";
-
-  return GFunc_t;
-});
-
-XPCOMUtils.defineLazyGetter(this, "GList", function() {
-  return ctypes.StructType("GList");
-});
-
-// void                g_list_free                         (GList *list);
-XPCOMUtils.defineLazyGetter(this, "g_list_free", function() {
-  var g_list_free = libgobject.declare(
-    "g_list_free", ctypes.default_abi, ctypes.void_t,
-    GList.ptr
-  );
-
-  if (!g_list_free)
-    throw "g_list_free is unavailable";
-
-  return g_list_free;
-});
-
-// guint               g_list_length                       (GList *list);
-XPCOMUtils.defineLazyGetter(this, "g_list_length", function() {
-  var g_list_length = libgobject.declare(
-    "g_list_length", ctypes.default_abi, guint,
-    GList.ptr
-  );
-
-  if (!g_list_length)
-    throw "g_list_length is unavailable";
-
-  return g_list_length;
-});
-
-XPCOMUtils.defineLazyGetter(this, "g_list_foreach", function() {
-  var g_list_foreach = libgobject.declare(
-    "g_list_foreach", ctypes.default_abi, ctypes.void_t,
-    GList.ptr,
-    GFunc, // func
-    gpointer // user_data
-  );
-
-  if (!g_list_foreach)
-    throw "g_list_foreach is unavailable";
-
-  return g_list_foreach;
-});
-
-var LibGObject = {
-  GCallback: GCallback,
-  GCallback_t: GCallback_t,
-  gpointer: gpointer,
-  gulong: gulong,
-  guint: guint,
-  guint32: guint32,
-  gint: gint,
-  gchar: gchar,
-  gboolean: gboolean,
-  GConnectFlags: GConnectFlags,
-  GClosureNotify: GClosureNotify,
-  g_object_unref: g_object_unref,
-
-  g_signal_connect: function(instance, detailed_signal, handler, data) {
-      return g_signal_connect_data(instance, detailed_signal,
-                                   handler, data, null, 0);
-  },
-
-  GList: GList,
-  GFunc: GFunc,
-  GFunc_t: GFunc_t,
-  g_list_free: g_list_free,
-  g_list_length: g_list_length,
-  g_list_foreach: g_list_foreach,
-};
diff --git a/src/modules/LibGdkWindow.jsm b/src/modules/LibGdkWindow.jsm
deleted file mode 100644
index 43a63f6..0000000
--- a/src/modules/LibGdkWindow.jsm
+++ /dev/null
@@ -1,285 +0,0 @@
-/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- *	 Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is messagingmenu-extension
- *
- * The Initial Developer of the Original Code is
- * Mozilla Messaging, Ltd.
- * Portions created by the Initial Developer are Copyright (C) 2010
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *    Mike Conley <mconley at mozillamessaging.com>
- *    Foudil Brétel <foudil.newbie+amo at gmail.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-var EXPORTED_SYMBOLS = ["LibGdkWindow"];
-
-const LIB_GDKWINDOW = "libgdk-x11-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");
-Cu.import("resource://moztray/LibGLib.jsm");
-Cu.import("resource://moztray/LibGObject.jsm");
-
-XPCOMUtils.defineLazyGetter(this, "libgdkwindow", function() {
-  var libgdkwindow = ctypes.open(LIB_GDKWINDOW);
-  if (!libgdkwindow)
-    throw "libgdkwindow is unavailable";
-
-  return libgdkwindow;
-});
-
-
-// Structures
-
-XPCOMUtils.defineLazyGetter(this, "GdkWindow", function() {
-  return ctypes.StructType("GdkWindow");
-});
-
-XPCOMUtils.defineLazyGetter(this, "GdkVisual", function() {
-  return ctypes.StructType("GdkVisual");
-});
-
-XPCOMUtils.defineLazyGetter(this, "GdkColormap", function() {
-  return ctypes.StructType("GdkColormap");
-});
-
-XPCOMUtils.defineLazyGetter(this, "GdkWindowType", function() {
-  return ctypes.StructType("GdkWindowType");
-});
-
-XPCOMUtils.defineLazyGetter(this, "GdkCursor", function() {
-  return ctypes.StructType("GdkCursor");
-});
-
-XPCOMUtils.defineLazyGetter(this, "GdkWindowTypeHint", function() {
-  return ctypes.StructType("GdkWindowTypeHint");
-});
-
-XPCOMUtils.defineLazyGetter(this, "GdkWindowClass", function() {
-  return ctypes.StructType("GdkWindowClass");
-});
-
-XPCOMUtils.defineLazyGetter(this, "GdkWindowAttributes", function() {
-  return ctypes.StructType("GdkWindowAttributes",
-                           [ { "title": LibGObject.gchar },
-                             { "event_mask": LibGObject.gint },
-                             { "x": LibGObject.gint },
-                             { "y": LibGObject.gint },
-                             { "width": LibGObject.gint },
-                             { "height": LibGObject.gint },
-                             { "wclass": LibGObject.gint },
-                             { "visual": GdkVisual.ptr },
-                             { "colormap": GdkColormap.ptr },
-                             { "window_type": LibGObject.gint },
-                             { "cursor": GdkCursor.ptr },
-                             { "wmclass_name": LibGObject.gchar },
-                             { "wmclass_class": LibGObject.gchar },
-                             { "override_redirect": LibGObject.gboolean },
-                             { "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",
-                         ctypes.default_abi,
-                         GdkWindow.ptr,
-                         GdkWindow.ptr,
-                         GdkWindowAttributes.ptr,
-                         LibGObject.gint);
-  if (!gdk_window_new)
-    throw "gdk_window_new is unavailable";
-  return gdk_window_new;
-});
-
-XPCOMUtils.defineLazyGetter(this, "gdk_window_destroy", function() {
-  var gdk_window_destroy =
-    libgdkwindow.declare("gdk_window_destroy",
-                         ctypes.default_abi,
-                         ctypes.void_t,
-                         GdkWindow.ptr);
-  if (!gdk_window_destroy)
-    throw "gdk_window_destroy is unavailable";
-  return gdk_window_destroy;
-});
-
-XPCOMUtils.defineLazyGetter(this, "gdk_x11_window_set_user_time", function() {
-  var gdk_x11_window_set_user_time =
-    libgdkwindow.declare("gdk_x11_window_set_user_time",
-                         ctypes.default_abi,
-                         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;
-});
-
-XPCOMUtils.defineLazyGetter(this, "gdk_window_hide", function() {
-  var gdk_window_hide =
-    libgdkwindow.declare("gdk_window_hide",
-                         ctypes.default_abi,
-                         ctypes.void_t,
-                         GdkWindow.ptr);
-  if (!gdk_window_hide)
-    throw "gdk_window_hide is unavailable";
-  return gdk_window_hide;
-});
-
-XPCOMUtils.defineLazyGetter(this, "GdkScreen", function() {
-  return ctypes.StructType("GdkScreen");
-});
-
-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;
-});
-
-XPCOMUtils.defineLazyGetter(this, "gdk_screen_get_toplevel_windows", function() {
-  var gdk_screen_get_toplevel_windows = libgdkwindow.declare(
-    "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,
-  GdkX11WindowSetUserTime: gdk_x11_window_set_user_time,
-  GdkWindowNew: gdk_window_new,
-  GdkWindowDestroy: gdk_window_destroy,
-  GdkWindowHide: gdk_window_hide,
-  GdkScreenGetDefault: gdk_screen_get_default,
-  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/LibGtkStatusIcon.jsm b/src/modules/LibGtkStatusIcon.jsm
deleted file mode 100644
index 0da7157..0000000
--- a/src/modules/LibGtkStatusIcon.jsm
+++ /dev/null
@@ -1,226 +0,0 @@
-/* -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-
-var EXPORTED_SYMBOLS = ["LibGtkStatusIcon"];
-
-const LIB_GTK = "libgtk-x11-2.0.so.0";
-
-const Cc = Components.classes;
-const Ci = Components.interfaces;
-const Cu = Components.utils;
-
-Cu.import("resource://gre/modules/XPCOMUtils.jsm");
-Cu.import("resource://gre/modules/ctypes.jsm");
-Cu.import("resource://moztray/LibGObject.jsm");
-Cu.import("resource://moztray/LibGdkWindow.jsm");
-
-
-XPCOMUtils.defineLazyGetter(this, "libgtk", function() {
-  var libgtk = ctypes.open(LIB_GTK);
-  if (!libgtk)
-    throw "libgtk is unavailable";
-  return libgtk;
-});
-
-
-// Structures
-
-XPCOMUtils.defineLazyGetter(this, "GCallback", function() {
-  return ctypes.void_t.ptr;
-});
-
-XPCOMUtils.defineLazyGetter(this, "GtkStatusIcon", function() {
-  return ctypes.StructType("GtkStatusIcon");
-});
-
-XPCOMUtils.defineLazyGetter(this, "GtkStyle", function() {
-  return ctypes.StructType("GtkStyle");
-});
-
-XPCOMUtils.defineLazyGetter(this, "GtkRequisition", function() {
-  return ctypes.StructType(
-    "GtkRequisition", [
-      { width: LibGObject.gint },
-      { height: LibGObject.gint }
-    ]);
-});
-
-XPCOMUtils.defineLazyGetter(this, "GtkAllocation", function() {
-  return  ctypes.StructType(
-    "GtkAllocation", [
-      { x: LibGObject.gint },
-      { y: LibGObject.gint },
-      { width: LibGObject.gint },
-      { height: LibGObject.gint }
-    ]);
-});
-
-/* NOTE: recursive struct needs define() and included structs MUST be
- * defined ! */
-XPCOMUtils.defineLazyGetter(this, "GtkWidget", function() {
-  var GtkWidget = ctypes.StructType("GtkWidget");
-  GtkWidget.define([
-    { "style": GtkStyle.ptr },
-    { "requisition": GtkRequisition },
-    { "allocation": GtkAllocation },
-    { "window": LibGdkWindow.GdkWindow.ptr },
-    { "parent": GtkWidget.ptr }
-  ]);
-  return GtkWidget;
-});
-
-XPCOMUtils.defineLazyGetter(this, "GtkMenu", function() {
-  return ctypes.StructType("GtkMenu");
-});
-
-// use ctypes.cast(menu, LibGtkStatusIcon.GtkMenuShell.ptr);
-XPCOMUtils.defineLazyGetter(this, "GtkMenuShell", function() {
-  return ctypes.StructType("GtkMenuShell");
-});
-
-XPCOMUtils.defineLazyGetter(this, "GtkImageMenuItem", function() {
-  return ctypes.StructType("GtkImageMenuItem");
-});
-
-XPCOMUtils.defineLazyGetter(this, "GtkMenuPositionFunc", function() {
-  return ctypes.FunctionType(
-    ctypes.default_abi, ctypes.void_t,
-    [GtkMenu.ptr, LibGObject.gint.ptr, LibGObject.gint.ptr,
-     LibGObject.gboolean.ptr, LibGObject.gpointer]).ptr;
-});
-
-XPCOMUtils.defineLazyGetter(this, "GCallbackMenuPopup_t", function() {
-  return ctypes.FunctionType(
-    ctypes.default_abi, ctypes.void_t,
-    [GtkStatusIcon.ptr, LibGObject.guint, LibGObject.guint,
-     LibGObject.gpointer]).ptr;
-});
-
-
-// Functions
-
-XPCOMUtils.defineLazyGetter(this, "gtk_status_icon_new", function() {
-  var gtk_status_icon_new = libgtk.declare(
-      "gtk_status_icon_new", ctypes.default_abi, GtkStatusIcon.ptr);
-  if (!gtk_status_icon_new)
-    throw "gtk_status_icon_new is unavailable";
-  return gtk_status_icon_new;
-});
-
-XPCOMUtils.defineLazyGetter(this, "gtk_status_icon_set_from_file", function() {
-  var gtk_status_icon_set_from_file = libgtk.declare(
-      "gtk_status_icon_set_from_file", ctypes.default_abi, ctypes.void_t,
-      GtkStatusIcon.ptr, ctypes.char.ptr);
-  if (!gtk_status_icon_set_from_file)
-    throw "gtk_status_icon_set_from_file is unavailable";
-  return gtk_status_icon_set_from_file;
-});
-
-XPCOMUtils.defineLazyGetter(this, "gtk_status_icon_set_tooltip_text", function() {
-  var gtk_status_icon_set_tooltip_text = libgtk.declare(
-    "gtk_status_icon_set_tooltip_text", ctypes.default_abi, ctypes.void_t,
-    GtkStatusIcon.ptr, ctypes.char.ptr);
-  if (!gtk_status_icon_set_tooltip_text)
-    throw "gtk_status_icon_set_tooltip_text unavailable";
-  return gtk_status_icon_set_tooltip_text;
-});
-
-XPCOMUtils.defineLazyGetter(this, "gtk_menu_new", function() {
-  var gtk_menu_new = libgtk.declare(
-    "gtk_menu_new", ctypes.default_abi, GtkMenu.ptr);
-  if (!gtk_menu_new)
-    throw "gtk_menu_new is unavailable";
-  return gtk_menu_new;
-});
-
-XPCOMUtils.defineLazyGetter(this, "gtk_image_menu_item_new_with_label", function() {
-  var gtk_image_menu_item_new_with_label = libgtk.declare(
-    "gtk_image_menu_item_new_with_label", ctypes.default_abi, GtkImageMenuItem.ptr,
-    LibGObject.gchar.ptr);
-  if (!gtk_image_menu_item_new_with_label)
-    throw "gtk_image_menu_item_new_with_label is unavailable";
-  return gtk_image_menu_item_new_with_label;
-});
-
-XPCOMUtils.defineLazyGetter(this, "gtk_image_new_from_stock", function() {
-  var gtk_image_new_from_stock = libgtk.declare(
-    "gtk_image_new_from_stock", ctypes.default_abi, GtkWidget.ptr,
-    LibGObject.gchar.ptr, ctypes.int); // enum
-  if (!gtk_image_new_from_stock)
-    throw "gtk_image_new_from_stock is unavailable";
-  return gtk_image_new_from_stock;
-});
-
-XPCOMUtils.defineLazyGetter(this, "gtk_image_menu_item_set_image", function() {
-  var gtk_image_menu_item_set_image = libgtk.declare(
-    "gtk_image_menu_item_set_image", ctypes.default_abi, ctypes.void_t,
-    GtkImageMenuItem.ptr, GtkWidget.ptr);
-  if (!gtk_image_menu_item_set_image)
-    throw "gtk_image_menu_item_set_image is unavailable";
-  return gtk_image_menu_item_set_image;
-});
-
-XPCOMUtils.defineLazyGetter(this, "gtk_menu_shell_append", function() {
-  var gtk_menu_shell_append = libgtk.declare(
-    "gtk_menu_shell_append", ctypes.default_abi, ctypes.void_t,
-    GtkMenuShell.ptr, GtkImageMenuItem.ptr);
-  if (!gtk_menu_shell_append)
-    throw "gtk_menu_shell_append is unavailable";
-  return gtk_menu_shell_append;
-});
-
-XPCOMUtils.defineLazyGetter(this, "gtk_widget_show_all", function() {
-  var gtk_widget_show_all = libgtk.declare(
-    "gtk_widget_show_all", ctypes.default_abi, ctypes.void_t,
-    GtkWidget.ptr);
-  if (!gtk_widget_show_all)
-    throw "gtk_widget_show_all is unavailable";
-  return gtk_widget_show_all;
-});
-
-XPCOMUtils.defineLazyGetter(this, "gtk_menu_popup", function() {
-  var gtk_menu_popup = libgtk.declare(
-    "gtk_menu_popup", ctypes.default_abi, ctypes.void_t,
-    GtkMenu.ptr, GtkWidget.ptr, GtkWidget.ptr,
-    GtkMenuPositionFunc, LibGObject.gpointer, LibGObject.guint,
-    LibGObject.guint);
-  if (!gtk_menu_popup)
-    throw "gtk_menu_popup is unavailable is unavailable";
-  return gtk_menu_popup;
-});
-
-XPCOMUtils.defineLazyGetter(this, "gtk_status_icon_position_menu", function() {
-  var gtk_status_icon_position_menu = libgtk.declare(
-    "gtk_status_icon_position_menu", ctypes.default_abi, ctypes.void_t,
-    GtkMenu.ptr, LibGObject.gint.ptr, LibGObject.gint.ptr,
-    LibGObject.gboolean.ptr, LibGObject.gpointer);
-  if (!gtk_status_icon_position_menu)
-    throw "gtk_status_icon_position_menu is unavailable";
-  return gtk_status_icon_position_menu;
-});
-
-var LibGtkStatusIcon = {
-  GTK_ICON_SIZE_MENU: 1,
-  libgtk: libgtk,
-  GCallback: GCallback,
-  GtkStatusIcon: GtkStatusIcon,
-  GtkStyle: GtkStyle,
-  GtkRequisition: GtkRequisition,
-  GtkAllocation: GtkAllocation,
-  GtkWidget: GtkWidget,
-  GtkMenu: GtkMenu,
-  GtkMenuShell: GtkMenuShell,
-  GtkImageMenuItem: GtkImageMenuItem,
-  GtkMenuPositionFunc: GtkMenuPositionFunc,
-  GCallbackMenuPopup_t: GCallbackMenuPopup_t,
-  gtk_status_icon_new: gtk_status_icon_new,
-  gtk_status_icon_set_from_file: gtk_status_icon_set_from_file,
-  gtk_status_icon_set_tooltip_text: gtk_status_icon_set_tooltip_text,
-  gtk_menu_new: gtk_menu_new,
-  gtk_image_menu_item_new_with_label: gtk_image_menu_item_new_with_label,
-  gtk_image_new_from_stock: gtk_image_new_from_stock,
-  gtk_image_menu_item_set_image: gtk_image_menu_item_set_image,
-  gtk_menu_shell_append: gtk_menu_shell_append,
-  gtk_widget_show_all: gtk_widget_show_all,
-  gtk_menu_popup: gtk_menu_popup,
-  gtk_status_icon_position_menu: gtk_status_icon_position_menu
-};
diff --git a/src/modules/MoztHandler.jsm b/src/modules/MoztHandler.jsm
index 3d1fce6..33810f8 100644
--- a/src/modules/MoztHandler.jsm
+++ b/src/modules/MoztHandler.jsm
@@ -8,8 +8,8 @@ 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/LibGtkStatusIcon.jsm");
+Cu.import("resource://moztray/gobject.jsm");
+Cu.import("resource://moztray/gtk.jsm");
 Cu.import("resource://moztray/commons.js");
 
 /**
@@ -77,7 +77,7 @@ mozt.Handler = {
     }
   },
 
-  // FIXME: parameters may not be needed !! see LibGObject.GCallback_t
+  // FIXME: parameters may not be needed !! see gobject.GCallback_t
   showHideToTray: function(a1, a2, a3) {
     LOG("showHideToTray");
 
@@ -144,10 +144,11 @@ mozt.Handler = {
     LOG("ARGS="+icon+", "+button+", "+activateTime+", "+menu);
 
     try {
-      var gtkMenuPtr = ctypes.cast(menu, LibGtkStatusIcon.GtkMenu.ptr);
-      var iconGpointer = ctypes.cast(icon, LibGObject.gpointer);
-      LibGtkStatusIcon.gtk_menu_popup(
-        gtkMenuPtr, null, null, LibGtkStatusIcon.gtk_status_icon_position_menu,
+      // TODO: move to MoztIconLinux
+      var gtkMenuPtr = ctypes.cast(menu, gtk.GtkMenu.ptr);
+      var iconGpointer = ctypes.cast(icon, gobject.gpointer);
+      gtk.gtk_menu_popup(
+        gtkMenuPtr, null, null, gtk.gtk_status_icon_position_menu,
         iconGpointer, button, activateTime);
     } catch (x) {
       LOG(x);
diff --git a/src/modules/MoztIconLinux.jsm b/src/modules/MoztIconLinux.jsm
index eb877a4..5b3bf39 100644
--- a/src/modules/MoztIconLinux.jsm
+++ b/src/modules/MoztIconLinux.jsm
@@ -8,9 +8,9 @@ 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/gobject.jsm");
+Cu.import("resource://moztray/gdk.jsm");
+Cu.import("resource://moztray/gtk.jsm");
 Cu.import("resource://moztray/commons.js");
 
 if ("undefined" == typeof(mozt.Handler))
@@ -34,7 +34,7 @@ mozt.IconLinux = {
     try {
 
       // init tray icon, some variables
-      this.trayIcon  = LibGtkStatusIcon.gtk_status_icon_new();
+      this.trayIcon  = gtk.gtk_status_icon_new();
       this.appName = Services.appinfo.name.toLowerCase();
       this.ICON_FILENAME_DEFAULT = mozt.Utils.chromeToPath(
         "chrome://moztray/skin/" +  this.appName + this.ICON_SUFFIX);
@@ -42,45 +42,45 @@ mozt.IconLinux = {
       this.setDefaultImage();
 
       // build icon popup menu
-      this.menu = LibGtkStatusIcon.gtk_menu_new();
+      this.menu = gtk.gtk_menu_new();
       // shouldn't need to convert to utf8 thank to js-ctypes
 		  var menuItemQuitLabel = mozt.Utils.strings.GetStringFromName("popupMenu.itemLabel.Quit");
-      var menuItemQuit = LibGtkStatusIcon.gtk_image_menu_item_new_with_label(
+      var menuItemQuit = gtk.gtk_image_menu_item_new_with_label(
         menuItemQuitLabel);
-      var menuItemQuitIcon = LibGtkStatusIcon.gtk_image_new_from_stock(
-        "gtk-quit", LibGtkStatusIcon.GTK_ICON_SIZE_MENU);
-      LibGtkStatusIcon.gtk_image_menu_item_set_image(menuItemQuit, menuItemQuitIcon);
-      var menuShell = ctypes.cast(this.menu, LibGtkStatusIcon.GtkMenuShell.ptr);
-      LibGtkStatusIcon.gtk_menu_shell_append(menuShell, menuItemQuit);
+      var menuItemQuitIcon = gtk.gtk_image_new_from_stock(
+        "gtk-quit", gtk.GTK_ICON_SIZE_MENU);
+      gtk.gtk_image_menu_item_set_image(menuItemQuit, menuItemQuitIcon);
+      var menuShell = ctypes.cast(this.menu, gtk.GtkMenuShell.ptr);
+      gtk.gtk_menu_shell_append(menuShell, menuItemQuit);
 
-      mozt_menuItemQuitActivateCb = LibGObject.GCallback_t(
+      mozt_menuItemQuitActivateCb = gobject.GCallback_t(
         function(){mozt.Handler.quitApplication();});
-      LibGObject.g_signal_connect(menuItemQuit, "activate",
+      gobject.g_signal_connect(menuItemQuit, "activate",
                                   mozt_menuItemQuitActivateCb, null);
 
-      var menuWidget = ctypes.cast(this.menu, LibGtkStatusIcon.GtkWidget.ptr);
-      LibGtkStatusIcon.gtk_widget_show_all(menuWidget);
+      var menuWidget = ctypes.cast(this.menu, gtk.GtkWidget.ptr);
+      gtk.gtk_widget_show_all(menuWidget);
 
       // here we do use a function handler because we need the args passed to
       // it ! But we need to abandon 'this' in popupMenu()
       mozt_popupMenuCb =
-        LibGtkStatusIcon.GCallbackMenuPopup_t(mozt.Handler.popupMenu);
-      LibGObject.g_signal_connect(this.trayIcon, "popup-menu",
+        gtk.GCallbackMenuPopup_t(mozt.Handler.popupMenu);
+      gobject.g_signal_connect(this.trayIcon, "popup-menu",
                                   mozt_popupMenuCb, this.menu);
 
       this.setDefaultTooltip();
 
       // watch out for binding problems ! here we prefer to keep 'this' in
       // showHideToTray() and abandon the args.
-      mozt_iconActivateCb = LibGObject.GCallback_t(
+      mozt_iconActivateCb = gobject.GCallback_t(
         function(){mozt.Handler.showHideToTray();});
-      LibGObject.g_signal_connect(this.trayIcon, "activate",
+      gobject.g_signal_connect(this.trayIcon, "activate",
                                   mozt_iconActivateCb, null);
 
 
       // TEST
       let special_icon =
-        LibGdkWindow.gdk_pixbuf_new_from_file("newmail.png" , null); // gerror ignored
+        gdk.gdk_pixbuf_new_from_file("newmail.png" , null); // gerror ignored
 
     } catch (x) {
       Components.utils.reportError(x);
@@ -96,8 +96,8 @@ mozt.IconLinux = {
     LOG(filename);
 
     try {
-      LibGtkStatusIcon.gtk_status_icon_set_from_file(this.trayIcon,
-                                                     filename);
+      gtk.gtk_status_icon_set_from_file(this.trayIcon,
+                                        filename);
     } catch (x) {
       ERROR(x);
       return false;
@@ -115,8 +115,8 @@ mozt.IconLinux = {
   setTooltip: function(toolTipStr) {
     if (!this.trayIcon)
       return false;
-    LibGtkStatusIcon.gtk_status_icon_set_tooltip_text(this.trayIcon,
-                                                      toolTipStr);
+    gtk.gtk_status_icon_set_tooltip_text(this.trayIcon,
+                                         toolTipStr);
     return true;
   },
 
diff --git a/src/modules/ctypes-utils.jsm b/src/modules/ctypes-utils.jsm
new file mode 100644
index 0000000..73c9321
--- /dev/null
+++ b/src/modules/ctypes-utils.jsm
@@ -0,0 +1,120 @@
+/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ *	 Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ * 
+ * The Original Code is Moztray
+ *
+ * The Initial Developer of the Original Code is
+ * Mozilla Messaging, Ltd.
+ * Portions created by the Initial Developer are Copyright (C) 2011
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *    Chris Coulson <chris.coulson at canonical.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+const Cu = Components.utils;
+
+Cu.import("resource://gre/modules/ctypes.jsm");
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+var EXPORTED_SYMBOLS  = [ "ctypes_library" ];
+
+["LOG", "WARN", "ERROR"].forEach(function(aName) {
+  this.__defineGetter__(aName, function() {
+    Components.utils.import("resource://gre/modules/AddonLogging.jsm");
+    LogManager.getLogger("moztray", this);
+    return this[aName];
+  });
+}, this);
+
+function ctypes_library(name, abis, defines) {
+  try {
+    LOG("Loading library: " + name);
+    var library;
+    for each (let abi in abis) {
+      let soname = "lib" + name + ".so." + abi.toString();
+      LOG("Trying " + soname);
+      try {
+        library = ctypes.open(soname);
+        this.ABI = abi;
+        LOG("Successfully loaded " + soname);
+        break;
+      } catch(e) {}
+    }
+
+    this.close = function() {
+      library.close();
+      this.ABI = -1;
+    };
+
+    this.available = function() {
+      return this.ABI != -1;
+    };
+
+    if (!library) {
+      LOG("Failed to load library: " + name);
+      this.ABI = -1;
+      return;
+    }
+
+    var self = this;
+    let lib = {
+      declare: function() {
+        try {
+          args = [];
+          args.push(arguments[0]);
+          args.push(ctypes.default_abi);
+          for each (let arg in Array.prototype.slice.call(arguments, 1)) {
+            args.push(arg);
+          }
+
+          return library.declare.apply(library, args);
+        } catch (ex) {
+          ERROR("Missing symbol " + arguments[0] + " in library " + name);
+          self.ABI = -1;
+          return null;
+        }
+      },
+
+      lazy_bind: function() {
+        var args = Array.prototype.slice.call(arguments, 0);
+        XPCOMUtils.defineLazyGetter(self, arguments[0], function() {
+          return lib.declare.apply(lib, args);
+        });
+      },
+
+      bind_now: function() {
+        self[arguments[0]] = this.declare.apply(this, arguments);
+      }
+    };
+
+    defines.call(this, lib);
+  } catch(e) {
+    ERROR(name+" definition error: "+e);
+    this.ABI = -1;
+  }
+}
diff --git a/src/modules/gdk.jsm b/src/modules/gdk.jsm
new file mode 100644
index 0000000..bd36902
--- /dev/null
+++ b/src/modules/gdk.jsm
@@ -0,0 +1,109 @@
+/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ *	 Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Moztray
+ *
+ * The Initial Developer of the Original Code is
+ * Mozilla Messaging, Ltd.
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *    Mike Conley <mconley at mozillamessaging.com>
+ *    Foudil Brétel <foudil.newbie+amo at gmail.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+var EXPORTED_SYMBOLS = [ "gdk" ];
+
+const GDK_LIBNAME = "gdk-x11-2.0";
+const GDK_ABIS    = [ 0 ];
+
+const Cu = Components.utils;
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+
+Cu.import("resource://gre/modules/ctypes.jsm");
+Cu.import("resource://moztray/ctypes-utils.jsm");
+Cu.import("resource://moztray/glib.jsm");
+Cu.import("resource://moztray/gobject.jsm");
+
+function gdk_defines(lib) {
+  this.GDK_INTERP_NEAREST = 1, // GdkInterpType
+
+  this.GdkWindow = ctypes.StructType("GdkWindow");
+  this.GdkVisual = ctypes.StructType("GdkVisual");
+  this.GdkColor = ctypes.StructType("GdkColor"), [
+    { "pixel": gobject.guint32 },
+    { "red": gobject.guint16 },
+    { "green": gobject.guint16 },
+    { "blue": gobject.guint16 }
+  ];
+  this.GdkColormap = ctypes.StructType("GdkColormap", [
+    { "size": gobject.gint },
+    { "colors": this.GdkColor.ptr }
+  ]);
+  this.GdkWindowType = ctypes.StructType("GdkWindowType");
+  this.GdkCursor = ctypes.StructType("GdkCursor");
+  this.GdkWindowTypeHint = ctypes.StructType("GdkWindowTypeHint");
+  this.GdkWindowClass = ctypes.StructType("GdkWindowClass");
+  this.GdkWindowAttributes = ctypes.StructType("GdkWindowAttributes", [
+    { "title": gobject.gchar },
+    { "event_mask": gobject.gint },
+    { "x": gobject.gint },
+    { "y": gobject.gint },
+    { "width": gobject.gint },
+    { "height": gobject.gint },
+    { "wclass": gobject.gint },
+    { "visual": this.GdkVisual.ptr },
+    { "colormap": this.GdkColormap.ptr },
+    { "window_type": gobject.gint },
+    { "cursor": this.GdkCursor.ptr },
+    { "wmclass_name": gobject.gchar },
+    { "wmclass_class": gobject.gchar },
+    { "override_redirect": gobject.gboolean },
+    { "type_hint": gobject.gint }]);
+  this.GdkPixbuf = ctypes.StructType("GdkPixbuf");
+  this.GdkScreen = ctypes.StructType("GdkScreen");
+
+  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);
+  lib.lazy_bind("gdk_x11_window_set_user_time", ctypes.void_t, this.GdkWindow.ptr, gobject.guint32);
+  lib.lazy_bind("gdk_window_hide", ctypes.void_t, this.GdkWindow.ptr);
+  lib.lazy_bind("gdk_screen_get_default", this.GdkScreen.ptr);
+  lib.lazy_bind("gdk_screen_get_toplevel_windows", gobject.GList.ptr, this.GdkScreen.ptr);
+  lib.lazy_bind("gdk_pixbuf_new_from_file", this.GdkPixbuf.ptr, gobject.gchar.ptr, glib.GError.ptr.ptr);
+  lib.lazy_bind("gdk_pixbuf_copy", this.GdkPixbuf.ptr, this.GdkPixbuf.ptr);
+  lib.lazy_bind("gdk_pixbuf_get_width", ctypes.int, this.GdkPixbuf.ptr);
+  lib.lazy_bind("gdk_pixbuf_get_height", ctypes.int, this.GdkPixbuf.ptr);
+  lib.lazy_bind("gdk_pixbuf_composite", ctypes.void_t, this.GdkPixbuf.ptr, this.GdkPixbuf.ptr, ctypes.int, ctypes.int, ctypes.int, ctypes.int, ctypes.double, ctypes.double, ctypes.double, ctypes.double, ctypes.int, ctypes.int);
+  lib.lazy_bind("gdk_screen_get_system_colormap", this.GdkColormap.ptr, this.GdkScreen.ptr);
+
+}
+
+if (!gdk) {
+  var gdk = new ctypes_library(GDK_LIBNAME, GDK_ABIS, gdk_defines);
+}
diff --git a/src/modules/glib.jsm b/src/modules/glib.jsm
new file mode 100644
index 0000000..13d1f87
--- /dev/null
+++ b/src/modules/glib.jsm
@@ -0,0 +1,21 @@
+/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+var EXPORTED_SYMBOLS = [ "glib" ];
+
+const GLIB_LIBNAME = "glib-2.0";
+const GLIB_ABIS    = [ 0 ];
+
+const Cu = Components.utils;
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+
+Cu.import("resource://gre/modules/ctypes.jsm");
+Cu.import("resource://moztray/ctypes-utils.jsm");
+
+function glib_defines(lib) {
+  this.GError = ctypes.StructType("GError");
+};
+
+if (!glib) {
+  var glib = new ctypes_library(GLIB_LIBNAME, GLIB_ABIS, glib_defines);
+}
diff --git a/src/modules/gobject.jsm b/src/modules/gobject.jsm
new file mode 100644
index 0000000..25f7d11
--- /dev/null
+++ b/src/modules/gobject.jsm
@@ -0,0 +1,92 @@
+/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ *	 Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ * 
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Moztray
+ *
+ * The Initial Developer of the Original Code is
+ * Mozilla Messaging, Ltd.
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *    Mike Conley <mconley at mozillamessaging.com>
+ *    Foudil Brétel <foudil.newbie+amo at gmail.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ * 
+ * ***** END LICENSE BLOCK ***** */
+
+var EXPORTED_SYMBOLS = [ "gobject" ];
+
+const GOBJECT_LIBNAME = "gobject-2.0";
+const GOBJECT_ABIS = [ 0 ];
+
+const Cu = Components.utils;
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+
+Cu.import("resource://gre/modules/ctypes.jsm");
+Cu.import("resource://moztray/ctypes-utils.jsm");
+
+function gobject_defines(lib) {
+  this.gpointer = ctypes.voidptr_t;
+  this.gulong = ctypes.unsigned_long;
+  this.guint = ctypes.unsigned_int;
+  this.guint32 = ctypes.uint32_t;
+  this.guint16 = ctypes.uint16_t;
+  this.gint = ctypes.int;
+  this.gchar = ctypes.unsigned_char;
+  this.gboolean = this.gint;
+  this.gfloat = ctypes.float;
+  this.GCallback = ctypes.voidptr_t;
+  this.GClosureNotify = this.gpointer;
+  this.GConnectFlags = this.guint;
+  this.GFunc = ctypes.void_t.ptr;
+  this.GList = ctypes.StructType("GList");
+
+  /* NOTE: if we needed more/different args, we'd need to implement another
+     FunctionType */
+  this.GCallback_t = ctypes.FunctionType(
+    ctypes.default_abi, ctypes.void_t, [this.gpointer, this.guint, this.gpointer]).ptr;
+  // intended for g_list_foreach.
+  this.GFunc_t = ctypes.FunctionType(
+    ctypes.default_abi, ctypes.void_t, [this.gpointer, this.gpointer]).ptr;
+
+  lib.lazy_bind("g_object_unref", ctypes.void_t, this.gpointer);
+  lib.lazy_bind("g_signal_connect_data", this.gulong, this.gpointer, this.gchar.ptr, this.GCallback, this.gpointer, this.GClosureNotify, this.GConnectFlags);
+
+  this.g_signal_connect = function(instance, detailed_signal, handler, data) {
+    return this.g_signal_connect_data(instance, detailed_signal, handler, data, null, 0);
+  }
+
+  lib.lazy_bind("g_object_unref", ctypes.void_t, this.gpointer);
+  lib.lazy_bind("g_list_free", ctypes.void_t, this.GList.ptr);
+  lib.lazy_bind("g_list_length", this.guint, this.GList.ptr);
+  lib.lazy_bind("g_list_foreach", ctypes.void_t, this.GList.ptr, this.GFunc, this.gpointer);
+
+}
+
+if (!gobject) {
+  var gobject = new ctypes_library(GOBJECT_LIBNAME, GOBJECT_ABIS, gobject_defines);
+}
diff --git a/src/modules/gtk.jsm b/src/modules/gtk.jsm
new file mode 100644
index 0000000..0eca501
--- /dev/null
+++ b/src/modules/gtk.jsm
@@ -0,0 +1,85 @@
+/* -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+var EXPORTED_SYMBOLS = [ "gtk" ];
+
+const GTK_LIBNAME = "gtk-x11-2.0";
+const GTK_ABIS    = [ 0 ];
+
+const Cu = Components.utils;
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+
+Cu.import("resource://gre/modules/ctypes.jsm");
+Cu.import("resource://moztray/ctypes-utils.jsm");
+Cu.import("resource://moztray/gdk.jsm");
+Cu.import("resource://moztray/gobject.jsm");
+
+function gtk_defines(lib) {
+  this.GTK_ICON_SIZE_MENU = 1;
+
+  this.GtkStatusIcon = ctypes.StructType("GtkStatusIcon");
+  this.GtkStyle = ctypes.StructType("GtkStyle");
+  this.GtkRequisition = ctypes.StructType("GtkRequisition", [
+    { width: gobject.gint },
+    { height: gobject.gint }
+  ]);
+  this.GtkAllocation = ctypes.StructType("GtkAllocation", [
+    { x: gobject.gint },
+    { y: gobject.gint },
+    { width: gobject.gint },
+    { height: gobject.gint }
+  ]);
+  /* NOTE: recursive struct needs define() and included structs MUST be
+   * defined ! */
+  this.GtkWidget = ctypes.StructType("GtkWidget");
+  this.GtkWidget.define([
+    { "style": this.GtkStyle.ptr },
+    { "requisition": this.GtkRequisition },
+    { "allocation": this.GtkAllocation },
+    { "window": gdk.GdkWindow.ptr },
+    { "parent": this.GtkWidget.ptr }
+  ]);
+
+  this.GtkMenu = ctypes.StructType("GtkMenu");
+  // use ctypes.cast(menu, LibGtkStatusIcon.GtkMenuShell.ptr);
+  this.GtkMenuShell = ctypes.StructType("GtkMenuShell");
+  this.GtkImageMenuItem = ctypes.StructType("GtkImageMenuItem");
+
+  // FIXME: rename to "_t"
+  this.GtkMenuPositionFunc = ctypes.FunctionType(
+    ctypes.default_abi, ctypes.void_t,
+    [this.GtkMenu.ptr, gobject.gint.ptr, gobject.gint.ptr,
+     gobject.gboolean.ptr, gobject.gpointer]).ptr;
+  this.GCallbackMenuPopup_t = ctypes.FunctionType(
+    ctypes.default_abi, ctypes.void_t,
+    [this.GtkStatusIcon.ptr, gobject.guint, gobject.guint,
+     gobject.gpointer]).ptr;
+
+  lib.lazy_bind("gtk_status_icon_new", this.GtkStatusIcon.ptr);
+  lib.lazy_bind("gtk_status_icon_set_from_file", ctypes.void_t,
+                this.GtkStatusIcon.ptr, ctypes.char.ptr);
+  lib.lazy_bind("gtk_status_icon_set_tooltip_text", ctypes.void_t,
+                this.GtkStatusIcon.ptr, ctypes.char.ptr);
+  lib.lazy_bind("gtk_menu_new", this.GtkMenu.ptr);
+  lib.lazy_bind("gtk_image_menu_item_new_with_label", this.GtkImageMenuItem.ptr,
+                gobject.gchar.ptr);
+  lib.lazy_bind("gtk_image_new_from_stock", this.GtkWidget.ptr,
+                gobject.gchar.ptr, ctypes.int); // enum
+  lib.lazy_bind("gtk_image_menu_item_set_image", ctypes.void_t,
+                this.GtkImageMenuItem.ptr, this.GtkWidget.ptr);
+  lib.lazy_bind("gtk_menu_shell_append", ctypes.void_t,
+                this.GtkMenuShell.ptr, this.GtkImageMenuItem.ptr);
+  lib.lazy_bind("gtk_widget_show_all", ctypes.void_t, this.GtkWidget.ptr);
+  lib.lazy_bind("gtk_menu_popup", ctypes.void_t,
+                this.GtkMenu.ptr, this.GtkWidget.ptr, this.GtkWidget.ptr,
+                this.GtkMenuPositionFunc, gobject.gpointer, gobject.guint,
+                gobject.guint);
+  lib.lazy_bind("gtk_status_icon_position_menu", ctypes.void_t,
+                this.GtkMenu.ptr, gobject.gint.ptr, gobject.gint.ptr,
+                gobject.gboolean.ptr, gobject.gpointer);
+
+}
+
+if (!gtk) {
+  var gtk = new ctypes_library(GTK_LIBNAME, GTK_ABIS, gtk_defines);
+}

-- 
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