QueryPointer result unpacking

This commit is contained in:
Andrey Sidorov 2012-12-20 00:54:19 +11:00
parent 5b17a21eff
commit a951aa26cb

View file

@ -58,7 +58,7 @@ var valueMaskName = {};
for (var req in valueMask) { for (var req in valueMask) {
var masks = valueMask[req]; var masks = valueMask[req];
var names = valueMaskName[req] = {}; var names = valueMaskName[req] = {};
for (var m in masks) for (var m in masks)
names[masks[m]] = m; names[masks[m]] = m;
} }
@ -83,7 +83,7 @@ function packValueMask(reqname, values)
masksList.sort(); masksList.sort();
var args = []; var args = [];
for (m in masksList) for (m in masksList)
{ {
var valueName = reqValueMaskName[masksList[m]]; var valueName = reqValueMaskName[masksList[m]];
args.push( values[valueName] ); args.push( values[valueName] );
} }
@ -102,14 +102,14 @@ the way requests are described here
pack_stream.pack(req[0], req[1]); pack_stream.pack(req[0], req[1]);
2) as array: [format, [opcode, request_length, additional known params]] 2) as array: [format, [opcode, request_length, additional known params]]
client.MapWindow[0](id) -> client.MapWindow[0](id) ->
req = reqs.MwpWindow; req = reqs.MwpWindow;
req[1].push(id); req[1].push(id);
pack_stream.pack( req[0], req[1] ); pack_stream.pack( req[0], req[1] );
- reply - reply
*/ */
module.exports = { module.exports = {
@ -117,6 +117,8 @@ module.exports = {
// create request packet - function OR format string // create request packet - function OR format string
function(id, parentId, x, y, width, height, borderWidth, depth, _class, visual, values) { function(id, parentId, x, y, width, height, borderWidth, depth, _class, visual, values) {
console.log(values);
if (borderWidth === undefined) if (borderWidth === undefined)
borderWidth = 0; borderWidth = 0;
if (depth === undefined) if (depth === undefined)
@ -135,12 +137,12 @@ module.exports = {
var bitmask = 0; var bitmask = 0;
// TODO: slice from function arguments? // TODO: slice from function arguments?
var args = [1, depth, packetLength, id, parentId, x, y, width, height, borderWidth, _class, visual]; var args = [1, depth, packetLength, id, parentId, x, y, width, height, borderWidth, _class, visual];
// TODO: the code is a little bit mess // TODO: the code is a little bit mess
// additional values need to be packed in the following way: // additional values need to be packed in the following way:
// bitmask (bytes #24 to #31 in the packet) - 32 bit indicating what adittional arguments we supply // bitmask (bytes #24 to #31 in the packet) - 32 bit indicating what adittional arguments we supply
// values list (bytes #32 .. #32+4*num_values) in order of corresponding bits TODO: it's actually not 4*num. Some values are 4b ytes, some - 1 byte // values list (bytes #32 .. #32+4*num_values) in order of corresponding bits TODO: it's actually not 4*num. Some values are 4b ytes, some - 1 byte
// TODO: replace with packValueMask // TODO: replace with packValueMask
var masksList = []; var masksList = [];
@ -174,27 +176,27 @@ module.exports = {
ChangeWindowAttributes:[ ChangeWindowAttributes:[
function(wid, values) { function(wid, values) {
var format = 'CxSLL'; var format = 'CxSLL';
var packetLength = 3 + (values ? Object.keys(values).length : 0); var packetLength = 3 + (values ? Object.keys(values).length : 0);
var vals = packValueMask('CreateWindow', values); var vals = packValueMask('CreateWindow', values);
var args = [2, packetLength, wid, vals[0]]; var args = [2, packetLength, wid, vals[0]];
var valArr = vals[1]; var valArr = vals[1];
for (var v in valArr) for (var v in valArr)
{ {
format += 'L'; format += 'L';
args.push(valArr[v]); args.push(valArr[v]);
} }
return [format, args]; return [format, args];
} }
], ],
GetWindowAttributes: [ GetWindowAttributes: [
['CxSL', [3, 2]], ['CxSL', [3, 2]],
function(buf) function(buf)
{ {
// TODO: change from array to named object fields // TODO: change from array to named object fields
var res = buf.unpack('LSCCLLCCCCCLLLS'); var res = buf.unpack('LSCCLLCCCCCLLLS');
return res; return res;
} }
], ],
@ -224,14 +226,14 @@ module.exports = {
], ],
// TODO: remove or leave as a convinient helper? this is actually a ConfigureWindow request // TODO: remove or leave as a convinient helper? this is actually a ConfigureWindow request
// with width and height argiments & arguments mask // with width and height argiments & arguments mask
ResizeWindow: [ ResizeWindow: [
function(win, width, height) { function(win, width, height) {
return ['CxSLSxxSxxSxx', [12, 5, win, 12, width, height]]; return ['CxSLSxxSxxSxx', [12, 5, win, 12, width, height]];
} }
], ],
MoveWindow: [ MoveWindow: [
function(win, x, y) { function(win, x, y) {
return ['CxSLSxxsxxsxx', [12, 5, win, 3, x, y]]; return ['CxSLSxxsxxsxx', [12, 5, win, 3, x, y]];
@ -243,13 +245,13 @@ module.exports = {
return ['CxSLSxxsxxsxxSxxSxx', [12, 7, win, 15, x, y, width, height]]; return ['CxSLSxxsxxsxxSxxSxx', [12, 7, win, 15, x, y, width, height]];
} }
], ],
RaiseWindow: [ RaiseWindow: [
function(win) { function(win) {
return ['CxSLSxxCxxx', [12, 4, win, 64]]; return ['CxSLSxxCxxx', [12, 4, win, 64]];
} }
], ],
QueryTree: [ QueryTree: [
['CxSL', [15, 2]], ['CxSL', [15, 2]],
@ -263,7 +265,7 @@ module.exports = {
for (var i=0; i < res[2]; ++i) for (var i=0; i < res[2]; ++i)
tree.children.push(buf.unpack('L', 24 + i*4)[0]); tree.children.push(buf.unpack('L', 24 + i*4)[0]);
return tree; return tree;
} }
], ],
// opcode 16 // opcode 16
@ -277,7 +279,7 @@ module.exports = {
function(buf) { function(buf) {
var res = buf.unpack('L')[0]; var res = buf.unpack('L')[0];
return res; return res;
} }
], ],
GetAtomName: [ GetAtomName: [
@ -286,7 +288,7 @@ module.exports = {
var nameLen = buf.unpack('S')[0]; var nameLen = buf.unpack('S')[0];
// Atom value starting from 24th byte in the buffer // Atom value starting from 24th byte in the buffer
return buf.unpackString(nameLen, 24); return buf.unpackString(nameLen, 24);
} }
], ],
ChangeProperty: [ ChangeProperty: [
@ -328,9 +330,9 @@ module.exports = {
} }
], ],
ListProperties: [ ListProperties: [
function(wid) function(wid)
{ {
return ['CxSL', [21, 2, wid]]; return ['CxSL', [21, 2, wid]];
}, },
@ -379,19 +381,26 @@ module.exports = {
function(destination, propagate, eventMask, eventRawData) function(destination, propagate, eventMask, eventRawData)
{ {
return [ 'CCSLLa', [25, propagate, 11, destination, eventMask, eventRawData] ]; return [ 'CCSLLa', [25, propagate, 11, destination, eventMask, eventRawData] ];
} }
], ],
QueryPointer: [ QueryPointer: [
[ 'CxSL', [38, 2] ], [ 'CxSL', [38, 2] ],
function(buf) { function(buf) {
var res = buf.unpack('LLSSSSS'); // TODO: should be unsigned var res = buf.unpack('LLssssS');
// TODO pack array into named fields return {
return res; root: res[0],
child: res[1],
rootX: res[2],
rootY: res[3],
childX: res[4],
childY: res[5],
keyMask: res[6]
};
} }
], ],
SetInputFocus: [ SetInputFocus: [
function (wid, revertTo) // revertTo: 0 - None, 1 - PointerRoot, 2 - Parent function (wid, revertTo) // revertTo: 0 - None, 1 - PointerRoot, 2 - Parent
@ -402,7 +411,7 @@ module.exports = {
WarpPointer: [ 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] ]; return [ 'CxSLLssSSss', [41, 6, srcWin, dstWin, srcX, srcY, srcWidth, srcHeight, dstX, dstY] ];
} }
@ -412,7 +421,7 @@ module.exports = {
function(pattern, max) function(pattern, max)
{ {
var req_len = 2+xutil.padded_length(pattern.length)/4; var req_len = 2+xutil.padded_length(pattern.length)/4;
return [ 'CxSSSp', [49, req_len, max, pattern.length, pattern] ]; return [ 'CxSSSp', [49, req_len, max, pattern.length, pattern] ];
}, },
function(buf) { function(buf) {
@ -435,7 +444,7 @@ module.exports = {
off += len; off += len;
} }
return res; return res;
} }
], ],
CreatePixmap: [ CreatePixmap: [
@ -447,7 +456,7 @@ module.exports = {
// opcode 55 // opcode 55
CreateGC: [ CreateGC: [
function(cid, drawable, values) { function(cid, drawable, values) {
var format = 'CxSLLL'; var format = 'CxSLLL';
var packetLength = 4 + (values ? Object.keys(values).length : 0); var packetLength = 4 + (values ? Object.keys(values).length : 0);
var args = [55, packetLength, cid, drawable]; var args = [55, packetLength, cid, drawable];
var vals = packValueMask('CreateGC', values); var vals = packValueMask('CreateGC', values);
@ -457,14 +466,14 @@ module.exports = {
{ {
format += 'L'; // TODO: we know format string length in advance and += inefficient for string format += 'L'; // TODO: we know format string length in advance and += inefficient for string
args.push(valArr[v]); args.push(valArr[v]);
} }
return [format, args]; return [format, args];
} }
], ],
ChangeGC: [ ChangeGC: [
function(cid, values) { function(cid, values) {
var format = 'CxSLL'; var format = 'CxSLL';
var packetLength = 3 + (values ? Object.keys(values).length : 0); var packetLength = 3 + (values ? Object.keys(values).length : 0);
var args = [56, packetLength, cid]; var args = [56, packetLength, cid];
var vals = packValueMask('CreateGC', values); var vals = packValueMask('CreateGC', values);
@ -474,7 +483,7 @@ module.exports = {
{ {
format += 'L'; // TODO: we know format string length in advance and += inefficient for string format += 'L'; // TODO: we know format string length in advance and += inefficient for string
args.push(valArr[v]); args.push(valArr[v]);
} }
return [format, args]; return [format, args];
} }
], ],
@ -514,8 +523,8 @@ module.exports = {
} }
return [format, args]; return [format, args];
} }
], ],
PolyFillRectangle: [ PolyFillRectangle: [
function(drawable, gc, coords) { // x1, y1, w1, h1, x2, y2, w2, h2... function(drawable, gc, coords) { // x1, y1, w1, h1, x2, y2, w2, h2...
@ -561,10 +570,10 @@ module.exports = {
GetImage: [ 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]]; return [ 'CCSLssSSL', [73, format, 5, drawable, x, y, width, height, planeMask]];
}, },
function(buf, depth) function(buf, depth)
{ {
var visualId = buf.unpack('L')[0]; var visualId = buf.unpack('L')[0];
return { return {
@ -574,7 +583,7 @@ module.exports = {
}; };
} }
], ],
PolyText8: [ PolyText8: [
function(drawable, gc, x, y, items) { function(drawable, gc, x, y, items) {
var format = 'CxSLLSS'; var format = 'CxSLLSS';
@ -587,7 +596,7 @@ module.exports = {
if (typeof it == 'string') if (typeof it == 'string')
{ {
if (it.length > 254) // TODO: split string in set of items if (it.length > 254) // TODO: split string in set of items
throw 'not supported yet'; throw 'not supported yet';
format += 'CCa'; format += 'CCa';
args.push(it.length); args.push(it.length);
args.push(0); // delta??? args.push(0); // delta???
@ -609,7 +618,7 @@ module.exports = {
} }
], ],
CreateColormap: CreateColormap:
[ [
function(cmid, wid, vid, alloc) function(cmid, wid, vid, alloc)
{ {
@ -626,11 +635,11 @@ module.exports = {
color.red = res[0]; color.red = res[0];
color.blue = res[1]; color.blue = res[1];
color.green = res[2]; color.green = res[2];
color.pixel = res[3]>>8; // it looks like 3 first bytes contain RGB value in response color.pixel = res[3]>>8; // it looks like 3 first bytes contain RGB value in response
return color; return color;
} }
], ],
QueryExtension: [ QueryExtension: [
function(name) { function(name) {
var padded = xutil.padded_string(name); var padded = xutil.padded_string(name);
@ -645,7 +654,7 @@ module.exports = {
ext.firstEvent = res[2]; ext.firstEvent = res[2];
ext.firstError = res[3]; ext.firstError = res[3];
return ext; return ext;
} }
], ],
@ -664,19 +673,19 @@ module.exports = {
if (off + len > buf.length) if (off + len > buf.length)
{ {
len = buf.length - off; len = buf.length - off;
if (len <= 0) if (len <= 0)
break; break;
} }
res.push(buf.unpackString(len, off)); res.push(buf.unpackString(len, off));
off += len; off += len;
} }
return res; return res;
} }
], ],
GetKeyboardMapping: [ GetKeyboardMapping: [
function(startCode, num) { function(startCode, num) {
return [ 'CxSCCxx', [101, 2, startCode, num] ] return [ 'CxSCCxx', [101, 2, startCode, num] ]
}, },
function(buff, listLength) { function(buff, listLength) {
var res = []; var res = [];
@ -717,7 +726,7 @@ module.exports = {
SetScreenSaver: [ SetScreenSaver: [
function(timeout, interval, preferBlanking, allowExposures) { function(timeout, interval, preferBlanking, allowExposures) {
return [ 'CxSSSCCxx', [107, 3, timeout, interval, preferBlanking, allowExposures]]; return [ 'CxSSSCCxx', [107, 3, timeout, interval, preferBlanking, allowExposures]];
} }
], ],
ForceScreenSaver: [ ForceScreenSaver: [
@ -726,5 +735,5 @@ module.exports = {
} }
] ]
} }