add option for showing icon only when some windows are hidden to tray

This commit is contained in:
foudfou 2012-01-15 23:57:35 +01:00
parent 6fc5ff1a05
commit 2d62194e86
10 changed files with 63 additions and 32 deletions

View File

@ -11,9 +11,10 @@ Features
* for all applications:
* show/hide a single or all windows
* a window restored to its previous state, position, size, virtual desktop
* ability to hide to tray on minimize
* ability to start minimized to tray
* a window gets restored to its previous state, position, size, virtual desktop
* optional hide to tray on minimize
* optional start minimized to tray
* optional show icon only when hidden to tray
* for mail applications:
* display unread messages count in tray icon

3
TODO
View File

@ -6,8 +6,6 @@ TODO
WONTFIX
-------
* ability to hide windows individually/globally
* disable notifications for excluded mail account servers. NOTE: toggle
`login_at_startup` and `check_new_mail` is a bad idea. Mainly because the
user may be toggling them after we store the previous values (and before we
@ -38,6 +36,5 @@ NEXT FEATURES
* mouse scrolls on tray icon hides/shows
* when restoring, if the window is iconified, deiconify it
* keyboard shortcut hide/show
* show icon only when hidden to tray
[Vote](https://docs.google.com/spreadsheet/viewform?hl=fr&formkey=dFJqUC1pLTQzNkJYQldFdzdSV1BaSkE6MQ#gid=0)

View File

@ -23,6 +23,7 @@
<preference id="pref_bool_hides_on_minimize" name="extensions.firetray.hides_on_minimize" type="bool"/>
<preference id="pref_bool_hides_single_window" name="extensions.firetray.hides_single_window" type="bool"/>
<preference id="pref_bool_start_hidden" name="extensions.firetray.start_hidden" type="bool"/>
<preference id="pref_bool_show_icon_on_hide" name="extensions.firetray.show_icon_on_hide" type="bool"/>
<preference id="pref_string_icon_text_color" name="extensions.firetray.icon_text_color" type="string" />
<preference id="pref_string_custom_mail_icon" name="extensions.firetray.custom_mail_icon" type="string" />
<preference id="pref_string_mail_accounts" name="extensions.firetray.mail_accounts" type="string"/>
@ -37,10 +38,10 @@
<tabpanels flex="1">
<tabpanel id="general_tabpanel" flex="1">
<vbox pack="start" align="left" flex="1">
<groupbox flex="1">
<groupbox>
<caption label="&windows_behaviour;" />
<checkbox id="ui_hides_on_close" preference="pref_bool_hides_on_close"
label="&bool_hides_on_close.label;"
accesskey="&bool_hides_on_close.accesskey;"
@ -58,6 +59,14 @@
accesskey="&bool_start_hidden.accesskey;"/>
</groupbox>
<groupbox>
<caption label="&icon_settings;" />
<checkbox id="ui_show_icon_on_hide" preference="pref_bool_show_icon_on_hide"
label="&bool_show_icon_on_hide.label;"
accesskey="&bool_show_icon_on_hide.accesskey;"/>
</groupbox>
</vbox>
</tabpanel>
<tabpanel id="input_tabpanel" flex="1" />

View File

@ -8,7 +8,6 @@
<!ENTITY mail_options "Mail">
<!ENTITY windows_behaviour "Windows behaviour">
<!ENTITY bool_hides_on_close.label "Closing window hides to tray">
<!ENTITY bool_hides_on_close.accesskey "C">
<!ENTITY bool_hides_single_window.tooltip "not all windows at once">
@ -19,6 +18,10 @@
<!ENTITY bool_start_hidden.label "Start application hidden to tray">
<!ENTITY bool_start_hidden.accesskey "S">
<!ENTITY icon_settings "Icon settings">
<!ENTITY bool_show_icon_on_hide.label "Show only if at least a window is hidden">
<!ENTITY bool_show_icon_on_hide.accesskey "w">
<!ENTITY mail_notification.label "Mail notification">
<!ENTITY mail_notification_disabled.label "disabled">
<!ENTITY mail_notification_disabled.accesskey "D">

View File

@ -10,6 +10,7 @@ pref("extensions.firetray.hides_on_close", true);
pref("extensions.firetray.hides_on_minimize", true);
pref("extensions.firetray.hides_single_window", false);
pref("extensions.firetray.start_hidden", false);
pref("extensions.firetray.show_icon_on_hide", false);
pref("extensions.firetray.mail_notification", 1);
pref("extensions.firetray.icon_text_color", "#000000");

View File

@ -75,6 +75,7 @@ firetray.Handler = {
LOG('inMailApp: '+this.inMailApp+', inBrowserApp: '+this.inBrowserApp);
firetray.StatusIcon.init();
firetray.Handler.showHideIcon();
LOG('StatusIcon initialized');
if (this.inMailApp) {
@ -146,12 +147,13 @@ firetray.Handler = {
}
},
// these get overridden in OS-specific Window handlers
setImage: function(filename) {},
setImageDefault: function() {},
setText: function(text, color) {},
setTooltip: function(localizedMessage) {},
setTooltipDefault: function() {},
// these get overridden in OS-specific Icon/Window handlers
setIconImage: function(filename) {},
setIconImageDefault: function() {},
setIconText: function(text, color) {},
setIconTooltip: function(localizedMessage) {},
setIconTooltipDefault: function() {},
setIconVisibility: function(visible) {},
registerWindow: function(win) {},
unregisterWindow: function(win) {},
getWindowIdFromChromeWindow: function(win) {},
@ -174,6 +176,12 @@ firetray.Handler = {
}
},
showHideIcon: function() {
if (firetray.Utils.prefService.getBoolPref('show_icon_on_hide'))
firetray.Handler.setIconVisibility(
(firetray.Handler.visibleWindowsCount !== firetray.Handler.windowsCount));
},
/** nsIBaseWindow, nsIXULWindow, ... */
getWindowInterface: function(win, iface) {
let winInterface, winOut;

View File

@ -53,7 +53,7 @@ firetray.Messaging = {
LOG("Disabling Messaging");
MailServices.mailSession.RemoveFolderListener(this.mailSessionListener);
firetray.Handler.setImageDefault();
firetray.Handler.setIconImageDefault();
this.initialized = false;
},
@ -120,22 +120,22 @@ firetray.Messaging = {
// update icon
if (this._unreadMsgCount == 0) {
firetray.Handler.setImageDefault();
firetray.Handler.setTooltipDefault();
firetray.Handler.setIconImageDefault();
firetray.Handler.setIconTooltipDefault();
} else if (this._unreadMsgCount > 0) {
switch (prefMailNotification) {
case FT_NOTIFICATION_UNREAD_MESSAGE_COUNT:
let prefIconTextColor = firetray.Utils.prefService.getCharPref("icon_text_color");
firetray.Handler.setText(this._unreadMsgCount.toString(), prefIconTextColor);
firetray.Handler.setIconText(this._unreadMsgCount.toString(), prefIconTextColor);
break;
case FT_NOTIFICATION_NEWMAIL_ICON:
firetray.Handler.setImage(firetray.Handler.FILENAME_NEWMAIL);
firetray.Handler.setIconImage(firetray.Handler.FILENAME_NEWMAIL);
break;
case FT_NOTIFICATION_CUSTOM_ICON:
let prefCustomIconPath = firetray.Utils.prefService.getCharPref("custom_mail_icon");
firetray.Handler.setImage(prefCustomIconPath);
firetray.Handler.setIconImage(prefCustomIconPath);
break;
default:
ERROR("Unknown notification mode");
@ -145,7 +145,7 @@ firetray.Messaging = {
this._unreadMsgCount,
firetray.Utils.strings.GetStringFromName("tooltip.unread_messages"))
.replace("#1", this._unreadMsgCount);;
firetray.Handler.setTooltip(localizedMessage);
firetray.Handler.setIconTooltip(localizedMessage);
} else {
throw "negative message count"; // should never happen

View File

@ -71,6 +71,7 @@ function gtk_defines(lib) {
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_status_icon_set_visible", ctypes.void_t, this.GtkStatusIcon.ptr, gobject.gboolean);
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

View File

@ -38,11 +38,11 @@ firetray.StatusIcon = {
return false;
}
firetray.Handler.setImageDefault();
firetray.Handler.setIconImageDefault();
this._buildPopupMenu();
firetray.Handler.setTooltipDefault();
firetray.Handler.setIconTooltipDefault();
LOG("showHideAllWindows: "+firetray.Handler.hasOwnProperty("showHideAllWindows"));
this.callbacks.iconActivate = gtk.GCallbackStatusIconActivate_t(
@ -148,7 +148,7 @@ firetray.StatusIcon = {
}; // firetray.StatusIcon
firetray.Handler.setImage = function(filename) {
firetray.Handler.setIconImage = function(filename) {
if (!firetray.StatusIcon.trayIcon)
return false;
LOG(filename);
@ -163,14 +163,14 @@ firetray.Handler.setImage = function(filename) {
return true;
};
firetray.Handler.setImageDefault = function() {
firetray.Handler.setIconImageDefault = function() {
if (!this.FILENAME_DEFAULT)
throw "Default application icon filename not set";
this.setImage(this.FILENAME_DEFAULT);
this.setIconImage(this.FILENAME_DEFAULT);
};
// GTK bug: Gdk-CRITICAL **: IA__gdk_window_get_root_coords: assertion `GDK_IS_WINDOW (window)' failed
firetray.Handler.setTooltip = function(toolTipStr) {
firetray.Handler.setIconTooltip = function(toolTipStr) {
if (!firetray.StatusIcon.trayIcon)
return false;
@ -184,14 +184,14 @@ firetray.Handler.setTooltip = function(toolTipStr) {
return true;
};
firetray.Handler.setTooltipDefault = function() {
firetray.Handler.setIconTooltipDefault = function() {
if (!this.appNameOriginal)
throw "application name not initialized";
this.setTooltip(this.appNameOriginal);
this.setIconTooltip(this.appNameOriginal);
};
firetray.Handler.setText = function(text, color) { // TODO: split into smaller functions;
LOG("setText, color="+color);
firetray.Handler.setIconText = function(text, color) { // TODO: split into smaller functions;
LOG("setIconText, color="+color);
if (typeof(text) != "string")
throw new TypeError();
@ -295,3 +295,10 @@ firetray.Handler.setText = function(text, color) { // TODO: split into smaller f
return true;
};
firetray.Handler.setIconVisibility = function(visible) {
if (!firetray.StatusIcon.trayIcon)
return false;
gtk.gtk_status_icon_set_visible(firetray.StatusIcon.trayIcon, visible);
return true;
};

View File

@ -506,6 +506,8 @@ firetray.Handler.showSingleWindow = function(xid) {
firetray.Handler.windows[xid].visibility = true;
firetray.Handler.visibleWindowsCount += 1;
firetray.Handler.showHideIcon();
};
// NOTE: we keep using high-level cross-plat BaseWindow.visibility (instead of
@ -520,6 +522,8 @@ firetray.Handler.hideSingleWindow = function(xid) {
firetray.Handler.windows[xid].visibility = false;
firetray.Handler.visibleWindowsCount -= 1;
firetray.Handler.showHideIcon();
};
firetray.Handler.showHideAllWindows = function(gtkStatusIcon, userData) {