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

show/hide mechanism in place: clicking on tray icon or closing a window.

NOTE: a WndProc on each mozilla window is not needed for this.
This commit is contained in:
foudfou 2014-02-05 22:48:14 +01:00
parent 8f8fad3afc
commit 7a0ff56cd1
8 changed files with 65 additions and 59 deletions

View File

@ -144,7 +144,7 @@ $(xpi_built): check_version check_loglevel $(build_dir) $(build_includes)
.PHONY: build
build: $(xpi_built)
@echo
@echo "Build finished successfully."
@echo "Build finished successfully in $(build_dir)."
@echo
# This cleans all temporary files and directories created by 'make'.

View File

@ -32,7 +32,6 @@ var firetrayChrome = { // each new window gets a new firetrayChrome !
return true;
},
/* NOTE: don't do firetray.Handler.initialized=false here, otherwise after a
window close, a new window will create a new handler (and hence, a new tray
icon) */

View File

@ -6,7 +6,7 @@
<em:unpack>true</em:unpack> <!-- needed for embedded icons -->
<em:type>2</em:type>
<em:name>FireTray</em:name>
<em:version>0.4.8</em:version> <!-- change FIRETRAY_VERSION accordingly ! -->
<em:version>0.4.99</em:version> <!-- change FIRETRAY_VERSION accordingly ! -->
<em:creator>Hua Luo, Francesco Solero, Foudil BRÉTEL</em:creator>
<em:contributor>Hua Luo, Francesco Solero (Firetray original authors)</em:contributor>
<em:homepageURL>https://github.com/foudfou/firetray</em:homepageURL>

View File

@ -36,6 +36,10 @@ firetray.Handler = {
inMailApp: false,
appHasChat: false,
appStarted: false,
/* TODO: we should rewrite firetray.Handler[wid].visible,
firetray.Handler.windowsCount, firetray.Handler.visibleWindowsCount as
getters. They mainly serve as a cache for computing the visibilityRate but
tend to be a bit heavy to handle. */
windows: {},
windowsCount: 0,
visibleWindowsCount: 0,

View File

@ -25,7 +25,7 @@ const Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://firetray/logging.jsm");
const FIRETRAY_VERSION = "0.4.8"; // needed for sync call of onVersionChange() :(
const FIRETRAY_VERSION = "0.4.99"; // needed for sync call of onVersionChange() :(
const FIRETRAY_ID = "{9533f794-00b4-4354-aa15-c2bbda6989f8}";
const FIRETRAY_PREF_BRANCH = "extensions.firetray.";
const FIRETRAY_SPLASH_PAGE = "http://foudfou.github.com/FireTray/";
@ -189,11 +189,11 @@ firetray.Utils = {
dumpObj: function(obj) {
let str = "";
for(i in obj) {
for(let prop in firetray.js.listAllProperties(obj)) {
try {
str += "obj["+i+"]: " + obj[i] + "\n";
str += "obj["+prop+"]: " + obj[prop] + "\n";
} catch(e) {
str += "obj["+i+"]: Unavailable\n";
str += "obj["+prop+"]: Unavailable\n";
}
}
log.info(str);
@ -297,6 +297,16 @@ firetray.js = {
if (!condition) {
throw message || "Assertion failed";
}
},
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects#Enumerating_all_properties_of_an_object
listAllProperties: function(obj){
var objectToInspect;
var result = [];
for(objectToInspect = obj; objectToInspect !== null; objectToInspect = Object.getPrototypeOf(objectToInspect)){
result = result.concat(Object.getOwnPropertyNames(objectToInspect));
}
return result;
}
};

View File

@ -100,6 +100,24 @@ function user32_defines(lib) {
lib.lazy_bind("UnregisterClassW", win32.BOOL, win32.LPCTSTR, win32.HINSTANCE);
lib.lazy_bind("CreateWindowExW", win32.HWND, win32.DWORD, win32.LPCTSTR, win32.LPCTSTR, win32.DWORD, ctypes.int, ctypes.int, ctypes.int, ctypes.int, win32.HWND, win32.HMENU, win32.HINSTANCE, win32.LPVOID);
lib.lazy_bind("DestroyWindow", win32.BOOL, win32.HWND);
lib.lazy_bind("ShowWindow", win32.BOOL, win32.HWND, ctypes.int);
lib.lazy_bind("IsWindowVisible", win32.BOOL, win32.HWND);
this.SW_HIDE = 0;
this.SW_SHOWNORMAL = 1;
this.SW_NORMAL = 1;
this.SW_SHOWMINIMIZED = 2;
this.SW_SHOWMAXIMIZED = 3;
this.SW_MAXIMIZE = 3;
this.SW_SHOWNOACTIVATE = 4;
this.SW_SHOW = 5;
this.SW_MINIMIZE = 6;
this.SW_SHOWMINNOACTIVE = 7;
this.SW_SHOWNA = 8;
this.SW_RESTORE = 9;
this.SW_SHOWDEFAULT = 10;
this.SW_FORCEMINIMIZE = 11;
this.SW_MAX = 11;
this.CW_USEDEFAULT = ctypes.int(0x80000000); // -2147483648

View File

@ -90,15 +90,6 @@ firetray.StatusIcon = {
log.debug("CreateWindow="+!hwnd_hidden.isNull()+" winLastError="+ctypes.winLastError);
this.callbacks.proxyWndProc = user32.WNDPROC(firetray.StatusIcon.proxyWndProc);
/*
// TESTING
let proc = user32.GetWindowLongW(hwnd_hidden, user32.GWLP_WNDPROC);
log.debug(" proc="+proc.toString(16)+" winLastError="+ctypes.winLastError);
this.callbacks.procPrev = user32.WNDPROC(
user32.SetWindowLongW(hwnd_hidden, user32.GWLP_WNDPROC,
ctypes.cast(this.callbacks.proxyWndProc, win32.LONG_PTR))
);
*/
let procPrev = user32.SetWindowLongW(hwnd_hidden, user32.GWLP_WNDPROC,
ctypes.cast(this.callbacks.proxyWndProc, win32.LONG_PTR));
log.debug("procPrev="+procPrev+" winLastError="+ctypes.winLastError);
@ -132,19 +123,7 @@ firetray.StatusIcon = {
switch (+lParam) {
case win32.WM_LBUTTONUP:
log.debug("WM_LBUTTONUP");
try {
for (let wid in firetray.Handler.windows) {
let hwnd = firetray.Win32.hexStrToHwnd(wid);
let rv = user32.SendMessageW(hwnd, firetray.Win32.WM_TRAYMESSAGEFWD, 0, 1);
log.debug("SendMessageW WM_TRAYMESSAGEFWD rv="+rv+" winLastError="+ctypes.winLastError);
}
} catch(error) {
log.error(error);
}
firetray.Handler.showHideAllWindows();
break;
case win32.WM_RBUTTONUP:
log.debug("WM_RBUTTONUP");

View File

@ -39,20 +39,22 @@ firetray.Window.shutdown = function() {
this.initialized = false;
};
firetray.Window.show = function(xid) {
log.debug("show xid="+xid);
firetray.Window.getVisibility = function(hwnd) {
let style = user32.GetWindowLongW(hwnd, user32.GWL_STYLE);
let visible = ((style & user32.WS_VISIBLE) != 0); // user32.IsWindowVisible(hwnd);
log.debug("visible="+visible);
return visible;
};
firetray.Window.hide = function(xid) {
log.debug("hide");
};
firetray.Window.startupHide = function(xid) {
log.debug('startupHide: '+xid);
};
firetray.Window.setVisibility = function(xid, visibility) {
// firetray.Window.{show,hide} useless
firetray.Window.setVisibility = function(wid, visible) {
log.debug("setVisibility="+visible);
let hwnd = firetray.Win32.hexStrToHwnd(wid);
let ret = user32.ShowWindow(hwnd, visible ? user32.SW_SHOW : user32.SW_HIDE);
log.debug(" ShowWindow="+ret+" winLastError="+ctypes.winLastError);
this.updateVisibility(wid, visible);
};
// firetray.Window.updateVisibility inherited
firetray.Window.wndProc = function(hWnd, uMsg, wParam, lParam) { // filterWindow
// log.debug("wndProc CALLED: hWnd="+hWnd+", uMsg="+uMsg+", wParam="+wParam+", lParam="+lParam);
@ -74,7 +76,7 @@ firetray.Window.wndProc = function(hWnd, uMsg, wParam, lParam) { // filterWindow
firetray.Window.restoreWndProc = function(wid) {
let procPrev = firetray.Handler.wndProcsOrig.get(wid);
let hwnd = new win32.HWND(ctypes.UInt64(wid));
let hwnd = firetray.Win32.hexStrToHwnd(wid);
log.debug("hwnd="+hwnd);
let proc = user32.WNDPROC(
user32.SetWindowLongW(hwnd, user32.GWLP_WNDPROC,
@ -120,15 +122,10 @@ firetray.Handler.registerWindow = function(win) {
this.windows[wid].baseWin = baseWin;
// SetupWnd(hwnd);
// ::SetPropW(hwnd, kIconData, reinterpret_cast<HANDLE>(iconData));
// ::SetPropW(hwnd, kIconMouseEventProc, reinterpret_cast<HANDLE>(callback));
// ::SetPropW(hwnd, kIcon, reinterpret_cast<HANDLE>(0x1));
try {
this.windowsCount += 1;
// NOTE: no need to check for window state to set visibility because all
// windows *are* shown at startup
firetray.Window.updateVisibility(wid, true);
firetray.Window.updateVisibility(wid, true); // windows *are* visible at startup
log.debug("window "+wid+" registered");
let wndProc = user32.WNDPROC(firetray.Window.wndProc);
@ -177,13 +174,15 @@ firetray.Handler.unregisterWindow = function(win) {
return true;
};
firetray.Handler.showWindow = firetray.Window.show;
firetray.Handler.hideWindow = firetray.Window.hide;
firetray.Handler.showWindow = function(wid) {
return firetray.Window.setVisibility(wid, true);
};
firetray.Handler.hideWindow = function(wid) {
return firetray.Window.setVisibility(wid, false);
};
firetray.Handler.showHideAllWindows = function(gtkStatusIcon, userData) {
log.debug("showHideAllWindows: "+userData);
// NOTE: showHideAllWindows being a callback, we need to use
// 'firetray.Handler' explicitely instead of 'this'
firetray.Handler.showHideAllWindows = function() {
log.debug("showHideAllWindows");
log.debug(" visibleWindowsCount="+firetray.Handler.visibleWindowsCount);
log.debug(" windowsCount="+firetray.Handler.windowsCount);
@ -195,7 +194,4 @@ firetray.Handler.showHideAllWindows = function(gtkStatusIcon, userData) {
} else {
firetray.Handler.hideAllWindows();
}
let stopPropagation = true;
return stopPropagation;
};