1
0
mirror of https://github.com/moparisthebest/FireTray synced 2024-12-22 05:48:49 -05:00

example of using libfirtray to display gtk version

This commit is contained in:
foudfou 2013-03-21 01:09:08 +01:00
parent d91bfd1259
commit 270807380d
8 changed files with 89 additions and 15 deletions

View File

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

View File

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

View File

@ -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;}

View File

@ -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);

View File

@ -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();

View File

@ -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");

View File

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

13
testing/gtk-version.c Normal file
View File

@ -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);
}