Compare commits

..

No commits in common. "master" and "v2.3.0" have entirely different histories.

31 changed files with 808 additions and 974 deletions

4
.gitignore vendored
View file

@ -1,4 +0,0 @@
*.log
yarn.lock
package-lock.json
node_modules

View file

@ -7,10 +7,14 @@ before_script:
env: env:
- NOLISTEN=tcp DISPLAY=:99.0 - NOLISTEN=tcp DISPLAY=:99.0
# - NOLISTEN=unix DISPLAY=:99.0 - NOLISTEN=unix DISPLAY=:99.0
# - NOLISTEN=unix DISPLAY=127.0.0.2:99.0 - NOLISTEN=unix DISPLAY=127.0.0.2:99.0
language: node_js language: node_js
node_js: node_js:
- '12' - '0.10'
- '14' - '0.12'
- '4.2'
- '5'
- '6'
- '7'

View file

@ -10,9 +10,8 @@ X11 protocol client for Node.js: implements the core X11 protocol, as well as Xr
npm install x11 npm install x11
Windows users: Windows users:
1) install [XMing](http://www.straightrunning.com/XmingNotes/) or [Cygwin/X](http://x.cygwin.com/)
1. install [XMing](http://www.straightrunning.com/XmingNotes/) or [Cygwin/X](http://x.cygwin.com/) 2) get node-x11 copy (using [git](http://code.google.com/p/msysgit/downloads/list?can=3) or from [Github](https://github.com/sidorares/node-x11/archives/master ))
2. get node-x11 copy (using [git](http://code.google.com/p/msysgit/downloads/list?can=3) or from [Github](https://github.com/sidorares/node-x11/archives/master))
## Example ## Example
@ -30,31 +29,18 @@ x11.createClient(function(err, display) {
var root = display.screen[0].root; var root = display.screen[0].root;
var wid = X.AllocID(); var wid = X.AllocID();
X.CreateWindow( X.CreateWindow(
wid, wid, root, // new window id, parent
root, // new window id, parent 0, 0, 100, 100, // x, y, w, h
0, 0, 0, 0, 0, // border, depth, class, visual
0,
500,
500, // x, y, w, h
0,
0,
0,
0, // border, depth, class, visual
{ eventMask: Exposure|PointerMotion } // other parameters { eventMask: Exposure|PointerMotion } // other parameters
); );
X.MapWindow(wid); X.MapWindow(wid);
var gc = X.AllocID(); var gc = X.AllocID();
X.CreateGC(gc, wid); X.CreateGC(gc, wid);
var white = display.screen[0].white_pixel;
var black = display.screen[0].black_pixel;
cidBlack = X.AllocID();
cidWhite = X.AllocID();
X.CreateGC(cidBlack, wid, { foreground: black, background: white });
X.CreateGC(cidWhite, wid, { foreground: white, background: black });
X.on('event', function(ev) { X.on('event', function(ev) {
if (ev.type == 12) { if (ev.type == 12)
X.PolyFillRectangle(wid, cidWhite, [0, 0, 500, 500]); {
X.PolyText8(wid, cidBlack, 50, 50, ['Hello, Node.JS!']); X.PolyText8(wid, gc, 50, 50, ['Hello, Node.JS!']);
} }
}); });
X.on('error', function(e) { X.on('error', function(e) {
@ -74,7 +60,6 @@ x11.createClient(function(err, display) {
![OpenGL teapot](http://img-fotki.yandex.ru/get/4132/37511094.30/0_81713_82a5ac48_L) ![OpenGL teapot](http://img-fotki.yandex.ru/get/4132/37511094.30/0_81713_82a5ac48_L)
## In use ## In use
- [ntk](https://github.com/sidorares/ntk) - higher level toolkit on top of X11 - [ntk](https://github.com/sidorares/ntk) - higher level toolkit on top of X11
- [node-remote](https://github.com/AndrewSwerlick/node-remote) - media center controller - [node-remote](https://github.com/AndrewSwerlick/node-remote) - media center controller
- [tiles](https://github.com/dominictarr/tiles) - tiling window manager - [tiles](https://github.com/dominictarr/tiles) - tiling window manager

View file

@ -252,7 +252,7 @@ function genReq(req, last)
if (req.body.length == 0) if (req.body.length == 0)
{ {
result.push(' function() {'); result.push(' function() {');
result.push(' return Buffer.from([' + req.opcode + ', 0, 1, 0]);'); result.push(' return new Buffer([' + req.opcode + ', 0, 1, 0]);');
} else { } else {
result.push(' function (args) {'); result.push(' function (args) {');
result.push(' var extraLength = 0;'); result.push(' var extraLength = 0;');
@ -287,10 +287,10 @@ function genReq(req, last)
var reqLen4 = ((reqLen + 3) >> 2); var reqLen4 = ((reqLen + 3) >> 2);
if (extraLength) if (extraLength)
result.push(' var data = Buffer.alloc(' + reqLen + ' + extraLength);'); result.push(' var data = new Buffer(' + reqLen + ' + extraLength);');
else { else {
result.pop(); result.pop();
result.push(' var data = Buffer.alloc(' + reqLen + ');'); result.push(' var data = new Buffer(' + reqLen + ');');
} }
result.push(' data[0] = ' + req.opcode + ';'); result.push(' data[0] = ' + req.opcode + ';');
if (req.body.length != 0) { if (req.body.length != 0) {

View file

@ -571,7 +571,7 @@ module.exports.readJpeg = function(path)
var imageData = {}; var imageData = {};
imageData.width = j.width; imageData.width = j.width;
imageData.height = j.height; imageData.height = j.height;
imageData.data = Buffer.from(j.width*j.height*4); imageData.data = new Buffer(j.width*j.height*4);
j.copyToImageData(imageData); j.copyToImageData(imageData);
return imageData; return imageData;
} }

View file

@ -874,7 +874,7 @@ module.exports.readPng = function(path)
var imageData = {}; var imageData = {};
imageData.width = j.width; imageData.width = j.width;
imageData.height = j.height; imageData.height = j.height;
imageData.data = Buffer.alloc(j.width*j.height*4); imageData.data = new Buffer(j.width*j.height*4);
j.render(imageData); j.render(imageData);
return imageData; return imageData;
} }

View file

@ -26,7 +26,7 @@ function padWidth(buf, width) {
return buf; return buf;
else { else {
var stride = (width+3)&~3; var stride = (width+3)&~3;
var res = Buffer.alloc(height*stride); var res = new Buffer(height*stride);
res.fill(0); res.fill(0);
for (var y=0; y < height; ++y) { for (var y=0; y < height; ++y) {
// memcpy(tmpbitmap+y*stride, bitmap->buffer+y*ginfo.width, ginfo.width); // memcpy(tmpbitmap+y*stride, bitmap->buffer+y*ginfo.width, ginfo.width);
@ -88,7 +88,7 @@ var xclient = x11.createClient({ debug: true }, function(err, display) {
var glyphFromCode = []; var glyphFromCode = [];
glyphs.forEach(function(g) { glyphs.forEach(function(g) {
if (!g.image || (g.image.length == 0)) { if (!g.image || (g.image.length == 0)) {
g.image = Buffer.alloc(64); g.image = new Buffer(64);
g.image.fill(0); g.image.fill(0);
g.width = 8; g.width = 8;
g.height = 8; g.height = 8;

View file

@ -6,7 +6,7 @@ var Pixmap = require('./pixmap').Pixmap;
var Buffer = require('buffer').Buffer; var Buffer = require('buffer').Buffer;
require('../../lib/unpackbuffer').addUnpack(Buffer); require('../../lib/unpackbuffer').addUnpack(Buffer);
var reversed = Buffer.alloc(256); var reversed = new Buffer(256);
for (var i=0; i < 256; ++i) for (var i=0; i < 256; ++i)
{ {
var res = 0; var res = 0;

View file

@ -8,7 +8,7 @@ var xclient = x11.createClient();
var Exposure = x11.eventMask.Exposure; var Exposure = x11.eventMask.Exposure;
var PointerMotion = x11.eventMask.PointerMotion; var PointerMotion = x11.eventMask.PointerMotion;
var bitmap = Buffer.alloc(128*128/8); // 16384 bits, 2048 bytes bitmap var bitmap = new Buffer(128*128/8); // 16384 bits, 2048 bytes bitmap
for (var i=0; i < bitmap.length; ++i) for (var i=0; i < bitmap.length; ++i)
{ {
bitmap[i] = i % 256; bitmap[i] = i % 256;

View file

@ -4,7 +4,7 @@ var x11 = require('../../lib');
var Exposure = x11.eventMask.Exposure; var Exposure = x11.eventMask.Exposure;
var PointerMotion = x11.eventMask.PointerMotion; var PointerMotion = x11.eventMask.PointerMotion;
var bitmap = Buffer.alloc(128*128*4); // 16384 bits, 2048 bytes bitmap var bitmap = new Buffer(128*128*4); // 16384 bits, 2048 bytes bitmap
for (var i=0; i < bitmap.length; ++i) for (var i=0; i < bitmap.length; ++i)
{ {
var byteNum = i%4; var byteNum = i%4;

View file

@ -25,7 +25,7 @@ var Buffer = require('buffer').Buffer;
var startpos = [4, 15]; var startpos = [4, 15];
var cupsize = [10, 20]; var cupsize = [10, 20];
var cup = Buffer.alloc(cupsize[0]*cupsize[1]); var cup = new Buffer(cupsize[0]*cupsize[1]);
var moveInterval; var moveInterval;
function clearCup() function clearCup()

View file

@ -56,8 +56,8 @@ var pc2 = [
function deskey(key, edf) function deskey(key, edf)
{ {
var i, j, l, m, n; var i, j, l, m, n;
var pc1m = Buffer.alloc(56); var pc1m = new Buffer(56);
var pcr = Buffer.alloc(56); var pcr = new Buffer(56);
var kn = new Array(32); var kn = new Array(32);
for ( j = 0; j < 56; j++ ) { for ( j = 0; j < 56; j++ ) {
@ -388,17 +388,17 @@ function desfunc(block, keys)
module.exports.response = function(challenge, password) module.exports.response = function(challenge, password)
{ {
var key = Buffer.alloc(8); var key = new Buffer(8);
key.fill(0); key.fill(0);
key.write(password.substring(0,8)); key.write(password.substring(0,8));
var in1 = challenge.slice(0,8); var in1 = challenge.slice(0,8);
var in2 = challenge.slice(8,16); var in2 = challenge.slice(8,16);
var res1 = Buffer.alloc(8); var res1 = new Buffer(8);
var res2 = Buffer.alloc(8); var res2 = new Buffer(8);
deskey(key, EN0); deskey(key, EN0);
des(in1, res1); des(in1, res1);
des(in2, res2); des(in2, res2);
var resp = Buffer.alloc(16); var resp = new Buffer(16);
res1.copy(resp); res1.copy(resp);
res2.copy(resp, 8); res2.copy(resp, 8);
return resp; return resp;

View file

@ -7,7 +7,7 @@
// It should create a pleasant looking hex dumb by default: // It should create a pleasant looking hex dumb by default:
// //
// var hexy = require('hexy.js'), // var hexy = require('hexy.js'),
// b = Buffer.from("\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789") // b = new Buffer("\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789")
// //
// console.log(hexy.hexy(b)) // console.log(hexy.hexy(b))
// //

View file

@ -400,7 +400,7 @@ RfbClient.prototype.readHextileTile = function(rect, cb)
}); });
return; return;
} }
tile.buffer = Buffer.alloc(tilebuflen); tile.buffer = new Buffer(tilebuflen);
function solidBackground() { function solidBackground() {
clog('solidBackground'); clog('solidBackground');
@ -667,8 +667,8 @@ function createConnection(params)
var wstream = fs.createWriteStream(params.rfbFileOut); var wstream = fs.createWriteStream(params.rfbFileOut);
wstream.write('FBS 001.001\n'); wstream.write('FBS 001.001\n');
stream.on('data', function(data) { stream.on('data', function(data) {
var sizeBuf = Buffer.alloc(4); var sizeBuf = new Buffer(4);
var timeBuf = Buffer.alloc(4); var timeBuf = new Buffer(4);
var size = data.length; var size = data.length;
sizeBuf.writeInt32BE(size, 0); sizeBuf.writeInt32BE(size, 0);
wstream.write(sizeBuf); wstream.write(sizeBuf);
@ -676,7 +676,7 @@ function createConnection(params)
timeBuf.writeInt32BE(+new Date() - start, 0); timeBuf.writeInt32BE(+new Date() - start, 0);
wstream.write(timeBuf); wstream.write(timeBuf);
var padding = 3 - ((size - 1) & 0x03); var padding = 3 - ((size - 1) & 0x03);
var pbuf = Buffer.alloc(padding); var pbuf = new Buffer(padding);
wstream.write(pbuf); wstream.write(pbuf);
}).on('end', function() { }).on('end', function() {
wstream.end(); wstream.end();

View file

@ -62,7 +62,7 @@ RfbServer.prototype.processSecurity = function()
break; break;
case rfb.security.VNC: case rfb.security.VNC:
// generate random 16 byte challenge // generate random 16 byte challenge
serv.challenge = Buffer.alloc(16); serv.challenge = new Buffer(16);
serv.challenge.write('1234567890abcdef'); serv.challenge.write('1234567890abcdef');
console.log(['sending challenge', serv.challenge]); console.log(['sending challenge', serv.challenge]);
serv.pack_stream.pack('a', [serv.challenge]).flush(); serv.pack_stream.pack('a', [serv.challenge]).flush();

View file

@ -34,7 +34,7 @@ function ReadFixedRequest(length, callback)
this.length = length; this.length = length;
this.callback = callback; this.callback = callback;
//clog(length); //clog(length);
this.data = Buffer.alloc(length); this.data = new Buffer(length);
this.received_bytes = 0; this.received_bytes = 0;
} }
@ -328,7 +328,7 @@ UnpackStream.prototype.pack = function(format, args)
} }
} }
var buf = Buffer.alloc(packetlength); var buf = new Buffer(packetlength);
var offset = 0; var offset = 0;
var arg = 0; var arg = 0;
for (var i = 0; i < format.length; ++i) for (var i = 0; i < format.length; ++i)

View file

@ -95,7 +95,7 @@ PixmapFromFile.prototype.mapColors = function(content,size){
} }
PixmapFromFile.prototype.toBuffer = function (colors,content,size) { PixmapFromFile.prototype.toBuffer = function (colors,content,size) {
var buf = Buffer.alloc(size.width*size.height*4); var buf = new Buffer(size.width*size.height*4);
var offset = 0, byte,color; var offset = 0, byte,color;
var copy; var copy;
if( !this.options.format || this.options.format.toUpperCase() === "BGRA"){ if( !this.options.format || this.options.format.toUpperCase() === "BGRA"){

View file

@ -50,7 +50,7 @@ function parseXauth( buf )
return auth; return auth;
} }
var homedir = require('os').homedir; var homedir = require('os-homedir');
var path = require('path'); var path = require('path');
function readXauthority(cb) { function readXauthority(cb) {

View file

@ -231,10 +231,9 @@ function packValueMask(reqname, values)
}); });
var args = []; var args = [];
for (var i=0,length=masksList.length;i<length;i++) for (m in masksList)
{ {
var value = masksList[i]; var valueName = reqValueMaskName[masksList[m]];
var valueName = reqValueMaskName[value];
format += reqValueMask[valueName].format format += reqValueMask[valueName].format
args.push( values[valueName] ); args.push( values[valueName] );
} }
@ -465,7 +464,7 @@ var templates = {
function(mode, wid, name, type, units, data) function(mode, wid, name, type, units, data)
{ {
var padded4 = (data.length + 3) >> 2; var padded4 = (data.length + 3) >> 2;
var pad = Buffer.alloc( (padded4<<2) - data.length); var pad = new Buffer( (padded4<<2) - data.length);
var format = 'CCSLLLCxxxLaa'; var format = 'CCSLLLCxxxLaa';
var requestLength = 6 + padded4; var requestLength = 6 + padded4;
var dataLenInFormatUnits = data.length / (units >> 3); var dataLenInFormatUnits = data.length / (units >> 3);
@ -851,7 +850,7 @@ var templates = {
var padded = xutil.padded_length(data.length); var padded = xutil.padded_length(data.length);
var reqLen = 6 + padded/4; // (length + 3) >> 2 ??? var reqLen = 6 + padded/4; // (length + 3) >> 2 ???
var padLength = padded - data.length; var padLength = padded - data.length;
var pad = Buffer.alloc(padLength); // TODO: new pack format 'X' - skip amount of bytes supplied in numerical argument var pad = new Buffer(padLength); // TODO: new pack format 'X' - skip amount of bytes supplied in numerical argument
// TODO: move code to calculate reqLength and use BigReq if needed outside of corereq.js // TODO: move code to calculate reqLength and use BigReq if needed outside of corereq.js
// NOTE: big req is used here (first 'L' in format, 0 and +1 in params), won't work if not enabled // NOTE: big req is used here (first 'L' in format, 0 and +1 in params), won't work if not enabled
@ -1021,12 +1020,6 @@ var templates = {
} }
], ],
Bell: [
function(percent) {
return ["CxCs",[108,1]];
}
],
ForceScreenSaver: [ ForceScreenSaver: [
function(activate) { function(activate) {
return [ 'CCS', [115, activate?1:0, 1] ]; return [ 'CCS', [115, activate?1:0, 1] ];

View file

@ -258,7 +258,7 @@ exports.requireExt = function(display, callback)
ext.BindTexImage = function(ctx, drawable, buffer, attribs) { ext.BindTexImage = function(ctx, drawable, buffer, attribs) {
if (!attribs) if (!attribs)
attribs = []; attribs = [];
var data = Buffer.alloc(12 + attribs.length*4); var data = new Buffer(12 + attribs.length*4);
data.writeUInt32LE(drawable, 0); data.writeUInt32LE(drawable, 0);
data.writeUInt32LE(buffer, 4); data.writeUInt32LE(buffer, 4);
data.writeUInt32LE(attribs.length, 8); data.writeUInt32LE(attribs.length, 8);
@ -268,7 +268,7 @@ exports.requireExt = function(display, callback)
} }
ext.ReleaseTexImage = function(ctx, drawable, buffer) { ext.ReleaseTexImage = function(ctx, drawable, buffer) {
var data = Buffer.alloc(8); var data = new Buffer(8);
data.writeUint32LE(drawable, 0); data.writeUint32LE(drawable, 0);
data.writeUint32LE(buffer, 4); data.writeUint32LE(buffer, 4);
ext.VendorPrivate(ctx, 1331, data); ext.VendorPrivate(ctx, 1331, data);
@ -287,7 +287,7 @@ exports.requireExt = function(display, callback)
X.pack_stream.pack('CCSLSSL', [ext.majorOpcode, 2, length, ctx, requestNum, requestTotal, data.length]); X.pack_stream.pack('CCSLSSL', [ext.majorOpcode, 2, length, ctx, requestNum, requestTotal, data.length]);
X.pack_stream.write_queue.push(data); X.pack_stream.write_queue.push(data);
var pad = Buffer.alloc(padLength); var pad = new Buffer(padLength);
pad.fill(0); pad.fill(0);
X.pack_stream.write_queue.push(pad); X.pack_stream.write_queue.push(pad);
X.pack_stream.flush(); X.pack_stream.flush();

View file

@ -16,7 +16,7 @@ module.exports = function(GLX, ctx) {
throw Error('Buffer too big. Make sure you are using RenderLarge for large commands'); throw Error('Buffer too big. Make sure you are using RenderLarge for large commands');
currentLength += len; currentLength += len;
var res = Buffer.alloc(len); var res = Buffer(len);
res.writeUInt16LE(len, 0); res.writeUInt16LE(len, 0);
res.writeUInt16LE(opcode, 2); res.writeUInt16LE(opcode, 2);
return res; return res;
@ -266,7 +266,7 @@ module.exports = function(GLX, ctx) {
typeSize[constants.BYTE] = 1; typeSize[constants.BYTE] = 1;
typeSize[constants.UNSIGNED_BYTE] = 1; typeSize[constants.UNSIGNED_BYTE] = 1;
var res = Buffer.alloc(60 + data.length*typeSize[type]); var res = new Buffer(60 + data.length*typeSize[type]);
res.writeUInt32LE(res.length, 0); res.writeUInt32LE(res.length, 0);
res.writeUInt32LE(110, 4); res.writeUInt32LE(110, 4);

View file

@ -5,14 +5,19 @@ var xutil = require('../xutil');
// http://cgit.freedesktop.org/xcb/proto/tree/src/render.xml?id=HEAD // http://cgit.freedesktop.org/xcb/proto/tree/src/render.xml?id=HEAD
// and http://www.x.org/releases/X11R7.6/doc/renderproto/renderproto.txt // and http://www.x.org/releases/X11R7.6/doc/renderproto/renderproto.txt
// TODO: move to templates // TODO: move to templates
exports.requireExt = function(display, callback) { exports.requireExt = function(display, callback)
{
var X = display.client; var X = display.client;
X.QueryExtension('RENDER', function(err, ext) { X.QueryExtension('RENDER', function(err, ext) {
if (!ext.present) {
if (!ext.present)
{
return callback(new Error('extension not available')); return callback(new Error('extension not available'));
} }
ext.QueryVersion = function(clientMaj, clientMin, callback) { ext.QueryVersion = function(clientMaj, clientMin, callback)
{
X.seq_num++; X.seq_num++;
X.pack_stream.pack('CCSLL', [ext.majorOpcode, 0, 3, clientMaj, clientMin]); X.pack_stream.pack('CCSLL', [ext.majorOpcode, 0, 3, clientMaj, clientMin]);
X.replies[X.seq_num] = [ X.replies[X.seq_num] = [
@ -23,9 +28,10 @@ exports.requireExt = function(display, callback) {
callback callback
]; ];
X.pack_stream.flush(); X.pack_stream.flush();
}; }
ext.QueryPictFormat = function(callback) { ext.QueryPictFormat = function(callback)
{
X.pack_stream.pack('CCS', [ext.majorOpcode, 1, 1]); X.pack_stream.pack('CCS', [ext.majorOpcode, 1, 1]);
X.seq_num++; X.seq_num++;
X.replies[X.seq_num] = [ X.replies[X.seq_num] = [
@ -40,7 +46,8 @@ exports.requireExt = function(display, callback) {
// formats list: // formats list:
var offset = 24; var offset = 24;
res.formats = []; res.formats = [];
for (var i = 0; i < num_formats; ++i) { for (var i=0; i < num_formats; ++i)
{
var format = {}; var format = {};
var f = buf.unpack('LCCxxSSSSSSSSL', offset); var f = buf.unpack('LCCxxSSSSSSSSL', offset);
res.formats.push(f); res.formats.push(f);
@ -51,9 +58,10 @@ exports.requireExt = function(display, callback) {
callback callback
]; ];
X.pack_stream.flush(); X.pack_stream.flush();
}; }
ext.QueryFilters = function(callback) { ext.QueryFilters = function(callback)
{
X.pack_stream.pack('CCSL', [ext.majorOpcode, 29, 2, display.screen[0].root]); X.pack_stream.pack('CCSL', [ext.majorOpcode, 29, 2, display.screen[0].root]);
X.seq_num++; X.seq_num++;
X.replies[X.seq_num] = [ X.replies[X.seq_num] = [
@ -63,12 +71,14 @@ exports.requireExt = function(display, callback) {
var num_filters = h[1]; var num_filters = h[1];
var aliases = []; var aliases = [];
var offset = 24; // LL + 16 bytes pad var offset = 24; // LL + 16 bytes pad
for (var i = 0; i < num_aliases; ++i) { for (var i=0; i < num_aliases; ++i)
{
aliases.push(buf.unpack('S', offset)[0]); aliases.push(buf.unpack('S', offset)[0]);
offset+=2; offset+=2;
} }
var filters = []; var filters = [];
for (var i = 0; i < num_filters; ++i) { for (var i=0; i < num_filters; ++i)
{
var len = buf.unpack('C', offset)[0]; var len = buf.unpack('C', offset)[0];
//if (!len) break; //if (!len) break;
offset++; offset++;
@ -80,7 +90,7 @@ exports.requireExt = function(display, callback) {
callback callback
]; ];
X.pack_stream.flush(); X.pack_stream.flush();
}; }
var valueList = [ var valueList = [
['repeat', 'Cxxx'], ['repeat', 'Cxxx'],
@ -106,19 +116,22 @@ exports.requireExt = function(display, callback) {
x: 1 x: 1
}; };
ext.CreatePicture = function(pid, drawable, pictformat, values) { ext.CreatePicture = function(pid, drawable, pictformat, values)
{
var mask = 0; var mask = 0;
var reqLen = 5; // + (values + pad)/4 var reqLen = 5; // + (values + pad)/4
var format = 'CCSLLLL'; var format = 'CCSLLLL';
var params = [ext.majorOpcode, 4, reqLen, pid, drawable, pictformat, mask]; var params = [ext.majorOpcode, 4, reqLen, pid, drawable, pictformat, mask];
if (values) { if (values)
{
var valuesLength = 0; var valuesLength = 0;
for (var i = 0; i < valueList.length; ++i) { for (var i=0; i < valueList.length; ++i)
{
var name = valueList[i][0]; var name = valueList[i][0];
var val = values[name]; var val = values[name];
if (val) { if (val) {
mask |= 1 << i; mask |= (1 << i);
params.push(val); params.push(val);
var valueFormat = valueList[i][1]; var valueFormat = valueList[i][1];
format += valueFormat; format += valueFormat;
@ -127,7 +140,8 @@ exports.requireExt = function(display, callback) {
} }
var pad4 = (valuesLength + 3) >> 2; var pad4 = (valuesLength + 3) >> 2;
var toPad = (pad4 << 2) - valuesLength; var toPad = (pad4 << 2) - valuesLength;
for (var i = 0; i < toPad; ++i) format += 'x'; for (var i=0; i < toPad; ++i)
format += 'x';
reqLen += pad4; reqLen += pad4;
params[2] = reqLen; params[2] = reqLen;
params[6] = mask; params[6] = mask;
@ -135,7 +149,7 @@ exports.requireExt = function(display, callback) {
X.pack_stream.pack(format, params); X.pack_stream.pack(format, params);
X.pack_stream.flush(); X.pack_stream.flush();
X.seq_num++; X.seq_num++;
}; }
ext.FreePicture = function(pid) { ext.FreePicture = function(pid) {
X.pack_stream.pack('CCSL', [ext.majorOpcode, 7, 2, pid]); X.pack_stream.pack('CCSL', [ext.majorOpcode, 7, 2, pid]);
@ -143,11 +157,13 @@ exports.requireExt = function(display, callback) {
X.seq_num++; X.seq_num++;
}; };
function floatToFix(f) { function floatToFix(f)
{
return parseInt(f*65536); return parseInt(f*65536);
} }
function colorToFix(f) { function colorToFix(f)
{
if (f < 0) f = 0; if (f < 0) f = 0;
if (f > 1) f = 1; if (f > 1) f = 1;
return parseInt(f*65535); return parseInt(f*65535);
@ -169,31 +185,26 @@ exports.requireExt = function(display, callback) {
}; };
// see example of blur filter here: https://github.com/richoH/rxvt-unicode/blob/master/src/background.C // see example of blur filter here: https://github.com/richoH/rxvt-unicode/blob/master/src/background.C
ext.SetPictureFilter = function(pid, name, filterParams) { ext.SetPictureFilter = function(pid, name, filterParams)
if (filterParams === 0) filterParams = [0]; {
if (!filterParams) filterParams = []; if (filterParams === 0)
if (!Array.isArray(filterParams)) filterParams = [filterParams]; filterParams = [0];
if (!filterParams)
filterParams = [];
if (!Array.isArray(filterParams))
filterParams = [filterParams];
var reqLen = 2; var reqLen = 2;
var format = 'CCSLSxxp'; var format = 'CCSLSxxp';
var params = [ext.majorOpcode, 30, reqLen, pid, name.length, name]; var params = [ext.majorOpcode, 30, reqLen, pid, name.length, name];
reqLen += xutil.padded_length(name.length+3)/4 + filterParams.length; reqLen += xutil.padded_length(name.length+3)/4 + filterParams.length;
if ( if (name == 'nearest' || name == 'bilinear' || name == 'fast' || name == 'good' || name == 'best') {
name == 'nearest' ||
name == 'bilinear' ||
name == 'fast' ||
name == 'good' ||
name == 'best'
) {
if (filterParams.length !== 0) { if (filterParams.length !== 0) {
throw 'Render.SetPictureFilter: "' + name + '" - unexpected parameters for filters'; throw 'Render.SetPictureFilter: "' + name + '" - unexpected parameters for filters';
} }
} else if (name == 'convolution') { } else if (name == 'convolution') {
if ( if (filterParams.length < 2 || ((filterParams[0]*filterParams[1] + 2) !== filterParams.length) ) {
filterParams.length < 2 ||
filterParams[0] * filterParams[1] + 2 !== filterParams.length
) {
throw 'Render.SetPictureFilter: "convolution" - incorrect matrix dimensions. Must be flat array [ w, h, elem1, elem2, ... ]'; throw 'Render.SetPictureFilter: "convolution" - incorrect matrix dimensions. Must be flat array [ w, h, elem1, elem2, ... ]';
} }
for (var i=0; i < filterParams.length; ++i) { for (var i=0; i < filterParams.length; ++i) {
@ -202,10 +213,7 @@ exports.requireExt = function(display, callback) {
} }
} else if (name == 'binomial' || name == 'gaussian') { } else if (name == 'binomial' || name == 'gaussian') {
if (filterParams.length !== 1) { if (filterParams.length !== 1) {
throw 'Render.SetPictureFilter: "' + throw 'Render.SetPictureFilter: "' + name + '" - incorrect number of parameters, must be exactly 1 number, instead got: ' + filterParams;
name +
'" - incorrect number of parameters, must be exactly 1 number, instead got: ' +
filterParams;
} }
format += 'L'; format += 'L';
params.push(floatToFix(filterParams[0])); params.push(floatToFix(filterParams[0]));
@ -218,22 +226,15 @@ exports.requireExt = function(display, callback) {
X.seq_num++; X.seq_num++;
}; };
ext.CreateSolidFill = function(pid, r, g, b, a) { ext.CreateSolidFill = function(pid, r, g, b, a)
X.pack_stream.pack('CCSLSSSS', [ {
ext.majorOpcode, X.pack_stream.pack('CCSLSSSS', [ext.majorOpcode, 33, 4, pid, colorToFix(r), colorToFix(g), colorToFix(b), colorToFix(a)]);
33,
4,
pid,
colorToFix(r),
colorToFix(g),
colorToFix(b),
colorToFix(a)
]);
X.pack_stream.flush(); X.pack_stream.flush();
X.seq_num++; X.seq_num++;
}; };
ext.RadialGradient = function(pid, p1, p2, r1, r2, stops) { ext.RadialGradient = function(pid, p1, p2, r1, r2, stops)
{
var reqLen = 9+stops.length*3; //header + params + 1xStopfix+2xColors var reqLen = 9+stops.length*3; //header + params + 1xStopfix+2xColors
var format = 'CCSLLLLLLLL'; var format = 'CCSLLLLLLLL';
var params = [ext.majorOpcode, 35, reqLen, pid]; var params = [ext.majorOpcode, 35, reqLen, pid];
@ -247,22 +248,26 @@ exports.requireExt = function(display, callback) {
// [ [float stopDist, [float r, g, b, a] ], ...] // [ [float stopDist, [float r, g, b, a] ], ...]
// stop distances // stop distances
for (var i = 0; i < stops.length; ++i) { for (var i=0; i < stops.length; ++i)
{
format += 'L'; format += 'L';
// TODO: we know total params length in advance. ? params[index] = // TODO: we know total params length in advance. ? params[index] =
params.push(floatToFix(stops[i][0])); params.push(floatToFix(stops[i][0]))
} }
// colors // colors
for (var i = 0; i < stops.length; ++i) { for (var i=0; i < stops.length; ++i)
{
format += 'SSSS'; format += 'SSSS';
for (var j = 0; j < 4; ++j) params.push(colorToFix(stops[i][1][j])); for (var j=0; j < 4; ++j)
params.push(colorToFix(stops[i][1][j]));
} }
X.pack_stream.pack(format, params); X.pack_stream.pack(format, params);
X.pack_stream.flush(); X.pack_stream.flush();
X.seq_num++; X.seq_num++;
}; };
ext.LinearGradient = function(pid, p1, p2, stops) { ext.LinearGradient = function(pid, p1, p2, stops)
{
var reqLen = 7+stops.length*3; //header + params + 1xStopfix+2xColors var reqLen = 7+stops.length*3; //header + params + 1xStopfix+2xColors
var format = 'CCSLLLLLL'; var format = 'CCSLLLLLL';
var params = [ext.majorOpcode, 34, reqLen, pid]; var params = [ext.majorOpcode, 34, reqLen, pid];
@ -275,22 +280,26 @@ exports.requireExt = function(display, callback) {
// [ [float stopDist, [float r, g, b, a] ], ...] // [ [float stopDist, [float r, g, b, a] ], ...]
// stop distances // stop distances
for (var i = 0; i < stops.length; ++i) { for (var i=0; i < stops.length; ++i)
{
format += 'L'; format += 'L';
// TODO: we know total params length in advance. ? params[index] = // TODO: we know total params length in advance. ? params[index] =
params.push(floatToFix(stops[i][0])); params.push(floatToFix(stops[i][0]))
} }
// colors // colors
for (var i = 0; i < stops.length; ++i) { for (var i=0; i < stops.length; ++i)
{
format += 'SSSS'; format += 'SSSS';
for (var j = 0; j < 4; ++j) params.push(colorToFix(stops[i][1][j])); for (var j=0; j < 4; ++j)
params.push(colorToFix(stops[i][1][j]));
} }
X.pack_stream.pack(format, params); X.pack_stream.pack(format, params);
X.pack_stream.flush(); X.pack_stream.flush();
X.seq_num++; X.seq_num++;
}; }
ext.ConicalGradient = function(pid, center, angle, stops) { ext.ConicalGradient = function(pid, center, angle, stops)
{
var reqLen = 6+stops.length*3; //header + params + 1xStopfix+2xColors var reqLen = 6+stops.length*3; //header + params + 1xStopfix+2xColors
var format = 'CCSLLLLL'; var format = 'CCSLLLLL';
var params = [ext.majorOpcode, 36, reqLen, pid]; var params = [ext.majorOpcode, 36, reqLen, pid];
@ -302,27 +311,33 @@ exports.requireExt = function(display, callback) {
// [ [float stopDist, [float r, g, b, a] ], ...] // [ [float stopDist, [float r, g, b, a] ], ...]
// stop distances // stop distances
for (var i = 0; i < stops.length; ++i) { for (var i=0; i < stops.length; ++i)
{
format += 'L'; format += 'L';
// TODO: we know total params length in advance. ? params[index] = // TODO: we know total params length in advance. ? params[index] =
params.push(floatToFix(stops[i][0])); params.push(floatToFix(stops[i][0]))
} }
// colors // colors
for (var i = 0; i < stops.length; ++i) { for (var i=0; i < stops.length; ++i)
{
format += 'SSSS'; format += 'SSSS';
for (var j = 0; j < 4; ++j) params.push(colorToFix(stops[i][1][j])); for (var j=0; j < 4; ++j)
params.push(colorToFix(stops[i][1][j]));
} }
X.pack_stream.pack(format, params); X.pack_stream.pack(format, params);
X.pack_stream.flush(); X.pack_stream.flush();
X.seq_num++; X.seq_num++;
}; }
ext.FillRectangles = function(op, pid, color, rects) { ext.FillRectangles = function(op, pid, color, rects)
{
var reqLen = 5+rects.length/2; var reqLen = 5+rects.length/2;
var format = 'CCSCxxxLSSSS'; var format = 'CCSCxxxLSSSS';
var params = [ext.majorOpcode, 26, reqLen, op, pid]; var params = [ext.majorOpcode, 26, reqLen, op, pid];
for (var j = 0; j < 4; ++j) params.push(colorToFix(color[j])); for (var j=0; j < 4; ++j)
for (var i = 0; i < rects.length; i += 4) { params.push(colorToFix(color[j]));
for (var i=0; i < rects.length; i+=4)
{
format += 'ssSS'; format += 'ssSS';
params.push(rects[i*4]); params.push(rects[i*4]);
params.push(rects[i*4 + 1]); params.push(rects[i*4 + 1]);
@ -332,51 +347,28 @@ exports.requireExt = function(display, callback) {
X.pack_stream.pack(format, params); X.pack_stream.pack(format, params);
X.pack_stream.flush(); X.pack_stream.flush();
X.seq_num++; X.seq_num++;
}; }
ext.Composite = function( ext.Composite = function(op, src, mask, dst, srcX, srcY, maskX, maskY, dstX, dstY, width, height)
op, {
src, X.pack_stream.pack(
mask, 'CCSCxxxLLLssssssSS',
dst, [ext.majorOpcode, 8, 9, op, src, mask, dst, srcX, srcY, maskX, maskY, dstX, dstY, width, height]
srcX, )
srcY,
maskX,
maskY,
dstX,
dstY,
width,
height
) {
X.pack_stream
.pack('CCSCxxxLLLssssssSS', [
ext.majorOpcode,
8,
9,
op,
src,
mask,
dst,
srcX,
srcY,
maskX,
maskY,
dstX,
dstY,
width,
height
])
.flush(); .flush();
X.seq_num++; X.seq_num++;
}; }
// note that Trapezoids is considered deprecated by Render extension // note that Trapezoids is considered deprecated by Render extension
ext.Trapezoids = function(op, src, srcX, srcY, dst, maskFormat, trapz) { ext.Trapezoids = function(op, src, srcX, srcY, dst, maskFormat, trapz)
{
var format = 'CCSCxxxLLLss'; var format = 'CCSCxxxLLLss';
var params = [ext.majorOpcode, 10, 6+trapz.length, op, src, dst, maskFormat, srcX, srcY]; var params = [ext.majorOpcode, 10, 6+trapz.length, op, src, dst, maskFormat, srcX, srcY];
for (var i = 0; i < trapz.length; i++) { for (var i=0; i < trapz.length; i++)
{
format += 'llllllllll'; format += 'llllllllll';
for (var j = 0; j < 10; ++j) params.push(floatToFix(trapz[i * 10 + j])); for (var j=0; j < 10; ++j)
params.push(floatToFix(trapz[i*10 + j]));
} }
X.pack_stream.pack(format, params); X.pack_stream.pack(format, params);
X.pack_stream.flush(); X.pack_stream.flush();
@ -386,7 +378,8 @@ exports.requireExt = function(display, callback) {
ext.AddTraps = function(pic, offX, offY, trapList) { ext.AddTraps = function(pic, offX, offY, trapList) {
var format = 'CCSLss'; var format = 'CCSLss';
var params = [ext.majorOpcode, 32, 3+trapList.length, pic, offX, offY]; var params = [ext.majorOpcode, 32, 3+trapList.length, pic, offX, offY];
for (var i = 0; i < trapList.length; i++) { for (var i=0; i < trapList.length; i++)
{
format += 'l'; format += 'l';
params.push(floatToFix(trapList[i])); params.push(floatToFix(trapList[i]));
} }
@ -395,10 +388,12 @@ exports.requireExt = function(display, callback) {
X.seq_num++; X.seq_num++;
}; };
ext.Triangles = function(op, src, srcX, srcY, dst, maskFormat, tris) { ext.Triangles = function(op, src, srcX, srcY, dst, maskFormat, tris)
{
var format = 'CCSCxxxLLLss'; var format = 'CCSCxxxLLLss';
var params = [ext.majorOpcode, 11, 6+tris.length, op, src, dst, maskFormat, srcX, srcY]; var params = [ext.majorOpcode, 11, 6+tris.length, op, src, dst, maskFormat, srcX, srcY];
for (var i = 0; i < tris.length; i += 6) { for (var i=0; i < tris.length; i+=6)
{
format += 'llllll'; format += 'llllll';
//TODO: Array.copy //TODO: Array.copy
params.push(floatToFix(tris[i + 0])); // x1 params.push(floatToFix(tris[i + 0])); // x1
@ -411,25 +406,25 @@ exports.requireExt = function(display, callback) {
X.pack_stream.pack(format, params); X.pack_stream.pack(format, params);
X.pack_stream.flush(); X.pack_stream.flush();
X.seq_num++; X.seq_num++;
}; }
ext.CreateGlyphSet = function(gsid, format) { ext.CreateGlyphSet = function(gsid, format) {
X.pack_stream.pack('CCSLL', [ext.majorOpcode, 17, 3, gsid, format]); X.pack_stream.pack('CCSLL', [ext.majorOpcode, 17, 3, gsid, format]);
X.pack_stream.flush(); X.pack_stream.flush();
X.seq_num++; X.seq_num++;
}; }
ext.ReferenceGlyphSet = function(gsid, existing) { ext.ReferenceGlyphSet = function(gsid, existing) {
X.pack_stream.pack('CCSLL', [ext.majorOpcode, 18, 3, gsid, existing]); X.pack_stream.pack('CCSLL', [ext.majorOpcode, 18, 3, gsid, existing]);
X.pack_stream.flush(); X.pack_stream.flush();
X.seq_num++; X.seq_num++;
}; }
ext.FreeGlyphSet = function(gsid) { ext.FreeGlyphSet = function(gsid) {
X.pack_stream.pack('CCSL', [ext.majorOpcode, 19, 2, gsid]); X.pack_stream.pack('CCSL', [ext.majorOpcode, 19, 2, gsid]);
X.pack_stream.flush(); X.pack_stream.flush();
X.seq_num++; X.seq_num++;
}; }
ext.AddGlyphs = function(gsid, glyphs) { ext.AddGlyphs = function(gsid, glyphs) {
var numGlyphs = glyphs.length; var numGlyphs = glyphs.length;
@ -442,7 +437,7 @@ exports.requireExt = function(display, callback) {
glyph = glyphs[i]; glyph = glyphs[i];
if (glyph.width % 4 !== 0) { if (glyph.width % 4 !== 0) {
var stride = (glyph.width+3)&~3; var stride = (glyph.width+3)&~3;
var res = Buffer.alloc(glyph.height * stride); var res = new Buffer(glyph.height*stride);
res.fill(0); res.fill(0);
for (var y=0; y < glyph.height; ++y) { for (var y=0; y < glyph.height; ++y) {
glyph.image.copy(res, y*stride, y*glyph.width, y*glyph.width + glyph.width); glyph.image.copy(res, y*stride, y*glyph.width, y*glyph.width + glyph.width);
@ -468,14 +463,7 @@ exports.requireExt = function(display, callback) {
} }
// width + heiht + origin xy + advance xy // width + heiht + origin xy + advance xy
for (i = 0; i < numGlyphs; i++) { for (i = 0; i < numGlyphs; i++) {
X.pack_stream.pack('SSssss', [ X.pack_stream.pack('SSssss', [glyphs[i].width, glyphs[i].height, -glyphs[i].x, glyphs[i].y, glyphs[i].offX, glyphs[i].offY]);
glyphs[i].width,
glyphs[i].height,
-glyphs[i].x,
glyphs[i].y,
glyphs[i].offX,
glyphs[i].offY
]);
} }
// image // image
for (i = 0; i < numGlyphs; i++) { for (i = 0; i < numGlyphs; i++) {
@ -483,29 +471,12 @@ exports.requireExt = function(display, callback) {
} }
X.pack_stream.flush(); X.pack_stream.flush();
X.seq_num++; X.seq_num++;
}; }
// As far as I know this is not implemented in any X server and always retuen "Bad implementation" //AddGlyphsFromPicture, opcode=21 (not in spec)
// Also documentation looks misleading as it's not mention glyph ids. // FreeGlyps - opcode 22
ext.AddGlyphsFromPicture = function(gsid, src, glyphs) { // gsid(L) , glyphs.length (L) + each glyph id (L)
var len = 3 + glyphs.length * 5; //
X.pack_stream.pack('CCSLLL', [ext.majorOpcode, 21, 0, len + 1, gsid, src]);
for (i = 0; i < glyphs.length; i++) {
X.pack_stream.pack('L', [glyphs[i].id]);
}
for (i = 0; i < glyphs.length; i++) {
X.pack_stream.pack('SSssssss', [
glyphs[i].width,
glyphs[i].height,
-glyphs[i].x,
glyphs[i].y,
glyphs[i].offX,
glyphs[i].offY,
glyphs[i].srcX,
glyphs[i].srcY
]);
}
};
// each GlyphEle: // each GlyphEle:
// 1 byte - number of glyphs // 1 byte - number of glyphs
@ -521,128 +492,29 @@ exports.requireExt = function(display, callback) {
// glyphs as input: // glyphs as input:
// [ "just string (0,0) offset is used", [ 10, 10, "string offseted 10,10 from previous pen position" ], 1234567 ] 1234567 is glypfset id or FONT // [ "just string (0,0) offset is used", [ 10, 10, "string offseted 10,10 from previous pen position" ], 1234567 ] 1234567 is glypfset id or FONT
// TODO: pre-process input so strings larger than 254 chars are supported // TODO: pre-process input so strings larger than 254 chars are supported
// (split them into multiple entries with 0,0 offset) // (split them into multiple entries with 0,0 offset)
var formatFromBits = [ var formatFromBits = [,,,,,,,,'C',,,,,,,,'S',,,,,,,,,,,,,,,,'L'];
, var bufferWriteBits = [,,,,,,,,'writeUInt8',,,,,,,,'writeUInt16LE',,,,,,,,,,,,,,,,'writeUInt32LE'];
,
,
,
,
,
,
,
'C',
,
,
,
,
,
,
,
'S',
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
'L'
];
var bufferWriteBits = [
,
,
,
,
,
,
,
,
'writeUInt8',
,
,
,
,
,
,
,
'writeUInt16LE',
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
'writeUInt32LE'
];
// 8/16/32 bit string + 4-byte pad // 8/16/32 bit string + 4-byte pad
function wstring(bits, s) { function wstring(bits, s) {
var charLength = bits / 8; var charLength = bits / 8;
var dataLength = s.length*charLength; var dataLength = s.length*charLength;
var res = Buffer.alloc(xutil.padded_length(dataLength)); var res = new Buffer(xutil.padded_length(dataLength));
debugger; debugger;
var write = res[bufferWriteBits[bits]]; var write = res[bufferWriteBits[bits]]
res.fill(0); res.fill(0);
for (var i = 0; i < s.length; i++) write.call(res, s.charCodeAt(i), i * charLength); for(var i=0; i < s.length; i++)
write.call(res, s.charCodeAt(i), i*charLength);
return res; return res;
} }
var compositeGlyphsOpcodeFromBits = [ var compositeGlyphsOpcodeFromBits = [,,,,,,,,23,,,,,,,,24,,,,,,,,,,,,,,,,25];
, ext.CompositeGlyphs = function(glyphBits, op, src, dst, maskFormat, gsid, srcX, srcY, glyphs)
, {
,
,
,
,
,
,
23,
,
,
,
,
,
,
,
24,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
25
];
ext.CompositeGlyphs = function(glyphBits, op, src, dst, maskFormat, gsid, srcX, srcY, glyphs) {
var opcode = compositeGlyphsOpcodeFromBits[glyphBits]; var opcode = compositeGlyphsOpcodeFromBits[glyphBits];
var charFormat = formatFromBits[glyphBits]; var charFormat = formatFromBits[glyphBits];
var charLength = glyphBits / 8; var charLength = glyphBits / 8;
@ -662,18 +534,10 @@ exports.requireExt = function(display, callback) {
break; break;
} }
} }
X.pack_stream.pack('CCSCxxxLLLLss', [ X.pack_stream.pack(
ext.majorOpcode, 'CCSCxxxLLLLss',
opcode, [ext.majorOpcode, opcode, length, op, src, dst, maskFormat, gsid, srcX, srcY]
length, );
op,
src,
dst,
maskFormat,
gsid,
srcX,
srcY
]);
for (var i=0; i < glyphs.length; ++i) { for (var i=0; i < glyphs.length; ++i) {
var g = glyphs[i]; var g = glyphs[i];
switch (typeof g) { switch (typeof g) {
@ -692,15 +556,18 @@ exports.requireExt = function(display, callback) {
X.seq_num++; X.seq_num++;
}; };
ext.CompositeGlyphs8 = function(op, src, dst, maskFormat, gsid, srcX, srcY, glyphs) { ext.CompositeGlyphs8 = function(op, src, dst, maskFormat, gsid, srcX, srcY, glyphs)
{
return ext.CompositeGlyphs(8, op, src, dst, maskFormat, gsid, srcX, srcY, glyphs); return ext.CompositeGlyphs(8, op, src, dst, maskFormat, gsid, srcX, srcY, glyphs);
}; };
ext.CompositeGlyphs16 = function(op, src, dst, maskFormat, gsid, srcX, srcY, glyphs) { ext.CompositeGlyphs16 = function(op, src, dst, maskFormat, gsid, srcX, srcY, glyphs)
{
return ext.CompositeGlyphs(16, op, src, dst, maskFormat, gsid, srcX, srcY, glyphs); return ext.CompositeGlyphs(16, op, src, dst, maskFormat, gsid, srcX, srcY, glyphs);
}; };
ext.CompositeGlyphs32 = function(op, src, dst, maskFormat, gsid, srcX, srcY, glyphs) { ext.CompositeGlyphs32 = function(op, src, dst, maskFormat, gsid, srcX, srcY, glyphs)
{
return ext.CompositeGlyphs(32, op, src, dst, maskFormat, gsid, srcX, srcY, glyphs); return ext.CompositeGlyphs(32, op, src, dst, maskFormat, gsid, srcX, srcY, glyphs);
}; };
@ -723,36 +590,32 @@ exports.requireExt = function(display, callback) {
// 11 - colormap or none // 11 - colormap or none
ext.QueryPictFormat(function(err, formats) { ext.QueryPictFormat(function(err, formats) {
if (err) return callback(err); if (err)
return callback(err);
for (var i=0; i < formats.formats.length; ++i) { for (var i=0; i < formats.formats.length; ++i) {
var f = formats.formats[i]; var f = formats.formats[i];
if (f[2] == 1 && f[10] == 1) ext.mono1 = f[0]; if (f[2] == 1 && f[10] == 1)
if (f[2] == 24 && f[3] == 16 && f[5] == 8 && f[7] == 0) ext.rgb24 = f[0]; ext.mono1 = f[0] ;
if (f[2] == 24 && f[3] == 16 && f[5] == 8 && f[7] == 0)
ext.rgb24 = f[0];
// 1, 32, 16, 255, 8, 255, 0, 255, 24, 255, 0 // 1, 32, 16, 255, 8, 255, 0, 255, 24, 255, 0
if ( if (f[2] == 32 && f[3] == 16 && f[4] == 255 && f[5] == 8 && f[6] == 255 && f[7] == 0 && f[9] == 24)
f[2] == 32 &&
f[3] == 16 &&
f[4] == 255 &&
f[5] == 8 &&
f[6] == 255 &&
f[7] == 0 &&
f[9] == 24
)
ext.rgba32 = f[0] ; ext.rgba32 = f[0] ;
if (f[2] == 8 && f[10] == 255) ext.a8 = f[0]; if (f[2] == 8 && f[10] == 255)
ext.a8 = f[0];
} }
callback(null, ext); callback(null, ext);
}); });
[ [
'PICTFORMAT argument does not name a defined PICTFORMAT', "PICTFORMAT argument does not name a defined PICTFORMAT",
'PICTURE argument does not name a defined PICTURE', "PICTURE argument does not name a defined PICTURE",
'PICTOP argument does not name a defined PICTOP', "PICTOP argument does not name a defined PICTOP",
'GLYPHSET argument does not name a defined GLYPHSET', "GLYPHSET argument does not name a defined GLYPHSET",
'GLYPH argument does not name a defined GLYPH in the glyphset' "GLYPH argument does not name a defined GLYPH in the glyphset"
].forEach(function(desc, code) { ].forEach(function(desc, code) {
X.errorParsers[ext.firstError + code] = function(err) { X.errorParsers[ext.firstError + code] = function(err) {
err.message = 'XRender: a value for a ' + desc; err.message = "XRender: a value for a " + desc;
}; };
}); });
@ -864,4 +727,4 @@ exports.requireExt = function(display, callback) {
Best: 'best' Best: 'best'
}; };
}); });
}; }

View file

@ -7,7 +7,7 @@
// It should create a pleasant looking hex dumb by default: // It should create a pleasant looking hex dumb by default:
// //
// var hexy = require('hexy.js'), // var hexy = require('hexy.js'),
// b = Buffer.alloc("\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789") // b = new Buffer("\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789")
// //
// console.log(hexy.hexy(b)) // console.log(hexy.hexy(b))
// //

View file

@ -23,7 +23,7 @@ function ReadFixedRequest(length, callback)
{ {
this.length = length; this.length = length;
this.callback = callback; this.callback = callback;
this.data = Buffer.alloc(length); this.data = new Buffer(length);
this.received_bytes = 0; this.received_bytes = 0;
} }
@ -201,7 +201,7 @@ UnpackStream.prototype.pstr = function(str)
var len = xutil.padded_length(str.length); var len = xutil.padded_length(str.length);
if (len == 0) if (len == 0)
return; // nothing to write return; // nothing to write
var buf = Buffer.alloc(len); var buf = new Buffer(len);
buf.write(str, 'binary'); buf.write(str, 'binary');
this.write_queue.push(buf); this.write_queue.push(buf);
} }
@ -231,7 +231,7 @@ UnpackStream.prototype.pack = function(format, args)
} }
} }
var buf = Buffer.alloc(packetlength); var buf = new Buffer(packetlength);
var offset = 0; var offset = 0;
var arg = 0; var arg = 0;
for (var i = 0; i < format.length; ++i) for (var i = 0; i < format.length; ++i)
@ -269,14 +269,12 @@ UnpackStream.prototype.pack = function(format, args)
buf[offset++] = (n >> 16) & 0xff; buf[offset++] = (n >> 16) & 0xff;
buf[offset++] = (n >> 24) & 0xff; buf[offset++] = (n >> 24) & 0xff;
break; break;
case 'a': // string, buffer, or array case 'a': // string or buffer
var str = args[arg++]; var str = args[arg++];
if (Buffer.isBuffer(str)) if (Buffer.isBuffer(str))
{ {
str.copy(buf, offset); str.copy(buf, offset);
offset += str.length; offset += str.length;
} else if(Array.isArray(str)) {
for(var item of str) buf[offset++] = item;
} else { } else {
// TODO: buffer.write could be faster // TODO: buffer.write could be faster
for (var c = 0; c < str.length; ++c) for (var c = 0; c < str.length; ++c)

View file

@ -322,14 +322,7 @@ XClient.prototype.unpackEvent = function(type, seq, extra, code, raw, headerBuf)
event.x = values[5]; event.x = values[5];
event.y = values[6]; event.y = values[6];
event.values = values event.values = values
} else if (type == 9) { // FocusIn
event.name = "FocusIn";
event.mode = raw.unpack('C')[0];
event.wid = extra;
} else if (type == 10) { // FocusOut
event.name = "FocusOut";
event.mode = raw.unpack('C')[0];
event.wid = extra;
} else if (type == 12) { // Expose } else if (type == 12) { // Expose
var values = raw.unpack('SSSSS'); var values = raw.unpack('SSSSS');
event.name = 'Expose' event.name = 'Expose'
@ -515,7 +508,7 @@ XClient.prototype.expectReplyHeader = function()
// raw event 32-bytes packet (primarily for use in SendEvent); // raw event 32-bytes packet (primarily for use in SendEvent);
// TODO: Event::pack based on event parameters, inverse to unpackEvent // TODO: Event::pack based on event parameters, inverse to unpackEvent
ev.rawData = Buffer.alloc(32); ev.rawData = new Buffer(32);
headerBuf.copy(ev.rawData); headerBuf.copy(ev.rawData);
buf.copy(ev.rawData, 8); buf.copy(ev.rawData, 8);

View file

@ -40,15 +40,17 @@
"node": "*" "node": "*"
}, },
"devDependencies": { "devDependencies": {
"async": "^3.0.1", "mocha": "*",
"mocha": "^7.1.2", "should": "*",
"sax": "^1.2.4", "sax": "*",
"should": "^13.2.1", "async": "*",
"sinon": "^7.2.5" "sinon": "*"
}, },
"scripts": { "scripts": {
"test": "node test-runner.js", "test": "node test-runner.js",
"prepublish": "npm prune" "prepublish": "npm prune"
}, },
"dependencies": {} "dependencies": {
"os-homedir": "^1.0.1"
}
} }

View file

@ -63,7 +63,7 @@ describe('Atoms and atom names cache', function() {
}); });
}); });
xit('should be used after the first request for non-std atom_names', function(done) { it('should be used after the first request for non-std atom_names', function(done) {
var self = this; var self = this;
var my_name; var my_name;
/* /*
@ -94,7 +94,7 @@ describe('Atoms and atom names cache', function() {
function(err) { function(err) {
should.not.exist(err); should.not.exist(err);
should.exist(my_name); should.exist(my_name);
self.spy.resetHistory(); self.spy.reset();
self.X.InternAtom(true, my_name, function(err, atom) { self.X.InternAtom(true, my_name, function(err, atom) {
should.not.exist(err); should.not.exist(err);
my_atom.should.equal(atom); my_atom.should.equal(atom);

View file

@ -27,7 +27,7 @@ describe('ChangeProperty', function() {
var self = this; var self = this;
this.X.InternAtom(false, TEST_PROPERTY, function(err, atom) { this.X.InternAtom(false, TEST_PROPERTY, function(err, atom) {
should.not.exist(err); should.not.exist(err);
var raw = Buffer.alloc(4); var raw = new Buffer(4);
raw.writeUInt32LE(self.wid, 0); raw.writeUInt32LE(self.wid, 0);
self.X.ChangeProperty(0, self.wid, atom, self.X.atoms.WINDOW, 32, raw); self.X.ChangeProperty(0, self.wid, atom, self.X.atoms.WINDOW, 32, raw);
self.X.once('event', function(ev) { self.X.once('event', function(ev) {
@ -47,7 +47,7 @@ describe('ChangeProperty', function() {
var self = this; var self = this;
this.X.InternAtom(false, TEST_PROPERTY, function(err, atom) { this.X.InternAtom(false, TEST_PROPERTY, function(err, atom) {
should.not.exist(err); should.not.exist(err);
var raw = Buffer.from(new Array(8)); var raw = new Buffer(new Array(8));
raw.writeUInt32LE(self.wid, 0); raw.writeUInt32LE(self.wid, 0);
raw.writeUInt32LE(self.wid_helper, 4); raw.writeUInt32LE(self.wid_helper, 4);
self.X.ChangeProperty(0, self.wid, atom, self.X.atoms.ATOM, 32, raw); self.X.ChangeProperty(0, self.wid, atom, self.X.atoms.ATOM, 32, raw);
@ -69,7 +69,7 @@ describe('ChangeProperty', function() {
var self = this; var self = this;
this.X.InternAtom(false, TEST_PROPERTY, function(err, atom) { this.X.InternAtom(false, TEST_PROPERTY, function(err, atom) {
should.not.exist(err); should.not.exist(err);
var raw = Buffer.alloc(0); var raw = new Buffer(0);
self.X.ChangeProperty(0, self.wid, atom, self.X.atoms.WINDOW, 32, raw); self.X.ChangeProperty(0, self.wid, atom, self.X.atoms.WINDOW, 32, raw);
self.X.once('event', function(ev) { self.X.once('event', function(ev) {
ev.type.should.equal(28); ev.type.should.equal(28);

View file

@ -40,7 +40,7 @@ describe('ClientMessage', function() {
}); });
var X = dpy.client; var X = dpy.client;
var eventData = Buffer.alloc(32); var eventData = new Buffer(32);
eventData.writeInt8(33, 0); //Event Type 33 = ClientMessage eventData.writeInt8(33, 0); //Event Type 33 = ClientMessage
eventData.writeInt8(8, 1); //Format eventData.writeInt8(8, 1); //Format
eventData.writeInt32LE(self.wid, 4); //Window ID eventData.writeInt32LE(self.wid, 4); //Window ID
@ -67,7 +67,7 @@ describe('ClientMessage', function() {
}); });
var X = dpy.client; var X = dpy.client;
var eventData = Buffer.alloc(32); var eventData = new Buffer(32);
eventData.writeInt8(33, 0); //Event Type 33 = ClientMessage eventData.writeInt8(33, 0); //Event Type 33 = ClientMessage
eventData.writeInt8(16, 1); //Format eventData.writeInt8(16, 1); //Format
eventData.writeInt32LE(self.wid, 4); //Window ID eventData.writeInt32LE(self.wid, 4); //Window ID
@ -94,7 +94,7 @@ describe('ClientMessage', function() {
}); });
var X = dpy.client; var X = dpy.client;
var eventData = Buffer.alloc(32); var eventData = new Buffer(32);
eventData.writeInt8(33, 0); //Event Type 33 = ClientMessage eventData.writeInt8(33, 0); //Event Type 33 = ClientMessage
eventData.writeInt8(32, 1); //Format eventData.writeInt8(32, 1); //Format
eventData.writeInt32LE(self.wid, 4); //Window ID eventData.writeInt32LE(self.wid, 4); //Window ID

View file

@ -11,7 +11,7 @@ describe('KillKlient request', function() {
should.not.exist(err); should.not.exist(err);
display = dpy; display = dpy;
X = display.client; X = display.client;
var root = display.screen[0].root; root = display.screen[0].root;
var eventMask = x11.eventMask.SubstructureNotify; var eventMask = x11.eventMask.SubstructureNotify;
X.ChangeWindowAttributes(root, { eventMask: eventMask }); X.ChangeWindowAttributes(root, { eventMask: eventMask });
done(); done();