[Pkg-mozext-commits] [firetray] 17/84: show/hide mechanism in place: clicking on tray icon or closing a window.

David Prévot taffit at moszumanska.debian.org
Sun Jul 20 01:42:42 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository firetray.

commit 7a0ff56cd1e641c3a8097e80ddf411ad55242c1d
Author: foudfou <foudil.newbie+git at gmail.com>
Date:   Wed Feb 5 22:48:14 2014 +0100

    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.
---
 src/Makefile                             |  2 +-
 src/chrome/content/overlay.js            |  1 -
 src/install.rdf                          |  2 +-
 src/modules/FiretrayHandler.jsm          |  4 +++
 src/modules/commons.js                   | 18 +++++++---
 src/modules/ctypes/winnt/user32.jsm      | 18 ++++++++++
 src/modules/winnt/FiretrayStatusIcon.jsm | 23 +------------
 src/modules/winnt/FiretrayWindow.jsm     | 56 +++++++++++++++-----------------
 8 files changed, 65 insertions(+), 59 deletions(-)

diff --git a/src/Makefile b/src/Makefile
index 6742dc5..2f3641c 100755
--- a/src/Makefile
+++ b/src/Makefile
@@ -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'.
diff --git a/src/chrome/content/overlay.js b/src/chrome/content/overlay.js
index 0153dde..ef0d805 100644
--- a/src/chrome/content/overlay.js
+++ b/src/chrome/content/overlay.js
@@ -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) */
diff --git a/src/install.rdf b/src/install.rdf
index f948aac..46118a8 100644
--- a/src/install.rdf
+++ b/src/install.rdf
@@ -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>
diff --git a/src/modules/FiretrayHandler.jsm b/src/modules/FiretrayHandler.jsm
index 993c8d9..e89b7c0 100644
--- a/src/modules/FiretrayHandler.jsm
+++ b/src/modules/FiretrayHandler.jsm
@@ -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,
diff --git a/src/modules/commons.js b/src/modules/commons.js
index cf8697a..bcb9762 100644
--- a/src/modules/commons.js
+++ b/src/modules/commons.js
@@ -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;
   }
 };
 
diff --git a/src/modules/ctypes/winnt/user32.jsm b/src/modules/ctypes/winnt/user32.jsm
index 579618b..cf4f1f5 100644
--- a/src/modules/ctypes/winnt/user32.jsm
+++ b/src/modules/ctypes/winnt/user32.jsm
@@ -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
 
diff --git a/src/modules/winnt/FiretrayStatusIcon.jsm b/src/modules/winnt/FiretrayStatusIcon.jsm
index 51a5af5..312117b 100644
--- a/src/modules/winnt/FiretrayStatusIcon.jsm
+++ b/src/modules/winnt/FiretrayStatusIcon.jsm
@@ -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");
diff --git a/src/modules/winnt/FiretrayWindow.jsm b/src/modules/winnt/FiretrayWindow.jsm
index b84eaab..723270d 100644
--- a/src/modules/winnt/FiretrayWindow.jsm
+++ b/src/modules/winnt/FiretrayWindow.jsm
@@ -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,25 +174,24 @@ 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);
+  log.debug("  visibleWindowsCount="+firetray.Handler.visibleWindowsCount);
+  log.debug("  windowsCount="+firetray.Handler.windowsCount);
   let visibilityRate = firetray.Handler.visibleWindowsCount/firetray.Handler.windowsCount;
-  log.debug("visibilityRate="+visibilityRate);
+  log.debug("  visibilityRate="+visibilityRate);
   if ((0.5 < visibilityRate) && (visibilityRate < 1)
       || visibilityRate === 0) { // TODO: should be configurable
     firetray.Handler.showAllWindows();
   } else {
     firetray.Handler.hideAllWindows();
   }
-
-  let stopPropagation = true;
-  return stopPropagation;
 };

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/firetray.git



More information about the Pkg-mozext-commits mailing list