[Pkg-mozext-commits] [firetray] 108/399: use a fixed-sized array in XGetWindowProperty()
David Prévot
taffit at alioth.debian.org
Tue Oct 29 18:23:23 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 ec9a59af4d9e51c370cfd899b49060e2260dbc8b
Author: foudfou <foudil.newbie+git at gmail.com>
Date: Mon Dec 12 12:38:18 2011 +0100
use a fixed-sized array in XGetWindowProperty()
---
src/modules/FiretrayIconLinux.jsm | 19 +++++++++----------
src/modules/x11.jsm | 24 ++++++++++++++++++++----
2 files changed, 29 insertions(+), 14 deletions(-)
diff --git a/src/modules/FiretrayIconLinux.jsm b/src/modules/FiretrayIconLinux.jsm
index 3fd56ee..c954266 100644
--- a/src/modules/FiretrayIconLinux.jsm
+++ b/src/modules/FiretrayIconLinux.jsm
@@ -268,21 +268,18 @@ firetray.IconLinux = {
let prop = x11.current.Atoms._NET_WM_STATE;
LOG("prop="+prop);
- /* we may need to provide a fixed array size for csting later with ctypes */
- const MAX_SIZE = XATOMS_EWMH_WM_STATES.length;
- let ulongArray_t = ctypes.unsigned_long.array(MAX_SIZE);
-
// infos returned by XGetWindowProperty()
let actual_type = new x11.Atom;
let actual_format = new ctypes.int;
let nitems = new ctypes.unsigned_long;
let bytes_after = new ctypes.unsigned_long;
- // let prop_value = new ctypes.unsigned_char.ptr;
- let prop_value = new ulongArray_t;
+ let prop_value = new x11.xpropArray_t;
// look for _NET_WM_STATE_HIDDEN (408)
+ let bufSize = ctypes.long(XPROP_MAX_COUNT*XPROP_BASE_TYPE_LONG_PROPORTION*XPROP_BASE_TYPE.size); // cast not necessary
+ let offset = ctypes.long(0);
let res = x11.XGetWindowProperty( // FIXME: needs to be XFree'd
- x11.current.Display, xwin, prop, 0, MAX_SIZE*ctypes.unsigned_long.size, 0, x11.AnyPropertyType,
+ x11.current.Display, xwin, prop, offset, bufSize, 0, x11.AnyPropertyType,
actual_type.address(), actual_format.address(), nitems.address(), bytes_after.address(), prop_value.address());
LOG("XGetWindowProperty res="+res+", actual_type="+actual_type.value+", actual_format="+actual_format.value+", bytes_after="+bytes_after.value+", nitems="+nitems.value);
@@ -299,14 +296,16 @@ firetray.IconLinux = {
// LOG("prop_value.str="+prop_value.readString());
/* If the returned format is 32, the property data will be stored as an
array of longs (which in a 64-bit application will be 64-bit values
- that are padded in the upper 4 bytes). */
+ that are padded in the upper 4 bytes). [man XGetWindowProperty] */
if (actual_format.value == 32) {
- // var props = ctypes.cast(prop_value, ctypes.unsigned_char.array(nitems.value*2));
var props = ctypes.cast(prop_value, ctypes.unsigned_long.array(nitems.value));
} else
ERROR("unsupported format: "+actual_format.value);
- LOG("props="+props+", size="+props.size);
+ LOG("props="+props+", size="+props.constructor.size);
LOG("props.length="+props.length);
+ // LOG("props.source="+props[0].toSource());
+ // LOG("props.hi="+ctypes.UInt64.hi(props[0]));
+ // LOG("props.lo="+ctypes.UInt64.lo(props[0]));
// for (let i=0; i<nitems.value; ++i) {
// // LOG(props[i]);
diff --git a/src/modules/x11.jsm b/src/modules/x11.jsm
index 727f209..502f41d 100644
--- a/src/modules/x11.jsm
+++ b/src/modules/x11.jsm
@@ -1,7 +1,10 @@
/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-var EXPORTED_SYMBOLS = [ "x11",
- "XATOMS", "XATOMS_ICCCM", "XATOMS_EWMH_GENERAL", "XATOMS_EWMH_WM_STATES" ];
+var EXPORTED_SYMBOLS = [
+ "x11",
+ "XATOMS", "XATOMS_ICCCM", "XATOMS_EWMH_GENERAL", "XATOMS_EWMH_WM_STATES",
+ "XPROP_MAX_COUNT", "XPROP_BASE_TYPE", "XPROP_BASE_TYPE_LONG_PROPORTION"
+];
const X11_LIBNAME = "X11";
const X11_ABIS = [ 6 ];
@@ -33,6 +36,13 @@ const XATOMS_EWMH_WM_STATES = [
];
const XATOMS = XATOMS_ICCCM.concat(XATOMS_EWMH_WM_STATES).concat(XATOMS_EWMH_GENERAL);
+/* needed for XGetWindowProperty: we need to use a fixed sized array for ctypes
+ casting */
+const XPROP_MAX_COUNT = XATOMS_EWMH_WM_STATES.length;
+const XPROP_BASE_TYPE = ctypes.unsigned_char;
+const XPROP_BASE_TYPE_LONG_PROPORTION = ctypes.unsigned_long.size / XPROP_BASE_TYPE.size;
+
+
function x11_defines(lib) {
/* fundamental types need to be guessed :-( */
// http://mxr.mozilla.org/mozilla-central/source/configure.in
@@ -68,7 +78,7 @@ function x11_defines(lib) {
this.WithdrawnState = 0; /* for windows that are not mapped */
this.NormalState = 1; /* most applications want to start this way */
this.IconicState = 3; /* application wants to start as an icon */
- // Xtom
+ // Xatom
this.XA_ATOM = 4;
this.Bool = ctypes.int;
@@ -105,9 +115,15 @@ function x11_defines(lib) {
{ "state": ctypes.int } /* NewValue or Deleted */
]);
+ // custom type needed for XGetWindowProperty
+ this.xpropArray_t = XPROP_BASE_TYPE.array(XPROP_MAX_COUNT*XPROP_BASE_TYPE_LONG_PROPORTION);
+
lib.lazy_bind("XFree", ctypes.int, ctypes.void_t.ptr);
lib.lazy_bind("XInternAtom", this.Atom, this.Display.ptr, ctypes.char.ptr, this.Bool); // only_if_exsits
- lib.lazy_bind("XGetWindowProperty", ctypes.int, this.Display.ptr, this.Window, this.Atom, ctypes.long, ctypes.long, this.Bool, this.Atom, this.Atom.ptr, ctypes.int.ptr, ctypes.unsigned_long.ptr, ctypes.unsigned_long.ptr, ctypes.unsigned_long.array(XATOMS_EWMH_WM_STATES.length).ptr);
+ // int XGetWindowProperty(
+ // Display *display, Window w, Atom property, long long_offset, long long_length, Bool delete, Atom req_type,
+ // Atom *actual_type_return, int *actual_format_return, unsigned long *nitems_return, unsigned long *bytes_after_return, unsigned char **prop_return);
+ lib.lazy_bind("XGetWindowProperty", ctypes.int, this.Display.ptr, this.Window, this.Atom, ctypes.long, ctypes.long, this.Bool, this.Atom, this.Atom.ptr, ctypes.int.ptr, ctypes.unsigned_long.ptr, ctypes.unsigned_long.ptr, ctypes.unsigned_char.array(XPROP_MAX_COUNT*XPROP_BASE_TYPE_LONG_PROPORTION).ptr);
lib.lazy_bind("XChangeProperty", ctypes.int, this.Display.ptr, this.Window, this.Atom, this.Atom, ctypes.int, ctypes.int, ctypes.unsigned_char.ptr, ctypes.int);
}
--
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