diff --git a/lib/x11/corereqs.js b/lib/x11/corereqs.js index 1dddafa..9e67cc9 100644 --- a/lib/x11/corereqs.js +++ b/lib/x11/corereqs.js @@ -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) { diff --git a/lib/x11/unpackstream.js b/lib/x11/unpackstream.js index 1e963b6..d20d975 100644 --- a/lib/x11/unpackstream.js +++ b/lib/x11/unpackstream.js @@ -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) diff --git a/lib/x11/xcore.js b/lib/x11/xcore.js index e62ddc3..ec821f4 100644 --- a/lib/x11/xcore.js +++ b/lib/x11/xcore.js @@ -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 = []; diff --git a/lib/x11/xutil.js b/lib/x11/xutil.js index 87e4599..d75b2b6 100644 --- a/lib/x11/xutil.js +++ b/lib/x11/xutil.js @@ -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? diff --git a/test/changeprop.js b/test/changeprop.js new file mode 100644 index 0000000..d2181f5 --- /dev/null +++ b/test/changeprop.js @@ -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); +}); \ No newline at end of file diff --git a/test/genstdatoms.js b/test/genstdatoms.js new file mode 100644 index 0000000..795a96e --- /dev/null +++ b/test/genstdatoms.js @@ -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(); +});