From 0a767831c8194484379ddea6b8f4b276d780c49e Mon Sep 17 00:00:00 2001 From: sbosse Date: Mon, 21 Jul 2025 23:01:53 +0200 Subject: [PATCH] Mon 21 Jul 22:43:21 CEST 2025 --- .../core/examples/smoketest/listproperties.js | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 js/x11/core/examples/smoketest/listproperties.js diff --git a/js/x11/core/examples/smoketest/listproperties.js b/js/x11/core/examples/smoketest/listproperties.js new file mode 100644 index 0000000..1713e3f --- /dev/null +++ b/js/x11/core/examples/smoketest/listproperties.js @@ -0,0 +1,75 @@ +var x11 = require('../../lib'); + +x11.createClient(function(err, display) { + var X = display.client; + + function quotize(i) { return '\"' + i + '\"'; } + function decodeProperty(type, data, cb) { + switch(type) { + case 'STRING': + var result = []; + var s = ''; + for (var i=0; i < data.length; ++i) + { + if (data[i] == 0) { + result.push(s); + s = ''; + continue; + } + s += String.fromCharCode(data[i]); + } + result.push(s); + return cb(result.map(quotize).join(', ')); + + case 'ATOM': + var numAtoms = data.length/4; + var res = []; + for (var i=0; i < data.length; i+=4) { + var a = data.unpack('L', i)[0]; + X.GetAtomName(a, function(err, str) { + res.push(str); + if (res.length === numAtoms) + cb(res.join(', ')); + }); + } + return; + + case 'INTEGER': + var numAtoms = data.length/4; + var res = []; + for (var i=0; i < data.length; i+=4) { + res.push(data.unpack('L', i)[0]); + } + return cb(res.join(', ')); + + case 'WINDOW': + var numAtoms = data.length/4; + var res = []; + for (var i=0; i < data.length; i+=4) { + res.push(data.unpack('L', i)[0]); + } + return cb('window id# ' + res.map(function(n) {return '0x'+n.toString(16);}).join(', ')); + + default: + return cb('WTF ' + type); + } + } + + var id = parseInt(process.argv[2]); + var root = display.screen[0].root; + X.ListProperties(id, function(err, props) { + props.forEach(function(p) { + X.GetProperty(0, id, p, 0, 0, 10000000, function(err, propValue) { + X.GetAtomName(propValue.type, function(err, typeName) { + X.GetAtomName(p, function(err, propName) { + decodeProperty(typeName, propValue.data, function(decodedData) { + console.log(propName + '(' + typeName + ') = ' + decodedData); + }); + }); + }); + }); + }) + }); + X.on('event', console.log); + X.on('error', console.error); +});