[Pkg-mozext-commits] [firetray] 351/399: example of using libfirtray to display gtk version

David Prévot taffit at alioth.debian.org
Tue Oct 29 18:24:12 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 270807380d1f35ea8e7cba38f98239f5ec42d317
Author: foudfou <foudil.newbie+git at gmail.com>
Date:   Thu Mar 21 01:09:08 2013 +0100

    example of using libfirtray to display gtk version
---
 src/chrome.manifest                  |    1 +
 src/lib/linux/Makefile               |    6 ++---
 src/lib/linux/firetray.c             |    4 +++
 src/lib/linux/firetray.h             |    8 ++++++
 src/modules/ctypes/libfiretray.jsm   |   45 +++++++++++++++++++++++++++++++---
 src/modules/linux/FiretrayWindow.jsm |    7 ++++++
 testing/Makefile                     |   20 +++++++++------
 testing/gtk-version.c                |   13 ++++++++++
 8 files changed, 89 insertions(+), 15 deletions(-)

diff --git a/src/chrome.manifest b/src/chrome.manifest
index 2ce3ab7..8a86e6f 100644
--- a/src/chrome.manifest
+++ b/src/chrome.manifest
@@ -3,6 +3,7 @@ skin		firetray	classic/1.0	chrome/skin/
 locale		firetray	en-US		chrome/locale/en-US/
 locale		firetray	sk-SK		chrome/locale/sk-SK/
 resource	firetray			modules/
+resource	firetray-lib			lib/linux/firetray_x86_64-gcc4.so	abi=Linux_x86_64-gcc3
 
 overlay	chrome://browser/content/browser.xul	chrome://firetray/content/overlay.xul
 overlay	chrome://messenger/content/messenger.xul	chrome://firetray/content/overlay.xul
diff --git a/src/lib/linux/Makefile b/src/lib/linux/Makefile
index 84fe586..864147f 100644
--- a/src/lib/linux/Makefile
+++ b/src/lib/linux/Makefile
@@ -14,13 +14,11 @@ libs = firetray_$(platform)-gcc$(GCCVERSION).so
 all: $(libs)
 	@echo
 	@echo add this line to chrome.manifest:
-	@echo "resource	firetray-lib			lib/linux/$(libs)"
+	@echo "resource	firetray-lib			lib/linux/$(libs)	abi=Linux_x86_64-gcc3"
 	@echo
 	@echo and use
 	@echo 'Cu.import("resource://firetray/ctypes/libfiretray.jsm");'
-	@echo 'libfiretray.init();'
-	@echo '//...'
-	@echo 'libfiretray.shutdown();'
+	@echo 'firetray.Handler.subscribeLibsForClosing([libfiretray]);'
 	@echo
 
 $(libs): firetray.o
