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

Merge branch 'hide'

Conflicts:
	src/chrome/content/overlay.js
	src/modules/LibGtkStatusIcon.js
This commit is contained in:
foudfou 2011-08-03 15:56:06 +02:00
commit 8e4e14c8f6
13 changed files with 1013 additions and 32 deletions

View File

@ -140,8 +140,9 @@ $(build_dir)/$(chrome_source_root)/%.js: $(chrome_source_root)/%.js
then \
cp -f $< $@; \
else \
echo "Stripping comments from JS file $<"; \
echo "Stripping debug calls from JS file $<"; \
sed '/mozt\.Debug\.dump/d' $< > $@; \
sed '/mozt\.Debug\.debug/d' $< > $@; \
fi
$(build_dir)/$(modules_dir)/commons.js: $(modules_dir)/commons.js

View File

@ -1,16 +1,120 @@
/* -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
Components.utils.import("resource://moztray/commons.js");
// TODO: Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource://gre/modules/ctypes.jsm");
Components.utils.import("resource://moztray/LibC.js");
Components.utils.import("resource://moztray/LibGObject.js");
Components.utils.import("resource://moztray/LibGtkStatusIcon.js");
Components.utils.import("resource://moztray/commons.js");
const MOZT_ICON_DIR = "chrome/skin/";
const MOZT_ICON_SUFFIX = "32.png";
/**
* mozt namespace.
*/
if ("undefined" == typeof(mozt)) {
var mozt = {};
};
mozt.Handler = {
_windowsHidden: false,
_getBaseWindow: function(win) {
var bw;
try { // thx Neil Deakin !!
bw = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShellTreeItem)
.treeOwner
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIBaseWindow);
} catch (ex) {
bw = null;
setTimeout(function() {throw ex; }, 0);
// ignore no-interface exception
}
return bw;
},
_getAllWindows: function() {
mozt.Debug.debug("_getAllWindows");
var baseWindows = new Array();
var e = mozt.Utils.windowMediator.getEnumerator(null);
while (e.hasMoreElements()) {
var w = e.getNext();
baseWindows[baseWindows.length] = this._getBaseWindow(w);
}
return baseWindows;
},
/*
* might need to remember position...
* var outX = {}, outY = {}, outCX = {}, outCY = {};
* bw.getPositionAndSize(outX, outY, outCX, outCY);
* mozt.Debug.debug("pos: "
* + outX.value + ", "
* + outY.value + ", "
* + outCX.value + ", "
* + outCY.value
* );
*/
showHideToTray: function(a1, a2, a3) {
mozt.Debug.debug("showHideToTray");
var baseWindows;
try {
baseWindows = this._getAllWindows();
} catch (x) {
mozt.Debug.debug(x);
}
mozt.Debug.debug("baseWindows: " + baseWindows.length);
for(var i=0; i<baseWindows.length; i++) {
var bw = baseWindows[i];
mozt.Debug.debug('isHidden: ' + this._windowsHidden);
mozt.Debug.debug("bw.visibility: " + bw.visibility);
try {
if (this._windowsHidden) {
bw.visibility = true;
} else {
bw.visibility = false;
}
} catch (x) {
mozt.Debug.debug(x);
}
mozt.Debug.debug("bw.visibility: " + bw.visibility);
mozt.Debug.debug("bw.title: " + bw.title);
mozt.Debug.debug("bw.parentNativeWindow: " + bw.parentNativeWindow);
}
if (this._windowsHidden) {
this._windowsHidden = false;
} else {
this._windowsHidden = true;
}
},
}; // mozt.Handler
var mozt_activateCb; // pointer to JS function. should not be eaten
// by GC ("Running global cleanup code from
// study base classes" ?)
mozt.Main = {
initialized: false,
onLoad: function() {
if (this.initialized)
return true; // prevent creating multiple tray icon
mozt.Debug.debug('initialized: ' + this.initialized);
// initialization code
this.initialized = null;
this.strings = document.getElementById("moztray-strings");
try {
@ -23,19 +127,66 @@ mozt.Main = {
return false;
}
LibGtkStatusIcon.init();
this.tray_icon = LibGtkStatusIcon.gtk_status_icon_new();
var mozApp = mozt.Utils.appInfoService.name;
var icon_filename = MOZT_ICON_DIR + mozApp.toLowerCase() + MOZT_ICON_SUFFIX;
LibGtkStatusIcon.gtk_status_icon_set_from_file(this.tray_icon,
icon_filename);
// TODO: produces:
// (firefox-bin:5302): Gdk-CRITICAL **: IA__gdk_window_get_root_coords: assertion `GDK_IS_WINDOW (window)' failed
// (thunderbird-bin:5380): Gdk-CRITICAL **: IA__gdk_window_get_root_coords: assertion `GDK_IS_WINDOW (window)' failed
LibGtkStatusIcon.gtk_status_icon_set_tooltip_text(this.tray_icon,
mozApp);
try {
mozt.Debug.dump('Moztray LOADED !');
// instanciate tray icon
LibGtkStatusIcon.init();
this.tray_icon = LibGtkStatusIcon.gtk_status_icon_new();
var mozApp = mozt.Utils.appInfoService.name.toLowerCase();
var iconFilename = MOZT_ICON_DIR + mozApp + MOZT_ICON_SUFFIX;
LibGtkStatusIcon.gtk_status_icon_set_from_file(this.tray_icon,
iconFilename);
// set tooltip.
// TODO: produces:
// (firefox-bin:5302): Gdk-CRITICAL **: IA__gdk_window_get_root_coords: assertion `GDK_IS_WINDOW (window)' failed
// (thunderbird-bin:5380): Gdk-CRITICAL **: IA__gdk_window_get_root_coords: assertion `GDK_IS_WINDOW (window)' failed
LibGtkStatusIcon.gtk_status_icon_set_tooltip_text(this.tray_icon,
mozApp);
LibGtkStatusIcon.shutdown();
// watch out for binding problems !
mozt_activateCb = LibGObject.GCallback_t(
function(){mozt.Handler.showHideToTray();});
LibGObject.g_signal_connect(this.tray_icon, "activate",
mozt_activateCb, null);
} catch (x) {
Components.utils.reportError(ex);
return false;
}
/*
try {
// Experimental stuff... needs
// Components.utils.import("resource://moztray/LibGdkWindow.js");
var gdkScreen = LibGdkWindow.GdkScreenGetDefault();
var tl = LibGdkWindow.GdkScreenGetToplevelWindows(gdkScreen);
mozt.Debug.debug(tl);
// gboolean gdk_window_is_visible (GdkWindow *window);
mozt_func = LibGObject.GFunc_t(mozt_funcGdkJS);
LibGObject.g_list_foreach(tl, mozt_func, null);
var gdkWinCount = LibGObject.g_list_length(tl);
mozt.Debug.debug('gdkWinCount: ' + gdkWinCount);
var pid = LibC.getpid();
mozt.Debug.debug(pid);
tl = LibGtkStatusIcon.gtk_window_list_toplevels();
mozt_func = LibGObject.GFunc_t(mozt_funcGtkJS);
LibGObject.g_list_foreach(tl, mozt_func, null);
var gtkWinCount = LibGObject.g_list_length(tl);
mozt.Debug.debug('gtkWinCount: ' + gtkWinCount);
} catch (x) {
mozt.Debug.debug(x);
}
*/
mozt.Debug.debug('Moztray LOADED !');
this.initialized = true;
return true;
},
@ -43,16 +194,15 @@ mozt.Main = {
onQuit: function() {
// Remove observer
mozt.Utils.prefService.removeObserver("", this);
LibGtkStatusIcon.shutdown();
mozt.Debug.dump('Moztray UNLOADED !');
mozt.Debug.debug('Moztray UNLOADED !');
this.initialized = false;
},
observe: function(subject, topic, data) {
// Observer for pref changes
if (topic != "nsPref:changed") return;
mozt.Debug.dump('Pref changed: '+data);
mozt.Debug.debug('Pref changed: '+data);
switch(data) {
// case 'enabled':

View File

@ -2,7 +2,7 @@
<?xml-stylesheet href="chrome://moztray/skin/overlay.css" type="text/css"?>
<!DOCTYPE overlay SYSTEM "chrome://moztray/locale/overlay.dtd">
<overlay id="moztray-overlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script src="overlay.js"/>
<script type="application/javascript;version=1.7" src="overlay.js"/>
<stringbundleset id="stringbundleset">
<stringbundle id="moztray-strings" src="chrome://moztray/locale/overlay.properties"/>

104
src/modules/LibC.js Normal file
View File

@ -0,0 +1,104 @@
/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
var EXPORTED_SYMBOLS = ["LibC"];
const LIB_C = "libc.so.6";
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, "libc", function() {
var libc = ctypes.open(LIB_C);
if (!libc)
throw "libc is unavailable";
return libc;
});
XPCOMUtils.defineLazyGetter(this, "FILE", function() {
return ctypes.StructType("FILE");
});
XPCOMUtils.defineLazyGetter(this, "pid_t", function() {
return ctypes.int;
});
XPCOMUtils.defineLazyGetter(this, "fdopen", function() {
var fdopen = libc.declare(
"fdopen", ctypes.default_abi, FILE.ptr,
ctypes.int,
ctypes.char.ptr
);
if (!fdopen)
throw "fdopen is unavailable";
return fdopen;
});
XPCOMUtils.defineLazyGetter(this, "puts", function() {
var puts = libc.declare(
"puts", ctypes.default_abi, ctypes.int32_t,
ctypes.char.ptr
);
if (!puts)
throw "puts is unavailable";
return puts;
});
XPCOMUtils.defineLazyGetter(this, "fputs", function() {
var fputs = libc.declare(
"fputs", ctypes.default_abi, ctypes.int32_t,
ctypes.char.ptr,
FILE.ptr
);
if (!fputs)
throw "fputs is unavailable";
return fputs;
});
XPCOMUtils.defineLazyGetter(this, "fflush", function() {
var fflush = libc.declare(
"fflush", ctypes.default_abi, ctypes.int32_t,
FILE.ptr
);
if (!fflush)
throw "fflush is unavailable";
return fflush;
});
// pid_t getpid(void);
XPCOMUtils.defineLazyGetter(this, "getpid", function() {
var getpid = libc.declare(
"getpid", ctypes.default_abi, pid_t
);
if (!getpid)
throw "getpid is unavailable";
return getpid;
});
var LibC = {
stderr: this.fdopen(2, "a"),
FILE: FILE,
pid_t: pid_t,
fdopen: fdopen,
puts: puts,
fputs: fputs,
fflush: fflush,
getpid: getpid,
}

230
src/modules/LibGObject.js Normal file
View File

@ -0,0 +1,230 @@
/* -*- 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@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.unsigned_int;
});
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, "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,
};

201
src/modules/LibGdkWindow.js Normal file
View File

@ -0,0 +1,201 @@
/* -*- 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@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 = ["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/LibGObject.js");
XPCOMUtils.defineLazyGetter(this, "libgdkwindow", function() {
var libgdkwindow = ctypes.open(LIB_GDKWINDOW);
if (!libgdkwindow)
throw "libgdkwindow is unavailable";
return libgdkwindow;
});
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, "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");
});
// GdkScreen * gdk_screen_get_default (void);
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;
});
// GList * gdk_screen_get_toplevel_windows (GdkScreen *screen);
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;
});
var LibGdkWindow = {
GdkWindow: GdkWindow,
GdkWindowAttributes: GdkWindowAttributes,
GdkX11WindowSetUserTime: gdk_x11_window_set_user_time,
GdkWindowNew: gdk_window_new,
GdkWindowDestroy: gdk_window_destroy,
GdkWindowHide: gdk_window_hide,
GdkScreen: GdkScreen,
GdkScreenGetDefault: gdk_screen_get_default,
GdkScreenGetToplevelWindows: gdk_screen_get_toplevel_windows,
}

View File

@ -15,14 +15,17 @@ var LibGtkStatusIcon = {
init: function() {
// 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...
// If we still don't have ctypes, this isn't going to work...
if (typeof(ctypes) == "undefined") {
throw ("Could not load JS-Ctypes");
}
Cu.import("resource://moztray/LibGObject.js");
Cu.import("resource://moztray/LibGdkWindow.js");
try {
// Try to start up dependencies - if they fail, they'll throw
// exceptions. ex: GObjectLib.init();
// exceptions. ex: LibGObject.init();
this._lib = ctypes.open(LIB_GTK);
if (!this._lib)
@ -47,8 +50,34 @@ var LibGtkStatusIcon = {
// Types
this.GtkStatusIcon = ctypes.StructType("GtkStatusIcon");
this.GtkStatusIconRef = ctypes.PointerType(this.GtkStatusIcon);
this.GdkPixbuf = ctypes.StructType("GdkPixbuf");
this.GdkPixbufRef = ctypes.PointerType(this.GdkPixbuf);
this.GtkWindow = ctypes.StructType(
"GtkWindow", [
]);
this.GtkStyle = ctypes.StructType("GtkStyle");
this.GtkRequisition = ctypes.StructType(
"GtkRequisition", [
{ width: LibGObject.gint },
{ height: LibGObject.gint }
]);
this.GtkAllocation = 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 ! */
this.GtkWidget = ctypes.StructType("GtkWidget");
this.GtkWidget.define([
{ "style": this.GtkStyle.ptr },
{ "requisition": this.GtkRequisition },
{ "allocation": this.GtkAllocation },
{ "window": LibGdkWindow.GdkWindow.ptr },
{ "parent": this.GtkWidget.ptr }
]);
// Consts
// this.INDICATOR_MESSAGES_SERVER_TYPE = "message";
@ -77,6 +106,22 @@ var LibGtkStatusIcon = {
ctypes.char.ptr
);
/*
this.gtk_window_list_toplevels = this._lib.declare(
"gtk_window_list_toplevels", ctypes.default_abi, LibGObject.GList.ptr
);
this.gtk_widget_show = this._lib.declare(
"gtk_widget_show", ctypes.default_abi, ctypes.void_t,
this.GtkWidget.ptr
);
this.gtk_widget_hide = this._lib.declare(
"gtk_widget_hide", ctypes.default_abi, ctypes.void_t,
this.GtkWidget.ptr
);
*/
}
};

View File

@ -6,10 +6,13 @@
* http://developer.mozilla.org/en/XUL_School/JavaScript_Object_Management.html
*/
var EXPORTED_SYMBOLS = [ "mozt", "Cc", "Ci" ];
var EXPORTED_SYMBOLS = [ "mozt", "Cc", "Ci", "Cu" ];
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
Cu.import("resource://moztray/LibC.js");
const FIREFOX_ID = "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}";
const THUNDERBIRD_ID = "{3550f703-e582-4d05-9a08-453d09bdfdc6}";
@ -22,12 +25,11 @@ const CHATZILLA_ID = "{59c81df5-4b7a-477b-912d-4e0fdf64e5f2}";
* mozt namespace.
*/
if ("undefined" == typeof(mozt)) {
var mozt = {
DEBUG_MODE: true,
};
var mozt = {};
};
mozt.Debug = {
DEBUG_MODE: true,
_initialized: false,
/**
@ -47,12 +49,12 @@ mozt.Debug = {
* IT'S IMPORTANT THAT DEBUG CALLS ARE WRITTEN ON A SINGLE LINE !
*/
dump: function(message) { // Debuging function -- prints to javascript console
if(!mozt.DEBUG_MODE) return;
if(!this.DEBUG_MODE) return;
this._consoleService.logStringMessage(message);
},
dumpObj: function(obj) {
if(!mozt.DEBUG_MODE) return;
if(!this.DEBUG_MODE) return;
var str = "";
for(i in obj) {
try {
@ -64,16 +66,47 @@ mozt.Debug = {
this.dump(str);
},
// dump to terminal (stderr)
debug: function(str) {
LibC.fputs(str + "\n", LibC.stderr);
LibC.fflush(LibC.stderr);
},
};
// build it !
mozt.Debug.init();
mozt.Utils = {
prefService: Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService)
.getBranch("extensions.moztray."),
appInfoService: Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo), // appInfoService.name.toLower
windowMediator: Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator)
};
// var xpcomShutdownObserver = {
// observe: function(subject, topic, data) {
// if (topic == "xpcom-will-shutdown") {
// mozt.Debug.debug('event: '
// + 'subj: ' + subject
// + 'topic ' + topic
// + 'data ' + data);
// }
// },
// get observerService() {
// return Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
// },
// register: function() {
// this.observerService.addObserver(this, "xpcom-will-shutdown", false);
// },
// unregister: function() {
// this.observerService.removeObserver(this, "xpcom-will-shutdown");
// },
// };
// xpcomShutdownObserver.register();

View File

@ -1,4 +1,17 @@
includes := $(shell pkg-config --libs --cflags gtk+-2.0)
all:
gcc $(includes) -o gtk_icon_example gkt_icon_example.c
.PHONY: all
all: gtk_icon_example trayicon hide
.PHONY: clean
clean:
rm gtk_icon_example trayicon hide
gtk_icon_example: gtk_icon_example.c
gcc $(includes) -o gtk_icon_example gtk_icon_example.c
trayicon: trayicon.c
gcc $(includes) -o trayicon trayicon.c
hide: hide.c
gcc $(includes) -o hide hide.c

Binary file not shown.

View File

@ -1,3 +1,5 @@
#include <stdio.h>
#include <gtk/gtk.h>
#include "firefox.xpm"
@ -37,11 +39,51 @@ static GtkStatusIcon *create_tray_icon() {
return tray_icon;
}
/*
- Hide/Show window to avoid minimizing it to the task bar (yes, use gtk_widget_hide() and gtk_widget_show()) when the user clicks on the system tray icon
- Listen to the "window-state-event" (GObject's signal) to detect when minimizing and, instead of doing that, hide the window (ie, "minimize to the tray").
*/
/* This callback quits the program */
gint delete_event( GtkWidget *widget,
GdkEvent *event,
gpointer
data )
{
gtk_main_quit ();
return FALSE;
}
static void winShowHide(GtkMenuItem *item, gpointer window)
{
/* GdkWindow * tl_window = gdk_window_get_toplevel((GdkWindow*)window); */
/* GdkWindowState ws = gdk_window_get_state((GdkWindow*)tl_window); */
/* printf("GdkWindowState: %d", ws); */
gdk_window_hide(window->window);
/* gtk_widget_show(GTK_WIDGET(window)); */
/* gtk_widget_hide(GTK_WIDGET(window)); */
}
int main(int argc, char **argv) {
GtkStatusIcon *tray_icon;
gtk_init(&argc, &argv);
tray_icon = create_tray_icon();
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "GtkStatusIcon Example");
gtk_widget_set_size_request (window, 200, -1);
/* Set a handler for delete_event that immediately exits GTK. */
g_signal_connect (G_OBJECT (window), "delete_event",
G_CALLBACK (delete_event), NULL);
g_signal_connect(G_OBJECT(tray_icon), "activate", G_CALLBACK(winShowHide), window);
gtk_widget_show_all (window);
gtk_main();
return 0;

53
testing/hide.c Normal file
View File

@ -0,0 +1,53 @@
#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>
int main(int argc, char **argv)
{
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *button;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_container_set_border_width(GTK_CONTAINER(window), 10);
g_signal_connect(window, "delete_event", (GCallback)gtk_main_quit, 0);
vbox = gtk_vbox_new(TRUE, 0);
gtk_container_add(GTK_CONTAINER(window), vbox);
button = gtk_button_new_with_label("Hide");
gtk_box_pack_start(GTK_BOX(vbox), button, TRUE,TRUE, 0);
g_signal_connect_swapped(button, "clicked",
(GCallback)gtk_widget_hide, window);
button = gtk_button_new_from_stock(GTK_STOCK_QUIT);
gtk_box_pack_start(GTK_BOX(vbox), button, TRUE,TRUE, 0);
g_signal_connect(button, "clicked", (GCallback)gtk_main_quit, 0);
gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
// gtk_window_set_default_size(GTK_WINDOW(window),500,500);
// gtk_window_stick(GTK_WINDOW(window)); /* on all desktops or not */
gtk_window_set_keep_above(GTK_WINDOW(window), TRUE);
//gtk_window_set_keep_below(GTK_WINDOW(window),TRUE);
gtk_window_set_skip_taskbar_hint(GTK_WINDOW(window), TRUE);
gtk_window_set_skip_pager_hint(GTK_WINDOW(window), TRUE);
gtk_window_move(GTK_WINDOW(window), 100, 100);
// gtk_window_set_opacity(GTK_WINDOW(window), 0); /* not working hmmmm*/
gtk_widget_show_all(window);
gtk_main();
return (EXIT_SUCCESS);
}

109
testing/trayicon.c Normal file
View File

@ -0,0 +1,109 @@
// http://www.codeproject.com/KB/cross-platform/GTKTrayIcon.aspx
#include <gtk/gtk.h>
static void trayView(GtkMenuItem *item, gpointer user_data);
static void trayExit(GtkMenuItem *item, gpointer user_data);
static void trayIconActivated(GObject *trayIcon, gpointer data);
static void trayIconPopup(GtkStatusIcon *status_icon, guint button, guint32 activate_time, gpointer popUpMenu);
static void destroy (GtkWidget*, gpointer);
static gboolean delete_event (GtkWidget*, GdkEvent*, gpointer);
static gboolean window_state_event (GtkWidget *widget, GdkEventWindowState *event, gpointer user_data);
int main(int argc, char *argv[])
{
gtk_init (&argc, &argv);
GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "GtkStatusIcon Example");
gtk_widget_set_size_request (window, 200, -1);
//set try icon file
GtkStatusIcon *trayIcon = gtk_status_icon_new_from_file ("firefox32.png");
//set popup menu for tray icon
GtkWidget *menu, *menuItemView, *menuItemExit;
menu = gtk_menu_new();
menuItemView = gtk_menu_item_new_with_label ("View");
menuItemExit = gtk_menu_item_new_with_label ("Exit");
g_signal_connect (G_OBJECT (menuItemView), "activate", G_CALLBACK (trayView), window);
g_signal_connect (G_OBJECT (menuItemExit), "activate", G_CALLBACK (trayExit), NULL);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuItemView);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuItemExit);
gtk_widget_show_all (menu);
//set tooltip
gtk_status_icon_set_tooltip (trayIcon, "MsgWatcherGTK");
//connect handlers for mouse events
g_signal_connect(GTK_STATUS_ICON (trayIcon), "activate", GTK_SIGNAL_FUNC (trayIconActivated), window);
g_signal_connect(GTK_STATUS_ICON (trayIcon), "popup-menu", GTK_SIGNAL_FUNC (trayIconPopup), menu);
gtk_status_icon_set_visible(trayIcon, FALSE); //set icon initially invisible
GtkWidget *menuBar, *menuItemTopLvl, *mainMenu, *mainMenuItemExit;
menuBar = gtk_menu_bar_new ();
menuItemTopLvl = gtk_menu_item_new_with_label ("Menu");
gtk_menu_shell_append (GTK_MENU_SHELL (menuBar), menuItemTopLvl);
mainMenu = gtk_menu_new ();
gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuItemTopLvl), mainMenu);
mainMenuItemExit = gtk_menu_item_new_with_label ("Quit");
g_signal_connect (G_OBJECT (mainMenuItemExit), "activate", G_CALLBACK (trayExit), NULL);
gtk_menu_shell_append (GTK_MENU_SHELL (mainMenu), mainMenuItemExit);
g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (destroy), NULL);
g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (delete_event), trayIcon);
g_signal_connect (G_OBJECT (window), "window-state-event", G_CALLBACK (window_state_event), trayIcon);
gtk_container_add (GTK_CONTAINER (window), menuBar);
gtk_widget_show_all (window);
gtk_main ();
return 0;
}
static void trayView(GtkMenuItem *item, gpointer window)
{
gtk_widget_show(GTK_WIDGET(window));
gtk_window_deiconify(GTK_WINDOW(window));
}
static void trayExit(GtkMenuItem *item, gpointer user_data)
{
printf("exit");
gtk_main_quit();
}
static void trayIconActivated(GObject *trayIcon, gpointer window)
{
gtk_widget_show(GTK_WIDGET(window));
gtk_window_deiconify(GTK_WINDOW(window));
}
static void trayIconPopup(GtkStatusIcon *status_icon, guint button, guint32 activate_time, gpointer popUpMenu)
{
gtk_menu_popup(GTK_MENU(popUpMenu), NULL, NULL, gtk_status_icon_position_menu, status_icon, button, activate_time);
}
static void destroy (GtkWidget *window, gpointer data)
{
gtk_main_quit ();
}
static gboolean delete_event (GtkWidget *window, GdkEvent *event, gpointer data)
{
return FALSE;
}
static gboolean window_state_event (GtkWidget *widget, GdkEventWindowState *event, gpointer trayIcon)
{
if(event->changed_mask == GDK_WINDOW_STATE_ICONIFIED &&
(event->new_window_state == GDK_WINDOW_STATE_ICONIFIED
|| event->new_window_state == (GDK_WINDOW_STATE_ICONIFIED | GDK_WINDOW_STATE_MAXIMIZED)))
{
gtk_widget_hide (GTK_WIDGET(widget));
gtk_status_icon_set_visible(GTK_STATUS_ICON(trayIcon), TRUE);
}
else if(event->changed_mask == GDK_WINDOW_STATE_WITHDRAWN &&
(event->new_window_state == GDK_WINDOW_STATE_ICONIFIED
|| event->new_window_state == (GDK_WINDOW_STATE_ICONIFIED | GDK_WINDOW_STATE_MAXIMIZED)))
{
gtk_status_icon_set_visible(GTK_STATUS_ICON(trayIcon), FALSE);
}
return TRUE;
}