GetProperty request

This commit is contained in:
sidorares 2011-07-21 16:07:34 +10:00
parent adb7de62bf
commit a1d1bb6e42
4 changed files with 54 additions and 2 deletions

View file

@ -201,10 +201,33 @@ module.exports = {
}
],
DeleteProperty: [
[ 'CxLLL', [19, 3] ] // wid, propNameAtom
],
GetProperty: [
function(del, wid, name, type, longOffset, longLength) // - offest and maxLength in 4-byte units
{
return [ 'CCSLLLLL', [20, del, 6, wid, name, type, longOffset, longLength ] ];
},
function(buf, format) {
var res = buf.unpack('LLL');
var prop = {};
prop.type = res[0];
prop.bytesAfter = res[1];
var len = res[2]*(format >> 3)
prop.data = buf.slice(24, 24+len);
return prop;
}
],
QueryPointer: [
[ 'CxSL', [38, 2] ],
function(buf) {
var res = buf.unpack('LLSSSSS'); // TODO: should be unsigned
// TODO pack array into named fields
return res;
}
],

View file

@ -253,7 +253,7 @@ XClient.prototype.expectReplyHeader = function()
var reqName = handler[0];
var req = coreRequests[reqName];
var unpack = req[1];
var result = unpack( data );
var result = unpack( data, opt_data );
var callback = handler[1];
callback(result);
delete client.replies[seq_num];

View file

@ -16,7 +16,6 @@ xclient.on('connect', function(display) {
// mode: 0 replace, 1 prepend, 2 append
// mode, wid, name, type, format, data
X.ChangeProperty(0, wid, xclient.atoms.WM_NAME, xclient.atoms.STRING, 8, 'Hello, NodeJS');
setInterval(function() {
X.ChangeProperty(0, wid, xclient.atoms.WM_NAME, xclient.atoms.STRING, 8, 'Hello, NodeJS ' + new Date());
}, 100);

30
test/getprop.js Normal file
View file

@ -0,0 +1,30 @@
var x11 = require('../lib/x11');
var xclient = x11.createClient();
var PropertyChange = x11.eventMask.PropertyChange;
xclient.on('connect', function(display) {
var X = this;
var root = display.screen[0].root;
var wid = X.AllocID();
var white = display.screen[0].white_pixel;
var black = display.screen[0].black_pixel;
X.CreateWindow(wid, root, 10, 10, 400, 300, 1, 1, 0, { backgroundPixel: white, eventMask: PropertyChange });
X.MapWindow(wid);
// mode: 0 replace, 1 prepend, 2 append
// mode, wid, name, type, format, data
X.ChangeProperty(0, wid, xclient.atoms.WM_NAME, xclient.atoms.STRING, 8, 'Hello, NodeJS');
setInterval(function() {
X.ChangeProperty(0, wid, xclient.atoms.WM_NAME, xclient.atoms.STRING, 8, 'Hello, NodeJS ' + new Date());
}, 1000);
xclient.on('event', function(ev) {
X.GetProperty(0, wid, xclient.atoms.WM_NAME, xclient.atoms.STRING, 0, 10000000, function(prop) {
if (prop.type == xclient.atoms.STRING)
prop.data = prop.data.toString();
console.log(prop.data);
});
});
});