[Pkg-mozext-commits] [firetray] 17/399: * enable show/hide from tray icon ! thx Neil !! * fix Makefile * use closures for GCallback_t

David Prévot taffit at alioth.debian.org
Tue Oct 29 18:23:06 UTC 2013


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

taffit pushed a commit to branch dfsg-clean
in repository firetray.

commit e9321f534b4c0563c054e81f1c5577dae7a41422
Author: foudfou <foudil.newbie+git at gmail.com>
Date:   Mon Jul 25 02:27:30 2011 +0200

    * enable show/hide from tray icon ! thx Neil !!
    * fix Makefile
    * use closures for GCallback_t
    
    BUG: windows aren't restored at the same position, or with the same z-order
    https://developer.mozilla.org/en/nsIWindowMediator#getZOrderXULWindowEnumerator%28%29
    
    BUG: new window creates a new tray icon
---
 src/Makefile                  |    3 +-
 src/chrome/content/overlay.js |  239 ++++++++++++++++++++---------------------
 src/modules/LibGObject.js     |   12 +--
 src/modules/commons.js        |   13 +--
 4 files changed, 128 insertions(+), 139 deletions(-)

diff --git a/src/Makefile b/src/Makefile
index eb4232c..243049d 100755
--- a/src/Makefile
+++ b/src/Makefile
@@ -140,8 +140,9 @@ $(build_dir)/$(chrome_source_root)/%.js: $(chrome_source_root)/%.js
   then \
     cp -f $< $@; \
   else \
-    echo "Stripping comments from JS file $<"; \
+    echo "Stripping debug calls from JS file $<"; \
     sed '/mozt\.Debug\.dump/d' $< > $@; \
+    sed '/mozt\.Debug\.debug/d' $< > $@; \
   fi
 
 $(build_dir)/$(modules_dir)/commons.js: $(modules_dir)/commons.js
diff --git a/src/chrome/content/overlay.js b/src/chrome/content/overlay.js
index 1ab5cbd..4bfc80c 100644
--- a/src/chrome/content/overlay.js
+++ b/src/chrome/content/overlay.js
@@ -4,7 +4,6 @@
 Components.utils.import("resource://gre/modules/ctypes.jsm");
 Components.utils.import("resource://moztray/LibC.js");
 Components.utils.import("resource://moztray/LibGObject.js");
-Components.utils.import("resource://moztray/LibGdkWindow.js");
 Components.utils.import("resource://moztray/LibGtkStatusIcon.js");
 Components.utils.import("resource://moztray/commons.js");
 
@@ -12,130 +11,110 @@ const MOZT_ICON_DIR = "chrome/skin/";
 const MOZT_ICON_SUFFIX = "32.png";
 
 
