fix ChangeGC request, add PolyRectangle, lint

This commit is contained in:
Andrey Sidorov 2015-03-15 14:07:21 +11:00
parent 20886399ed
commit 208ce038b0

View file

@ -202,8 +202,7 @@ for (var req in valueMask) {
names[masks[m].mask] = m;
}
function packValueMask(reqname, values)
{
function packValueMask(reqname, values) {
var bitmask = 0;
var masksList = [];
var format = '';
@ -213,8 +212,7 @@ function packValueMask(reqname, values)
if (!reqValueMask)
throw new Error(reqname + ': no value mask description');
for (var value in values)
{
for (var value in values) {
var v = reqValueMask[value];
if (v) {
var valueBit = v.mask;
@ -231,13 +229,12 @@ function packValueMask(reqname, values)
});
var args = [];
for (m in masksList)
{
for (m in masksList) {
var valueName = reqValueMaskName[masksList[m]];
format += reqValueMask[valueName].format
format += reqValueMask[valueName].format;
args.push(values[valueName]);
}
return [format, bitmask, args]
return [format, bitmask, args];
}
/*
@ -276,7 +273,7 @@ var templates = {
if (visual === undefined)
visual = 0;
if (values === undefined)
values = {}
values = {};
var format = 'CCSLLssSSSSLL';
@ -313,8 +310,7 @@ var templates = {
GetWindowAttributes: [
['CxSL', [3, 2]],
function(buf, backingStore)
{
function(buf, backingStore) {
// TODO: change from array to named object fields
var res = buf.unpack('LSCCLLCCCCLLLS');
var ret = {
@ -335,9 +331,8 @@ var templates = {
],
ChangeSaveSet: [
function(isInsert, wid)
{
return [ 'CCSL', [6, (isInsert ? 0 : 1), 2, wid]]
function(isInsert, wid) {
return ['CCSL', [6, (isInsert ? 0 : 1), 2, wid]];
}
],
@ -377,31 +372,46 @@ var templates = {
ResizeWindow: [
function(win, width, height) {
return module.exports.ConfigureWindow[0](win, { width : width, height: height });
return module.exports.ConfigureWindow[0](win, {
width: width,
height: height
});
}
],
MoveWindow: [
function(win, x, y) {
return module.exports.ConfigureWindow[0](win, { x : x, y: y });
return module.exports.ConfigureWindow[0](win, {
x: x,
y: y
});
}
],
MoveResizeWindow: [
function(win, x, y, width, height) {
return module.exports.ConfigureWindow[0](win, { x : x, y: y, width : width, height: height });
return module.exports.ConfigureWindow[0](win, {
x: x,
y: y,
width: width,
height: height
});
}
],
RaiseWindow: [
function(win) {
return module.exports.ConfigureWindow[0](win, { stackMode : 0 });
return module.exports.ConfigureWindow[0](win, {
stackMode: 0
});
}
],
LowerWindow: [
function(win) {
return module.exports.ConfigureWindow[0](win, { stackMode : 1 });
return module.exports.ConfigureWindow[0](win, {
stackMode: 1
});
}
],
@ -422,8 +432,7 @@ var templates = {
// opcode 16
InternAtom: [
function (returnOnlyIfExist, value)
{
function(returnOnlyIfExist, value) {
var padded = xutil.padded_string(value);
return ['CCSSxxa', [16, returnOnlyIfExist ? 1 : 0, 2 + padded.length / 4, value.length, padded]];
},
@ -461,8 +470,7 @@ var templates = {
ChangeProperty: [
// mode: 0 replace, 1 prepend, 2 append
// format: 8/16/32
function(mode, wid, name, type, units, data)
{
function(mode, wid, name, type, units, data) {
var padded4 = (data.length + 3) >> 2;
var pad = new Buffer((padded4 << 2) - data.length);
var format = 'CCSLLLCxxxLaa';
@ -491,7 +499,7 @@ var templates = {
var prop = {};
prop.type = res[0];
prop.bytesAfter = res[1];
var len = res[2]*(format >> 3)
var len = res[2] * (format >> 3);
prop.data = buf.slice(24, 24 + len);
return prop;
}
@ -499,8 +507,7 @@ var templates = {
ListProperties: [
function(wid)
{
function(wid) {
return ['CxSL', [21, 2, wid]];
},
@ -517,8 +524,7 @@ var templates = {
],
SetSelectionOwner: [
function(owner, selection, time)
{
function(owner, selection, time) {
if (!time)
time = 0; // current time
return ['CxSLLL', [22, 4, owner, selection, time]];
@ -526,8 +532,7 @@ var templates = {
],
GetSelectionOwner: [
function(selection)
{
function(selection) {
return ['CxSL', [23, 2, selection]];
},
@ -546,8 +551,7 @@ var templates = {
SendEvent: [
function(destination, propagate, eventMask, eventRawData)
{
function(destination, propagate, eventMask, eventRawData) {
return ['CCSLLa', [25, propagate, 11, destination, eventMask, eventRawData]];
}
],
@ -555,7 +559,8 @@ var templates = {
GrabPointer: [
function(wid, ownerEvents, mask, pointerMode, keybMode, confineTo, cursor, time) {
return ['CCSLSCCLLL', [26, ownerEvents, 6, wid, mask, pointerMode, keybMode,
confineTo, cursor, time] ];
confineTo, cursor, time
]];
},
function(buf, status) {
return status;
@ -571,7 +576,8 @@ var templates = {
GrabButton: [
function(wid, ownerEvents, mask, pointerMode, keybMode, confineTo, cursor, button, modifiers) {
return ['CCSLSCCLLCxS', [28, ownerEvents, 6, wid, mask, pointerMode, keybMode, confineTo,
cursor, button, modifiers ] ];
cursor, button, modifiers
]];
}
],
@ -649,8 +655,7 @@ var templates = {
function(srcWid, dstWid, srcX, srcY) {
return ['CxSLLSS', [40, 4, srcWid, dstWid, srcX, srcY]];
},
function(buf, sameScreen)
{
function(buf, sameScreen) {
var res = buf.unpack('Lss');
var ext = {};
ext.child = res[0];
@ -673,8 +678,7 @@ var templates = {
function() {
return ['CxS', [43, 1]];
},
function(buf, revertTo)
{
function(buf, revertTo) {
return {
focus: buf.unpack('L')[0],
revertTo: revertTo
@ -684,31 +688,36 @@ var templates = {
WarpPointer: [
function (srcWin, dstWin, srcX, srcY, srcWidth, srcHeight, dstX, dstY)
{
function(srcWin, dstWin, srcX, srcY, srcWidth, srcHeight, dstX, dstY) {
return ['CxSLLssSSss', [41, 6, srcWin, dstWin, srcX, srcY, srcWidth, srcHeight, dstX, dstY]];
}
],
QueryTextExtents: [
function(fontable, text) {
return ['CxSLLssSSss', [48, 6, srcWin, dstWin, srcX, srcY, srcWidth, srcHeight, dstX, dstY]];
},
function(buf) {
// TODO: wip
throw new Error('not implemented yet, please add deserializer');
}
],
ListFonts: [
function(pattern, max)
{
function(pattern, max) {
var req_len = 2 + xutil.padded_length(pattern.length) / 4;
return ['CxSSSp', [49, req_len, max, pattern.length, pattern]];
},
function(buf) {
console.log(buf);
// TODO: move to buffer.unpackStringList
var res = [];
var off = 24;
while (off < buf.length)
{
while (off < buf.length) {
var len = buf[off++];
if (len == 0)
if (len === 0)
break;
if (off + len > buf.length)
{
if (off + len > buf.length) {
len = buf.length - off;
if (len <= 0)
break;
@ -732,21 +741,15 @@ var templates = {
}
],
FreePixmap: [
function (pixmap) {
return [ 'CxSL', [54, 2, pixmap] ];
}
],
CreateCursor: [
function(cid, source, mask, foreRGB, backRGB, x, y) {
foreR = foreRGB.R
foreG = foreRGB.G
foreB = foreRGB.B
foreR = foreRGB.R;
foreG = foreRGB.G;
foreB = foreRGB.B;
backR = backRGB.R
backG = backRGB.G
backB = backRGB.B
backR = backRGB.R;
backG = backRGB.G;
backB = backRGB.B;
return ['CxSLLLSSSSSSSS', [93, 8, cid, source, mask, foreR, foreG, foreB, backR, backG, backB, x, y]];
}
],
@ -758,9 +761,9 @@ var templates = {
var vals = packValueMask('CreateGC', values);
var packetLength = 4 + (values ? vals[2].length : 0);
var args = [55, packetLength, cid, drawable];
format += vals[0]
format += vals[0];
args.push(vals[1]); // values bitmask
args = args.concat(vals[2])
args = args.concat(vals[2]);
return [format, args];
}
],
@ -771,38 +774,34 @@ var templates = {
var vals = packValueMask('CreateGC', values);
var packetLength = 3 + (values ? vals[2].length : 0);
var args = [56, packetLength, cid];
args.push(vals[0]); // values bitmask
var valArr = vals[1];
for (var v in valArr)
{
format += 'L'; // TODO: we know format string length in advance and += inefficient for string
args.push(vals[1]); // values bitmask
var valArr = vals[2];
for (var v = 0; v < valArr.length; ++v) {
format += vals[0][v];
args.push(valArr[v]);
}
return [format, args];
}
],
ClearArea: [
function(wid, x, y, width, height, exposures) {
return [ 'CCSLssSS', [61, exposures, 4, wid, x, y, width, height] ];
}
],
//
CopyArea: [
function(srcDrawable, dstDrawable, gc, srcX, srcY, dstX, dstY, width, height) {
return [ 'CxSLLLssssSS', [62, 7, srcDrawable, dstDrawable, gc, srcX, srcY, dstX, dstY, width, height] ];
}
],
PolyPoint: [
function(coordMode, drawable, gc, points)
{
function(coordMode, drawable, gc, points) {
var format = 'CCSLL';
var args = [64, coordMode, 3 + points.length / 2, drawable, gc];
for (var i=0; i < points.length; ++i)
{
for (var i = 0; i < points.length; ++i) {
format += 'S';
args.push(points[i]);
}
@ -812,12 +811,10 @@ var templates = {
PolyLine: [
// TODO: remove copy-paste - exectly same as PolyPoint, only differ with opcode
function(coordMode, drawable, gc, points)
{
function(coordMode, drawable, gc, points) {
var format = 'CCSLL';
var args = [65, coordMode, 3 + points.length / 2, drawable, gc];
for (var i=0; i < points.length; ++i)
{
for (var i = 0; i < points.length; ++i) {
format += 'S';
args.push(points[i]);
}
@ -826,13 +823,25 @@ var templates = {
],
PolyRectangle: [
function(drawable, gc, coords) { // x1, y1, w1, h1, x2, y2, w2, h2...
var format = 'CxSLL';
var numrects4bytes = coords.length / 2;
var args = [67, 3 + numrects4bytes, drawable, gc];
for (var i = 0; i < coords.length; ++i) {
format += 'S';
args.push(coords[i]);
}
return [format, args];
}
],
PolyFillRectangle: [
function(drawable, gc, coords) { // x1, y1, w1, h1, x2, y2, w2, h2...
var format = 'CxSLL';
var numrects4bytes = coords.length / 2;
var args = [70, 3 + numrects4bytes, drawable, gc];
for (var i=0; i < coords.length; ++i)
{
for (var i = 0; i < coords.length; ++i) {
format += 'S';
args.push(coords[i]);
}
@ -845,8 +854,7 @@ var templates = {
var format = 'CxSLL';
var numrects4bytes = coords.length / 2;
var args = [71, 3 + numrects4bytes, drawable, gc];
for (var i=0; i < coords.length; ++i)
{
for (var i = 0; i < coords.length; ++i) {
format += 'S';
args.push(coords[i]);
}
@ -869,12 +877,10 @@ var templates = {
],
GetImage: [
function(format, drawable, x, y, width, height, planeMask)
{
function(format, drawable, x, y, width, height, planeMask) {
return ['CCSLssSSL', [73, format, 5, drawable, x, y, width, height, planeMask]];
},
function(buf, depth)
{
function(buf, depth) {
var visualId = buf.unpack('L')[0];
return {
depth: depth,
@ -886,15 +892,14 @@ var templates = {
PolyText8: [
function(drawable, gc, x, y, items) {
console.log(['PolyText', 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)
{
for (var i = 0; i < numItems; ++i) {
var it = items[i];
if (typeof it == 'string')
{
if (typeof it == 'string') {
if (it.length > 254) // TODO: split string in set of items
throw 'not supported yet';
format += 'CCa';
@ -910,7 +915,7 @@ var templates = {
var padLen = len4 * 4 - reqLen;
args[1] = len4; // set request length to calculated value
var pad = '';
for (var i=0; i < padLen; ++i)
for (i = 0; i < padLen; ++i)
pad += String.fromCharCode(0);
format += 'a';
args.push(pad);
@ -918,10 +923,8 @@ var templates = {
}
],
CreateColormap:
[
function(cmid, wid, vid, alloc)
{
CreateColormap: [
function(cmid, wid, vid, alloc) {
return ['CCSLLL', [78, alloc, 4, cmid, wid, vid]];
}
],
@ -965,13 +968,11 @@ var templates = {
// TODO: move to buffer.unpackStringList
var res = [];
var off = 24;
while (off < buf.length)
{
while (off < buf.length) {
var len = buf[off++];
if (len == 0)
if (len === 0)
break;
if (off + len > buf.length)
{
if (off + len > buf.length) {
len = buf.length - off;
if (len <= 0)
break;
@ -985,7 +986,7 @@ var templates = {
GetKeyboardMapping: [
function(startCode, num) {
return [ 'CxSCCxx', [101, 2, startCode, num] ]
return ['CxSCCxx', [101, 2, startCode, num]];
},
function(buff, listLength) {
var res = [];
@ -1001,13 +1002,12 @@ var templates = {
// todo: move up to keep reque
GetGeometry: [
function(drawable) {
return ['CxSL', [14, 2, drawable]]
return ['CxSL', [14, 2, drawable]];
},
function(buff, depth)
{
function(buff, depth) {
var res = buff.unpack('LssSSSx');
var ext = {};
ext.windowid = res[0]
ext.windowid = res[0];
ext.xPos = res[1];
ext.yPos = res[2];
ext.width = res[3];