[Pkg-mozext-commits] [firetray] 103/399: * add x11.jsm + test code (NOW ABLE TO ADD A WINDOW FILTER !) * use init() everywhere instead of enable() * fix constant definitions in gdk.jsm, pango.jsm * add testing/xtypes.c for displaying sizeof X types

David Prévot taffit at alioth.debian.org
Tue Oct 29 18:23:22 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 57b443037d4b5e3a51ac9f1c584c7dc6b5f5c4e4
Author: foudfou <foudil.newbie+git at gmail.com>
Date:   Mon Dec 5 02:53:41 2011 +0100

    * add x11.jsm + test code (NOW ABLE TO ADD A WINDOW FILTER !)
    * use init() everywhere instead of enable()
    * fix constant definitions in gdk.jsm, pango.jsm
    * add testing/xtypes.c for displaying sizeof X types
---
 src/chrome/content/options.js     |    4 +-
 src/chrome/content/overlay.js     |    2 +-
 src/modules/FiretrayHandler.jsm   |    7 +-
 src/modules/FiretrayIconLinux.jsm |   80 +++++++++++++++---
 src/modules/FiretrayMessaging.jsm |   19 ++---
 src/modules/gdk.jsm               |   22 ++---
 src/modules/pango.jsm             |   24 +++---
 src/modules/x11.jsm               |  161 +++++++++++++++++++++++++++++++++++++
 testing/Makefile                  |    8 +-
 testing/xtypes.c                  |   14 ++++
 10 files changed, 292 insertions(+), 49 deletions(-)

