mirror of
https://github.com/danbulant/node-x11
synced 2026-06-15 12:41:29 +00:00
GetProperty request
This commit is contained in:
parent
adb7de62bf
commit
a1d1bb6e42
4 changed files with 54 additions and 2 deletions
|
|
@ -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;
|
||||
}
|
||||
],
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
|
|
|
|||
|
|
@ -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
30
test/getprop.js
Normal 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);
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue