PolyText8 request + example 'Hello, Node.JS!'

This commit is contained in:
sidorares 2011-07-18 19:56:11 +10:00
parent f3d3c51942
commit 8347e51fbf
3 changed files with 72 additions and 3 deletions

View file

@ -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];
}
]
}
}

View file

@ -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) {

37
test/polytext8.js Normal file
View file

@ -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);
});
});