-
-var mozt_getBaseWindow = function(win) {
-  var bw;
-  try {
-    bw = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-      .getInterface(Components.interfaces.nsIWebNavigation)
-      .QueryInterface(Components.interfaces.nsIDocShellTreeItem)
-      .treeOwner
-      .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-      .getInterface(Components.interfaces.nsIXULWindow)
-      .docShell
-      .QueryInterface(Components.interfaces.nsIBaseWindow);
-  } catch (ex) {
-    bw = null;
-    setTimeout(function() {throw ex; }, 0);
-    // ignore no-interface exception
-  }
-  return bw;
+/**
+ * mozt namespace.
+ */
+if ("undefined" == typeof(mozt)) {
+  var mozt = {};
 };
 
-var mozt_getAllWindows = function() {
-  try {
-    var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
-      .getService(Components.interfaces.nsIWindowMediator);
-  } catch (err) {
-    alert(err);
-    return;
-  }
-
-  var baseWindows = new Array();
-  var e = wm.getEnumerator(null);
-  while (e.hasMoreElements()) {
-    var w = e.getNext();
-    baseWindows[baseWindows.length] = mozt_getBaseWindow(w);
-  }
-
-  // e = wm.getEnumerator(null);
-  // // e = wm.getXULWindowEnumerator(null);
-  // while(e.hasMoreElements()) {
-  //   let win = e.getNext().QueryInterface(Components.interfaces.nsIDOMChromeWindow);
-  //   // let win = e.getNext().QueryInterface(Components.interfaces.nsIXULWindow);
-  //   mozt.Debug.debug("WINDOW TITLE = " + win.document.documentElement.getAttribute("title") );
-  // }
-
-  return baseWindows;
-};
+mozt.Handler = {
+  _windowsHidden: false,
+
+  _getBaseWindow: function(win) {
+    var bw;
+    try { // thx Neil Deakin !!
+      bw = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
+        .getInterface(Components.interfaces.nsIWebNavigation)
+        .QueryInterface(Components.interfaces.nsIDocShellTreeItem)
+        .treeOwner
+        .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
+        .getInterface(Components.interfaces.nsIBaseWindow);
+    } catch (ex) {
+      bw = null;
+      setTimeout(function() {throw ex; }, 0);
+      // ignore no-interface exception
+    }
+    return bw;
+  },
 
-var mozt_hideToTray = function() {
-  mozt.Debug.debug("mozt_hideToTray");
-/*
-  var toto = gBrowser.getBrowserForDocument(content.document)
-    .docShell
-    .QueryInterface(Components.interfaces.nsIBaseWindow)
-    .parentNativeWindow;
-  mozt.Debug.debug("toto: " + toto);
-*/
-  var baseWindows = mozt_getAllWindows();
-  mozt.Debug.dump("baseWindows: " + baseWindows.length);
-  for(var i=0; i<baseWindows.length; i++) {
-    var bw = baseWindows[i];
-    // bw.visibility = false;
-    // mozt.Debug.dumpObj(bw);
-    if (bw instanceof Ci.nsIBaseWindow) {
+  _getAllWindows: function() {
+    mozt.Debug.debug("_getAllWindows");
+    var baseWindows = new Array();
+    var e = mozt.Utils.windowMediator.getEnumerator(null);
+    while (e.hasMoreElements()) {
+      var w = e.getNext();
+      baseWindows[baseWindows.length] = this._getBaseWindow(w);
+    }
+    return baseWindows;
+  },
+
+  /*
+   * might need to remember position...
+   * var outX = {}, outY = {}, outCX = {}, outCY = {};
+   * bw.getPositionAndSize(outX, outY, outCX, outCY);
+   * mozt.Debug.debug("pos: "
+   *                  + outX.value + ", "
+   *                  + outY.value + ", "
+   *                  + outCX.value + ", "
+   *                  + outCY.value
+   *                 );
+   */
+  showHideToTray: function(a1, a2, a3) {
+    mozt.Debug.debug("showHideToTray");
+
+    var baseWindows;
+    try {
+      baseWindows = this._getAllWindows();
+    } catch (x) {
+      mozt.Debug.debug(x);
+    }
+    mozt.Debug.debug("baseWindows: " + baseWindows.length);
+    for(var i=0; i<baseWindows.length; i++) {
+      var bw = baseWindows[i];
+
+      mozt.Debug.debug('isHidden: ' + this._windowsHidden);
       mozt.Debug.debug("bw.visibility: " + bw.visibility);
+      try {
+        if (this._windowsHidden) {
+          bw.visibility = true;
+        } else {
+          bw.visibility = false;
+        }
+      } catch (x) {
+        mozt.Debug.debug(x);
+      }
+      mozt.Debug.debug("bw.visibility: " + bw.visibility);
+
       mozt.Debug.debug("bw.title: " + bw.title);
       mozt.Debug.debug("bw.parentNativeWindow: " + bw.parentNativeWindow);
+    }
 
-      // try {
-      //   bw.visibility = false;
-      //   // bw.parentNativeWindow = null;
-      // } catch (x) {
-      //   mozt.Debug.debug(x);
-      // }
-
+    if (this._windowsHidden) {
+      this._windowsHidden = false;
+    } else {
+      this._windowsHidden = true;
     }
 
-    // var parentWin = bw.parentNativeWindow;
-    // var gdkWin = new LibGdkWindow.GdkWindow.ptr;
-    // try {
-    //   // gdkWin = ctypes.cast(tmp, LibGdkWindow.GdkWindow.ptr);
-    // } catch (x) {
-    //   mozt.Debug.debug(x);
-    // }
-    // if (!gdkWin) mozt.Debug.debug("gdkWin undefined");
-    // mozt.Debug.dumpObj(gdkWin);
-    // LibGdkWindow.GdkWindowHide(gdkWin);
-  }
-
-}
-
-var mozt_trayCb;
-var mozt_isHidden = false;
-var mozt_trayCbJS = function() {
-  if (mozt_isHidden) {
-    mozt_isHidden = false;
-    mozt_restoreFromTray();
-  } else {
-    mozt_isHidden = true;
-    mozt_hideToTray();
-  }
-};
+  },
 
-var mozt_func;
-var mozt_funcGdkJS = function(data, userData) {
-  try {
-    mozt.Debug.debug("GDK Window");
-    mozt.Debug.debug(data + "\t" + userData);
-  } catch(e) {mozt.Debug.debug(ex);}
-};
+}; // mozt.Handler
 
-var mozt_funcGtkJS = function(data, userData) {
-  try {
-    ctypes.cast(data, LibGtkStatusIcon.GtkWidget.ptr);
-    mozt.Debug.debug("GTK Window " + data);
-    LibGtkStatusIcon.gtk_widget_hide(data);
-  } catch(e) {mozt.Debug.debug(ex);}
-};
 
+var mozt_activateCb;            // pointer to JS function. should not be eaten
+                                // by GC ("Running global cleanup code from
+                                // study base classes" ?)
 
 mozt.Main = {
+  initialized: false,
 
   onLoad: function() {
+    if (this.initialized)
+      return true;              // prevent creating multiple tray icon
+
+    mozt.Debug.debug('initialized: ' + this.initialized);
+
     // initialization code
-    this.initialized = null;
     this.strings = document.getElementById("moztray-strings");
 
     try {
@@ -148,23 +127,35 @@ mozt.Main = {
       return false;
     }
 
-    LibGtkStatusIcon.init();
-    this.tray_icon  = LibGtkStatusIcon.gtk_status_icon_new();
-    var mozApp = mozt.Utils.appInfoService.name.toLowerCase();
-    var icon_filename = MOZT_ICON_DIR + mozApp + MOZT_ICON_SUFFIX;
-    LibGtkStatusIcon.gtk_status_icon_set_from_file(this.tray_icon,
-                                                   icon_filename);
-        // gtk_status_icon_set_tooltip(tray_icon,
-        //                             "Example Tray Icon");
-        // gtk_status_icon_set_visible(tray_icon, TRUE);
+    try {
 
-    mozt_trayCb = LibGObject.GCallbackFunction(mozt_trayCbJS);
+      // instanciate tray icon
+      LibGtkStatusIcon.init();
+      this.tray_icon  = LibGtkStatusIcon.gtk_status_icon_new();
+      var mozApp = mozt.Utils.appInfoService.name.toLowerCase();
+      var iconFilename = MOZT_ICON_DIR + mozApp + MOZT_ICON_SUFFIX;
+      LibGtkStatusIcon.gtk_status_icon_set_from_file(this.tray_icon,
+                                                     iconFilename);
+      // gtk_status_icon_set_tooltip(tray_icon,
+      //                             "Example Tray Icon");
+      // gtk_status_icon_set_visible(tray_icon, TRUE);
+      LibGtkStatusIcon.shutdown();
+
+      // watch out for binding problems !
+      mozt_activateCb = LibGObject.GCallback_t(
+        function(){mozt.Handler.showHideToTray();});
+      LibGObject.g_signal_connect(this.tray_icon, "activate",
+                                  mozt_activateCb, null);
 
-    LibGObject.g_signal_connect(this.tray_icon, "activate",
-                                mozt_trayCb, null);
+    } catch (x) {
+      Components.utils.reportError(ex);
+      return false;
+    }
 
+/*
     try {
-      // Experimental stuff...
+      // Experimental stuff... needs
+      // Components.utils.import("resource://moztray/LibGdkWindow.js");
 
       var gdkScreen = LibGdkWindow.GdkScreenGetDefault();
       var tl = LibGdkWindow.GdkScreenGetToplevelWindows(gdkScreen);
@@ -188,6 +179,7 @@ mozt.Main = {
     } catch (x) {
       mozt.Debug.debug(x);
     }
+*/
 
     mozt.Debug.debug('Moztray LOADED !');
     this.initialized = true;
@@ -197,16 +189,15 @@ mozt.Main = {
   onQuit: function() {
     // Remove observer
     mozt.Utils.prefService.removeObserver("", this);
-    LibGtkStatusIcon.shutdown();
 
-    mozt.Debug.dump('Moztray UNLOADED !');
+    mozt.Debug.debug('Moztray UNLOADED !');
     this.initialized = false;
   },
 
   observe: function(subject, topic, data) {
     // Observer for pref changes
     if (topic != "nsPref:changed") return;
-    mozt.Debug.dump('Pref changed: '+data);
+    mozt.Debug.debug('Pref changed: '+data);
 
     switch(data) {
     // case 'enabled':
diff --git a/src/modules/LibGObject.js b/src/modules/LibGObject.js
index 106d90f..6c93f86 100644
--- a/src/modules/LibGObject.js
+++ b/src/modules/LibGObject.js
@@ -95,17 +95,17 @@ XPCOMUtils.defineLazyGetter(this, "GClosureNotify", function() {
   return gpointer;
 });
 
-XPCOMUtils.defineLazyGetter(this, "GCallbackFunction", function() {
-  var GCallbackFunction =
+XPCOMUtils.defineLazyGetter(this, "GCallback_t", function() {
+  var GCallback_t =
     ctypes.FunctionType(ctypes.default_abi,
                         ctypes.void_t,
                         [gpointer,
                          guint,
                          gpointer]).ptr;
-  if (!GCallbackFunction)
-    throw "GCallbackFunction is unavailable";
+  if (!GCallback_t)
+    throw "GCallback_t is unavailable";
 
-  return GCallbackFunction;
+  return GCallback_t;
 });
 
 XPCOMUtils.defineLazyGetter(this, "g_signal_connect_data", function() {
@@ -204,7 +204,7 @@ XPCOMUtils.defineLazyGetter(this, "g_list_foreach", function() {
 
 var LibGObject = {
   GCallback: GCallback,
-  GCallbackFunction: GCallbackFunction,
+  GCallback_t: GCallback_t,
   gpointer: gpointer,
   gulong: gulong,
   guint: guint,
diff --git a/src/modules/commons.js b/src/modules/commons.js
index 2a32eb2..80fc524 100644
--- a/src/modules/commons.js
+++ b/src/modules/commons.js
@@ -25,12 +25,11 @@ const CHATZILLA_ID = "{59c81df5-4b7a-477b-912d-4e0fdf64e5f2}";
  * mozt namespace.
  */
 if ("undefined" == typeof(mozt)) {
-  var mozt = {
-    DEBUG_MODE: true,
-  };
+  var mozt = {};
 };
 
 mozt.Debug = {
+  DEBUG_MODE: true,
   _initialized: false,
 
   /**
@@ -50,12 +49,12 @@ mozt.Debug = {
    * IT'S IMPORTANT THAT DEBUG CALLS ARE WRITTEN ON A SINGLE LINE !
    */
   dump: function(message) { // Debuging function -- prints to javascript console
-    if(!mozt.DEBUG_MODE) return;
+    if(!this.DEBUG_MODE) return;
     this._consoleService.logStringMessage(message);
   },
 
   dumpObj: function(obj) {
-    if(!mozt.DEBUG_MODE) return;
+    if(!this.DEBUG_MODE) return;
     var str = "";
     for(i in obj) {
       try {
@@ -78,14 +77,12 @@ mozt.Debug.init();
 
 
 mozt.Utils = {
-
   prefService: Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService)
     .getBranch("extensions.moztray."),
 
   appInfoService: Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo), // appInfoService.name.toLower
 
-  observerService: Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService),
-
+  windowMediator: Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator)
 };
 
 

-- 
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