From 8347e51fbf84a33fb74ff671e7558c6a8726db72 Mon Sep 17 00:00:00 2001 From: sidorares Date: Mon, 18 Jul 2011 19:56:11 +1000 Subject: [PATCH] PolyText8 request + example 'Hello, Node.JS!' --- lib/x11/corereqs.js | 36 +++++++++++++++++++++++++++++++++++- test/polyfillrect.js | 2 -- test/polytext8.js | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 test/polytext8.js diff --git a/lib/x11/corereqs.js b/lib/x11/corereqs.js index dc13214..770f553 100644 --- a/lib/x11/corereqs.js +++ b/lib/x11/corereqs.js @@ -216,5 +216,39 @@ module.exports = { } return [format, args]; } + ], + + PolyText8: [ + function(drawable, gc, x, y, items) { + var format = 'CxSLLSS'; + var numItems = items.length; + var reqLen = 16; + var args = [74, 0, drawable, gc, x, y]; + for (var i=0; i < numItems; ++i) + { + var it = items[i]; + if (typeof it == 'string') + { + if (it.length > 254) // TODO: split string in set of items + throw 'not supported yet'; + format += 'CCa'; + args.push(it.length); + args.push(0); // delta??? + args.push(it); + reqLen += 2 + it.length; + } else { + throw 'not supported yet'; + } + } + var len4 = xutil.padded_length(reqLen)/4; + var padLen = len4*4 - reqLen; + args[1] = len4; // set request length to calculated value + var pad = ''; + for (var i=0; i < padLen; ++i) + pad += String.fromCharCode(0); + format += 'a'; + args.push(pad); + return [format, args]; + } ] -} +} \ No newline at end of file diff --git a/test/polyfillrect.js b/test/polyfillrect.js index f66c6ed..6b2d70f 100644 --- a/test/polyfillrect.js +++ b/test/polyfillrect.js @@ -11,7 +11,6 @@ xclient.on('connect', function(display) { var black = display.screen[0].black_pixel; var wid = X.AllocID(); - console.log('wid: ' + wid); X.CreateWindow( wid, root, 10, 10, 400, 300, @@ -23,7 +22,6 @@ xclient.on('connect', function(display) { X.MapWindow(wid); var gc = X.AllocID(); - console.log('GC: ' + gc); X.CreateGC(gc, wid, { foreground: black, background: white } ); X.on('event', function(ev) { diff --git a/test/polytext8.js b/test/polytext8.js new file mode 100644 index 0000000..ec57559 --- /dev/null +++ b/test/polytext8.js @@ -0,0 +1,37 @@ +var x11 = require('../lib/x11'); + +var xclient = x11.createClient(); +var Exposure = x11.eventMask.Exposure; +var PointerMotion = x11.eventMask.PointerMotion; + +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(); + console.log('GC: ' + gc); + X.CreateGC(gc, wid, { foreground: black, background: white } ); + + X.on('event', function(ev) { + if (ev.type == 12) + { + X.PolyText8(wid, gc, 50, 50, ['Hello, Node.JS!', ' Hello, world!']); + } + }); + X.on('error', function(e) { + console.log(e); + }); +}); \ No newline at end of file