PolyLine, QueryExtensions requests

This commit is contained in:
Andrey Sidorov 2011-07-19 09:25:27 +10:00
parent ea8bc9ed5b
commit 7de07994a5
3 changed files with 98 additions and 1 deletions

View file

@ -200,6 +200,7 @@ module.exports = {
[ 'CxSL', [17, 2] ],
function(buf) {
var nameLen = buf.unpack('S')[0];
// Atom value starting from 24th byte in the buffer
return buf.unpackString(nameLen, 24);
}
],
@ -231,6 +232,23 @@ module.exports = {
console.error([format, args]);
return [format, args];
}
],
PolyLine: [
// TODO: remove copy-paste - exectly same as PolyPoint, only differ with opcode
function(coordMode, drawable, gc, points)
{
var format = 'CCSLL';
var args = [65, coordMode, 3+points.length, drawable, gc];
for (var i=0; i < points.length; ++i)
{
format += 'S';
args.push(points[i]);
}
console.error([format, args]);
return [format, args];
}
],
PolyText8: [
@ -265,5 +283,24 @@ module.exports = {
args.push(pad);
return [format, args];
}
]
],
ListExtensions: [
[ 'CxS', [99, 1] ],
function(buf) {
// TODO: move to buffer.unpackStringList
var res = [];
var off = 24;
while (off < buf.length)
{
var len = buf[off++];
if (len == 0)
break;
res.push(buf.unpackString(len, off));
off += len;
}
return res;
}
]
}

8
test/listext.js Normal file
View file

@ -0,0 +1,8 @@
var x11 = require('../lib/x11');
var X = x11.createClient();
X.on('connect', function(display) {
X.ListExtensions(function(list) {
console.log(list);
X.close();
});
});

52
test/polyline.js Normal file
View file

@ -0,0 +1,52 @@
var x11 = require('../lib/x11');
var xclient = x11.createClient();
var Exposure = x11.eventMask.Exposure;
var PointerMotion = x11.eventMask.PointerMotion;
var pts = [100, 1000, 10, 20, 10, 0, 0, 3];
var prevPoint;
xclient.on('connect', function(display) {
var X = this;
var root = display.screen[0].root;
var white = display.screen[0].white_pixel;
var black = display.screen[0].black_pixel;
var wid = X.AllocID();
X.CreateWindow(
wid, root,
10, 10, 400, 300,
1, 1, 0,
{
backgroundPixel: white, eventMask: Exposure|PointerMotion
}
);
X.MapWindow(wid);
var gc = X.AllocID();
X.CreateGC(gc, wid, { foreground: black, background: white } );
X.on('event', function(ev) {
if (ev.type == 12)
{
if (pts.length > 2)
X.PolyLine(0, wid, gc, pts);
} else if (ev.type == 6) {
//pts.push(ev.x);
//pts.push(ev.y);
//if (prevPoint)
// X.PolyLine(0, wid, gc, [prevPoint.x, prevPoint.y, ev.x, ev.y]);
//
//prevPoint = { x: ev.x, y: ev.y };
//if (pts.length > 2)
// X.PolyLine(0, wid, gc, pts);
}
});
X.on('error', function(e) {
console.log(e);
});
});