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) {
var masks = valueMask[req];
var names = valueMaskName[req] = {};
for (var m in masks)
for (var m in masks)
names[masks[m]] = m;
}
@ -83,7 +83,7 @@ function packValueMask(reqname, values)
masksList.sort();
var args = [];
for (m in masksList)
{
{
var valueName = reqValueMaskName[masksList[m]];
args.push( values[valueName] );
}
@ -102,14 +102,14 @@ the way requests are described here
pack_stream.pack(req[0], req[1]);
2) as array: [format, [opcode, request_length, additional known params]]
client.MapWindow[0](id) ->
req = reqs.MwpWindow;
req[1].push(id);
pack_stream.pack( req[0], req[1] );
- reply
*/
module.exports = {
@ -117,6 +117,8 @@ module.exports = {
// create request packet - function OR format string
function(id, parentId, x, y, width, height, borderWidth, depth, _class, visual, values) {
console.log(values);
if (borderWidth === undefined)
borderWidth = 0;
if (depth === undefined)
@ -135,12 +137,12 @@ module.exports = {
var bitmask = 0;
// TODO: slice from function arguments?
var args = [1, depth, packetLength, id, parentId, x, y, width, height, borderWidth, _class, visual];
// TODO: the code is a little bit mess
// 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
// 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
var masksList = [];
@ -174,27 +176,27 @@ module.exports = {
ChangeWindowAttributes:[
function(wid, values) {
var format = 'CxSLL';
var format = 'CxSLL';
var packetLength = 3 + (values ? Object.keys(values).length : 0);
var vals = packValueMask('CreateWindow', values);
var args = [2, packetLength, wid, vals[0]];
var valArr = vals[1];
for (var v in valArr)
{
format += 'L';
format += 'L';
args.push(valArr[v]);
}
}
return [format, args];
}
],
GetWindowAttributes: [
['CxSL', [3, 2]],
function(buf)
function(buf)
{
// TODO: change from array to named object fields
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
ResizeWindow: [
function(win, width, height) {
return ['CxSLSxxSxxSxx', [12, 5, win, 12, width, height]];
}
],
MoveWindow: [
function(win, 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]];
}
],
RaiseWindow: [
function(win) {
return ['CxSLSxxCxxx', [12, 4, win, 64]];
}
],
QueryTree: [
['CxSL', [15, 2]],
@ -263,7 +265,7 @@ module.exports = {
for (var i=0; i < res[2]; ++i)
tree.children.push(buf.unpack('L', 24 + i*4)[0]);
return tree;
}
}
],
// opcode 16
@ -277,7 +279,7 @@ module.exports = {
function(buf) {
var res = buf.unpack('L')[0];
return res;
}
}
],
GetAtomName: [
@ -286,7 +288,7 @@ module.exports = {
var nameLen = buf.unpack('S')[0];
// Atom value starting from 24th byte in the buffer
return buf.unpackString(nameLen, 24);
}
}
],
ChangeProperty: [
@ -328,9 +330,9 @@ module.exports = {
}
],
ListProperties: [
function(wid)
ListProperties: [
function(wid)
{
return ['CxSL', [21, 2, wid]];
},
@ -379,19 +381,26 @@ module.exports = {
function(destination, propagate, eventMask, eventRawData)
{
return [ 'CCSLLa', [25, propagate, 11, destination, eventMask, eventRawData] ];
return [ 'CCSLLa', [25, propagate, 11, destination, eventMask, eventRawData] ];
}
],
QueryPointer: [
[ 'CxSL', [38, 2] ],
function(buf) {
var res = buf.unpack('LLSSSSS'); // TODO: should be unsigned
// TODO pack array into named fields
return res;
var res = buf.unpack('LLssssS');
return {
root: res[0],
child: res[1],
rootX: res[2],
rootY: res[3],
childX: res[4],
childY: res[5],
keyMask: res[6]
};
}
],
SetInputFocus: [
function (wid, revertTo) // revertTo: 0 - None, 1 - PointerRoot, 2 - Parent
@ -402,7 +411,7 @@ module.exports = {
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] ];
}
@ -412,7 +421,7 @@ module.exports = {
function(pattern, max)
{
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) {
@ -435,7 +444,7 @@ module.exports = {
off += len;
}
return res;
}
}
],
CreatePixmap: [
@ -447,7 +456,7 @@ module.exports = {
// opcode 55
CreateGC: [
function(cid, drawable, values) {
var format = 'CxSLLL';
var format = 'CxSLLL';
var packetLength = 4 + (values ? Object.keys(values).length : 0);
var args = [55, packetLength, cid, drawable];
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
args.push(valArr[v]);
}
}
return [format, args];
}
],
ChangeGC: [
function(cid, values) {
var format = 'CxSLL';
var format = 'CxSLL';
var packetLength = 3 + (values ? Object.keys(values).length : 0);
var args = [56, packetLength, cid];
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
args.push(valArr[v]);
}
}
return [format, args];
}
],
@ -514,8 +523,8 @@ module.exports = {
}
return [format, args];
}
],
],
PolyFillRectangle: [
function(drawable, gc, coords) { // x1, y1, w1, h1, x2, y2, w2, h2...
@ -561,10 +570,10 @@ module.exports = {
GetImage: [
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 {
@ -574,7 +583,7 @@ module.exports = {
};
}
],
PolyText8: [
function(drawable, gc, x, y, items) {
var format = 'CxSLLSS';
@ -587,7 +596,7 @@ module.exports = {
if (typeof it == 'string')
{
if (it.length > 254) // TODO: split string in set of items
throw 'not supported yet';
throw 'not supported yet';
format += 'CCa';
args.push(it.length);
args.push(0); // delta???
@ -609,7 +618,7 @@ module.exports = {
}
],
CreateColormap:
CreateColormap:
[
function(cmid, wid, vid, alloc)
{
@ -626,11 +635,11 @@ module.exports = {
color.red = res[0];
color.blue = res[1];
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;
}
}
],
QueryExtension: [
function(name) {
var padded = xutil.padded_string(name);
@ -645,7 +654,7 @@ module.exports = {
ext.firstEvent = res[2];
ext.firstError = res[3];
return ext;
}
}
],
@ -664,19 +673,19 @@ module.exports = {
if (off + len > buf.length)
{
len = buf.length - off;
if (len <= 0)
if (len <= 0)
break;
}
res.push(buf.unpackString(len, off));
off += len;
}
return res;
}
}
],
GetKeyboardMapping: [
function(startCode, num) {
return [ 'CxSCCxx', [101, 2, startCode, num] ]
return [ 'CxSCCxx', [101, 2, startCode, num] ]
},
function(buff, listLength) {
var res = [];
@ -717,7 +726,7 @@ module.exports = {
SetScreenSaver: [
function(timeout, interval, preferBlanking, allowExposures) {
return [ 'CxSSSCCxx', [107, 3, timeout, interval, preferBlanking, allowExposures]];
}
}
],
ForceScreenSaver: [
@ -726,5 +735,5 @@ module.exports = {
}
]
}