diff --git a/src/chrome/content/options.js b/src/chrome/content/options.js
index 9e4d32f..d37e90c 100644
--- a/src/chrome/content/options.js
+++ b/src/chrome/content/options.js
@@ -103,11 +103,11 @@ firetray.UIOptions = {
     if (isNotificationDisabled) {
       document.getElementById("broadcaster-notification-disabled")
         .setAttribute("disabled", "true"); // UI update
-      firetray.Messaging.disable();
+      firetray.Messaging.shutdown();
     } else {
       document.getElementById("broadcaster-notification-disabled")
         .removeAttribute("disabled"); // UI update (enables!)
-      firetray.Messaging.enable();
+      firetray.Messaging.init();
       firetray.Messaging.updateUnreadMsgCount();
     }
 
diff --git a/src/chrome/content/overlay.js b/src/chrome/content/overlay.js
index cad2ccd..348bf6b 100644
--- a/src/chrome/content/overlay.js
+++ b/src/chrome/content/overlay.js
@@ -30,7 +30,7 @@ firetray.Main = {
     let init = firetray.Handler.initialized || firetray.Handler.init();
 
     // update unread messages count
-    if (firetray.Handler.inMailApp && firetray.Messaging.enabled)
+    if (firetray.Handler.inMailApp && firetray.Messaging.initialized)
       firetray.Messaging.updateUnreadMsgCount();
 
     // prevent window closing.
diff --git a/src/modules/FiretrayHandler.jsm b/src/modules/FiretrayHandler.jsm
index ee7c984..6566c98 100644
--- a/src/modules/FiretrayHandler.jsm
+++ b/src/modules/FiretrayHandler.jsm
@@ -52,10 +52,11 @@ firetray.Handler = {
     this._updateHandledDOMWindows();
 
     // OS/platform checks
+    this.runtimeABI = Services.appinfo.XPCOMABI;
     this.runtimeOS = Services.appinfo.OS; // "WINNT", "Linux", "Darwin"
     // version checked during install, so we shouldn't need to care
     let xulVer = Services.appinfo.platformVersion; // Services.vc.compare(xulVer,"2.0a")>=0
-    LOG("OS=" + this.runtimeOS + ", XULrunner=" + xulVer);
+    LOG("OS=" + this.runtimeOS + ", ABI=" + this.runtimeABI + ", XULrunner=" + xulVer);
     switch (this.runtimeOS) {
     case "Linux":
       Cu.import("resource://firetray/FiretrayIconLinux.jsm");
@@ -79,7 +80,7 @@ firetray.Handler = {
         Cu.import("resource://firetray/FiretrayMessaging.jsm");
         let prefMailNotification = firetray.Utils.prefService.getIntPref("mail_notification");
         if (prefMailNotification !== NOTIFICATION_DISABLED) {
-          firetray.Messaging.enable();
+          firetray.Messaging.init();
           firetray.Messaging.updateUnreadMsgCount();
         }
       } catch (x) {
@@ -95,7 +96,7 @@ firetray.Handler = {
 
   shutdown: function() {
     if (this.inMailApp)
-      firetray.Messaging.disable();
+      firetray.Messaging.shutdown();
 
     switch (this.runtimeOS) {
     case "Linux":
diff --git a/src/modules/FiretrayIconLinux.jsm b/src/modules/FiretrayIconLinux.jsm
index 04334cf..b3b68aa 100644
--- a/src/modules/FiretrayIconLinux.jsm
+++ b/src/modules/FiretrayIconLinux.jsm
@@ -15,6 +15,7 @@ Cu.import("resource://firetray/gdk.jsm");
 Cu.import("resource://firetray/gtk.jsm");
 Cu.import("resource://firetray/libc.jsm");
 Cu.import("resource://firetray/pango.jsm");
+Cu.import("resource://firetray/x11.jsm");
 Cu.import("resource://firetray/commons.js");
 
 const Services2 = {};
@@ -34,6 +35,7 @@ var firetray_iconActivateCb;
 var firetray_popupMenuCb;
 var firetray_menuItemQuitActivateCb;
 var firetray_findGtkWindowByTitleCb;
+var firetray_filterWindowCb;
 
 /**
  * custum type used to pass data in to and out of firetray_findGtkWindowByTitleCb
@@ -48,6 +50,7 @@ firetray.IconLinux = {
   tryIcon: null,
   menu: null,
   MIN_FONT_SIZE: 4,
+  X11Atoms: {},
 
   init: function() {
     try {
@@ -77,6 +80,20 @@ firetray.IconLinux = {
       return false;
     }
 
+    // TEST - should probably be done in Main.onLoad()
+    this._initX11Atoms();
+    let win = Services.wm.getMostRecentWindow(null);
+    let gdkWin = this.getGdkWindowHandle(win);
+    // TODO: register window here ? (and unregister in shutdown)
+    try {
+      let that = this;
+      let filterData = null;    // FIXME
+      firetray_filterWindowCb = gdk.GdkFilterFunc_t(that.filterWindow);
+      gdk.gdk_window_add_filter(gdkWin, firetray_filterWindowCb, filterData);
+    } catch(x) {
+      ERROR(x);
+    }
+
     return true;
   },
 
@@ -110,8 +127,8 @@ firetray.IconLinux = {
     gtk.gtk_widget_show_all(menuWidget);
 
     /* NOTE: here we do use a function handler (instead of a function
-     * definition) because we need the args passed to it ! On the other hand
-     * we need to abandon 'this' in popupMenu() */
+       definition) because we need the args passed to it ! On the other hand we
+       need to abandon 'this' in popupMenu() */
     let that = this;
     firetray_popupMenuCb =
       gtk.GCallbackMenuPopup_t(that.popupMenu);
@@ -216,24 +233,67 @@ firetray.IconLinux = {
     return gdkWin;
   },
 
-  // NOTE: doesn't work during initialization probably since windows aren't
-  // fully realized (?)
-  testWindowHandle: function() {
+  getGdkWindowHandle: function(win) {
     try {
-      let win = Services.wm.getMostRecentWindow(null);
       let gtkWin = firetray.IconLinux._getGtkWindowHandle(win);
       LOG("FOUND: "+gtk.gtk_window_get_title(gtkWin).readString());
-      gtk.gtk_window_set_decorated(gtkWin, false);
-
       let gdkWin = this._getGdkWindowFromGtkWindow(gtkWin);
       if (!gdkWin.isNull()) {
         LOG("has window");
-        LOG(gdk.gdk_window_get_width(gdkWin));
-        gdk.gdk_window_iconify(gdkWin);
+        return gdkWin;
       }
     } catch (x) {
       ERROR(x);
     }
+    return null;
+  },
+
+  _initX11Atoms: function() {
+    try {
+      let gdkDisplay = gdk.gdk_display_get_default();
+      let x11Display = gdk.gdk_x11_display_get_xdisplay(gdkDisplay);
+      this.X11Atoms.DeleteWindow = x11.XInternAtom(x11Display, "WM_DELETE_WINDOW", 0); // only_if_exsits=false
+      LOG("X11Atoms.DeleteWindow="+this.X11Atoms.DeleteWindow);
+      return true;
+    } catch (x) {
+      ERROR(x);
+      return false;
+    }
+  },
+
+  filterWindow: function(xev, gdkEv, data) {
+    if (!xev)
+      return gdk.GDK_FILTER_CONTINUE;
+
+    try {
+      let xany = ctypes.cast(xev, x11.XAnyEvent.ptr);
+      switch (xany.contents.type) {
+      case x11.MapNotify:
+        LOG("MapNotify");
+        break;
+      case x11.UnmapNotify:
+        LOG("UnmapNotify");
+        break;
+      case x11.ClientMessage:
+        LOG("ClientMessage");
+        let xclient = ctypes.cast(xev, x11.XClientMessageEvent.ptr);
+        LOG("xclient.contents.data="+xclient.contents.data);
+        // NOTE: need toString() for comparison !
+        if (xclient.contents.data[0].toString() ===
+            firetray.IconLinux.X11Atoms.DeleteWindow.toString()) {
+          LOG("Delete Window prevented");
+          return gdk.GDK_FILTER_REMOVE;
+        }
+        break;
+      default:
+        // LOG("xany.type="+xany.contents.type);
+        break;
+      }
+    } catch(x) {
+      ERROR(x);
+    }
+
+    return gdk.GDK_FILTER_CONTINUE;
   }
 
 }; // firetray.IconLinux
diff --git a/src/modules/FiretrayMessaging.jsm b/src/modules/FiretrayMessaging.jsm
index bcdae8e..aa4cff2 100644
--- a/src/modules/FiretrayMessaging.jsm
+++ b/src/modules/FiretrayMessaging.jsm
@@ -31,31 +31,32 @@ if ("undefined" == typeof(firetray)) {
 
 firetray.Messaging = {
   _unreadMsgCount: 0,
-  enabled: false,
+  initialized: false,
 
-  enable: function() {
-    if (this.enabled) {
-      LOG("Messaging already enabled");
+  init: function() {
+    if (this.initialized) {
+      LOG("Messaging already initialized");
       return;
     }
-
     LOG("Enabling Messaging");
+
     let that = this;
     let mailSessionNotificationFlags = Ci.nsIFolderListener.intPropertyChanged;
     MailServices.mailSession.AddFolderListener(that.mailSessionListener,
                                                mailSessionNotificationFlags);
 
-    this.enabled = true;
+    this.initialized = true;
   },
 
-  disable: function() {
-    if (!this.enabled)
+  shutdown: function() {
+    if (!this.initialized)
       return;
+    LOG("Disabling Messaging");
 
     MailServices.mailSession.RemoveFolderListener(this.mailSessionListener);
     firetray.Handler.setImageDefault();
 
-    this.enabled = false;
+    this.initialized = false;
   },
 
   mailSessionListener: {
diff --git a/src/modules/gdk.jsm b/src/modules/gdk.jsm
index 3dbfc8f..eb26212 100644
--- a/src/modules/gdk.jsm
+++ b/src/modules/gdk.jsm
@@ -51,13 +51,15 @@ Cu.import("resource://firetray/ctypes-utils.jsm");
 Cu.import("resource://firetray/cairo.jsm");
 Cu.import("resource://firetray/glib.jsm");
 Cu.import("resource://firetray/gobject.jsm");
+Cu.import("resource://firetray/x11.jsm");
 
 function gdk_defines(lib) {
-  this.GDK_INTERP_NEAREST = 0, // enum GdkInterpType
-  // enum GdkFilterReturn
-  this.GDK_FILTER_CONTINUE  = 0,
-  this.GDK_FILTER_TRANSLATE = 1,
-  this.GDK_FILTER_REMOVE    = 2,
+  this.GdkInterpType = ctypes.int; // enum
+  this.GDK_INTERP_NEAREST = 0;
+  this.GdkFilterReturn = ctypes.int; // enum
+  this.GDK_FILTER_CONTINUE  = 0;
+  this.GDK_FILTER_TRANSLATE = 1;
+  this.GDK_FILTER_REMOVE    = 2;
 
   this.GdkWindow = ctypes.StructType("GdkWindow");
   this.GdkByteOrder = ctypes.int; // enum
@@ -115,12 +117,11 @@ function gdk_defines(lib) {
   this.GdkPixmap = ctypes.StructType("GdkPixmap");
   this.GdkDrawable = ctypes.StructType("GdkDrawable");
   this.GdkGC = ctypes.StructType("GdkGC");
-  this.GdkInterpType = ctypes.int;
-  this.GdkFilterReturn = ctypes.int;
-  this.GdkXEvent = ctypes.void_t;
+  this.GdkXEvent = ctypes.void_t; // will probably be cast to XEvent
   this.GdkEvent = ctypes.void_t;
+  this.GdkDisplay = ctypes.StructType("GdkDisplay");
+  this.GdkFilterFunc = ctypes.voidptr_t;
 
-  // GdkFilterReturn (*GdkFilterFunc) (GdkXEvent *xevent, GdkEvent *event, gpointer  data);
   this.GdkFilterFunc_t = ctypes.FunctionType(
     ctypes.default_abi, this.GdkFilterReturn,
     [this.GdkXEvent.ptr, this.GdkEvent.ptr, gobject.gpointer]).ptr;
@@ -160,7 +161,8 @@ function gdk_defines(lib) {
   lib.lazy_bind("gdk_window_get_width", ctypes.int, this.GdkWindow.ptr);
 
   lib.lazy_bind("gdk_window_add_filter", ctypes.void_t, this.GdkWindow.ptr, this.GdkFilterFunc, gobject.gpointer);
-
+  lib.lazy_bind("gdk_display_get_default", this.GdkDisplay.ptr);
+  lib.lazy_bind("gdk_x11_display_get_xdisplay", x11.Display.ptr, this.GdkDisplay.ptr);
 }
 
 if (!gdk) {
diff --git a/src/modules/pango.jsm b/src/modules/pango.jsm
index 0ff2465..58edf46 100644
--- a/src/modules/pango.jsm
+++ b/src/modules/pango.jsm
@@ -17,18 +17,18 @@ Cu.import("resource://firetray/cairo.jsm");
 Cu.import("resource://firetray/gobject.jsm");
 
 function pango_defines(lib) {
-  this.PANGO_WEIGHT_THIN = 100,
-  this.PANGO_WEIGHT_ULTRALIGHT = 200,
-  this.PANGO_WEIGHT_LIGHT = 300,
-  this.PANGO_WEIGHT_BOOK = 380,
-  this.PANGO_WEIGHT_NORMAL = 400,
-  this.PANGO_WEIGHT_MEDIUM = 500,
-  this.PANGO_WEIGHT_SEMIBOLD = 600,
-  this.PANGO_WEIGHT_BOLD = 700,
-  this.PANGO_WEIGHT_ULTRABOLD = 800,
-  this.PANGO_WEIGHT_HEAVY = 900,
-  this.PANGO_WEIGHT_ULTRAHEAVY = 1000,
-  this.PANGO_SCALE = 1024,
+  this.PANGO_WEIGHT_THIN = 100;
+  this.PANGO_WEIGHT_ULTRALIGHT = 200;
+  this.PANGO_WEIGHT_LIGHT = 300;
+  this.PANGO_WEIGHT_BOOK = 380;
+  this.PANGO_WEIGHT_NORMAL = 400;
+  this.PANGO_WEIGHT_MEDIUM = 500;
+  this.PANGO_WEIGHT_SEMIBOLD = 600;
+  this.PANGO_WEIGHT_BOLD = 700;
+  this.PANGO_WEIGHT_ULTRABOLD = 800;
+  this.PANGO_WEIGHT_HEAVY = 900;
+  this.PANGO_WEIGHT_ULTRAHEAVY = 1000;
+  this.PANGO_SCALE = 1024;
 
   this.PangoFontDescription = ctypes.StructType("PangoFontDescription");
   this.PangoLayout = ctypes.StructType("PangoLayout");
diff --git a/src/modules/x11.jsm b/src/modules/x11.jsm
new file mode 100644
index 0000000..998d917
--- /dev/null
+++ b/src/modules/x11.jsm
@@ -0,0 +1,161 @@
+/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+var EXPORTED_SYMBOLS = [ "x11" ];
+
+const X11_LIBNAME = "X11";
+const X11_ABIS    = [ 6 ];
+
+const Cu = Components.utils;
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/ctypes.jsm");
+Cu.import("resource://firetray/ctypes-utils.jsm");
+
+function x11_defines(lib) {
+  // X.h
+  this.UnmapNotify = 18;
+  this.MapNotify = 19;
+  this.ClientMessage = 33;
+
+  this.Bool = ctypes.int;
+  this.Display = ctypes.StructType("Display");
+  // union not supported by js-ctypes
+  // https://bugzilla.mozilla.org/show_bug.cgi?id=535378 "You can always
+  // typecast pointers, at least as long as you know which type is the biggest"
+  this.XEvent = ctypes.void_t;
+  this.XAnyEvent = ctypes.StructType("XAnyEvent", [
+    { "type": ctypes.int },
+    { "serial": ctypes.unsigned_long },
+    { "send_event": this.Bool },
+    { "display": this.Display.ptr },
+    { "window": x11.Window }
+  ]);
+  this.XClientMessageEvent = ctypes.StructType("XClientMessageEvent", [
+    { "type": ctypes.int },
+    { "serial": ctypes.unsigned_long },
+    { "send_event": this.Bool },
+    { "display": this.Display.ptr },
+    { "window": x11.Window },
+    { "message_type": x11.Atom },
+    { "format": ctypes.int },
+    { "data": ctypes.long.array(5) } // actually a union char b[20]; short s[10]; long l[5];
+  ]);
+
+  lib.lazy_bind("XInternAtom", x11.Atom, this.Display.ptr, ctypes.char.ptr, this.Bool);
+
+}
+
+if (!x11) {
+  var x11 = {};
+
+  // We *try to guess* the size of Atom and Window...
+  try {
+    // http://mxr.mozilla.org/mozilla-central/source/configure.in
+    if (/^(Alpha|hppa|ia64|ppc64|s390|x86_64)-/.test(Services.appinfo.XPCOMABI)) {
+      x11.CARD32 = ctypes.unsigned_int;
+      x11.Atom = ctypes.unsigned_long;
+      x11.Window = ctypes.unsigned_long;
+    } else {
+      x11.CARD32 = ctypes.unsigned_long;
+      x11.Atom = x11.CARD32;
+      x11.Window = x11.CARD32;
+    }
+  } catch(x) {
+    ERROR(x);
+  }
+
+  x11 = new ctypes_library(X11_LIBNAME, X11_ABIS, x11_defines);
+}
+
+/* Xorg 1.10.4
+#if defined (_LP64) || \
+    defined(__alpha) || defined(__alpha__) || \
+    defined(__ia64__) || defined(ia64) || \
+    defined(__sparc64__) || \
+    defined(__s390x__) || \
+    (defined(__hppa__) && defined(__LP64__)) || \
+    defined(__amd64__) || defined(amd64) || \
+    defined(__powerpc64__) || \
+    (defined(sgi) && (_MIPS_SZLONG == 64))
+#define LONG64
+#endif
+
+# ifdef LONG64
+typedef unsigned long CARD64;
+typedef unsigned int CARD32;
+# else
+typedef unsigned long CARD32;
+# endif
+
+#  ifndef _XSERVER64
+typedef unsigned long Atom;
+#  else
+typedef CARD32 Atom;
+#  endif
+*/
+
+/*
+XEvent {
+        int type;
+        XAnyEvent xany;
+        XKeyEvent xkey;
+        XButtonEvent xbutton;
+        XMotionEvent xmotion;
+        XCrossingEvent xcrossing;
+        XFocusChangeEvent xfocus;
+        XExposeEvent xexpose;
+        XGraphicsExposeEvent xgraphicsexpose;
+        XNoExposeEvent xnoexpose;
+        XVisibilityEvent xvisibility;
+        XCreateWindowEvent xcreatewindow;
+        XDestroyWindowEvent xdestroywindow;
+        XUnmapEvent xunmap;
+        XMapEvent xmap;
+        XMapRequestEvent xmaprequest;
+        XReparentEvent xreparent;
+        XConfigureEvent xconfigure;
+        XGravityEvent xgravity;
+        XResizeRequestEvent xresizerequest;
+        XConfigureRequestEvent xconfigurerequest;
+        XCirculateEvent xcirculate;
+        XCirculateRequestEvent xcirculaterequest;
+        XPropertyEvent xproperty;
+        XSelectionClearEvent xselectionclear;
+        XSelectionRequestEvent xselectionrequest;
+        XSelectionEvent xselection;
+        XColormapEvent xcolormap;
+        XClientMessageEvent xclient;
+        XMappingEvent xmapping;
+        XErrorEvent xerror;
+        XKeymapEvent xkeymap;
+        XGenericEvent xgeneric;
+        XGenericEventCookie xcookie;
+        long pad[24];
+}
+
+GdkEvent {
+  GdkEventType              type;
+  GdkEventAny               any;
+  GdkEventExpose            expose;
+  GdkEventNoExpose          no_expose;
+  GdkEventVisibility        visibility;
+  GdkEventMotion            motion;
+  GdkEventButton            button;
+  GdkEventScroll            scroll;
+  GdkEventKey               key;
+  GdkEventCrossing          crossing;
+  GdkEventFocus             focus_change;
+  GdkEventConfigure         configure;
+  GdkEventProperty          property;
+  GdkEventSelection         selection;
+  GdkEventOwnerChange       owner_change;
+  GdkEventProximity         proximity;
+  GdkEventClient            client;
+  GdkEventDND               dnd;
+  GdkEventWindowState       window_state;
+  GdkEventSetting           setting;
+  GdkEventGrabBroken        grab_broken;
+};
+*/
diff --git a/testing/Makefile b/testing/Makefile
index 146b217..8ce91e4 100644
--- a/testing/Makefile
+++ b/testing/Makefile
@@ -1,11 +1,12 @@
 includes := $(shell pkg-config --libs --cflags gtk+-2.0)
+executables :=  gtk_icon_example trayicon hide xtypes
 
 .PHONY: all
-all: gtk_icon_example trayicon hide
+all: $(executables)
 
 .PHONY: clean
 clean:
-	rm gtk_icon_example trayicon hide
+	rm $(executables)
 
 gtk_icon_example: gtk_icon_example.c
 	gcc $(includes) -o gtk_icon_example gtk_icon_example.c
@@ -15,3 +16,6 @@ trayicon: trayicon.c
 
 hide: hide.c
 	gcc $(includes) -o hide hide.c
+
+xtypes: xtypes.c
+	gcc $(includes) -o xtypes xtypes.c
diff --git a/testing/xtypes.c b/testing/xtypes.c
new file mode 100644
index 0000000..0393235
--- /dev/null
+++ b/testing/xtypes.c
@@ -0,0 +1,14 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <X11/Xlib.h>
+#include <X11/Xmd.h>
+
+int main(int argc, char **argv) {
+  printf("sizeof(int)=%d\n",sizeof(int));
+  printf("sizeof(long)=%d\n",sizeof(long));
+  printf("sizeof(CARD32)=%d\n",sizeof(CARD32));
+  printf("sizeof(Atom)=%d\n",sizeof(Atom)); /* supposed to be CARD32 */
+  printf("sizeof(Window)=%d\n",sizeof(Window));
+  return(EXIT_SUCCESS);
+}

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