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

Merge branch 'start_hidden'

This commit is contained in:
foudfou 2012-02-21 00:22:41 +01:00
commit 803143a535
4 changed files with 119 additions and 68 deletions

View File

@ -17,20 +17,15 @@ var firetrayChrome = { // each new window gets a new firetrayChrome !
let init = firetray.Handler.initialized || firetray.Handler.init(); let init = firetray.Handler.initialized || firetray.Handler.init();
LOG("ONLOAD"); firetray.Handler.dumpWindows(); LOG("ONLOAD"); firetray.Handler.dumpWindows();
firetray.Handler.registerWindow(win); let winId = firetray.Handler.registerWindow(win);
// update unread messages count
if (firetray.Handler.inMailApp && firetray.Messaging.initialized) if (firetray.Handler.inMailApp && firetray.Messaging.initialized)
firetray.Messaging.updateMsgCount(); firetray.Messaging.updateMsgCount();
// prevent window closing.
win.addEventListener('close', firetrayChrome.onClose, true); win.addEventListener('close', firetrayChrome.onClose, true);
if (!firetray.Handler.appStarted if (firetray.Handler.windows[winId].startHidden) {
&& firetray.Utils.prefService.getBoolPref('start_hidden')) {
LOG('start_hidden'); LOG('start_hidden');
let winId = firetray.Handler.getWindowIdFromChromeWindow(win);
LOG('winId='+winId);
firetray.Handler.hideSingleWindow(winId); firetray.Handler.hideSingleWindow(winId);
} }
@ -63,7 +58,7 @@ var firetrayChrome = { // each new window gets a new firetrayChrome !
firetray.Handler.hideSingleWindow(winId); firetray.Handler.hideSingleWindow(winId);
} else } else
firetray.Handler.hideAllWindows(); firetray.Handler.hideAllWindows();
event && event.preventDefault(); // no event when called directly (xul) event && event.preventDefault();
} }
} }
}; };

View File

