mirror of
https://github.com/moparisthebest/FireTray
synced 2024-12-22 22:08:49 -05:00
Merge branch 'start_hidden'
This commit is contained in:
commit
803143a535
@ -17,20 +17,15 @@ var firetrayChrome = { // each new window gets a new firetrayChrome !
|
||||
let init = firetray.Handler.initialized || firetray.Handler.init();
|
||||
|
||||
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)
|
||||
firetray.Messaging.updateMsgCount();
|
||||
|
||||
// prevent window closing.
|
||||
win.addEventListener('close', firetrayChrome.onClose, true);
|
||||
|
||||
if (!firetray.Handler.appStarted
|
||||
&& firetray.Utils.prefService.getBoolPref('start_hidden')) {
|
||||
if (firetray.Handler.windows[winId].startHidden) {
|
||||
LOG('start_hidden');
|
||||
let winId = firetray.Handler.getWindowIdFromChromeWindow(win);
|
||||
LOG('winId='+winId);
|
||||
firetray.Handler.hideSingleWindow(winId);
|
||||
}
|
||||
|
||||
@ -63,7 +58,7 @@ var firetrayChrome = { // each new window gets a new firetrayChrome !
|
||||
firetray.Handler.hideSingleWindow(winId);
|
||||
} else
|
||||
firetray.Handler.hideAllWindows();
|
||||
event && event.preventDefault(); // no event when called directly (xul)
|
||||
event && event.preventDefault();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -139,11 +139,10 @@ firetray.Handler = {
|
||||
LOG("RECEIVED: "+topic+", launching timer");
|
||||
// sessionstore-windows-restored does not come after the realization of
|
||||
// all windows... so we wait a little
|
||||
var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
||||
timer.initWithCallback({ notify: function() {
|
||||
firetray.Utils.timer(function() {
|
||||
firetray.Handler.appStarted = true;
|
||||
LOG("*** appStarted ***");
|
||||
}}, FIRETRAY_DELAY_BROWSER_STARTUP_MILLISECONDS, Ci.nsITimer.TYPE_ONE_SHOT);
|
||||
}, FIRETRAY_DELAY_BROWSER_STARTUP_MILLISECONDS, Ci.nsITimer.TYPE_ONE_SHOT);
|
||||
break;
|
||||
case "xpcom-will-shutdown":
|
||||
LOG("xpcom-will-shutdown");
|
||||
@ -360,7 +359,7 @@ firetray.PrefListener = new PrefListener(
|
||||
LOG('Pref changed: '+name);
|
||||
switch (name) {
|
||||
case 'hides_single_window':
|
||||
firetray.Handler.updatePopupMenu();
|
||||
firetray.Handler.showHidePopupMenuItems();
|
||||
break;
|
||||
case 'show_icon_on_hide':
|
||||
firetray.Handler.showHideIcon();
|
||||
|
@ -151,6 +151,9 @@ firetray.PopupMenu = {
|
||||
},
|
||||
|
||||
showSingleWindowItem: function(xid) {
|
||||
if (!this.windowItemsHandled())
|
||||
return;
|
||||
|
||||
LOG("showSingleWindowItem");
|
||||
let menuItemWindow = firetray.Handler.gtkPopupMenuWindowItems.get(xid);
|
||||
this.showItem(menuItemWindow);
|
||||
@ -173,13 +176,15 @@ firetray.PopupMenu = {
|
||||
this.hideSingleWindowItemAndSeparator(xid);
|
||||
},
|
||||
|
||||
// PopupMenu.hideItem(firetray.Handler.gtkPopupMenuWindowItems.get(xid))
|
||||
hideSingleWindowItemAndSeparator: function(xid) {
|
||||
this.hideSingleWindowItem(xid);
|
||||
this.hideWindowSeparator();
|
||||
},
|
||||
|
||||
hideSingleWindowItemAndSeparatorMaybe: function(xid) {
|
||||
if (!this.windowItemsHandled())
|
||||
return;
|
||||
|
||||
this.hideSingleWindowItem(xid);
|
||||
if (firetray.Handler.visibleWindowsCount === firetray.Handler.windowsCount)
|
||||
this.hideWindowSeparator();
|
||||
@ -202,19 +207,20 @@ firetray.PopupMenu = {
|
||||
hideWindowSeparator: function() {
|
||||
LOG("hiding menuSeparatorWindows");
|
||||
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.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();
|
||||
};
|
||||
firetray.Handler.showHidePopupMenuItems = firetray.PopupMenu.showHideWindowItems;
|
||||
|
@ -188,7 +188,65 @@ firetray.Window = {
|
||||
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 = {};
|
||||
firetray.Handler.windows[xid].baseWin.getPositionAndSize(gx, gy, gwidth, gheight);
|
||||
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);
|
||||
},
|
||||
|
||||
restoreWindowPositionAndSize: function(xid) {
|
||||
restorePositionAndSize: function(xid) {
|
||||
if ("undefined" === typeof(firetray.Handler.windows[xid].savedX))
|
||||
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));
|
||||
firetray.Handler.windows[xid].savedStates = winStates;
|
||||
LOG("save: windowStates="+winStates);
|
||||
},
|
||||
|
||||
restoreWindowStates: function(xid) {
|
||||
restoreStates: function(xid) {
|
||||
let winStates = firetray.Handler.windows[xid].savedStates;
|
||||
LOG("restored WindowStates: " + winStates);
|
||||
if (winStates & FIRETRAY_XWINDOW_MAXIMIZED) {
|
||||
@ -235,15 +293,15 @@ firetray.Window = {
|
||||
delete firetray.Handler.windows[xid].savedStates;
|
||||
},
|
||||
|
||||
saveWindowDesktop: function(xid) {
|
||||
saveDesktop: function(xid) {
|
||||
let winDesktop = firetray.Window.getXWindowDesktop(x11.Window(xid));
|
||||
firetray.Handler.windows[xid].savedDesktop = winDesktop;
|
||||
LOG("save: windowDesktop="+winDesktop);
|
||||
},
|
||||
|
||||
restoreWindowDesktop: function(xid) {
|
||||
restoreDesktop: function(xid) {
|
||||
let desktopDest = firetray.Handler.windows[xid].savedDesktop;
|
||||
if (desktopDest === null) return;
|
||||
if (desktopDest === null || "undefined" === typeof(desktopDest)) return;
|
||||
|
||||
let dataSize = 1;
|
||||
let data = ctypes.long(dataSize);
|
||||
@ -254,6 +312,14 @@ firetray.Window = {
|
||||
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) {
|
||||
let xev = new x11.XClientMessageEvent;
|
||||
xev.type = x11.ClientMessage;
|
||||
@ -389,9 +455,12 @@ firetray.Window = {
|
||||
|
||||
getWindowTitle: function(xid) {
|
||||
let title = firetray.Handler.windows[xid].baseWin.title;
|
||||
LOG("baseWin.title="+title);
|
||||
let tailIndex = title.indexOf(" - Mozilla "+firetray.Handler.appNameOriginal);
|
||||
if (tailIndex !== -1)
|
||||
return title.substring(0, tailIndex)
|
||||
return title.substring(0, tailIndex);
|
||||
else if (title === "Mozilla "+firetray.Handler.appNameOriginal)
|
||||
return title;
|
||||
else
|
||||
return null;
|
||||
},
|
||||
@ -484,12 +553,22 @@ firetray.Handler.registerWindow = function(win) {
|
||||
} catch (x) {
|
||||
firetray.Window.unregisterWindowByXID(xid);
|
||||
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();
|
||||
|
||||
return true;
|
||||
return xid;
|
||||
};
|
||||
|
||||
firetray.Handler.unregisterWindow = function(win) {
|
||||
@ -499,41 +578,13 @@ firetray.Handler.unregisterWindow = function(win) {
|
||||
};
|
||||
|
||||
firetray.Handler.showSingleWindow = function(xid) {
|
||||
LOG("show xid="+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();
|
||||
LOG("showSingleWindow xid="+xid);
|
||||
this.windows[xid].show(xid);
|
||||
};
|
||||
|
||||
// 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) {
|
||||
LOG("hideSingleWindow");
|
||||
|
||||
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();
|
||||
LOG("hideSingleWindow xid="+xid);
|
||||
this.windows[xid].hide(xid);
|
||||
};
|
||||
|
||||
firetray.Handler.showHideAllWindows = function(gtkStatusIcon, userData) {
|
||||
|
Loading…
Reference in New Issue
Block a user