From 7de07994a5f25cd2d2e19f02d56ecdcd37945c1c Mon Sep 17 00:00:00 2001 From: Andrey Sidorov Date: Tue, 19 Jul 2011 09:25:27 +1000 Subject: [PATCH] PolyLine, QueryExtensions requests --- lib/x11/corereqs.js | 39 +++++++++++++++++++++++++++++++++- test/listext.js | 8 +++++++ test/polyline.js | 52 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 test/listext.js create mode 100644 test/polyline.js diff --git a/lib/x11/corereqs.js b/lib/x11/corereqs.js index 8cff01c..af2c8cd 100644 --- a/lib/x11/corereqs.js +++ b/lib/x11/corereqs.js @@ -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; + } + ] } diff --git a/test/listext.js b/test/listext.js new file mode 100644 index 0000000..da516cb --- /dev/null +++ b/test/listext.js @@ -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(); + }); +}); diff --git a/test/polyline.js b/test/polyline.js new file mode 100644 index 0000000..24095a9 --- /dev/null +++ b/test/polyline.js @@ -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); + }); +});