@ -139,11 +139,10 @@ firetray.Handler = {
LOG("RECEIVED: "+topic+", launching timer"); LOG("RECEIVED: "+topic+", launching timer");
// sessionstore-windows-restored does not come after the realization of // sessionstore-windows-restored does not come after the realization of
// all windows... so we wait a little // all windows... so we wait a little
var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); firetray.Utils.timer(function() {
timer.initWithCallback({ notify: function() {
firetray.Handler.appStarted = true; firetray.Handler.appStarted = true;
LOG("*** appStarted ***"); LOG("*** appStarted ***");
}}, FIRETRAY_DELAY_BROWSER_STARTUP_MILLISECONDS, Ci.nsITimer.TYPE_ONE_SHOT); }, FIRETRAY_DELAY_BROWSER_STARTUP_MILLISECONDS, Ci.nsITimer.TYPE_ONE_SHOT);
break; break;
case "xpcom-will-shutdown": case "xpcom-will-shutdown":
LOG("xpcom-will-shutdown"); LOG("xpcom-will-shutdown");
@ -360,7 +359,7 @@ firetray.PrefListener = new PrefListener(
LOG('Pref changed: '+name); LOG('Pref changed: '+name);
switch (name) { switch (name) {
case 'hides_single_window': case 'hides_single_window':
firetray.Handler.updatePopupMenu(); firetray.Handler.showHidePopupMenuItems();
break; break;
case 'show_icon_on_hide': case 'show_icon_on_hide':
firetray.Handler.showHideIcon(); firetray.Handler.showHideIcon();

View File

@ -151,6 +151,9 @@ firetray.PopupMenu = {
}, },
showSingleWindowItem: function(xid) { showSingleWindowItem: function(xid) {
if (!this.windowItemsHandled())
return;
LOG("showSingleWindowItem"); LOG("showSingleWindowItem");
let menuItemWindow = firetray.Handler.gtkPopupMenuWindowItems.get(xid); let menuItemWindow = firetray.Handler.gtkPopupMenuWindowItems.get(xid);
this.showItem(menuItemWindow); this.showItem(menuItemWindow);
@ -173,13 +176,15 @@ firetray.PopupMenu = {
this.hideSingleWindowItemAndSeparator(xid); this.hideSingleWindowItemAndSeparator(xid);
}, },
// PopupMenu.hideItem(firetray.Handler.gtkPopupMenuWindowItems.get(xid))
hideSingleWindowItemAndSeparator: function(xid) { hideSingleWindowItemAndSeparator: function(xid) {
this.hideSingleWindowItem(xid); this.hideSingleWindowItem(xid);
this.hideWindowSeparator(); this.hideWindowSeparator();
}, },
hideSingleWindowItemAndSeparatorMaybe: function(xid) { hideSingleWindowItemAndSeparatorMaybe: function(xid) {
if (!this.windowItemsHandled())
return;
this.hideSingleWindowItem(xid); this.hideSingleWindowItem(xid);
if (firetray.Handler.visibleWindowsCount === firetray.Handler.windowsCount) if (firetray.Handler.visibleWindowsCount === firetray.Handler.windowsCount)
this.hideWindowSeparator(); this.hideWindowSeparator();
@ -202,19 +207,20 @@ firetray.PopupMenu = {
hideWindowSeparator: function() { hideWindowSeparator: function() {
LOG("hiding menuSeparatorWindows"); LOG("hiding menuSeparatorWindows");
gtk.gtk_widget_hide(ctypes.cast(this.menuSeparatorWindows, gtk.GtkWidget.ptr)); gtk.gtk_widget_hide(ctypes.cast(this.menuSeparatorWindows, gtk.GtkWidget.ptr));
},
showHideWindowItems: function() {
if (this.windowItemsHandled())
this.showAllWindowItemsOnlyVisibleWindows();
else
this.hideAllWindowItems();
},
windowItemsHandled: function() {
return (firetray.Handler.inBrowserApp &&
firetray.Utils.prefService.getBoolPref('hides_single_window'));
} }
}; // firetray.PopupMenu }; // firetray.PopupMenu
firetray.Handler.showHidePopupMenuItems = firetray.PopupMenu.showHideWindowItems;
firetray.Handler.popupMenuWindowItemsHandled = function() {
return (firetray.Handler.inBrowserApp &&
firetray.Utils.prefService.getBoolPref('hides_single_window'));
};
firetray.Handler.updatePopupMenu = function() {
if (firetray.Handler.popupMenuWindowItemsHandled())
firetray.PopupMenu.showAllWindowItemsOnlyVisibleWindows();
else
firetray.PopupMenu.hideAllWindowItems();
};

View File

@ -188,7 +188,65 @@ firetray.Window = {
return true; return true;
}, },
saveWindowPositionAndSize: function(xid) { showSingleStateful: function(xid) {
LOG("showSingleStateful xid="+xid);
// try to restore previous state. TODO: z-order respected ?
firetray.Window.restorePositionAndSize(xid);
firetray.Window.restoreStates(xid);
// better visual effect if visibility set here instead of before
firetray.Window.setVisibility(xid, true);
firetray.Window.restoreDesktop(xid); // after show
firetray.Window.activate(xid);
firetray.PopupMenu.hideSingleWindowItemAndSeparatorMaybe(xid);
firetray.Handler.showHideIcon();
},
showSingleStatelessOnce: function(xid) {
LOG("showSingleStateless");
firetray.Window.setVisibility(xid, true);
firetray.PopupMenu.hideSingleWindowItemAndSeparatorMaybe(xid);
firetray.Handler.showHideIcon();
firetray.Handler.windows[xid].show = firetray.Window.showSingleStateful; // reset
},
// NOTE: we keep using high-level cross-plat BaseWindow.visibility (instead of
// gdk_window_show_unraised)
/* FIXME: hiding windows should also hide child windows */
hideSingleStateful: function(xid) {
LOG("hideSingleStateful");
firetray.Window.savePositionAndSize(xid);
firetray.Window.saveStates(xid);
firetray.Window.saveDesktop(xid);
firetray.Window.setVisibility(xid, false);
firetray.PopupMenu.showSingleWindowItem(xid);
firetray.Handler.showHideIcon();
},
/**
* hides without saving window states (position, size, ...) This is needed
* when application starts hidden: as windows are not realized, their state
* is not accurate.
*/
hideSingleStatelessOnce: function(xid) {
LOG("hideSingleStateless");
firetray.Window.setVisibility(xid, false);
firetray.PopupMenu.showSingleWindowItem(xid);
firetray.Handler.showHideIcon();
firetray.Handler.windows[xid].hide = firetray.Window.hideSingleStateful; // reset
},
savePositionAndSize: function(xid) {
let gx = {}, gy = {}, gwidth = {}, gheight = {}; let gx = {}, gy = {}, gwidth = {}, gheight = {};
firetray.Handler.windows[xid].baseWin.getPositionAndSize(gx, gy, gwidth, gheight); firetray.Handler.windows[xid].baseWin.getPositionAndSize(gx, gy, gwidth, gheight);
firetray.Handler.windows[xid].savedX = gx.value; firetray.Handler.windows[xid].savedX = gx.value;
@ -198,7 +256,7 @@ firetray.Window = {
LOG("save: gx="+gx.value+", gy="+gy.value+", gwidth="+gwidth.value+", gheight="+gheight.value); LOG("save: gx="+gx.value+", gy="+gy.value+", gwidth="+gwidth.value+", gheight="+gheight.value);
}, },
restoreWindowPositionAndSize: function(xid) { restorePositionAndSize: function(xid) {
if ("undefined" === typeof(firetray.Handler.windows[xid].savedX)) if ("undefined" === typeof(firetray.Handler.windows[xid].savedX))
return; // windows[xid].saved* may not be initialized return; // windows[xid].saved* may not be initialized
@ -215,13 +273,13 @@ firetray.Window = {
}); });
}, },
saveWindowStates: function(xid) { saveStates: function(xid) {
let winStates = firetray.Window.getXWindowStates(x11.Window(xid)); let winStates = firetray.Window.getXWindowStates(x11.Window(xid));
firetray.Handler.windows[xid].savedStates = winStates; firetray.Handler.windows[xid].savedStates = winStates;
LOG("save: windowStates="+winStates); LOG("save: windowStates="+winStates);
}, },
restoreWindowStates: function(xid) { restoreStates: function(xid) {
let winStates = firetray.Handler.windows[xid].savedStates; let winStates = firetray.Handler.windows[xid].savedStates;
LOG("restored WindowStates: " + winStates); LOG("restored WindowStates: " + winStates);
if (winStates & FIRETRAY_XWINDOW_MAXIMIZED) { if (winStates & FIRETRAY_XWINDOW_MAXIMIZED) {
@ -235,15 +293,15 @@ firetray.Window = {
delete firetray.Handler.windows[xid].savedStates; delete firetray.Handler.windows[xid].savedStates;
}, },
saveWindowDesktop: function(xid) { saveDesktop: function(xid) {
let winDesktop = firetray.Window.getXWindowDesktop(x11.Window(xid)); let winDesktop = firetray.Window.getXWindowDesktop(x11.Window(xid));
firetray.Handler.windows[xid].savedDesktop = winDesktop; firetray.Handler.windows[xid].savedDesktop = winDesktop;
LOG("save: windowDesktop="+winDesktop); LOG("save: windowDesktop="+winDesktop);
}, },
restoreWindowDesktop: function(xid) { restoreDesktop: function(xid) {
let desktopDest = firetray.Handler.windows[xid].savedDesktop; let desktopDest = firetray.Handler.windows[xid].savedDesktop;
if (desktopDest === null) return; if (desktopDest === null || "undefined" === typeof(desktopDest)) return;
let dataSize = 1; let dataSize = 1;
let data = ctypes.long(dataSize); let data = ctypes.long(dataSize);
@ -254,6 +312,14 @@ firetray.Window = {
delete firetray.Handler.windows[xid].savedDesktop; delete firetray.Handler.windows[xid].savedDesktop;
}, },
setVisibility: function(xid, visibility) {
firetray.Handler.windows[xid].baseWin.visibility = visibility;
firetray.Handler.windows[xid].visibility = visibility;
firetray.Handler.visibleWindowsCount = visibility ?
firetray.Handler.visibleWindowsCount + 1 :
firetray.Handler.visibleWindowsCount - 1 ;
},
xSendClientMessgeEvent: function(xid, atom, data, dataSize) { xSendClientMessgeEvent: function(xid, atom, data, dataSize) {
let xev = new x11.XClientMessageEvent; let xev = new x11.XClientMessageEvent;
xev.type = x11.ClientMessage; xev.type = x11.ClientMessage;
@ -389,9 +455,12 @@ firetray.Window = {
getWindowTitle: function(xid) { getWindowTitle: function(xid) {
let title = firetray.Handler.windows[xid].baseWin.title; let title = firetray.Handler.windows[xid].baseWin.title;
LOG("baseWin.title="+title);
let tailIndex = title.indexOf(" - Mozilla "+firetray.Handler.appNameOriginal); let tailIndex = title.indexOf(" - Mozilla "+firetray.Handler.appNameOriginal);
if (tailIndex !== -1) if (tailIndex !== -1)
return title.substring(0, tailIndex) return title.substring(0, tailIndex);
else if (title === "Mozilla "+firetray.Handler.appNameOriginal)
return title;
else else
return null; return null;
}, },
@ -484,12 +553,22 @@ firetray.Handler.registerWindow = function(win) {
} catch (x) { } catch (x) {
firetray.Window.unregisterWindowByXID(xid); firetray.Window.unregisterWindowByXID(xid);
ERROR(x); ERROR(x);
return false; return null;
}
if (!firetray.Handler.appStarted &&
firetray.Utils.prefService.getBoolPref('start_hidden')) {
this.windows[xid].startHidden = true;
this.windows[xid].hide = firetray.Window.hideSingleStatelessOnce;
this.windows[xid].show = firetray.Window.showSingleStatelessOnce;
} else {
this.windows[xid].startHidden = false;
this.windows[xid].hide = firetray.Window.hideSingleStateful;
this.windows[xid].show = firetray.Window.showSingleStateful;
} }
LOG("AFTER"); firetray.Handler.dumpWindows(); LOG("AFTER"); firetray.Handler.dumpWindows();
return xid;
return true;
}; };
firetray.Handler.unregisterWindow = function(win) { firetray.Handler.unregisterWindow = function(win) {
@ -499,41 +578,13 @@ firetray.Handler.unregisterWindow = function(win) {
}; };
firetray.Handler.showSingleWindow = function(xid) { firetray.Handler.showSingleWindow = function(xid) {
LOG("show xid="+xid); LOG("showSingleWindow xid="+xid);
this.windows[xid].show(xid);
// try to restore previous state. TODO: z-order respected ?
firetray.Window.restoreWindowPositionAndSize(xid);
firetray.Window.restoreWindowStates(xid);
firetray.Handler.windows[xid].baseWin.visibility = true; // show
firetray.Window.restoreWindowDesktop(xid); // after show
firetray.Window.activate(xid);
// TODO: we need want to restore to the original monitor (screen)
firetray.Handler.windows[xid].visibility = true;
firetray.Handler.visibleWindowsCount += 1;
if (firetray.Handler.popupMenuWindowItemsHandled())
firetray.PopupMenu.hideSingleWindowItemAndSeparatorMaybe(xid);
firetray.Handler.showHideIcon();
}; };
// NOTE: we keep using high-level cross-plat BaseWindow.visibility (instead of
// gdk_window_show_unraised)
/* FIXME: hiding windows should also hide child windows */
firetray.Handler.hideSingleWindow = function(xid) { firetray.Handler.hideSingleWindow = function(xid) {
LOG("hideSingleWindow"); LOG("hideSingleWindow xid="+xid);
this.windows[xid].hide(xid);
firetray.Window.saveWindowPositionAndSize(xid);
firetray.Window.saveWindowStates(xid);
firetray.Window.saveWindowDesktop(xid);
firetray.Handler.windows[xid].baseWin.visibility = false; // hide
firetray.Handler.windows[xid].visibility = false;
firetray.Handler.visibleWindowsCount -= 1;
if (firetray.Handler.popupMenuWindowItemsHandled())
firetray.PopupMenu.showSingleWindowItem(xid);
firetray.Handler.showHideIcon();
}; };
firetray.Handler.showHideAllWindows = function(gtkStatusIcon, userData) { firetray.Handler.showHideAllWindows = function(gtkStatusIcon, userData) {