1
0
mirror of https://github.com/moparisthebest/FireTray synced 2024-08-13 15:53:47 -04:00

* fix non-import of IM stuff in Firefox

* add minimal tooltip for Chat icon
* fix findActiveWindow() — gtk_window_is_active() not reliable
This commit is contained in:
foudfou 2012-08-25 19:02:14 +02:00
parent 9f46ef6343
commit 5c12abb1ee
7 changed files with 47 additions and 38 deletions

View File

@ -31,7 +31,6 @@ firetray.Handler = {
initialized: false,
inBrowserApp: false,
inMailApp: false,
isIMEnabled: false,
appStarted: false,
windows: {},
windowsCount: 0,
@ -39,7 +38,6 @@ firetray.Handler = {
observedTopics: {},
ctypesLibs: {}, // {"lib1": lib1, "lib2": lib2}
appId: (function(){return Services.appinfo.ID;})(),
appName: (function(){return Services.appinfo.name;})(),
appStartupTopic: null,

View File

@ -60,8 +60,6 @@ firetray.InstantMessaging = {
let convIsActiveTabInActiveWin = this.isConvActiveTabInActiveWindow(conv);
F.LOG("convIsActiveTabInActiveWin="+convIsActiveTabInActiveWin);
let [unreadTargettedCount, unreadTotalCount] = this.countUnreadMessages();
F.LOG("unreadTotalCount="+unreadTotalCount);
if (!convIsActiveTabInActiveWin) { // don't blink when conv tab already on top
this.acknowledgeOnFocus.must = true;
this.acknowledgeOnFocus.conv = conv;
@ -73,7 +71,12 @@ firetray.InstantMessaging = {
let unreadMsgCount = data;
if (unreadMsgCount == 0)
this.stopIconBlinkingMaybe();
// FIXME: setToolTip
let localizedTooltip = PluralForm.get(
unreadMsgCount,
firetray.Utils.strings.GetStringFromName("tooltip.unread_messages"))
.replace("#1", unreadMsgCount);
firetray.IMStatusIcon.setIconTooltip(localizedTooltip);
break;
default:
@ -82,9 +85,12 @@ firetray.InstantMessaging = {
},
stopIconBlinkingMaybe: function() {
F.WARN("acknowledgeOnFocus.must="+this.acknowledgeOnFocus.must);
F.LOG("acknowledgeOnFocus.must="+this.acknowledgeOnFocus.must);
// if (!this.acknowledgeOnFocus.must) return;
let convIsActiveTabInActiveWin = this.isConvActiveTabInActiveWindow(
this.acknowledgeOnFocus.conv);
F.LOG("convIsActiveTabInActiveWin="+convIsActiveTabInActiveWin);
if (this.acknowledgeOnFocus.must && convIsActiveTabInActiveWin) {
firetray.IMStatusIcon.setIconBlinking(false);
@ -95,7 +101,7 @@ firetray.InstantMessaging = {
isConvActiveTabInActiveWindow: function(conv) {
let activeWin = firetray.Handler.findActiveWindow(),
activeChatTab = null;
if (!activeWin) return false;
if (!firetray.Handler.windows[activeWin]) return false;
activeChatTab = this.findActiveChatTab(activeWin);
let convNameRegex = new RegExp(" - "+conv.name+"$");
@ -111,18 +117,6 @@ firetray.InstantMessaging = {
return null;
},
// lifted from chat-messenger-overlay.js
countUnreadMessages: function() {
let convs = Services.conversations.getUIConversations();
let unreadTargettedCount = 0;
let unreadTotalCount = 0;
for each (let conv in convs) {
unreadTargettedCount += conv.unreadTargetedMessageCount;
unreadTotalCount += conv.unreadIncomingMessageCount;
}
return [unreadTargettedCount, unreadTotalCount];
},
updateIcon: function() {
let userStatus = Services.core.globalUserStatus.statusType;
F.LOG("IM status="+userStatus);

View File

@ -44,11 +44,8 @@ firetray.Messaging = {
that.mailSessionListener.notificationFlags);
// FIXME: add im-icon pref
// FIXME: watch out account-added !!
if (Services.prefs.getBoolPref("mail.chat.enabled") && this.existsIMAccount()) {
if (Services.prefs.getBoolPref("mail.chat.enabled") && this.existsIMAccount())
firetray.InstantMessaging.init();
firetray.Handler.isIMEnabled = true;
}
this.initialized = true;
},
@ -89,12 +86,10 @@ firetray.Messaging = {
this.cleanExcludedAccounts();
if (subject.QueryInterface(Ci.imIAccount) && !this.existsIMAccount())
firetray.InstantMessaging.shutdown();
// FIXME: clean InstantMessaging.accounts or just update (?)
break;
case "account-added":
if (subject.QueryInterface(Ci.imIAccount) && !firetray.InstantMessaging.initialized)
firetray.InstantMessaging.init();
// FIXME: clean InstantMessaging.accounts or just update (?)
break;
default:
F.WARN("unhandled topic: "+topic);

View File

@ -1,4 +1,4 @@
/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
@ -152,6 +152,8 @@ function gobject_defines(lib) {
lib.lazy_bind("g_signal_handler_block", ctypes.void_t, this.gpointer, this.gulong);
lib.lazy_bind("g_signal_handler_unblock", ctypes.void_t, this.gpointer, this.gulong);
/* NOTE: we can't easily work with g_object_get_property() because it uses
GValue, which is an opaque struct, and thus can't be initialized by ctypes */
}
new ctypes_library(GOBJECT_LIBNAME, GOBJECT_ABIS, gobject_defines, this);

View File

@ -116,6 +116,8 @@ function gtk_defines(lib) {
lib.lazy_bind("gtk_widget_get_parent_window", gdk.GdkWindow.ptr, this.GtkWidget.ptr);
lib.lazy_bind("gtk_window_set_decorated", ctypes.void_t, this.GtkWindow.ptr, gobject.gboolean);
lib.lazy_bind("gtk_widget_is_focus", gobject.gboolean, this.GtkWidget.ptr);
lib.lazy_bind("gtk_widget_has_focus", gobject.gboolean, this.GtkWidget.ptr);
lib.lazy_bind("gtk_widget_hide_on_delete", gobject.gboolean, this.GtkWidget.ptr);
lib.lazy_bind("gtk_widget_hide", ctypes.void_t, this.GtkWidget.ptr);
lib.lazy_bind("gtk_widget_show", ctypes.void_t, this.GtkWidget.ptr);

View File

@ -43,6 +43,7 @@ firetray.IMStatusIcon = {
this.trayIcon = gtk.gtk_status_icon_new();
this.loadThemedIcons();
this.setIconImage(FIRETRAY_IM_STATUS_OFFLINE);
this.setIconTooltipDefault();
this.initialized = true;
return true;
@ -81,7 +82,16 @@ firetray.IMStatusIcon = {
gtk.gtk_status_icon_set_blinking(this.trayIcon, blink);
},
/* we could also use x11.FocusIn... just wanted to try a different method */
setIconTooltip: function(txt) {
if (!this.trayIcon) return false;
gtk.gtk_status_icon_set_tooltip_text(this.trayIcon, txt);
return true;
},
setIconTooltipDefault: function() {
this.setIconTooltip(firetray.Handler.appName+" Chat");
},
attachOnFocusInCallback: function(xid) {
F.LOG("attachOnFocusInCallback xid="+xid);
this.callbacks.onFocusIn[xid] = gtk.GCallbackWidgetFocuEvent_t(firetray.IMStatusIcon.onFocusIn);

View File

@ -595,8 +595,7 @@ firetray.Handler.registerWindow = function(win) {
this.windows[xid].filterWindowCb = gdk.GdkFilterFunc_t(firetray.Window.filterWindow);
gdk.gdk_window_add_filter(gdkWin, this.windows[xid].filterWindowCb, null);
// FIXME: isn't it (c)leaner to do it in x11 window filter ?
if (firetray.Handler.isIMEnabled) {
if (firetray.Handler.inMailApp && firetray.InstantMessaging.initialized) { // missing import ok
Cu.import("resource://firetray/linux/FiretrayIMStatusIcon.jsm");
firetray.IMStatusIcon.attachOnFocusInCallback(xid);
}
@ -662,17 +661,26 @@ firetray.Handler.activateLastWindow = function(gtkStatusIcon, gdkEvent, userData
return stopPropagation;
};
/* gtk_window_is_active() not reliable */
firetray.Handler.findActiveWindow = function() {
let rootWin = x11.XDefaultRootWindow(x11.current.Display);
let [propsFound, nitems] =
firetray.Window.getXWindowProperties(rootWin, x11.current.Atoms._NET_ACTIVE_WINDOW);
F.LOG("ACTIVE_WINDOW propsFound, nitems="+propsFound+", "+nitems);
if (!propsFound) return null;
let activeWin = null;
for (let xid in firetray.Handler.windows) {
let gtkWin = firetray.Handler.gtkWindows.get(xid);
let isActive = gtk.gtk_window_is_active(gtkWin);
F.LOG(xid+" is active="+isActive);
if (isActive) {
activeWin = xid;
break;
}
}
if (firetray.js.strEquals(nitems.value, 0))
F.WARN("active window not found");
else if (firetray.js.strEquals(nitems.value, 1))
activeWin = propsFound.contents[0];
else
throw new RangeError("more than one active window found");
x11.XFree(propsFound);
F.LOG("ACTIVE_WINDOW="+activeWin);
return activeWin;
};