diff --git a/src/lib/linux/firetray.c b/src/lib/linux/firetray.c
index e1a09a4..d63e619 100644
--- a/src/lib/linux/firetray.c
+++ b/src/lib/linux/firetray.c
@@ -14,3 +14,7 @@ int gtk_is_window(void* obj) {
 int gtk_is_widget(void* obj) {
   return GTK_IS_WIDGET(obj) ? 1 : 0;
 }
+
+unsigned int gtk_get_major_version(void) {return (unsigned int)gtk_major_version;}
+unsigned int gtk_get_minor_version(void) {return (unsigned int)gtk_minor_version;}
+unsigned int gtk_get_micro_version(void) {return (unsigned int)gtk_micro_version;}
diff --git a/src/lib/linux/firetray.h b/src/lib/linux/firetray.h
index f393184..ba6fd5e 100644
--- a/src/lib/linux/firetray.h
+++ b/src/lib/linux/firetray.h
@@ -1,3 +1,11 @@
+#include <gdk/gdk.h>
+
 extern int gdk_is_window(void* obj);
 extern int gtk_is_window(void* obj);
 extern int gtk_is_widget(void* obj);
+
+/* the library version (not headers). These functions are provided natively in
+ * gtk+-3.0 */
+extern unsigned int gtk_get_major_version(void);
+extern unsigned int gtk_get_minor_version(void);
+extern unsigned int gtk_get_micro_version(void);
diff --git a/src/modules/ctypes/libfiretray.jsm b/src/modules/ctypes/libfiretray.jsm
index 80ce05b..1f94787 100644
--- a/src/modules/ctypes/libfiretray.jsm
+++ b/src/modules/ctypes/libfiretray.jsm
@@ -9,18 +9,36 @@ const Cu = Components.utils;
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://firetray/logging.jsm");
 
+let log = firetray.Logging.getLogger("firetray.libfiretray");
+
 const _path = (function(){
   var uri = Services.io.newURI('resource://firetray-lib', null, null);
-  if (uri instanceof Ci.nsIFileURL)
-    return uri.file.path;
-  throw new Error("path not resolved");
+  path = null;
+  try {
+    if (uri instanceof Ci.nsIFileURL)
+      path = uri.file.path;
+  } catch(error) {
+    log.error(error);
+    throw new Error("path not resolved");
+  }
+  return path;
 })();
 
+/*
+ * the firetray is not a standard lib, with standard naming, so we have to
+ * mimic ctypes-utils
+ */
 var libfiretray = {
 
   _lib: null,
+  name: 'libfiretray',
+  _available: false,
+  available: function(){return this._available;}, // compliance with ctypes-utils
 
   init: function() {
+    log.info("__URI__1="+this.__URI__);
+    log.info("__URI__2="+this.global.__URI__);
+
     // If ctypes doesn't exist, try to get it
     Cu.import("resource://gre/modules/ctypes.jsm");
     // If we still don't have ctypes, this isn't going to work...
@@ -41,20 +59,41 @@ var libfiretray = {
       throw(e);
     }
 
+    this._available = true;
+
     // Ok, we got everything - let's declare.
     this._declare();
   },
 
   shutdown: function() {
+    log.debug("Closing library " + this.name);
     // Close our connection to the library.
     if (this._lib)
       this._lib.close();
+
+    this._available = false;
+
+    if (!("__URI__" in this.global) || !this.global.__URI__) {
+      // We could have already been unloaded by now
+      return;
+    }
+
+    log.debug("Unloading JS module " + this.global.__URI__);
+    Cu.unload(this.global.__URI__);
   },
 
   _declare: function() {
     this.gdk_is_window = this._lib.declare("gdk_is_window", ctypes.default_abi, ctypes.int, ctypes.void_t.ptr);
     this.gtk_is_window = this._lib.declare("gtk_is_window", ctypes.default_abi, ctypes.int, ctypes.void_t.ptr);
     this.gtk_is_widget = this._lib.declare("gtk_is_widget", ctypes.default_abi, ctypes.int, ctypes.void_t.ptr);
+    this.gtk_get_major_version = this._lib.declare("gtk_get_major_version", ctypes.default_abi, ctypes.unsigned_int);
+    this.gtk_get_minor_version = this._lib.declare("gtk_get_minor_version", ctypes.default_abi, ctypes.unsigned_int);
+    this.gtk_get_micro_version = this._lib.declare("gtk_get_micro_version", ctypes.default_abi, ctypes.unsigned_int);
   }
 
 };
+libfiretray.global = this;
+
+libfiretray.close = libfiretray.shutdown; // compliance with ctypes-utils
+
+libfiretray.init();
diff --git a/src/modules/linux/FiretrayWindow.jsm b/src/modules/linux/FiretrayWindow.jsm
index 78832e4..acb2a31 100644
--- a/src/modules/linux/FiretrayWindow.jsm
+++ b/src/modules/linux/FiretrayWindow.jsm
@@ -68,6 +68,13 @@ firetray.Window = {
     if (!gtkVersionCheck.isNull())
       log.error("gtk_check_version="+gtkVersionCheck.readString());
 
+    Cu.import("resource://firetray/ctypes/libfiretray.jsm");
+    firetray.Handler.subscribeLibsForClosing([libfiretray]);
+    log.info("GTK VERSION="+
+             libfiretray.gtk_get_major_version()+"."+
+             libfiretray.gtk_get_minor_version()+"."+
+             libfiretray.gtk_get_micro_version());
+
     if (firetray.Handler.isChatEnabled()) {
       Cu.import("resource://firetray/FiretrayChat.jsm");
       Cu.import("resource://firetray/linux/FiretrayChatStatusIcon.jsm");
diff --git a/testing/Makefile b/testing/Makefile
index fac4438..8c94a14 100644
--- a/testing/Makefile
+++ b/testing/Makefile
@@ -1,6 +1,7 @@
-includes := $(shell pkg-config --libs --cflags gtk+-2.0)
+includes_gtk := $(shell pkg-config --libs --cflags gtk+-2.0)
+includes_gdk_gtk := $(shell pkg-config --libs --cflags gdk-2.0 gtk+-2.0)
 executables :=  gtk_icon_example trayicon hide xtypes x11XGetWindowProp \
-	window_state_event xev_desktop teststatusicon
+	window_state_event xev_desktop teststatusicon gtk-version
 
 .PHONY: all
 all: $(executables)
@@ -10,25 +11,28 @@ clean:
 	rm $(executables)
 
 gtk_icon_example: gtk_icon_example.c
-	gcc $(includes) -o gtk_icon_example gtk_icon_example.c
+	gcc $(includes_gtk) -o gtk_icon_example gtk_icon_example.c
 
 trayicon: trayicon.c
-	gcc $(includes) -o trayicon trayicon.c
+	gcc $(includes_gtk) -o trayicon trayicon.c
 
 hide: hide.c
-	gcc $(includes) -o hide hide.c
+	gcc $(includes_gtk) -o hide hide.c
 
 xtypes: xtypes.c
-	gcc $(includes) -o xtypes xtypes.c
+	gcc $(includes_gtk) -o xtypes xtypes.c
 
 x11XGetWindowProp: x11XGetWindowProp.c
 	gcc -Wall x11XGetWindowProp.c -o x11XGetWindowProp -lm -lXext -lX11
 
 window_state_event: window_state_event.c
-	gcc $(includes) -o window_state_event window_state_event.c
+	gcc $(includes_gtk) -o window_state_event window_state_event.c
 
 xev_desktop: xev_desktop.c
 	gcc -lXm -lXt -lX11 -o xev_desktop xev_desktop.c
 
 teststatusicon: teststatusicon.c prop-editor.c
-	gcc $(includes) -o teststatusicon teststatusicon.c prop-editor.c
+	gcc $(includes_gtk) -o teststatusicon teststatusicon.c prop-editor.c
+
+gtk-version: gtk-version.c ../src/lib/linux/firetray_x86_64-gcc4.so
+	gcc $(includes_gdk_gtk) ../src/lib/linux/firetray_x86_64-gcc4.so -o gtk-version gtk-version.c
diff --git a/testing/gtk-version.c b/testing/gtk-version.c
new file mode 100644
index 0000000..eb6c421
--- /dev/null
+++ b/testing/gtk-version.c
@@ -0,0 +1,13 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "../src/lib/linux/firetray.h"
+
+int main(int argc, char** argv) {
+  printf("gtk version: %d.%d.%d\n",
+         gtk_get_major_version(),
+         gtk_get_minor_version(),
+         gtk_get_micro_version()
+    );
+
+  return(EXIT_SUCCESS);
+}

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