1
0
mirror of https://github.com/moparisthebest/FireTray synced 2025-01-08 12:08:05 -05:00

Add popup menu items for hidden windows.

Still need to handle 'hides_single_window' switching.
This commit is contained in:
foudfou 2014-04-05 17:10:55 +02:00
parent 46ceaec9d0
commit 74ac8d54d7
8 changed files with 76 additions and 25 deletions

View File

@ -340,6 +340,9 @@ firetray.Handler = {
activateLastWindowCb: function(gtkStatusIcon, gdkEvent, userData) {},
getActiveWindow: function() {},
windowGetAttention: function(winId) {},
showHidePopupMenuItems: function() {}, // linux
addPopupWindowItemAndSeparatorMaybe: function(wid) {}, // winnt
removePopupWindowItemAndSeparatorMaybe: function(wid) {}, // winnt
showAllWindows: function() {
log.debug("showAllWindows");

View File

@ -24,4 +24,20 @@ FiretrayWindow.prototype = {
return null;
},
getWindowTitle: function(wid) {
let title = firetray.Handler.windows[wid].baseWin.title;
log.debug("|baseWin.title="+title+"|");
let tailIndex;
tailIndex = title.indexOf(" - Mozilla "+firetray.Handler.appName);
if (tailIndex === -1)
tailIndex = title.indexOf(" - "+firetray.Handler.appName);
if (tailIndex !== -1)
return title.substring(0, tailIndex);
else if (title === "Mozilla "+firetray.Handler.appName)
return title;
else
return null;
}
};

View File

@ -299,6 +299,7 @@ function user32_defines(lib) {
this.MIIM_FTYPE = 0x00000100;
lib.lazy_bind("InsertMenuW", win32.BOOL, win32.HMENU, win32.UINT, win32.UINT, win32.UINT_PTR, win32.LPCTSTR);
lib.lazy_bind("DeleteMenu", win32.BOOL, win32.HMENU, win32.UINT, win32.UINT);
this.MF_INSERT = 0x00000000;
this.MF_CHANGE = 0x00000080;
@ -353,6 +354,8 @@ function user32_defines(lib) {
this.TPM_HORIZONTAL = 0x0000;
this.TPM_VERTICAL = 0x0040;
lib.lazy_bind("GetMenuItemCount", ctypes.int, win32.HMENU);
lib.lazy_bind("CalculatePopupWindowPosition", win32.BOOL, win32.POINT.ptr, win32.SIZE, win32.UINT, win32.RECT.ptr, win32.RECT.ptr);
lib.lazy_bind("TrackPopupMenu", win32.BOOL, win32.HMENU, win32.UINT, ctypes.int, ctypes.int, ctypes.int, win32.HWND, win32.RECT.ptr);
lib.lazy_bind("SetForegroundWindow", win32.BOOL, win32.HWND);

View File

@ -204,7 +204,6 @@ firetray.ChatStatusIcon = {
{ notify: firetray.ChatStatusIcon.fadeStep },
ALPHA_STEP_SLEEP_MILLISECONDS, Ci.nsITimer.TYPE_ONE_SHOT);
} catch (e if e instanceof StopIteration) {
if (firetray.ChatStatusIcon.events['stop-fade']) {

View File

@ -172,8 +172,7 @@ firetray.PopupMenu = {
},
hideWindowItemAndSeparatorMaybe: function(xid) {
if (!this.windowItemsHandled())
return;
if (!this.windowItemsHandled()) return;
this.hideWindowItem(xid);
if (firetray.Handler.visibleWindowsCount === firetray.Handler.windowsCount)
@ -212,4 +211,5 @@ firetray.PopupMenu = {
}; // firetray.PopupMenu
firetray.Handler.showHidePopupMenuItems = firetray.PopupMenu.showHideWindowItems;
firetray.Handler.showHidePopupMenuItems =
firetray.PopupMenu.showHideWindowItems.bind(firetray.PopupMenu);

View File

@ -498,22 +498,6 @@ firetray.Window.getXWindowDesktop = function(xwin) {
return desktop;
};
firetray.Window.getWindowTitle = function(xid) {
let title = firetray.Handler.windows[xid].baseWin.title;
log.debug("|baseWin.title="+title+"|");
let tailIndex;
tailIndex = title.indexOf(" - Mozilla "+firetray.Handler.appName);
if (tailIndex === -1)
tailIndex = title.indexOf(" - "+firetray.Handler.appName);
if (tailIndex !== -1)
return title.substring(0, tailIndex);
else if (title === "Mozilla "+firetray.Handler.appName)
return title;
else
return null;
};
firetray.Window.checkSubscribedEventMasks = function(xid) {
let xWindowAttributes = new x11.XWindowAttributes;
let status = x11.XGetWindowAttributes(x11.current.Display, xid, xWindowAttributes.address());

View File

@ -46,23 +46,23 @@ firetray.PopupMenu = {
},
create: function() {
this.menu = user32.CreatePopupMenu(); // FIXME: destroy
this.menu = user32.CreatePopupMenu();
log.debug("menu="+this.menu);
this.insertMenuItem('Quit', 'quit', IDM_QUIT);
user32.InsertMenuW(this.menu, 0, user32.MF_BYPOSITION|user32.MF_SEPARATOR, 0, null);
this.insertSeparator();
this.insertMenuItem('Preferences', 'prefs', IDM_PREF);
let menuSeparatorAdded = false;
if (firetray.Handler.inBrowserApp) {
user32.InsertMenuW(this.menu, 0, user32.MF_BYPOSITION|user32.MF_SEPARATOR, 0, null);
this.insertSeparator();
menuSeparatorAdded = true;
this.insertMenuItem('NewWindow', 'new-wnd', IDM_NEW_WND);
}
if (firetray.Handler.inMailApp) {
if (!menuSeparatorAdded) {
user32.InsertMenuW(this.menu, 0, user32.MF_BYPOSITION|user32.MF_SEPARATOR, 0, null);
this.insertSeparator();
}
this.insertMenuItem('NewMessage', 'new-msg', IDM_NEW_MSG);
this.insertMenuItem('ResetIcon', 'reset', IDM_RESET);
@ -99,7 +99,48 @@ firetray.PopupMenu = {
}
},
insertSeparator: function() {
user32.InsertMenuW(this.menu, 0, user32.MF_BYPOSITION|user32.MF_SEPARATOR,
0, null);
},
// FIXME: need to handle hides_single_window=false
addWindowItemAndSeparatorMaybe: function(wid) {
if (firetray.Handler.visibleWindowsCount === firetray.Handler.windowsCount)
this.insertSeparator();
this.addWindowItem(wid);
},
removeWindowItemAndSeparatorMaybe: function(wid) {
this.removeWindowItem(wid);
if (firetray.Handler.visibleWindowsCount === firetray.Handler.windowsCount - 1)
user32.DeleteMenu(this.menu, 0, user32.MF_BYPOSITION);
},
addWindowItem: function(wid) {
let title = firetray.Window.getWindowTitle(wid);
let mii = new user32.MENUITEMINFOW();
mii.cbSize = user32.MENUITEMINFOW.size;
mii.fMask = user32.MIIM_ID | user32.MIIM_STRING | user32.MIIM_DATA;
mii.wID = ctypes.UInt64(wid);
mii.dwTypeData = win32._T(title);
if (!user32.InsertMenuItemW(this.menu, 0, true, mii.address())) {
log.error("InsertMenuItemW failed winLastError="+ctypes.winLastError);
}
},
removeWindowItem: function(wid) {
let itemId = ctypes.UInt64(wid);
if (!user32.DeleteMenu(this.menu, itemId, user32.MF_BYCOMMAND)) {
log.error("DeleteMenu failed winLastError="+ctypes.winLastError);
}
},
processMenuItem: function(itemId) {
let wid = firetray.Win32.hwndToHexStr(win32.HWND(itemId));
if (firetray.Handler.windows[wid]) {
firetray.Handler.showWindow(wid);
return;
}
switch (itemId) {
case IDM_PREF: firetray.Handler.openPrefWindow(); break;
case IDM_QUIT: firetray.Handler.quitApplication(); break;
@ -113,4 +154,7 @@ firetray.PopupMenu = {
}; // firetray.PopupMenu
firetray.Handler.showHidePopupMenuItems = firetray.PopupMenu.showHideWindowItems;
firetray.Handler.addPopupMenuWindowItemAndSeparatorMaybe =
firetray.PopupMenu.addWindowItemAndSeparatorMaybe.bind(firetray.PopupMenu);
firetray.Handler.removePopupMenuWindowItemAndSeparatorMaybe =
firetray.PopupMenu.removeWindowItemAndSeparatorMaybe.bind(firetray.PopupMenu);

View File

@ -201,9 +201,11 @@ firetray.Handler.unregisterWindow = function(win) {
};
firetray.Handler.showWindow = function(wid) {
firetray.Handler.removePopupMenuWindowItemAndSeparatorMaybe(wid);
return firetray.Window.setVisibility(wid, true);
};
firetray.Handler.hideWindow = function(wid) {
firetray.Handler.addPopupMenuWindowItemAndSeparatorMaybe(wid);
return firetray.Window.setVisibility(wid, false);
};