ChangePropery request

This commit is contained in:
sidorares 2011-07-21 15:28:14 +10:00
parent 783ac4b416
commit adb7de62bf
6 changed files with 77 additions and 10 deletions

View file

@ -187,6 +187,20 @@ module.exports = {
}
],
ChangeProperty: [
// mode: 0 replace, 1 prepend, 2 append
// format: 8/16/32
function(mode, wid, name, type, units, data)
{
var padded4 = (data.length + 3) >> 2;
var pad = new Buffer( (padded4<<2) - data.length);
var format = 'CCSLLLCxxxLaa';
var requestLength = 6 + padded4;
var dataLenInFormatUnits = data.length / (units >> 3);
return [format, [18, mode, requestLength, wid, name, type, units, dataLenInFormatUnits, data, pad] ];
}
],
QueryPointer: [
[ 'CxSL', [38, 2] ],
function(buf) {

View file

@ -219,7 +219,8 @@ UnpackStream.prototype.pack = function(format, arguments)
} else if (f == 'p') {
packetlength += xutil.padded_length(arguments[arg++].length);
} else if (f == 'a') {
packetlength += arguments[arg++].length;
packetlength += arguments[arg].length;
arg++;
} else {
// this is a fixed-length format, get length from argument_length table
packetlength += argument_length[f];
@ -228,9 +229,6 @@ UnpackStream.prototype.pack = function(format, arguments)
}
var buf = new Buffer(packetlength);
for (var i=0; i < packetlength; ++i)
buf[i] = 255;
var offset = 0;
var arg = 0;
for (var i = 0; i < format.length; ++i)

View file

@ -15,7 +15,7 @@ require('./unpackbuffer').addUnpack(Buffer);
var xerrors = require('./xerrors');
var coreRequests = require('./corereqs');
var stdatoms = require('./corereqs');
var stdatoms = require('./stdatoms');
function XClient(stream)
{
@ -119,10 +119,11 @@ XClient.prototype.importRequestsFromTemplates = function(target, reqs)
if (callback)
this.replies[this.seq_num] = [reqName, callback];
//console.log([format, requestArguments]);
client.pack_stream.pack(format, requestArguments);
var b = client.pack_stream.write_queue[0];
client.pack_stream.flush();
} else if (templateType == 'Array'){
var format = reqTemplate[0];
var requestArguments = [];

View file

@ -1,10 +1,13 @@
function padded_length(len)
{
return ((len + 3) >> 2) << 2;
/*
var rem = len % 4;
var padded_length = len;
var pl = len;
if (rem)
padded_length = len + 4 - rem;
return padded_length;
return len + 4 - rem;
return len;
*/
}
// TODO: make it return buffer?

23
test/changeprop.js Normal file
View file

@ -0,0 +1,23 @@
var x11 = require('../lib/x11');
var xclient = x11.createClient();
var PointerMotion = x11.eventMask.PointerMotion;
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: PointerMotion });
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());
}, 100);
});

28
test/genstdatoms.js Normal file
View file

@ -0,0 +1,28 @@
var x11 = require('../lib/x11');
var xclient = x11.createClient();
var atomId = 1;
xclient.on('connect', function(display) {
var X = this;
function listAtoms()
{
function getAtom(a)
{
X.GetAtomName(a, function(str) {
if (a == 1)
console.log('module.exports = {')
if (a != 68)
console.log(' %s: %d,', str, a);
else
console.log(' %s: %d\n}', str, a);
listAtoms();
});
}
if (atomId <= 68)
getAtom(atomId);
else
X.terminate();
atomId++;
}
listAtoms();
});