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

fix start_hidden which was based on 'resize' events.

"Too small window" bug with Lightning installed.

start_hidden is not so easy to achieve since:
- we can't rely on appStarted (window displayed in between)
- we can't rely on 'load' event (window not fully realized - position, size)
- we can't rely on 'resize' event (window displayed/shown/resized a variable
  number of times)
Besides, nsIBaseWindow.visibility remains the surest way to hide windows at
startup.
This commit is contained in:
foudfou 2012-07-24 02:00:44 +02:00
parent 9b124d237f
commit 4fb215ce82
4 changed files with 40 additions and 43 deletions

View File

@ -12,7 +12,6 @@ var firetrayChrome = { // each new window gets a new firetrayChrome !
strings: null,
winId: null,
startedHidden: false,
onLoad: function(win) {
this.strings = document.getElementById("firetray-strings"); // chrome-specific
@ -22,9 +21,9 @@ var firetrayChrome = { // each new window gets a new firetrayChrome !
F.LOG("ONLOAD"); firetray.Handler.dumpWindows();
this.winId = firetray.Handler.registerWindow(win);
win.setTimeout(firetrayChrome.startHiddenMaybe, 0, this.winId);
win.addEventListener('close', firetrayChrome.onClose, true);
win.addEventListener('resize', firetrayChrome.onResize, true);
F.LOG('Firetray LOADED: ' + init);
return true;
@ -55,34 +54,19 @@ var firetrayChrome = { // each new window gets a new firetrayChrome !
F.LOG('hides_on_close: '+hides_on_close+', hides_single_window='+hides_single_window);
if (hides_on_close) {
if (hides_single_window) {
firetray.Handler.hideSingleWindow(firetrayChrome.winId);
firetray.Handler.hideWindow(firetrayChrome.winId);
} else
firetray.Handler.hideAllWindows();
event && event.preventDefault();
}
},
/**
* at startup windows are displayed/shown/resized multiple times. We can't
* just set baseWin.visibility=false on 'load' because the window is not
* fully realized (position, size incorrect), neither when appStarted because
* windows would be displayed in between
*/
onResize: function(event) {
F.LOG('onResize'+'. appStarted='+firetray.Handler.appStarted);
let win = event.originalTarget;
win.removeEventListener('resize', firetrayChrome.onResize, true);
startHiddenMaybe: function(winId) {
F.LOG('startHiddenMaybe'+'. appStarted='+firetray.Handler.appStarted);
if(!firetray.Handler.appStarted &&
firetray.Utils.prefService.getBoolPref('start_hidden')) {
F.LOG('start_hidden: '+firetrayChrome.winId);
let baseWin = firetray.Handler.getWindowInterface(win, "nsIBaseWindow");
baseWin.visibility = false;
if (!firetrayChrome.startedHidden) {
firetray.Handler.windows[firetrayChrome.winId].visible = false;
firetray.Handler.visibleWindowsCount -= 1;
firetrayChrome.startedHidden = true;
}
if (firetray.Utils.prefService.getBoolPref('start_hidden') &&
!firetray.Handler.appStarted) { // !appStarted for new windows !
firetray.Handler.startupHideWindow(winId);
}
}

View File

@ -181,8 +181,9 @@ firetray.Handler = {
registerWindow: function(win) {},
unregisterWindow: function(win) {},
getWindowIdFromChromeWindow: function(win) {},
hideSingleWindow: function(winId) {},
showSingleWindow: function(winId) {},
hideWindow: function(winId) {},
startupHideWindow: function(winId) {},
showWindow: function(winId) {},
showHideAllWindows: function() {},
activateLastWindow: function(gtkStatusIcon, gdkEvent, userData) {},
@ -190,14 +191,14 @@ firetray.Handler = {
F.LOG("showAllWindows");
for (let winId in firetray.Handler.windows) {
if (!firetray.Handler.windows[winId].visible)
firetray.Handler.showSingleWindow(winId);
firetray.Handler.showWindow(winId);
}
},
hideAllWindows: function() {
F.LOG("hideAllWindows");
for (let winId in firetray.Handler.windows) {
if (firetray.Handler.windows[winId].visible)
firetray.Handler.hideSingleWindow(winId);
firetray.Handler.hideWindow(winId);
}
},

View File

@ -104,7 +104,7 @@ firetray.PopupMenu = {
this.setWindowItemLabel(menuItemWindow, xid.toString()); // default to xid
this.callbacks.menuItemWindowActivate[xid] = gobject.GCallback_t(
function(){firetray.Handler.showSingleWindow(xid);});
function(){firetray.Handler.showWindow(xid);});
gobject.g_signal_connect(menuItemWindow, "activate",
firetray.PopupMenu.callbacks.menuItemWindowActivate[xid], null);
@ -130,14 +130,14 @@ firetray.PopupMenu = {
showAllWindowItemsOnlyVisibleWindows: function() {
for (let xid in firetray.Handler.windows)
if (!firetray.Handler.windows[xid].visible)
this.showSingleWindowItem(xid);
this.showWindowItem(xid);
},
showSingleWindowItem: function(xid) {
showWindowItem: function(xid) {
if (!this.windowItemsHandled())
return;
F.LOG("showSingleWindowItem");
F.LOG("showWindowItem");
let menuItemWindow = firetray.Handler.gtkPopupMenuWindowItems.get(xid);
this.showItem(menuItemWindow);
this.setWindowItemLabel(menuItemWindow, firetray.Window.getWindowTitle(xid));
@ -156,25 +156,25 @@ firetray.PopupMenu = {
hideAllWindowItems: function() {
for (let xid in firetray.Handler.windows)
this.hideSingleWindowItemAndSeparator(xid);
this.hideWindowItemAndSeparator(xid);
},
hideSingleWindowItemAndSeparator: function(xid) {
this.hideSingleWindowItem(xid);
hideWindowItemAndSeparator: function(xid) {
this.hideWindowItem(xid);
this.hideWindowSeparator();
},
hideSingleWindowItemAndSeparatorMaybe: function(xid) {
hideWindowItemAndSeparatorMaybe: function(xid) {
if (!this.windowItemsHandled())
return;
this.hideSingleWindowItem(xid);
this.hideWindowItem(xid);
if (firetray.Handler.visibleWindowsCount === firetray.Handler.windowsCount)
this.hideWindowSeparator();
},
hideSingleWindowItem: function(xid) {
F.LOG("hideSingleWindowItem");
hideWindowItem: function(xid) {
F.LOG("hideWindowItem");
let menuItemWindow = firetray.Handler.gtkPopupMenuWindowItems.get(xid);
this.hideItem(menuItemWindow);
},

View File

@ -204,7 +204,7 @@ firetray.Window = {
if (firetray.Utils.prefService.getBoolPref('show_activates'))
firetray.Window.activate(xid);
firetray.PopupMenu.hideSingleWindowItemAndSeparatorMaybe(xid);
firetray.PopupMenu.hideWindowItemAndSeparatorMaybe(xid);
firetray.Handler.showHideIcon();
},
@ -218,7 +218,18 @@ firetray.Window = {
firetray.Window.setVisibility(xid, false);
firetray.PopupMenu.showSingleWindowItem(xid);
firetray.PopupMenu.showWindowItem(xid);
firetray.Handler.showHideIcon();
},
startupHide: function(xid) {
F.LOG('startupHide: '+xid);
firetray.Handler.windows[xid].baseWin.visibility = false;
firetray.Handler.windows[xid].visible = false;
firetray.Handler.visibleWindowsCount -= 1;
firetray.PopupMenu.showWindowItem(xid);
firetray.Handler.showHideIcon();
},
@ -492,7 +503,7 @@ firetray.Window = {
let hides_single_window = firetray.Utils.prefService.getBoolPref('hides_single_window');
if (hides_on_minimize) {
if (hides_single_window) {
firetray.Handler.hideSingleWindow(xwin);
firetray.Handler.hideWindow(xwin);
} else
firetray.Handler.hideAllWindows();
}
@ -569,8 +580,9 @@ firetray.Handler.unregisterWindow = function(win) {
return firetray.Window.unregisterWindowByXID(xid);
};
firetray.Handler.showSingleWindow = firetray.Window.show;
firetray.Handler.hideSingleWindow = firetray.Window.hide;
firetray.Handler.showWindow = firetray.Window.show;
firetray.Handler.hideWindow = firetray.Window.hide;
firetray.Handler.startupHideWindow = firetray.Window.startupHide;
firetray.Handler.showHideAllWindows = function(gtkStatusIcon, userData) {
F.LOG("showHideAllWindows: "+userData);