diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..ed057dc --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "protocols"] + path = protocols + url = git://github.com/CrypticSwarm/XProto2JSON.git diff --git a/generateFiles.js b/generateFiles.js new file mode 100644 index 0000000..4ceccb3 --- /dev/null +++ b/generateFiles.js @@ -0,0 +1,211 @@ +var fs = require('fs') + , jqtpl = require("jqtpl") + , typeLookup = JSON.parse(fs.readFileSync('protocols/xTypes.json')) + , xProto = JSON.parse(fs.readFileSync('protocols/xProtocol.json')) + , data = { requests: xProto.request + , structs: xProto.struct + , getValueMask: getValueMask + , getDelim: getDelim + , enumVal: enumVal + , getBufPack: getBufPack + , isListType: isListType + , prepPropName: prepPropName + , firstType: firstType + , shiftedFirstType: shiftedFirstType + , prePackFirst: prePackFirst + , isValueMask: isValueMask + , isListAccountedFor: isListAccountedFor + , bufPackType: bufPackType + , requestLengthIndex: requestLengthIndex + , listLenIndex: listLenIndex + , realIndex: realIndex + , unpackList: unpackList + , packList: packList + , getFieldRef: getFieldRef + , isFieldFirst: isFieldFirst + , listLengthName: listLengthName + , fieldName: fieldName + , nonPad: nonPad + , constructOp: constructOp + } + +;['requests', 'structs'].forEach(function(name) { + var tplFile = fs.readFileSync('stubs/' + name + '.tpl').toString().replace(/\n\s*{{/g, '{{').replace(/}}\s*$/g, '}}') + fs.writeFileSync('lib/x11/autogen/' + name + '.js', jqtpl.tmpl(tplFile, data)) +}) + +function getValueMask(requestName) { + return typeLookup.valuemaskEnum[requestName] && xProto.enum[typeLookup.valuemaskEnum[requestName]].field +} + +function getDelim(i, first, rest) { + return i == 0 ? (first != null ? first : '{') : (rest != null ? rest : ',') +} + +function enumVal(val) { + return val.value ? val.value + : val.bit ? 1 << val.bit + : 0 +} + +function isListType(field) { + return field.fieldType === 'list' || field.fieldType === 'valueparam' +} + +function getBufPack(field) { + return !field ? 'x' + : field.fieldType === 'pad' ? new Array(parseInt(field.bytes) + 1).join('x') + : isListType(field) ? '' + : typeLookup.packTypes[field.type] +} + +function bufPackType(type) { + return typeLookup.packTypes[type] +} + +function prepPropName(short) { + return short === 'new' ? '_new' + : short === 'class' ? '_class' + : short === 'delete' ? '_delete' + : short +} + +function firstType(field, type) { + var f + return field.some(function(field) { + f = field + return field.fieldType == type + }) && f +} + +function shiftedFirstType(field, type) { + return firstType(field.slice(1), 'field') +} + +function prePackFirst(request) { + return request.opcode < 128 +} + +function requestLengthIndex(request) { + return prePackFirst(request) && request.field && request.field[0].fieldType != 'pad' ? 2 : 1 +} + +function isValueMask(field) { + return field.fieldType == 'valueparam' +} + +function listLenName(field) { + return field.fieldType == 'list' ? field.name + '_len' + : field['value-mask-name'] +} + +function isListAccountedFor(request, field) { + var name = listLenName(field) + return field.name == 'keysyms' + || field.name == 'keycodes' + || field.name == 'event' + || !request.field.every(function(f) { + return name != f.name + }) +} + +function listLenIndex(request, field) { + var index = 1 + , name = listLenName(field) + for (var i = 0, len = request.field.length; i < len; ++i) { + if (request.field[i].name == name) return index + if (request.field[i].fieldType == 'field') index++; + } +} + +function realIndex(request, field) { + var index = 0 + for (var i = 0, len = request.length; i < len; ++i) { + if (request[i] == field) return index + if (request[i].fieldType == 'field') index++; + } +} + +function unpackList(indents, obj, buf, offset, list, name) { + var subData = {} //Object.create(data) + , key + for (key in data) subData[key] = data[key] + subData.buf = buf + subData.offset = offset + subData.obj = obj + subData.list = list + subData.theName = name + var tplFile = fs.readFileSync('stubs/unpackList.tpl').toString().replace(/\n\s*{{/g, '{{').replace(/}}\s*$/g, '}}') + return indent(indents, jqtpl.tmpl(tplFile, subData)) +} + +function packList(indents, args, format, list, name) { + var subData = {} //Object.create(data) + , key + for (key in data) subData[key] = data[key] + subData.args = args + subData.format = format + subData.list = list + subData.theName = name + var tplFile = fs.readFileSync('stubs/packList.tpl').toString().replace(/\n\s*{{/g, '{{').replace(/}}\s*$/g, '}}') + return indent(indents, jqtpl.tmpl(tplFile, subData)) +} + +function indent(num, lines) { + var indent = new Array(num + 1).join(' ') + return lines.split('\n').map(function(line) { + return line ? indent + line : '' + }).join('\n') +} + +function getFieldRef(name, field, obj) { //todo read operators appropriately + return field.fieldType == 'valueparam' ? field['value-mask-name'] + : field.fieldref ? field.fieldref + : field.value ? field.value + : name == 'GetProperty' ? obj + ".format / 8 * " + obj + ".value_len" + : name == 'GetModifierMapping' ? obj + ".keycodes_per_modifier * 8" + : "0" +} + +function listLengthName(field) { + return field.fieldType == 'valueparam' ? field['value-mask-name'] + : field.fieldref ? field.fieldref + : field.value ? field.value + : field.name + '_len' +} + +function isFieldFirst(fields) { + return fields[0].fieldType == 'field' +} + +function fieldName(field) { + return prepPropName( + field.fieldType == 'valueparam' ? field['value-list-name'] + : field.name + ) +} + +function nonPad(fields){ + return fields && fields.filter(function(field){ + return field.fieldType != 'pad' + }) +} + +function constructOp(field, obj) { + function prependObj(item) { + return item == 'length' ? item : obj + '.' + item + } + + function handleOp(op) { + var params = [] + if (op.value) params.push(op.value) + if (op.fieldref) { + if (Array.isArray(op.fieldref)) params.concat(op.fieldref.map(prependObj)) + else params.push(prependObj(op.fieldref)) + } + if (op.op) params.push(handleOp(op.op)) + return params.join(op.operation) + } + + return handleOp(field.op) +} diff --git a/lib/x11/autogen/requests.js b/lib/x11/autogen/requests.js new file mode 100644 index 0000000..3e997e5 --- /dev/null +++ b/lib/x11/autogen/requests.js @@ -0,0 +1,2823 @@ +var packMask = require('../valuemask') + , xutil = require('../xutil') + , structs = require('./structs') + , valueMask = + { CreateWindow: + { BackPixmap: 1 + , BackPixel: 2 + , BorderPixmap: 4 + , BorderPixel: 8 + , BitGravity: 16 + , WinGravity: 32 + , BackingStore: 64 + , BackingPlanes: 128 + , BackingPixel: 256 + , OverrideRedirect: 512 + , SaveUnder: 1024 + , EventMask: 2048 + , DontPropagate: 4096 + , Colormap: 8192 + , Cursor: 16384 + } + , CreateGC: + { Function: 1 + , PlaneMask: 2 + , Foreground: 4 + , Background: 8 + , LineWidth: 16 + , LineStyle: 32 + , CapStyle: 64 + , JoinStyle: 128 + , FillStyle: 256 + , FillRule: 512 + , Tile: 1024 + , Stipple: 2048 + , TileStippleOriginX: 4096 + , TileStippleOriginY: 8192 + , Font: 16384 + , SubwindowMode: 32768 + , GraphicsExposures: 65536 + , ClipOriginX: 131072 + , ClipOriginY: 262144 + , ClipMask: 524288 + , DashOffset: 1048576 + , DashList: 2097152 + , ArcMode: 4194304 + } +} + , parameterOrder = xutil.parameterOrder + , size = xutil.formatSize + , associate = xutil.associate + +function padEnd(form, addSize, index) { + var s = size(form[0]) + addSize + form[0] += new Array(s * 4 % 4 + 1).join('x') + form[1][index] = Math.ceil(s) + return form +} + +module.exports = +{ CreateWindow: + [ function(obj, cb) { + var format = 'CCSLLssSSSSL' + , args = [ null + , 'depth' + , null + , 'wid' + , 'parent' + , 'x' + , 'y' + , 'width' + , 'height' + , 'border_width' + , '_class' + , 'visual' + , 'value_mask' + , 'value_list' + ] + , addSize = 0 + var packed = packMask(valueMask['CreateWindow'], obj.value_mask) + obj.value_mask = packed[0] + format += "L" + obj.value_list = packed[1] + format += new Array(packed[1].length + 1).join("L") + args = parameterOrder(args, obj) + args[0] = 1 + return padEnd([format, args], addSize, 2) + } + ] +, ChangeWindowAttributes: + [ function(obj, cb) { + var format = 'CxSL' + , args = [ null + , null + , 'window' + , 'value_mask' + , 'value_list' + ] + , addSize = 0 + var packed = packMask(valueMask['ChangeWindowAttributes'], obj.value_mask) + obj.value_mask = packed[0] + format += "L" + obj.value_list = packed[1] + format += new Array(packed[1].length + 1).join("L") + args = parameterOrder(args, obj) + args[0] = 2 + return padEnd([format, args], addSize, 1) + } + ] +, GetWindowAttributes: + [ function(obj, cb) { + var format = 'CxSL' + , args = [ null + , null + , 'window' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 3 + return padEnd([format, args], addSize, 1) + } + , function(buf, prop, length) { + var fields = + [ 'visual' + , 'class' + , 'bit_gravity' + , 'win_gravity' + , 'backing_planes' + , 'backing_pixel' + , 'save_under' + , 'map_is_installed' + , 'map_state' + , 'override_redirect' + , 'colormap' + , 'all_event_masks' + , 'your_event_mask' + , 'do_not_propagate_mask' ] + , format = "LSCCLLCCCCLLLSxx" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + reply.backing_store = prop + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + return reply + + } + ] +, DestroyWindow: + [ function(obj, cb) { + var format = 'CxSL' + , args = [ null + , null + , 'window' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 4 + return padEnd([format, args], addSize, 1) + } + ] +, DestroySubwindows: + [ function(obj, cb) { + var format = 'CxSL' + , args = [ null + , null + , 'window' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 5 + return padEnd([format, args], addSize, 1) + } + ] +, ChangeSaveSet: + [ function(obj, cb) { + var format = 'CCSL' + , args = [ null + , 'mode' + , null + , 'window' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 6 + return padEnd([format, args], addSize, 2) + } + ] +, ReparentWindow: + [ function(obj, cb) { + var format = 'CxSLLss' + , args = [ null + , null + , 'window' + , 'parent' + , 'x' + , 'y' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 7 + return padEnd([format, args], addSize, 1) + } + ] +, MapWindow: + [ function(obj, cb) { + var format = 'CxSL' + , args = [ null + , null + , 'window' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 8 + return padEnd([format, args], addSize, 1) + } + ] +, MapSubwindows: + [ function(obj, cb) { + var format = 'CxSL' + , args = [ null + , null + , 'window' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 9 + return padEnd([format, args], addSize, 1) + } + ] +, UnmapWindow: + [ function(obj, cb) { + var format = 'CxSL' + , args = [ null + , null + , 'window' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 10 + return padEnd([format, args], addSize, 1) + } + ] +, UnmapSubwindows: + [ function(obj, cb) { + var format = 'CxSL' + , args = [ null + , null + , 'window' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 11 + return padEnd([format, args], addSize, 1) + } + ] +, ConfigureWindow: + [ function(obj, cb) { + var format = 'CxSLSxx' + , args = [ null + , null + , 'window' + , 'value_mask' + , 'value_list' + ] + , addSize = 0 + var packed = packMask(valueMask['ConfigureWindow'], obj.value_mask) + obj.value_mask = packed[0] + obj.value_list = packed[1] + format += new Array(packed[1].length + 1).join("L") + args = parameterOrder(args, obj) + args[0] = 12 + return padEnd([format, args], addSize, 1) + } + ] +, CirculateWindow: + [ function(obj, cb) { + var format = 'CCSL' + , args = [ null + , 'direction' + , null + , 'window' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 13 + return padEnd([format, args], addSize, 2) + } + ] +, GetGeometry: + [ function(obj, cb) { + var format = 'CxSL' + , args = [ null + , null + , 'drawable' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 14 + return padEnd([format, args], addSize, 1) + } + , function(buf, prop, length) { + var fields = + [ 'root' + , 'x' + , 'y' + , 'width' + , 'height' + , 'border_width' ] + , format = "LssSSSxx" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + reply.depth = prop + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + return reply + + } + ] +, QueryTree: + [ function(obj, cb) { + var format = 'CxSL' + , args = [ null + , null + , 'window' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 15 + return padEnd([format, args], addSize, 1) + } + , function(buf, prop, length) { + var fields = + [ 'root' + , 'parent' + , 'children_len' ] + , format = "LLSxxxxxxxxxxxxxx" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + var len = reply.children_len + reply.children = buf.unpack(new Array(len + 1).join("L"), unpacked.offset) + unpacked.offset = reply.children.offset + return reply + + } + ] +, InternAtom: + [ function(obj, cb) { + var format = 'CCSSxx' + , args = [ null + , 'only_if_exists' + , null + , 'name_len' + , 'name' + ] + , addSize = 0 + var len = xutil.padded_length(obj.name.length) + , buf_name = new Buffer(len) + obj.name_len = Buffer.byteLength(obj.name) + buf_name.write(obj.name) + obj.name = buf_name + format += 'a' + addSize += (len / 4) + args = parameterOrder(args, obj) + args[0] = 16 + return padEnd([format, args], addSize, 2) + } + , function(buf, prop, length) { + var fields = + [ 'atom' ] + , format = "L" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + return reply + + } + ] +, GetAtomName: + [ function(obj, cb) { + var format = 'CxSL' + , args = [ null + , null + , 'atom' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 17 + return padEnd([format, args], addSize, 1) + } + , function(buf, prop, length) { + var fields = + [ 'name_len' ] + , format = "Sxxxxxxxxxxxxxxxxxxxxxx" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + reply.name = buf.slice(unpacked.offset, unpacked.offset + reply.name_len).toString() + unpacked.offset += reply.name_len + return reply + + } + ] +, ChangeProperty: + [ function(obj, cb) { + var format = 'CCSLLLCxxxL' + , args = [ null + , 'mode' + , null + , 'window' + , 'property' + , 'type' + , 'format' + , 'data_len' + , 'data' + ] + , addSize = 0 + var len = xutil.padded_length(obj.data.length) + , buf_name = new Buffer(len) + obj.data_len = Buffer.byteLength(obj.data) + buf_name.write(obj.data) + obj.data = buf_name + format += 'a' + addSize += (len / 4) + args = parameterOrder(args, obj) + args[0] = 18 + return padEnd([format, args], addSize, 2) + } + ] +, DeleteProperty: + [ function(obj, cb) { + var format = 'CxSLL' + , args = [ null + , null + , 'window' + , 'property' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 19 + return padEnd([format, args], addSize, 1) + } + ] +, GetProperty: + [ function(obj, cb) { + var format = 'CCSLLLLL' + , args = [ null + , '_delete' + , null + , 'window' + , 'property' + , 'type' + , 'long_offset' + , 'long_length' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 20 + return padEnd([format, args], addSize, 2) + } + , function(buf, prop, length) { + var fields = + [ 'type' + , 'bytes_after' + , 'value_len' ] + , format = "LLLxxxxxxxxxxxx" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + reply.format = prop + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + reply.value = buf.slice(unpacked.offset, unpacked.offset + reply.value_len).toString() + unpacked.offset += reply.value_len + return reply + + } + ] +, ListProperties: + [ function(obj, cb) { + var format = 'CxSL' + , args = [ null + , null + , 'window' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 21 + return padEnd([format, args], addSize, 1) + } + , function(buf, prop, length) { + var fields = + [ 'atoms_len' ] + , format = "Sxxxxxxxxxxxxxxxxxxxxxx" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + var len = reply.atoms_len + reply.atoms = buf.unpack(new Array(len + 1).join("L"), unpacked.offset) + unpacked.offset = reply.atoms.offset + return reply + + } + ] +, SetSelectionOwner: + [ function(obj, cb) { + var format = 'CxSLLL' + , args = [ null + , null + , 'owner' + , 'selection' + , 'time' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 22 + return padEnd([format, args], addSize, 1) + } + ] +, GetSelectionOwner: + [ function(obj, cb) { + var format = 'CxSL' + , args = [ null + , null + , 'selection' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 23 + return padEnd([format, args], addSize, 1) + } + , function(buf, prop, length) { + var fields = + [ 'owner' ] + , format = "L" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + return reply + + } + ] +, ConvertSelection: + [ function(obj, cb) { + var format = 'CxSLLLLL' + , args = [ null + , null + , 'requestor' + , 'selection' + , 'target' + , 'property' + , 'time' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 24 + return padEnd([format, args], addSize, 1) + } + ] +, SendEvent: + [ function(obj, cb) { + var format = 'CCSLL' + , args = [ null + , 'propagate' + , null + , 'destination' + , 'event_mask' + , 'event' + ] + , addSize = 0 + + var buf_name = new Buffer(32) + buffer.write(obj.event) + addSize += 32 / 4 + format += 'a' + args = parameterOrder(args, obj) + args[0] = 25 + return padEnd([format, args], addSize, 2) + } + ] +, GrabPointer: + [ function(obj, cb) { + var format = 'CCSLSCCLLL' + , args = [ null + , 'owner_events' + , null + , 'grab_window' + , 'event_mask' + , 'pointer_mode' + , 'keyboard_mode' + , 'confine_to' + , 'cursor' + , 'time' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 26 + return padEnd([format, args], addSize, 2) + } + , function(buf, prop, length) { + var fields = [] + , format = "" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + reply.status = prop + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + return reply + + } + ] +, UngrabPointer: + [ function(obj, cb) { + var format = 'CxSL' + , args = [ null + , null + , 'time' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 27 + return padEnd([format, args], addSize, 1) + } + ] +, GrabButton: + [ function(obj, cb) { + var format = 'CCSLSCCLLCxS' + , args = [ null + , 'owner_events' + , null + , 'grab_window' + , 'event_mask' + , 'pointer_mode' + , 'keyboard_mode' + , 'confine_to' + , 'cursor' + , 'button' + , 'modifiers' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 28 + return padEnd([format, args], addSize, 2) + } + ] +, UngrabButton: + [ function(obj, cb) { + var format = 'CCSLSxx' + , args = [ null + , 'button' + , null + , 'grab_window' + , 'modifiers' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 29 + return padEnd([format, args], addSize, 2) + } + ] +, ChangeActivePointerGrab: + [ function(obj, cb) { + var format = 'CxSLLSxx' + , args = [ null + , null + , 'cursor' + , 'time' + , 'event_mask' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 30 + return padEnd([format, args], addSize, 1) + } + ] +, GrabKeyboard: + [ function(obj, cb) { + var format = 'CCSLLCCxx' + , args = [ null + , 'owner_events' + , null + , 'grab_window' + , 'time' + , 'pointer_mode' + , 'keyboard_mode' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 31 + return padEnd([format, args], addSize, 2) + } + , function(buf, prop, length) { + var fields = [] + , format = "" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + reply.status = prop + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + return reply + + } + ] +, UngrabKeyboard: + [ function(obj, cb) { + var format = 'CxSL' + , args = [ null + , null + , 'time' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 32 + return padEnd([format, args], addSize, 1) + } + ] +, GrabKey: + [ function(obj, cb) { + var format = 'CCSLSCCCxxx' + , args = [ null + , 'owner_events' + , null + , 'grab_window' + , 'modifiers' + , 'key' + , 'pointer_mode' + , 'keyboard_mode' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 33 + return padEnd([format, args], addSize, 2) + } + ] +, UngrabKey: + [ function(obj, cb) { + var format = 'CCSLSxx' + , args = [ null + , 'key' + , null + , 'grab_window' + , 'modifiers' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 34 + return padEnd([format, args], addSize, 2) + } + ] +, AllowEvents: + [ function(obj, cb) { + var format = 'CCSL' + , args = [ null + , 'mode' + , null + , 'time' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 35 + return padEnd([format, args], addSize, 2) + } + ] +, GrabServer: + [ function(obj, cb) { + var format = 'CxS' + , args = [ null + , null + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 36 + return padEnd([format, args], addSize, 1) + } + ] +, UngrabServer: + [ function(obj, cb) { + var format = 'CxS' + , args = [ null + , null + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 37 + return padEnd([format, args], addSize, 1) + } + ] +, QueryPointer: + [ function(obj, cb) { + var format = 'CxSL' + , args = [ null + , null + , 'window' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 38 + return padEnd([format, args], addSize, 1) + } + , function(buf, prop, length) { + var fields = + [ 'root' + , 'child' + , 'root_x' + , 'root_y' + , 'win_x' + , 'win_y' + , 'mask' ] + , format = "LLssssSxx" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + reply.same_screen = prop + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + return reply + + } + ] +, GetMotionEvents: + [ function(obj, cb) { + var format = 'CxSLLL' + , args = [ null + , null + , 'window' + , 'start' + , 'stop' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 39 + return padEnd([format, args], addSize, 1) + } + , function(buf, prop, length) { + var fields = + [ 'events_len' ] + , format = "Lxxxxxxxxxxxxxxxxxxxx" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + var i = 0 + , len = reply.events_len + reply.events = [] + for (; i < len; ++i) { + var result = structs.TIMECOORD.unpack(buf, unpacked.offset) + reply.events.push(result[0]) + unpacked.offset = result[1] + } + return reply + + } + ] +, TranslateCoordinates: + [ function(obj, cb) { + var format = 'CxSLLss' + , args = [ null + , null + , 'src_window' + , 'dst_window' + , 'src_x' + , 'src_y' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 40 + return padEnd([format, args], addSize, 1) + } + , function(buf, prop, length) { + var fields = + [ 'child' + , 'dst_x' + , 'dst_y' ] + , format = "Lss" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + reply.same_screen = prop + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + return reply + + } + ] +, WarpPointer: + [ function(obj, cb) { + var format = 'CxSLLssSSss' + , args = [ null + , null + , 'src_window' + , 'dst_window' + , 'src_x' + , 'src_y' + , 'src_width' + , 'src_height' + , 'dst_x' + , 'dst_y' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 41 + return padEnd([format, args], addSize, 1) + } + ] +, SetInputFocus: + [ function(obj, cb) { + var format = 'CCSLL' + , args = [ null + , 'revert_to' + , null + , 'focus' + , 'time' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 42 + return padEnd([format, args], addSize, 2) + } + ] +, GetInputFocus: + [ function(obj, cb) { + var format = 'CxS' + , args = [ null + , null + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 43 + return padEnd([format, args], addSize, 1) + } + , function(buf, prop, length) { + var fields = + [ 'focus' ] + , format = "L" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + reply.revert_to = prop + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + return reply + + } + ] +, QueryKeymap: + [ function(obj, cb) { + var format = 'CxS' + , args = [ null + , null + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 44 + return padEnd([format, args], addSize, 1) + } + , function(buf, prop, length) { + var fields = [] + , format = "" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + return reply + + } + ] +, OpenFont: + [ function(obj, cb) { + var format = 'CxSLSxx' + , args = [ null + , null + , 'fid' + , 'name_len' + , 'name' + ] + , addSize = 0 + var len = xutil.padded_length(obj.name.length) + , buf_name = new Buffer(len) + obj.name_len = Buffer.byteLength(obj.name) + buf_name.write(obj.name) + obj.name = buf_name + format += 'a' + addSize += (len / 4) + args = parameterOrder(args, obj) + args[0] = 45 + return padEnd([format, args], addSize, 1) + } + ] +, CloseFont: + [ function(obj, cb) { + var format = 'CxSL' + , args = [ null + , null + , 'font' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 46 + return padEnd([format, args], addSize, 1) + } + ] +, QueryFont: + [ function(obj, cb) { + var format = 'CxSL' + , args = [ null + , null + , 'font' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 47 + return padEnd([format, args], addSize, 1) + } + , function(buf, prop, length) { + var fields = + [ 'min_bounds' + , 'max_bounds' + , 'min_char_or_byte2' + , 'max_char_or_byte2' + , 'default_char' + , 'properties_len' + , 'draw_direction' + , 'min_byte1' + , 'max_byte1' + , 'all_chars_exist' + , 'font_ascent' + , 'font_descent' + , 'char_infos_len' ] + , format = "undefinedxxxxundefinedxxxxSSSSCCCCssL" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + var i = 0 + , len = reply.properties_len + reply.properties = [] + for (; i < len; ++i) { + var result = structs.FONTPROP.unpack(buf, unpacked.offset) + reply.properties.push(result[0]) + unpacked.offset = result[1] + } + var i = 0 + , len = reply.char_infos_len + reply.char_infos = [] + for (; i < len; ++i) { + var result = structs.CHARINFO.unpack(buf, unpacked.offset) + reply.char_infos.push(result[0]) + unpacked.offset = result[1] + } + return reply + + } + ] +, QueryTextExtents: + [ function(obj, cb) { + var format = 'CCSL' + , args = [ null + , 'odd_length' + , null + , 'font' + , 'string' + ] + , addSize = 0 + + obj.string = Array.isArray(obj.string) ? obj.string : [obj.string] + var i = 0 + , len = obj.string.length + obj.string_len = len + for (; i < len; ++i) { + var result = structs.CHAR2B.pack(obj.string[i], format) + format = result[0] + obj.string[i] = result[1] + addSize += result[2] + } + args = parameterOrder(args, obj) + args[0] = 48 + return padEnd([format, args], addSize, 2) + } + , function(buf, prop, length) { + var fields = + [ 'font_ascent' + , 'font_descent' + , 'overall_ascent' + , 'overall_descent' + , 'overall_width' + , 'overall_left' + , 'overall_right' ] + , format = "sssslll" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + reply.draw_direction = prop + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + return reply + + } + ] +, ListFonts: + [ function(obj, cb) { + var format = 'CxSSS' + , args = [ null + , null + , 'max_names' + , 'pattern_len' + , 'pattern' + ] + , addSize = 0 + var len = xutil.padded_length(obj.pattern.length) + , buf_name = new Buffer(len) + obj.pattern_len = Buffer.byteLength(obj.pattern) + buf_name.write(obj.pattern) + obj.pattern = buf_name + format += 'a' + addSize += (len / 4) + args = parameterOrder(args, obj) + args[0] = 49 + return padEnd([format, args], addSize, 1) + } + , function(buf, prop, length) { + var fields = + [ 'names_len' ] + , format = "Sxxxxxxxxxxxxxxxxxxxxxx" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + var i = 0 + , len = reply.names_len + reply.names = [] + for (; i < len; ++i) { + var result = structs.STR.unpack(buf, unpacked.offset) + reply.names.push(result[0]) + unpacked.offset = result[1] + } + return reply + + } + ] +, ListFontsWithInfo: + [ function(obj, cb) { + var format = 'CxSSS' + , args = [ null + , null + , 'max_names' + , 'pattern_len' + , 'pattern' + ] + , addSize = 0 + var len = xutil.padded_length(obj.pattern.length) + , buf_name = new Buffer(len) + obj.pattern_len = Buffer.byteLength(obj.pattern) + buf_name.write(obj.pattern) + obj.pattern = buf_name + format += 'a' + addSize += (len / 4) + args = parameterOrder(args, obj) + args[0] = 50 + return padEnd([format, args], addSize, 1) + } + , function(buf, prop, length) { + var fields = + [ 'min_bounds' + , 'max_bounds' + , 'min_char_or_byte2' + , 'max_char_or_byte2' + , 'default_char' + , 'properties_len' + , 'draw_direction' + , 'min_byte1' + , 'max_byte1' + , 'all_chars_exist' + , 'font_ascent' + , 'font_descent' + , 'replies_hint' ] + , format = "undefinedxxxxundefinedxxxxSSSSCCCCssL" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + reply.name_len = prop + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + var i = 0 + , len = reply.properties_len + reply.properties = [] + for (; i < len; ++i) { + var result = structs.FONTPROP.unpack(buf, unpacked.offset) + reply.properties.push(result[0]) + unpacked.offset = result[1] + } + reply.name = buf.slice(unpacked.offset, unpacked.offset + reply.name_len).toString() + unpacked.offset += reply.name_len + return reply + + } + ] +, SetFontPath: + [ function(obj, cb) { + var format = 'CxSS' + , args = [ null + , null + , 'font_qty' + , 'path' + ] + , addSize = 0 + var len = xutil.padded_length(obj.path.length) + , buf_name = new Buffer(len) + obj.path_len = Buffer.byteLength(obj.path) + buf_name.write(obj.path) + obj.path = buf_name + format += 'a' + addSize += (len / 4) + args = parameterOrder(args, obj) + args[0] = 51 + return padEnd([format, args], addSize, 1) + } + ] +, GetFontPath: + [ function(obj, cb) { + var format = 'CxS' + , args = [ null + , null + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 52 + return padEnd([format, args], addSize, 1) + } + , function(buf, prop, length) { + var fields = + [ 'path_len' ] + , format = "Sxxxxxxxxxxxxxxxxxxxxxx" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + var i = 0 + , len = reply.path_len + reply.path = [] + for (; i < len; ++i) { + var result = structs.STR.unpack(buf, unpacked.offset) + reply.path.push(result[0]) + unpacked.offset = result[1] + } + return reply + + } + ] +, CreatePixmap: + [ function(obj, cb) { + var format = 'CCSLLSS' + , args = [ null + , 'depth' + , null + , 'pid' + , 'drawable' + , 'width' + , 'height' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 53 + return padEnd([format, args], addSize, 2) + } + ] +, FreePixmap: + [ function(obj, cb) { + var format = 'CxSL' + , args = [ null + , null + , 'pixmap' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 54 + return padEnd([format, args], addSize, 1) + } + ] +, CreateGC: + [ function(obj, cb) { + var format = 'CxSLL' + , args = [ null + , null + , 'cid' + , 'drawable' + , 'value_mask' + , 'value_list' + ] + , addSize = 0 + var packed = packMask(valueMask['CreateGC'], obj.value_mask) + obj.value_mask = packed[0] + format += "L" + obj.value_list = packed[1] + format += new Array(packed[1].length + 1).join("L") + args = parameterOrder(args, obj) + args[0] = 55 + return padEnd([format, args], addSize, 1) + } + ] +, ChangeGC: + [ function(obj, cb) { + var format = 'CxSL' + , args = [ null + , null + , 'gc' + , 'value_mask' + , 'value_list' + ] + , addSize = 0 + var packed = packMask(valueMask['ChangeGC'], obj.value_mask) + obj.value_mask = packed[0] + format += "L" + obj.value_list = packed[1] + format += new Array(packed[1].length + 1).join("L") + args = parameterOrder(args, obj) + args[0] = 56 + return padEnd([format, args], addSize, 1) + } + ] +, CopyGC: + [ function(obj, cb) { + var format = 'CxSLLL' + , args = [ null + , null + , 'src_gc' + , 'dst_gc' + , 'value_mask' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 57 + return padEnd([format, args], addSize, 1) + } + ] +, SetDashes: + [ function(obj, cb) { + var format = 'CxSLSS' + , args = [ null + , null + , 'gc' + , 'dash_offset' + , 'dashes_len' + , 'dashes' + ] + , addSize = 0 + + obj.dashes = Array.isArray(obj.dashes) ? obj.dashes : [obj.dashes] + var len = obj.dashes.length + format += new Array(len + 1).join("C") + obj.dashes_len = len + args = parameterOrder(args, obj) + args[0] = 58 + return padEnd([format, args], addSize, 1) + } + ] +, SetClipRectangles: + [ function(obj, cb) { + var format = 'CCSLss' + , args = [ null + , 'ordering' + , null + , 'gc' + , 'clip_x_origin' + , 'clip_y_origin' + , 'rectangles' + ] + , addSize = 0 + + obj.rectangles = Array.isArray(obj.rectangles) ? obj.rectangles : [obj.rectangles] + var i = 0 + , len = obj.rectangles.length + obj.rectangles_len = len + for (; i < len; ++i) { + var result = structs.RECTANGLE.pack(obj.rectangles[i], format) + format = result[0] + obj.rectangles[i] = result[1] + addSize += result[2] + } + args = parameterOrder(args, obj) + args[0] = 59 + return padEnd([format, args], addSize, 2) + } + ] +, FreeGC: + [ function(obj, cb) { + var format = 'CxSL' + , args = [ null + , null + , 'gc' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 60 + return padEnd([format, args], addSize, 1) + } + ] +, ClearArea: + [ function(obj, cb) { + var format = 'CCSLssSS' + , args = [ null + , 'exposures' + , null + , 'window' + , 'x' + , 'y' + , 'width' + , 'height' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 61 + return padEnd([format, args], addSize, 2) + } + ] +, CopyArea: + [ function(obj, cb) { + var format = 'CxSLLLssssSS' + , args = [ null + , null + , 'src_drawable' + , 'dst_drawable' + , 'gc' + , 'src_x' + , 'src_y' + , 'dst_x' + , 'dst_y' + , 'width' + , 'height' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 62 + return padEnd([format, args], addSize, 1) + } + ] +, CopyPlane: + [ function(obj, cb) { + var format = 'CxSLLLssssSSL' + , args = [ null + , null + , 'src_drawable' + , 'dst_drawable' + , 'gc' + , 'src_x' + , 'src_y' + , 'dst_x' + , 'dst_y' + , 'width' + , 'height' + , 'bit_plane' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 63 + return padEnd([format, args], addSize, 1) + } + ] +, PolyPoint: + [ function(obj, cb) { + var format = 'CCSLL' + , args = [ null + , 'coordinate_mode' + , null + , 'drawable' + , 'gc' + , 'points' + ] + , addSize = 0 + + obj.points = Array.isArray(obj.points) ? obj.points : [obj.points] + var i = 0 + , len = obj.points.length + obj.points_len = len + for (; i < len; ++i) { + var result = structs.POINT.pack(obj.points[i], format) + format = result[0] + obj.points[i] = result[1] + addSize += result[2] + } + args = parameterOrder(args, obj) + args[0] = 64 + return padEnd([format, args], addSize, 2) + } + ] +, PolyLine: + [ function(obj, cb) { + var format = 'CCSLL' + , args = [ null + , 'coordinate_mode' + , null + , 'drawable' + , 'gc' + , 'points' + ] + , addSize = 0 + + obj.points = Array.isArray(obj.points) ? obj.points : [obj.points] + var i = 0 + , len = obj.points.length + obj.points_len = len + for (; i < len; ++i) { + var result = structs.POINT.pack(obj.points[i], format) + format = result[0] + obj.points[i] = result[1] + addSize += result[2] + } + args = parameterOrder(args, obj) + args[0] = 65 + return padEnd([format, args], addSize, 2) + } + ] +, PolySegment: + [ function(obj, cb) { + var format = 'CxSLL' + , args = [ null + , null + , 'drawable' + , 'gc' + , 'segments' + ] + , addSize = 0 + + obj.segments = Array.isArray(obj.segments) ? obj.segments : [obj.segments] + var i = 0 + , len = obj.segments.length + obj.segments_len = len + for (; i < len; ++i) { + var result = structs.SEGMENT.pack(obj.segments[i], format) + format = result[0] + obj.segments[i] = result[1] + addSize += result[2] + } + args = parameterOrder(args, obj) + args[0] = 66 + return padEnd([format, args], addSize, 1) + } + ] +, PolyRectangle: + [ function(obj, cb) { + var format = 'CxSLL' + , args = [ null + , null + , 'drawable' + , 'gc' + , 'rectangles' + ] + , addSize = 0 + + obj.rectangles = Array.isArray(obj.rectangles) ? obj.rectangles : [obj.rectangles] + var i = 0 + , len = obj.rectangles.length + obj.rectangles_len = len + for (; i < len; ++i) { + var result = structs.RECTANGLE.pack(obj.rectangles[i], format) + format = result[0] + obj.rectangles[i] = result[1] + addSize += result[2] + } + args = parameterOrder(args, obj) + args[0] = 67 + return padEnd([format, args], addSize, 1) + } + ] +, PolyArc: + [ function(obj, cb) { + var format = 'CxSLL' + , args = [ null + , null + , 'drawable' + , 'gc' + , 'arcs' + ] + , addSize = 0 + + obj.arcs = Array.isArray(obj.arcs) ? obj.arcs : [obj.arcs] + var i = 0 + , len = obj.arcs.length + obj.arcs_len = len + for (; i < len; ++i) { + var result = structs.ARC.pack(obj.arcs[i], format) + format = result[0] + obj.arcs[i] = result[1] + addSize += result[2] + } + args = parameterOrder(args, obj) + args[0] = 68 + return padEnd([format, args], addSize, 1) + } + ] +, FillPoly: + [ function(obj, cb) { + var format = 'CxSLLCCxx' + , args = [ null + , null + , 'drawable' + , 'gc' + , 'shape' + , 'coordinate_mode' + , 'points' + ] + , addSize = 0 + + obj.points = Array.isArray(obj.points) ? obj.points : [obj.points] + var i = 0 + , len = obj.points.length + obj.points_len = len + for (; i < len; ++i) { + var result = structs.POINT.pack(obj.points[i], format) + format = result[0] + obj.points[i] = result[1] + addSize += result[2] + } + args = parameterOrder(args, obj) + args[0] = 69 + return padEnd([format, args], addSize, 1) + } + ] +, PolyFillRectangle: + [ function(obj, cb) { + var format = 'CxSLL' + , args = [ null + , null + , 'drawable' + , 'gc' + , 'rectangles' + ] + , addSize = 0 + + obj.rectangles = Array.isArray(obj.rectangles) ? obj.rectangles : [obj.rectangles] + var i = 0 + , len = obj.rectangles.length + obj.rectangles_len = len + for (; i < len; ++i) { + var result = structs.RECTANGLE.pack(obj.rectangles[i], format) + format = result[0] + obj.rectangles[i] = result[1] + addSize += result[2] + } + args = parameterOrder(args, obj) + args[0] = 70 + return padEnd([format, args], addSize, 1) + } + ] +, PolyFillArc: + [ function(obj, cb) { + var format = 'CxSLL' + , args = [ null + , null + , 'drawable' + , 'gc' + , 'arcs' + ] + , addSize = 0 + + obj.arcs = Array.isArray(obj.arcs) ? obj.arcs : [obj.arcs] + var i = 0 + , len = obj.arcs.length + obj.arcs_len = len + for (; i < len; ++i) { + var result = structs.ARC.pack(obj.arcs[i], format) + format = result[0] + obj.arcs[i] = result[1] + addSize += result[2] + } + args = parameterOrder(args, obj) + args[0] = 71 + return padEnd([format, args], addSize, 1) + } + ] +, PutImage: + [ function(obj, cb) { + var format = 'CCSLLSSssCCxx' + , args = [ null + , 'format' + , null + , 'drawable' + , 'gc' + , 'width' + , 'height' + , 'dst_x' + , 'dst_y' + , 'left_pad' + , 'depth' + , 'data' + ] + , addSize = 0 + + obj.data = Array.isArray(obj.data) ? obj.data : [obj.data] + var len = obj.data.length + format += new Array(len + 1).join("C") + obj.data_len = len + args = parameterOrder(args, obj) + args[0] = 72 + return padEnd([format, args], addSize, 2) + } + ] +, GetImage: + [ function(obj, cb) { + var format = 'CCSLssSSL' + , args = [ null + , 'format' + , null + , 'drawable' + , 'x' + , 'y' + , 'width' + , 'height' + , 'plane_mask' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 73 + return padEnd([format, args], addSize, 2) + } + , function(buf, prop, length) { + var fields = + [ 'visual' ] + , format = "Lxxxxxxxxxxxxxxxxxxxx" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + reply.depth = prop + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + var len = 4*length + reply.data = buf.unpack(new Array(len + 1).join("C"), unpacked.offset) + unpacked.offset = reply.data.offset + return reply + + } + ] +, PolyText8: + [ function(obj, cb) { + var format = 'CxSLLss' + , args = [ null + , null + , 'drawable' + , 'gc' + , 'x' + , 'y' + , 'items' + ] + , addSize = 0 + + obj.items = Array.isArray(obj.items) ? obj.items : [obj.items] + var len = obj.items.length + format += new Array(len + 1).join("C") + obj.items_len = len + args = parameterOrder(args, obj) + args[0] = 74 + return padEnd([format, args], addSize, 1) + } + ] +, PolyText16: + [ function(obj, cb) { + var format = 'CxSLLss' + , args = [ null + , null + , 'drawable' + , 'gc' + , 'x' + , 'y' + , 'items' + ] + , addSize = 0 + + obj.items = Array.isArray(obj.items) ? obj.items : [obj.items] + var len = obj.items.length + format += new Array(len + 1).join("C") + obj.items_len = len + args = parameterOrder(args, obj) + args[0] = 75 + return padEnd([format, args], addSize, 1) + } + ] +, ImageText8: + [ function(obj, cb) { + var format = 'CCSLLss' + , args = [ null + , 'string_len' + , null + , 'drawable' + , 'gc' + , 'x' + , 'y' + , 'string' + ] + , addSize = 0 + var len = xutil.padded_length(obj.string.length) + , buf_name = new Buffer(len) + obj.string_len = Buffer.byteLength(obj.string) + buf_name.write(obj.string) + obj.string = buf_name + format += 'a' + addSize += (len / 4) + args = parameterOrder(args, obj) + args[0] = 76 + return padEnd([format, args], addSize, 2) + } + ] +, ImageText16: + [ function(obj, cb) { + var format = 'CCSLLss' + , args = [ null + , 'string_len' + , null + , 'drawable' + , 'gc' + , 'x' + , 'y' + , 'string' + ] + , addSize = 0 + + obj.string = Array.isArray(obj.string) ? obj.string : [obj.string] + var i = 0 + , len = obj.string.length + obj.string_len = len + for (; i < len; ++i) { + var result = structs.CHAR2B.pack(obj.string[i], format) + format = result[0] + obj.string[i] = result[1] + addSize += result[2] + } + args = parameterOrder(args, obj) + args[0] = 77 + return padEnd([format, args], addSize, 2) + } + ] +, CreateColormap: + [ function(obj, cb) { + var format = 'CCSLLL' + , args = [ null + , 'alloc' + , null + , 'mid' + , 'window' + , 'visual' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 78 + return padEnd([format, args], addSize, 2) + } + ] +, FreeColormap: + [ function(obj, cb) { + var format = 'CxSL' + , args = [ null + , null + , 'cmap' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 79 + return padEnd([format, args], addSize, 1) + } + ] +, CopyColormapAndFree: + [ function(obj, cb) { + var format = 'CxSLL' + , args = [ null + , null + , 'mid' + , 'src_cmap' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 80 + return padEnd([format, args], addSize, 1) + } + ] +, InstallColormap: + [ function(obj, cb) { + var format = 'CxSL' + , args = [ null + , null + , 'cmap' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 81 + return padEnd([format, args], addSize, 1) + } + ] +, UninstallColormap: + [ function(obj, cb) { + var format = 'CxSL' + , args = [ null + , null + , 'cmap' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 82 + return padEnd([format, args], addSize, 1) + } + ] +, ListInstalledColormaps: + [ function(obj, cb) { + var format = 'CxSL' + , args = [ null + , null + , 'window' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 83 + return padEnd([format, args], addSize, 1) + } + , function(buf, prop, length) { + var fields = + [ 'cmaps_len' ] + , format = "Sxxxxxxxxxxxxxxxxxxxxxx" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + var len = reply.cmaps_len + reply.cmaps = buf.unpack(new Array(len + 1).join("L"), unpacked.offset) + unpacked.offset = reply.cmaps.offset + return reply + + } + ] +, AllocColor: + [ function(obj, cb) { + var format = 'CxSLSSSxx' + , args = [ null + , null + , 'cmap' + , 'red' + , 'green' + , 'blue' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 84 + return padEnd([format, args], addSize, 1) + } + , function(buf, prop, length) { + var fields = + [ 'red' + , 'green' + , 'blue' + , 'pixel' ] + , format = "SSSxxL" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + return reply + + } + ] +, AllocNamedColor: + [ function(obj, cb) { + var format = 'CxSLSxx' + , args = [ null + , null + , 'cmap' + , 'name_len' + , 'name' + ] + , addSize = 0 + var len = xutil.padded_length(obj.name.length) + , buf_name = new Buffer(len) + obj.name_len = Buffer.byteLength(obj.name) + buf_name.write(obj.name) + obj.name = buf_name + format += 'a' + addSize += (len / 4) + args = parameterOrder(args, obj) + args[0] = 85 + return padEnd([format, args], addSize, 1) + } + , function(buf, prop, length) { + var fields = + [ 'pixel' + , 'exact_red' + , 'exact_green' + , 'exact_blue' + , 'visual_red' + , 'visual_green' + , 'visual_blue' ] + , format = "LSSSSSS" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + return reply + + } + ] +, AllocColorCells: + [ function(obj, cb) { + var format = 'CCSLSS' + , args = [ null + , 'contiguous' + , null + , 'cmap' + , 'colors' + , 'planes' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 86 + return padEnd([format, args], addSize, 2) + } + , function(buf, prop, length) { + var fields = + [ 'pixels_len' + , 'masks_len' ] + , format = "SSxxxxxxxxxxxxxxxxxxxx" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + var len = reply.pixels_len + reply.pixels = buf.unpack(new Array(len + 1).join("L"), unpacked.offset) + unpacked.offset = reply.pixels.offset + var len = reply.masks_len + reply.masks = buf.unpack(new Array(len + 1).join("L"), unpacked.offset) + unpacked.offset = reply.masks.offset + return reply + + } + ] +, AllocColorPlanes: + [ function(obj, cb) { + var format = 'CCSLSSSS' + , args = [ null + , 'contiguous' + , null + , 'cmap' + , 'colors' + , 'reds' + , 'greens' + , 'blues' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 87 + return padEnd([format, args], addSize, 2) + } + , function(buf, prop, length) { + var fields = + [ 'pixels_len' + , 'red_mask' + , 'green_mask' + , 'blue_mask' ] + , format = "SxxLLLxxxxxxxx" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + var len = reply.pixels_len + reply.pixels = buf.unpack(new Array(len + 1).join("L"), unpacked.offset) + unpacked.offset = reply.pixels.offset + return reply + + } + ] +, FreeColors: + [ function(obj, cb) { + var format = 'CxSLL' + , args = [ null + , null + , 'cmap' + , 'plane_mask' + , 'pixels' + ] + , addSize = 0 + + obj.pixels = Array.isArray(obj.pixels) ? obj.pixels : [obj.pixels] + var len = obj.pixels.length + format += new Array(len + 1).join("L") + obj.pixels_len = len + args = parameterOrder(args, obj) + args[0] = 88 + return padEnd([format, args], addSize, 1) + } + ] +, StoreColors: + [ function(obj, cb) { + var format = 'CxSL' + , args = [ null + , null + , 'cmap' + , 'items' + ] + , addSize = 0 + + obj.items = Array.isArray(obj.items) ? obj.items : [obj.items] + var i = 0 + , len = obj.items.length + obj.items_len = len + for (; i < len; ++i) { + var result = structs.COLORITEM.pack(obj.items[i], format) + format = result[0] + obj.items[i] = result[1] + addSize += result[2] + } + args = parameterOrder(args, obj) + args[0] = 89 + return padEnd([format, args], addSize, 1) + } + ] +, StoreNamedColor: + [ function(obj, cb) { + var format = 'CCSLLSxx' + , args = [ null + , 'flags' + , null + , 'cmap' + , 'pixel' + , 'name_len' + , 'name' + ] + , addSize = 0 + var len = xutil.padded_length(obj.name.length) + , buf_name = new Buffer(len) + obj.name_len = Buffer.byteLength(obj.name) + buf_name.write(obj.name) + obj.name = buf_name + format += 'a' + addSize += (len / 4) + args = parameterOrder(args, obj) + args[0] = 90 + return padEnd([format, args], addSize, 2) + } + ] +, QueryColors: + [ function(obj, cb) { + var format = 'CxSL' + , args = [ null + , null + , 'cmap' + , 'pixels' + ] + , addSize = 0 + + obj.pixels = Array.isArray(obj.pixels) ? obj.pixels : [obj.pixels] + var len = obj.pixels.length + format += new Array(len + 1).join("L") + obj.pixels_len = len + args = parameterOrder(args, obj) + args[0] = 91 + return padEnd([format, args], addSize, 1) + } + , function(buf, prop, length) { + var fields = + [ 'colors_len' ] + , format = "Sxxxxxxxxxxxxxxxxxxxxxx" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + var i = 0 + , len = reply.colors_len + reply.colors = [] + for (; i < len; ++i) { + var result = structs.RGB.unpack(buf, unpacked.offset) + reply.colors.push(result[0]) + unpacked.offset = result[1] + } + return reply + + } + ] +, LookupColor: + [ function(obj, cb) { + var format = 'CxSLSxx' + , args = [ null + , null + , 'cmap' + , 'name_len' + , 'name' + ] + , addSize = 0 + var len = xutil.padded_length(obj.name.length) + , buf_name = new Buffer(len) + obj.name_len = Buffer.byteLength(obj.name) + buf_name.write(obj.name) + obj.name = buf_name + format += 'a' + addSize += (len / 4) + args = parameterOrder(args, obj) + args[0] = 92 + return padEnd([format, args], addSize, 1) + } + , function(buf, prop, length) { + var fields = + [ 'exact_red' + , 'exact_green' + , 'exact_blue' + , 'visual_red' + , 'visual_green' + , 'visual_blue' ] + , format = "SSSSSS" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + return reply + + } + ] +, CreateCursor: + [ function(obj, cb) { + var format = 'CxSLLLSSSSSSSS' + , args = [ null + , null + , 'cid' + , 'source' + , 'mask' + , 'fore_red' + , 'fore_green' + , 'fore_blue' + , 'back_red' + , 'back_green' + , 'back_blue' + , 'x' + , 'y' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 93 + return padEnd([format, args], addSize, 1) + } + ] +, CreateGlyphCursor: + [ function(obj, cb) { + var format = 'CxSLLLSSSSSSSS' + , args = [ null + , null + , 'cid' + , 'source_font' + , 'mask_font' + , 'source_char' + , 'mask_char' + , 'fore_red' + , 'fore_green' + , 'fore_blue' + , 'back_red' + , 'back_green' + , 'back_blue' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 94 + return padEnd([format, args], addSize, 1) + } + ] +, FreeCursor: + [ function(obj, cb) { + var format = 'CxSL' + , args = [ null + , null + , 'cursor' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 95 + return padEnd([format, args], addSize, 1) + } + ] +, RecolorCursor: + [ function(obj, cb) { + var format = 'CxSLSSSSSS' + , args = [ null + , null + , 'cursor' + , 'fore_red' + , 'fore_green' + , 'fore_blue' + , 'back_red' + , 'back_green' + , 'back_blue' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 96 + return padEnd([format, args], addSize, 1) + } + ] +, QueryBestSize: + [ function(obj, cb) { + var format = 'CCSLSS' + , args = [ null + , '_class' + , null + , 'drawable' + , 'width' + , 'height' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 97 + return padEnd([format, args], addSize, 2) + } + , function(buf, prop, length) { + var fields = + [ 'width' + , 'height' ] + , format = "SS" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + return reply + + } + ] +, QueryExtension: + [ function(obj, cb) { + var format = 'CxSSxx' + , args = [ null + , null + , 'name_len' + , 'name' + ] + , addSize = 0 + var len = xutil.padded_length(obj.name.length) + , buf_name = new Buffer(len) + obj.name_len = Buffer.byteLength(obj.name) + buf_name.write(obj.name) + obj.name = buf_name + format += 'a' + addSize += (len / 4) + args = parameterOrder(args, obj) + args[0] = 98 + return padEnd([format, args], addSize, 1) + } + , function(buf, prop, length) { + var fields = + [ 'present' + , 'major_opcode' + , 'first_event' + , 'first_error' ] + , format = "CCCC" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + return reply + + } + ] +, ListExtensions: + [ function(obj, cb) { + var format = 'CxS' + , args = [ null + , null + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 99 + return padEnd([format, args], addSize, 1) + } + , function(buf, prop, length) { + var fields = [] + , format = "xxxxxxxxxxxxxxxxxxxxxxxx" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + reply.names_len = prop + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + var i = 0 + , len = reply.names_len + reply.names = [] + for (; i < len; ++i) { + var result = structs.STR.unpack(buf, unpacked.offset) + reply.names.push(result[0]) + unpacked.offset = result[1] + } + return reply + + } + ] +, ChangeKeyboardMapping: + [ function(obj, cb) { + var format = 'CCSCC' + , args = [ null + , 'keycode_count' + , null + , 'first_keycode' + , 'keysyms_per_keycode' + , 'keysyms' + ] + , addSize = 0 + + obj.keysyms = Array.isArray(obj.keysyms) ? obj.keysyms : [obj.keysyms] + var len = obj.keysyms.length + format += new Array(len + 1).join("L") + obj.keysyms_len = len + args = parameterOrder(args, obj) + args[0] = 100 + return padEnd([format, args], addSize, 2) + } + ] +, GetKeyboardMapping: + [ function(obj, cb) { + var format = 'CxSCC' + , args = [ null + , null + , 'first_keycode' + , 'count' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 101 + return padEnd([format, args], addSize, 1) + } + , function(buf, prop, length) { + var fields = [] + , format = "xxxxxxxxxxxxxxxxxxxxxxxx" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + reply.keysyms_per_keycode = prop + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + var len = length + reply.keysyms = buf.unpack(new Array(len + 1).join("L"), unpacked.offset) + unpacked.offset = reply.keysyms.offset + return reply + + } + ] +, ChangeKeyboardControl: + [ function(obj, cb) { + var format = 'CxS' + , args = [ null + , null + , 'value_mask' + , 'value_list' + ] + , addSize = 0 + var packed = packMask(valueMask['ChangeKeyboardControl'], obj.value_mask) + obj.value_mask = packed[0] + format += "L" + obj.value_list = packed[1] + format += new Array(packed[1].length + 1).join("L") + args = parameterOrder(args, obj) + args[0] = 102 + return padEnd([format, args], addSize, 1) + } + ] +, GetKeyboardControl: + [ function(obj, cb) { + var format = 'CxS' + , args = [ null + , null + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 103 + return padEnd([format, args], addSize, 1) + } + , function(buf, prop, length) { + var fields = + [ 'led_mask' + , 'key_click_percent' + , 'bell_percent' + , 'bell_pitch' + , 'bell_duration' ] + , format = "LCCSSxx" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + reply.global_auto_repeat = prop + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + return reply + + } + ] +, Bell: + [ function(obj, cb) { + var format = 'CCS' + , args = [ null + , 'percent' + , null + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 104 + return padEnd([format, args], addSize, 2) + } + ] +, ChangePointerControl: + [ function(obj, cb) { + var format = 'CxSsssCC' + , args = [ null + , null + , 'acceleration_numerator' + , 'acceleration_denominator' + , 'threshold' + , 'do_acceleration' + , 'do_threshold' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 105 + return padEnd([format, args], addSize, 1) + } + ] +, GetPointerControl: + [ function(obj, cb) { + var format = 'CxS' + , args = [ null + , null + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 106 + return padEnd([format, args], addSize, 1) + } + , function(buf, prop, length) { + var fields = + [ 'acceleration_numerator' + , 'acceleration_denominator' + , 'threshold' ] + , format = "SSSxxxxxxxxxxxxxxxxxx" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + return reply + + } + ] +, SetScreenSaver: + [ function(obj, cb) { + var format = 'CxSssCC' + , args = [ null + , null + , 'timeout' + , 'interval' + , 'prefer_blanking' + , 'allow_exposures' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 107 + return padEnd([format, args], addSize, 1) + } + ] +, GetScreenSaver: + [ function(obj, cb) { + var format = 'CxS' + , args = [ null + , null + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 108 + return padEnd([format, args], addSize, 1) + } + , function(buf, prop, length) { + var fields = + [ 'timeout' + , 'interval' + , 'prefer_blanking' + , 'allow_exposures' ] + , format = "SSCCxxxxxxxxxxxxxxxxxx" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + return reply + + } + ] +, ChangeHosts: + [ function(obj, cb) { + var format = 'CCSCxS' + , args = [ null + , 'mode' + , null + , 'family' + , 'address_len' + , 'address' + ] + , addSize = 0 + var len = xutil.padded_length(obj.address.length) + , buf_name = new Buffer(len) + obj.address_len = Buffer.byteLength(obj.address) + buf_name.write(obj.address) + obj.address = buf_name + format += 'a' + addSize += (len / 4) + args = parameterOrder(args, obj) + args[0] = 109 + return padEnd([format, args], addSize, 2) + } + ] +, ListHosts: + [ function(obj, cb) { + var format = 'CxS' + , args = [ null + , null + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 110 + return padEnd([format, args], addSize, 1) + } + , function(buf, prop, length) { + var fields = + [ 'hosts_len' ] + , format = "Sxxxxxxxxxxxxxxxxxxxxxx" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + reply.mode = prop + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + var i = 0 + , len = reply.hosts_len + reply.hosts = [] + for (; i < len; ++i) { + var result = structs.HOST.unpack(buf, unpacked.offset) + reply.hosts.push(result[0]) + unpacked.offset = result[1] + } + return reply + + } + ] +, SetAccessControl: + [ function(obj, cb) { + var format = 'CCS' + , args = [ null + , 'mode' + , null + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 111 + return padEnd([format, args], addSize, 2) + } + ] +, SetCloseDownMode: + [ function(obj, cb) { + var format = 'CCS' + , args = [ null + , 'mode' + , null + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 112 + return padEnd([format, args], addSize, 2) + } + ] +, KillClient: + [ function(obj, cb) { + var format = 'CxSL' + , args = [ null + , null + , 'resource' + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 113 + return padEnd([format, args], addSize, 1) + } + ] +, RotateProperties: + [ function(obj, cb) { + var format = 'CxSLSs' + , args = [ null + , null + , 'window' + , 'atoms_len' + , 'delta' + , 'atoms' + ] + , addSize = 0 + + obj.atoms = Array.isArray(obj.atoms) ? obj.atoms : [obj.atoms] + var len = obj.atoms.length + format += new Array(len + 1).join("L") + obj.atoms_len = len + args = parameterOrder(args, obj) + args[0] = 114 + return padEnd([format, args], addSize, 1) + } + ] +, ForceScreenSaver: + [ function(obj, cb) { + var format = 'CCS' + , args = [ null + , 'mode' + , null + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 115 + return padEnd([format, args], addSize, 2) + } + ] +, SetPointerMapping: + [ function(obj, cb) { + var format = 'CCS' + , args = [ null + , 'map_len' + , null + , 'map' + ] + , addSize = 0 + + obj.map = Array.isArray(obj.map) ? obj.map : [obj.map] + var len = obj.map.length + format += new Array(len + 1).join("C") + obj.map_len = len + args = parameterOrder(args, obj) + args[0] = 116 + return padEnd([format, args], addSize, 2) + } + , function(buf, prop, length) { + var fields = [] + , format = "" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + reply.status = prop + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + return reply + + } + ] +, GetPointerMapping: + [ function(obj, cb) { + var format = 'CxS' + , args = [ null + , null + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 117 + return padEnd([format, args], addSize, 1) + } + , function(buf, prop, length) { + var fields = [] + , format = "xxxxxxxxxxxxxxxxxxxxxxxx" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + reply.map_len = prop + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + var len = reply.map_len + reply.map = buf.unpack(new Array(len + 1).join("C"), unpacked.offset) + unpacked.offset = reply.map.offset + return reply + + } + ] +, SetModifierMapping: + [ function(obj, cb) { + var format = 'CCS' + , args = [ null + , 'keycodes_per_modifier' + , null + , 'keycodes' + ] + , addSize = 0 + + obj.keycodes = Array.isArray(obj.keycodes) ? obj.keycodes : [obj.keycodes] + var len = obj.keycodes.length + format += new Array(len + 1).join("C") + obj.keycodes_len = len + args = parameterOrder(args, obj) + args[0] = 118 + return padEnd([format, args], addSize, 2) + } + , function(buf, prop, length) { + var fields = [] + , format = "" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + reply.status = prop + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + return reply + + } + ] +, GetModifierMapping: + [ function(obj, cb) { + var format = 'CxS' + , args = [ null + , null + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 119 + return padEnd([format, args], addSize, 1) + } + , function(buf, prop, length) { + var fields = [] + , format = "xxxxxxxxxxxxxxxxxxxxxxxx" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + reply.keycodes_per_modifier = prop + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + var len = 8*reply.keycodes_per_modifier + reply.keycodes = buf.unpack(new Array(len + 1).join("C"), unpacked.offset) + unpacked.offset = reply.keycodes.offset + return reply + + } + ] +, NoOperation: + [ function(obj, cb) { + var format = 'CxS' + , args = [ null + , null + ] + , addSize = 0 + args = parameterOrder(args, obj) + args[0] = 127 + return padEnd([format, args], addSize, 1) + } + ] +} \ No newline at end of file diff --git a/lib/x11/autogen/structs.js b/lib/x11/autogen/structs.js new file mode 100644 index 0000000..7bc2aa1 --- /dev/null +++ b/lib/x11/autogen/structs.js @@ -0,0 +1,770 @@ +var structs = exports + , xutil = require('../xutil') + , parameterOrder = xutil.parameterOrder + , size = xutil.formatSize + , associate = xutil.associate + +structs.CHAR2B = {} + +structs.CHAR2B.pack = function packCHAR2B(obj, format) { + format = format || "" + format += 'CC' + var args = [ + 'byte1' + , 'byte2' ] + , addSize = 0 + args = parameterOrder(args, obj) + return [format, args, addSize] +} + +structs.CHAR2B.unpack = function unpackCHAR2B(buf, offset) { + offset = offset || 0 + var fields = + [ 'byte1' + , 'byte2' ] + , format = "CC" + , unpacked = buf.unpack(format, offset) + , ret = associate(fields, unpacked) + offset = unpacked.offset + return [ret, offset] +} + +structs.POINT = {} + +structs.POINT.pack = function packPOINT(obj, format) { + format = format || "" + format += 'ss' + var args = [ + 'x' + , 'y' ] + , addSize = 0 + args = parameterOrder(args, obj) + return [format, args, addSize] +} + +structs.POINT.unpack = function unpackPOINT(buf, offset) { + offset = offset || 0 + var fields = + [ 'x' + , 'y' ] + , format = "ss" + , unpacked = buf.unpack(format, offset) + , ret = associate(fields, unpacked) + offset = unpacked.offset + return [ret, offset] +} + +structs.RECTANGLE = {} + +structs.RECTANGLE.pack = function packRECTANGLE(obj, format) { + format = format || "" + format += 'ssSS' + var args = [ + 'x' + , 'y' + , 'width' + , 'height' ] + , addSize = 0 + args = parameterOrder(args, obj) + return [format, args, addSize] +} + +structs.RECTANGLE.unpack = function unpackRECTANGLE(buf, offset) { + offset = offset || 0 + var fields = + [ 'x' + , 'y' + , 'width' + , 'height' ] + , format = "ssSS" + , unpacked = buf.unpack(format, offset) + , ret = associate(fields, unpacked) + offset = unpacked.offset + return [ret, offset] +} + +structs.ARC = {} + +structs.ARC.pack = function packARC(obj, format) { + format = format || "" + format += 'ssSSss' + var args = [ + 'x' + , 'y' + , 'width' + , 'height' + , 'angle1' + , 'angle2' ] + , addSize = 0 + args = parameterOrder(args, obj) + return [format, args, addSize] +} + +structs.ARC.unpack = function unpackARC(buf, offset) { + offset = offset || 0 + var fields = + [ 'x' + , 'y' + , 'width' + , 'height' + , 'angle1' + , 'angle2' ] + , format = "ssSSss" + , unpacked = buf.unpack(format, offset) + , ret = associate(fields, unpacked) + offset = unpacked.offset + return [ret, offset] +} + +structs.FORMAT = {} + +structs.FORMAT.pack = function packFORMAT(obj, format) { + format = format || "" + format += 'CCCxxxxx' + var args = [ + 'depth' + , 'bits_per_pixel' + , 'scanline_pad' ] + , addSize = 0 + args = parameterOrder(args, obj) + return [format, args, addSize] +} + +structs.FORMAT.unpack = function unpackFORMAT(buf, offset) { + offset = offset || 0 + var fields = + [ 'depth' + , 'bits_per_pixel' + , 'scanline_pad' ] + , format = "CCCxxxxx" + , unpacked = buf.unpack(format, offset) + , ret = associate(fields, unpacked) + offset = unpacked.offset + return [ret, offset] +} + +structs.VISUALTYPE = {} + +structs.VISUALTYPE.pack = function packVISUALTYPE(obj, format) { + format = format || "" + format += 'LCCSLLLxxxx' + var args = [ + 'visual_id' + , '_class' + , 'bits_per_rgb_value' + , 'colormap_entries' + , 'red_mask' + , 'green_mask' + , 'blue_mask' ] + , addSize = 0 + args = parameterOrder(args, obj) + return [format, args, addSize] +} + +structs.VISUALTYPE.unpack = function unpackVISUALTYPE(buf, offset) { + offset = offset || 0 + var fields = + [ 'visual_id' + , 'class' + , 'bits_per_rgb_value' + , 'colormap_entries' + , 'red_mask' + , 'green_mask' + , 'blue_mask' ] + , format = "LCCSLLLxxxx" + , unpacked = buf.unpack(format, offset) + , ret = associate(fields, unpacked) + offset = unpacked.offset + return [ret, offset] +} + +structs.DEPTH = {} + +structs.DEPTH.pack = function packDEPTH(obj, format) { + format = format || "" + format += 'CxSxxxx' + var args = [ + 'depth' + , 'visuals_len' + , 'visuals' ] + , addSize = 0 + + obj.visuals = Array.isArray(obj.visuals) ? obj.visuals : [obj.visuals] + var i = 0 + , len = obj.visuals.length + obj.visuals_len = len + for (; i < len; ++i) { + var result = structs.VISUALTYPE.pack(obj.visuals[i], format) + format = result[0] + obj.visuals[i] = result[1] + addSize += result[2] + } + args = parameterOrder(args, obj) + return [format, args, addSize] +} + +structs.DEPTH.unpack = function unpackDEPTH(buf, offset) { + offset = offset || 0 + var fields = + [ 'depth' + , 'visuals_len' ] + , format = "CxSxxxx" + , unpacked = buf.unpack(format, offset) + , ret = associate(fields, unpacked) + offset = unpacked.offset + var i = 0 + , len = ret.visuals_len + ret.visuals = [] + for (; i < len; ++i) { + var result = structs.VISUALTYPE.unpack(buf, offset) + ret.visuals.push(result[0]) + offset = result[1] + } + return [ret, offset] +} + +structs.SCREEN = {} + +structs.SCREEN.pack = function packSCREEN(obj, format) { + format = format || "" + format += 'LLLLLSSSSSSLCCCC' + var args = [ + 'root' + , 'default_colormap' + , 'white_pixel' + , 'black_pixel' + , 'current_input_masks' + , 'width_in_pixels' + , 'height_in_pixels' + , 'width_in_millimeters' + , 'height_in_millimeters' + , 'min_installed_maps' + , 'max_installed_maps' + , 'root_visual' + , 'backing_stores' + , 'save_unders' + , 'root_depth' + , 'allowed_depths_len' + , 'allowed_depths' ] + , addSize = 0 + + obj.allowed_depths = Array.isArray(obj.allowed_depths) ? obj.allowed_depths : [obj.allowed_depths] + var i = 0 + , len = obj.allowed_depths.length + obj.allowed_depths_len = len + for (; i < len; ++i) { + var result = structs.DEPTH.pack(obj.allowed_depths[i], format) + format = result[0] + obj.allowed_depths[i] = result[1] + addSize += result[2] + } + args = parameterOrder(args, obj) + return [format, args, addSize] +} + +structs.SCREEN.unpack = function unpackSCREEN(buf, offset) { + offset = offset || 0 + var fields = + [ 'root' + , 'default_colormap' + , 'white_pixel' + , 'black_pixel' + , 'current_input_masks' + , 'width_in_pixels' + , 'height_in_pixels' + , 'width_in_millimeters' + , 'height_in_millimeters' + , 'min_installed_maps' + , 'max_installed_maps' + , 'root_visual' + , 'backing_stores' + , 'save_unders' + , 'root_depth' + , 'allowed_depths_len' ] + , format = "LLLLLSSSSSSLCCCC" + , unpacked = buf.unpack(format, offset) + , ret = associate(fields, unpacked) + offset = unpacked.offset + var i = 0 + , len = ret.allowed_depths_len + ret.allowed_depths = [] + for (; i < len; ++i) { + var result = structs.DEPTH.unpack(buf, offset) + ret.allowed_depths.push(result[0]) + offset = result[1] + } + return [ret, offset] +} + +structs.SetupRequest = {} + +structs.SetupRequest.pack = function packSetupRequest(obj, format) { + format = format || "" + format += 'CxSSSSxx' + var args = [ + 'byte_order' + , 'protocol_major_version' + , 'protocol_minor_version' + , 'authorization_protocol_name_len' + , 'authorization_protocol_data_len' + , 'authorization_protocol_name' + , 'authorization_protocol_data' ] + , addSize = 0 + var len = xutil.padded_length(obj.authorization_protocol_name.length) + , buf_name = new Buffer(len) + obj.authorization_protocol_name_len = Buffer.byteLength(obj.authorization_protocol_name) + buf_name.write(obj.authorization_protocol_name) + obj.authorization_protocol_name = buf_name + format += 'a' + addSize += (len / 4) + var len = xutil.padded_length(obj.authorization_protocol_data.length) + , buf_name = new Buffer(len) + obj.authorization_protocol_data_len = Buffer.byteLength(obj.authorization_protocol_data) + buf_name.write(obj.authorization_protocol_data) + obj.authorization_protocol_data = buf_name + format += 'a' + addSize += (len / 4) + args = parameterOrder(args, obj) + return [format, args, addSize] +} + +structs.SetupRequest.unpack = function unpackSetupRequest(buf, offset) { + offset = offset || 0 + var fields = + [ 'byte_order' + , 'protocol_major_version' + , 'protocol_minor_version' + , 'authorization_protocol_name_len' + , 'authorization_protocol_data_len' ] + , format = "CxSSSSxx" + , unpacked = buf.unpack(format, offset) + , ret = associate(fields, unpacked) + offset = unpacked.offset + ret.authorization_protocol_name = buf.slice(offset, offset + ret.authorization_protocol_name_len).toString() + offset += ret.authorization_protocol_name_len + ret.authorization_protocol_data = buf.slice(offset, offset + ret.authorization_protocol_data_len).toString() + offset += ret.authorization_protocol_data_len + return [ret, offset] +} + +structs.SetupFailed = {} + +structs.SetupFailed.pack = function packSetupFailed(obj, format) { + format = format || "" + format += 'CCSSS' + var args = [ + 'status' + , 'reason_len' + , 'protocol_major_version' + , 'protocol_minor_version' + , 'length' + , 'reason' ] + , addSize = 0 + var len = xutil.padded_length(obj.reason.length) + , buf_name = new Buffer(len) + obj.reason_len = Buffer.byteLength(obj.reason) + buf_name.write(obj.reason) + obj.reason = buf_name + format += 'a' + addSize += (len / 4) + args = parameterOrder(args, obj) + return [format, args, addSize] +} + +structs.SetupFailed.unpack = function unpackSetupFailed(buf, offset) { + offset = offset || 0 + var fields = + [ 'status' + , 'reason_len' + , 'protocol_major_version' + , 'protocol_minor_version' + , 'length' ] + , format = "CCSSS" + , unpacked = buf.unpack(format, offset) + , ret = associate(fields, unpacked) + offset = unpacked.offset + ret.reason = buf.slice(offset, offset + ret.reason_len).toString() + offset += ret.reason_len + return [ret, offset] +} + +structs.SetupAuthenticate = {} + +structs.SetupAuthenticate.pack = function packSetupAuthenticate(obj, format) { + format = format || "" + format += 'CxxxxxS' + var args = [ + 'status' + , 'length' + , 'reason' ] + , addSize = 0 + var len = xutil.padded_length(obj.reason.length) + , buf_name = new Buffer(len) + obj.reason_len = Buffer.byteLength(obj.reason) + buf_name.write(obj.reason) + obj.reason = buf_name + format += 'a' + addSize += (len / 4) + args = parameterOrder(args, obj) + return [format, args, addSize] +} + +structs.SetupAuthenticate.unpack = function unpackSetupAuthenticate(buf, offset) { + offset = offset || 0 + var fields = + [ 'status' + , 'length' ] + , format = "CxxxxxS" + , unpacked = buf.unpack(format, offset) + , ret = associate(fields, unpacked) + offset = unpacked.offset + ret.reason = buf.slice(offset, offset + ret.reason_len).toString() + offset += ret.reason_len + return [ret, offset] +} + +structs.Setup = {} + +structs.Setup.pack = function packSetup(obj, format) { + format = format || "" + format += 'CxSSSLLLLSSCCCCCCCCxxxx' + var args = [ + 'status' + , 'protocol_major_version' + , 'protocol_minor_version' + , 'length' + , 'release_number' + , 'resource_id_base' + , 'resource_id_mask' + , 'motion_buffer_size' + , 'vendor_len' + , 'maximum_request_length' + , 'roots_len' + , 'pixmap_formats_len' + , 'image_byte_order' + , 'bitmap_format_bit_order' + , 'bitmap_format_scanline_unit' + , 'bitmap_format_scanline_pad' + , 'min_keycode' + , 'max_keycode' + , 'vendor' + , 'pixmap_formats' + , 'roots' ] + , addSize = 0 + var len = xutil.padded_length(obj.vendor.length) + , buf_name = new Buffer(len) + obj.vendor_len = Buffer.byteLength(obj.vendor) + buf_name.write(obj.vendor) + obj.vendor = buf_name + format += 'a' + addSize += (len / 4) + + obj.pixmap_formats = Array.isArray(obj.pixmap_formats) ? obj.pixmap_formats : [obj.pixmap_formats] + var i = 0 + , len = obj.pixmap_formats.length + obj.pixmap_formats_len = len + for (; i < len; ++i) { + var result = structs.FORMAT.pack(obj.pixmap_formats[i], format) + format = result[0] + obj.pixmap_formats[i] = result[1] + addSize += result[2] + } + + obj.roots = Array.isArray(obj.roots) ? obj.roots : [obj.roots] + var i = 0 + , len = obj.roots.length + obj.roots_len = len + for (; i < len; ++i) { + var result = structs.SCREEN.pack(obj.roots[i], format) + format = result[0] + obj.roots[i] = result[1] + addSize += result[2] + } + args = parameterOrder(args, obj) + return [format, args, addSize] +} + +structs.Setup.unpack = function unpackSetup(buf, offset) { + offset = offset || 0 + var fields = + [ 'status' + , 'protocol_major_version' + , 'protocol_minor_version' + , 'length' + , 'release_number' + , 'resource_id_base' + , 'resource_id_mask' + , 'motion_buffer_size' + , 'vendor_len' + , 'maximum_request_length' + , 'roots_len' + , 'pixmap_formats_len' + , 'image_byte_order' + , 'bitmap_format_bit_order' + , 'bitmap_format_scanline_unit' + , 'bitmap_format_scanline_pad' + , 'min_keycode' + , 'max_keycode' ] + , format = "CxSSSLLLLSSCCCCCCCCxxxx" + , unpacked = buf.unpack(format, offset) + , ret = associate(fields, unpacked) + offset = unpacked.offset + ret.vendor = buf.slice(offset, offset + ret.vendor_len).toString() + offset += ret.vendor_len + var i = 0 + , len = ret.pixmap_formats_len + ret.pixmap_formats = [] + for (; i < len; ++i) { + var result = structs.FORMAT.unpack(buf, offset) + ret.pixmap_formats.push(result[0]) + offset = result[1] + } + var i = 0 + , len = ret.roots_len + ret.roots = [] + for (; i < len; ++i) { + var result = structs.SCREEN.unpack(buf, offset) + ret.roots.push(result[0]) + offset = result[1] + } + return [ret, offset] +} + +structs.TIMECOORD = {} + +structs.TIMECOORD.pack = function packTIMECOORD(obj, format) { + format = format || "" + format += 'Lss' + var args = [ + 'time' + , 'x' + , 'y' ] + , addSize = 0 + args = parameterOrder(args, obj) + return [format, args, addSize] +} + +structs.TIMECOORD.unpack = function unpackTIMECOORD(buf, offset) { + offset = offset || 0 + var fields = + [ 'time' + , 'x' + , 'y' ] + , format = "Lss" + , unpacked = buf.unpack(format, offset) + , ret = associate(fields, unpacked) + offset = unpacked.offset + return [ret, offset] +} + +structs.FONTPROP = {} + +structs.FONTPROP.pack = function packFONTPROP(obj, format) { + format = format || "" + format += 'LL' + var args = [ + 'name' + , 'value' ] + , addSize = 0 + args = parameterOrder(args, obj) + return [format, args, addSize] +} + +structs.FONTPROP.unpack = function unpackFONTPROP(buf, offset) { + offset = offset || 0 + var fields = + [ 'name' + , 'value' ] + , format = "LL" + , unpacked = buf.unpack(format, offset) + , ret = associate(fields, unpacked) + offset = unpacked.offset + return [ret, offset] +} + +structs.CHARINFO = {} + +structs.CHARINFO.pack = function packCHARINFO(obj, format) { + format = format || "" + format += 'sssssS' + var args = [ + 'left_side_bearing' + , 'right_side_bearing' + , 'character_width' + , 'ascent' + , 'descent' + , 'attributes' ] + , addSize = 0 + args = parameterOrder(args, obj) + return [format, args, addSize] +} + +structs.CHARINFO.unpack = function unpackCHARINFO(buf, offset) { + offset = offset || 0 + var fields = + [ 'left_side_bearing' + , 'right_side_bearing' + , 'character_width' + , 'ascent' + , 'descent' + , 'attributes' ] + , format = "sssssS" + , unpacked = buf.unpack(format, offset) + , ret = associate(fields, unpacked) + offset = unpacked.offset + return [ret, offset] +} + +structs.STR = {} + +structs.STR.pack = function packSTR(obj, format) { + format = format || "" + format += 'C' + var args = [ + 'name_len' + , 'name' ] + , addSize = 0 + var len = xutil.padded_length(obj.name.length) + , buf_name = new Buffer(len) + obj.name_len = Buffer.byteLength(obj.name) + buf_name.write(obj.name) + obj.name = buf_name + format += 'a' + addSize += (len / 4) + args = parameterOrder(args, obj) + return [format, args, addSize] +} + +structs.STR.unpack = function unpackSTR(buf, offset) { + offset = offset || 0 + var fields = + [ 'name_len' ] + , format = "C" + , unpacked = buf.unpack(format, offset) + , ret = associate(fields, unpacked) + offset = unpacked.offset + ret.name = buf.slice(offset, offset + ret.name_len).toString() + offset += ret.name_len + return [ret, offset] +} + +structs.SEGMENT = {} + +structs.SEGMENT.pack = function packSEGMENT(obj, format) { + format = format || "" + format += 'ssss' + var args = [ + 'x1' + , 'y1' + , 'x2' + , 'y2' ] + , addSize = 0 + args = parameterOrder(args, obj) + return [format, args, addSize] +} + +structs.SEGMENT.unpack = function unpackSEGMENT(buf, offset) { + offset = offset || 0 + var fields = + [ 'x1' + , 'y1' + , 'x2' + , 'y2' ] + , format = "ssss" + , unpacked = buf.unpack(format, offset) + , ret = associate(fields, unpacked) + offset = unpacked.offset + return [ret, offset] +} + +structs.COLORITEM = {} + +structs.COLORITEM.pack = function packCOLORITEM(obj, format) { + format = format || "" + format += 'LSSSCx' + var args = [ + 'pixel' + , 'red' + , 'green' + , 'blue' + , 'flags' ] + , addSize = 0 + args = parameterOrder(args, obj) + return [format, args, addSize] +} + +structs.COLORITEM.unpack = function unpackCOLORITEM(buf, offset) { + offset = offset || 0 + var fields = + [ 'pixel' + , 'red' + , 'green' + , 'blue' + , 'flags' ] + , format = "LSSSCx" + , unpacked = buf.unpack(format, offset) + , ret = associate(fields, unpacked) + offset = unpacked.offset + return [ret, offset] +} + +structs.RGB = {} + +structs.RGB.pack = function packRGB(obj, format) { + format = format || "" + format += 'SSSxx' + var args = [ + 'red' + , 'green' + , 'blue' ] + , addSize = 0 + args = parameterOrder(args, obj) + return [format, args, addSize] +} + +structs.RGB.unpack = function unpackRGB(buf, offset) { + offset = offset || 0 + var fields = + [ 'red' + , 'green' + , 'blue' ] + , format = "SSSxx" + , unpacked = buf.unpack(format, offset) + , ret = associate(fields, unpacked) + offset = unpacked.offset + return [ret, offset] +} + +structs.HOST = {} + +structs.HOST.pack = function packHOST(obj, format) { + format = format || "" + format += 'CxS' + var args = [ + 'family' + , 'address_len' + , 'address' ] + , addSize = 0 + + obj.address = Array.isArray(obj.address) ? obj.address : [obj.address] + var len = obj.address.length + format += new Array(len + 1).join("C") + obj.address_len = len + args = parameterOrder(args, obj) + return [format, args, addSize] +} + +structs.HOST.unpack = function unpackHOST(buf, offset) { + offset = offset || 0 + var fields = + [ 'family' + , 'address_len' ] + , format = "CxS" + , unpacked = buf.unpack(format, offset) + , ret = associate(fields, unpacked) + offset = unpacked.offset + var len = ret.address_len + ret.address = buf.unpack(new Array(len + 1).join("C"), offset) + offset = ret.address.offset + return [ret, offset] +} \ No newline at end of file diff --git a/lib/x11/unpackbuffer.js b/lib/x11/unpackbuffer.js index 706fcd8..b592b9c 100644 --- a/lib/x11/unpackbuffer.js +++ b/lib/x11/unpackbuffer.js @@ -50,6 +50,7 @@ module.exports.addUnpack = function(Buffer) } current_arg++; } + Object.defineProperty(data, 'offset', { enumerable: false, value: offset, writable: true }) return data; } diff --git a/lib/x11/valuemask.js b/lib/x11/valuemask.js new file mode 100644 index 0000000..d2e44aa --- /dev/null +++ b/lib/x11/valuemask.js @@ -0,0 +1,30 @@ +module.exports = packValueMask + +function orderValueMask(a, b) { + return a[0] < b[0] ? -1 + : a[0] > b[0] ? 1 + : 0 +} + +function getValue(item) { + return item[1] +} + +function packValueMask(list, values) +{ + var bitmask = 0 + , masksList = [] + , v + , valueBit + , args + + for (var v in values) { + valueBit = list[v] + if (valueBit == null) throw new Error(': incorrect value param ' + v); + masksList.push([valueBit, values[v]]); + bitmask |= valueBit; + } + args = masksList.sort(orderValueMask).map(getValue); + return [bitmask, args] +} + diff --git a/lib/x11/xcore.js b/lib/x11/xcore.js index 25d77cd..b879393 100644 --- a/lib/x11/xcore.js +++ b/lib/x11/xcore.js @@ -16,7 +16,7 @@ require('./unpackbuffer').addUnpack(Buffer); var os = require('os'); var xerrors = require('./xerrors'); -var coreRequests = require('./corereqs'); +var coreRequests = require('./autogen/requests'); var stdatoms = require('./stdatoms'); function XClient(stream, displayNum, screenNum) @@ -271,7 +271,7 @@ XClient.prototype.expectReplyHeader = function() var handler = client.replies[seq_num]; if (handler) { var unpack = handler[0]; - var result = unpack( data, opt_data ); + var result = unpack( data, opt_data, bodylength ); var callback = handler[1]; callback(result); // TODO: add multiple replies flag and delete handler only after last reply (eg ListFontsWithInfo) diff --git a/lib/x11/xutil.js b/lib/x11/xutil.js index d75b2b6..6fbf5d7 100644 --- a/lib/x11/xutil.js +++ b/lib/x11/xutil.js @@ -25,5 +25,54 @@ function padded_string(str) return res; } +function flatten(arr) { + var ret = [] + arr.forEach(function(item, i) { + if (Array.isArray(item)) ret = ret.concat(flatten(item)) + else ret[i] = item + }) + return ret +} + +function parameterOrder(params, obj) { + return flatten(params.map(function(name, i) { + return name && obj[name] + })) +} + +function size(str) { + var i = str.length + , size = 0 + while(i--) { + switch(str[i]) { + case 'C': + case 'c': + case 'x': + size += 1 + break; + case 'S': + case 's': + size += 2 + break; + case 'L': + case 'l': + size += 4 + break; + } + } + return size / 4 +} + +function associate(arr1, arr2) { + var ret = {} + for(var i = 0, len = Math.min(arr1.length, arr2.length); i < len; ++i) { + ret[arr1[i]] = arr2[i] + } + return ret +} + module.exports.padded_length = padded_length; module.exports.padded_string = padded_string; +module.exports.formatSize = size; +module.exports.associate = associate; +module.exports.parameterOrder = parameterOrder; diff --git a/protocols b/protocols new file mode 160000 index 0000000..27a52b2 --- /dev/null +++ b/protocols @@ -0,0 +1 @@ +Subproject commit 27a52b227e0fc375b682a9dacc1596e2a8bbc71d diff --git a/stubs/packList.tpl b/stubs/packList.tpl new file mode 100644 index 0000000..c361d2d --- /dev/null +++ b/stubs/packList.tpl @@ -0,0 +1,48 @@ +{{each(i, field) list}} +{{if isListType(field)}} + {{if isValueMask(field)}} +var packed = packMask(valueMask['${theName}'], obj.${prepPropName(field['value-mask-name'])}) +obj.${field['value-mask-name']} = packed[0] + {{if !(isListAccountedFor(requests[theName], field))}} +format += "${bufPackType(field['value-mask-type'])}" + {{/if}} +obj.${field['value-list-name']} = packed[1] +format += new Array(packed[1].length + 1).join("${bufPackType('CARD32')}") + + {{else field.type == 'char' || field.type == 'void' }} + {{if field.value == null }} +var len = xutil.padded_length(obj.${prepPropName(field.name)}.length) + , buf_name = new Buffer(len) +obj.${listLengthName(field)} = Buffer.byteLength(obj.${prepPropName(field.name)}) +buf_name.write(obj.${field.name}) +obj.${field.name} = buf_name +format += 'a' +addSize += (len / 4) + {{else}} + +var buf_name = new Buffer(${field.value}) +buffer.write(obj.${field.name}) +addSize += ${field.value} / 4 +format += 'a' + {{/if}} + {{else}} + +obj.${prepPropName(field.name)} = Array.isArray(obj.${prepPropName(field.name)}) ? obj.${prepPropName(field.name)} : [obj.${prepPropName(field.name)}] + {{if bufPackType(field.type)}} +var len = obj.${prepPropName(field.name)}.length +format += new Array(len + 1).join("${bufPackType(field.type)}") +obj.${listLengthName(field)} = len + {{else}} +var i = 0 + , len = obj.${prepPropName(field.name)}.length +obj.${listLengthName(field)} = len +for (; i < len; ++i) { + var result = structs.${field.type}.pack(obj.${prepPropName(field.name)}[i], format) + format = result[0] + obj.${prepPropName(field.name)}[i] = result[1] + addSize += result[2] +} + {{/if}} + {{/if}} +{{/if}} +{{/each}} diff --git a/stubs/requests.tpl b/stubs/requests.tpl new file mode 100644 index 0000000..31d6259 --- /dev/null +++ b/stubs/requests.tpl @@ -0,0 +1,76 @@ +var packMask = require('../valuemask') + , xutil = require('../xutil') + , structs = require('./structs') + , valueMask = +{{each(i, requestName) Object.keys(requests)}} +{{if getValueMask(requestName) }} + ${getDelim(i)} ${requestName}: + {{each(i, value) getValueMask(requestName)}} + ${getDelim(i)} ${value.name}: ${enumVal(value)} + {{/each}} + } +{{/if}} +{{/each}} +} + , parameterOrder = xutil.parameterOrder + , size = xutil.formatSize + , associate = xutil.associate + +function padEnd(form, addSize, index) { + var s = size(form[0]) + addSize + form[0] += new Array(s * 4 % 4 + 1).join('x') + form[1][index] = Math.ceil(s) + return form +} + +module.exports = +{{each(i, reqName) Object.keys(requests)}} +${getDelim(i)} ${reqName}: + [ function(obj, cb) { + var format = '{{if prePackFirst(requests[reqName])}}C${getBufPack(requests[reqName].field && requests[reqName].field[0])}{{else}}S{{/if}}S{{each(j, field) requests[reqName].field}}{{if !(prePackFirst(requests[reqName]) && j === 0)}}${getBufPack(field)}{{/if}}{{/each}}' + , args = [ null + {{if prePackFirst(requests[reqName]) && requests[reqName].field && requests[reqName].field[0].name}} + , '${prepPropName(requests[reqName].field[0].name)}' + {{/if}} + , null + {{each(j, field) requests[reqName].field}} + {{if field.fieldType != 'pad' && !(j === 0 && prePackFirst(requests[reqName]))}} + {{if field.fieldType == 'valueparam' && !(isListAccountedFor(requests[reqName], field))}} + , '${listLengthName(field)}' + {{/if}} + , '${fieldName(field)}' + {{/if}} + {{/each}} + ] + , addSize = 0 + {{html packList(3, "args", "format", requests[reqName].field, reqName)}} + args = parameterOrder(args, obj) + args[0] = ${requests[reqName].opcode} + return padEnd([format, args], addSize, ${requestLengthIndex(requests[reqName])}) + } + {{if requests[reqName].reply}} + , function(buf, prop, length) { + var fields{{if shiftedFirstType(requests[reqName].reply.field, 'field')}} = + {{each(j, field) requests[reqName].reply.field.slice(1)}} + {{if field.fieldType == 'field'}} + ${getDelim(realIndex(requests[reqName].reply.field.slice(1), field), '[')} '${field.name}' + {{/if}} + {{/each}} ] + {{else}} = [] + {{/if}} + , format = "{{each(j, field) requests[reqName].reply.field.slice(1)}}${getBufPack(field)}{{/each}}" + , unpacked = buf.unpack(format) + , reply = associate(fields, unpacked) + {{if isFieldFirst(requests[reqName].reply.field)}} + reply.${requests[reqName].reply.field[0].name} = prop + {{/if}} + Object.defineProperty(reply, '_raw', { value: buf, enumerable: false }) + Object.defineProperty(reply, '_offset', { value: unpacked.offset, enumerable: false }) + {{html unpackList(3, "reply", "buf", "unpacked.offset", requests[reqName].reply.field, reqName)}} + return reply + + } + {{/if}} + ] +{{/each}} +} diff --git a/stubs/structs.tpl b/stubs/structs.tpl new file mode 100644 index 0000000..08eeace --- /dev/null +++ b/stubs/structs.tpl @@ -0,0 +1,43 @@ +var structs = exports + , xutil = require('../xutil') + , parameterOrder = xutil.parameterOrder + , size = xutil.formatSize + , associate = xutil.associate + +{{each(structName, attr) structs}} + +structs.${structName} = {} + +structs.${structName}.pack = function pack${structName}(obj, format) { + format = format || "" + format += '{{each(j, field) structs[structName].field}}${getBufPack(field)}{{/each}}' + var args = [ {{each(i, field) nonPad(attr.field)}} + {{if field.fieldType == 'valueparam' && !(isListAccountedFor(structs[structName], field))}} + ${getDelim(i, " ", ", ")}'${listLengthName(field)}' + {{/if}} + ${getDelim(i, " ", ", ")}'${fieldName(field)}' + {{/each}} ] + , addSize = 0 + {{html packList(1, "args", "format", structs[structName].field, structName)}} + args = parameterOrder(args, obj) + return [format, args, addSize] +} + +structs.${structName}.unpack = function unpack${structName}(buf, offset) { + offset = offset || 0 + var fields{{if structs[structName].field}} = + {{each(j, field) structs[structName].field}} + {{if field.fieldType == 'field'}} + ${getDelim(realIndex(structs[structName].field, field), '[')} '${field.name}' + {{/if}} + {{/each}} ] + {{else}} + {{/if}} + , format = "{{each(j, field) structs[structName].field}}${getBufPack(field)}{{/each}}" + , unpacked = buf.unpack(format, offset) + , ret = associate(fields, unpacked) + offset = unpacked.offset + {{html unpackList(1, "ret", "buf", "offset", structs[structName].field, structName)}} + return [ret, offset] +} +{{/each}} diff --git a/stubs/unpackList.tpl b/stubs/unpackList.tpl new file mode 100644 index 0000000..14e1bb1 --- /dev/null +++ b/stubs/unpackList.tpl @@ -0,0 +1,30 @@ +{{each(i, field) list}} +{{if isListType(field)}} + {{if field.type == 'char' || field.type == 'void' }} +${obj}.${prepPropName(field.name)} = ${buf}.slice(${offset}, ${offset} + ${obj}.${listLengthName(field)}).toString() +${offset} += ${obj}.${listLengthName(field)} + {{else}} + {{if field.value != null}} + {{else bufPackType(field.type)}} + {{if listLengthName(field) == 'length' }} +var len = length + {{else field.op}} +var len = ${constructOp(field, obj)} + {{else}} +var len = ${obj}.${listLengthName(field)} + {{/if}} +${obj}.${prepPropName(field.name)} = ${buf}.unpack(new Array(len + 1).join("${bufPackType(field.type)}"), ${offset}) +${offset} = ${obj}.${prepPropName(field.name)}.offset + {{else}} +var i = 0 + , len = ${obj}.${listLengthName(field)} +${obj}.${prepPropName(field.name)} = [] +for (; i < len; ++i) { + var result = structs.${field.type}.unpack(${buf}, ${offset}) + ${obj}.${prepPropName(field.name)}.push(result[0]) + ${offset} = result[1] +} + {{/if}} + {{/if}} +{{/if}} +{{/each}} diff --git a/test/alloccolor.js b/test/alloccolor.js index 0e9afb1..12c634e 100644 --- a/test/alloccolor.js +++ b/test/alloccolor.js @@ -13,32 +13,32 @@ xclient.on('connect', function(display) { var wid = X.AllocID(); X.CreateWindow( - wid, root, - 10, 10, 400, 300, - 1, 1, 0, - { - backgroundPixel: white, eventMask: Exposure|PointerMotion - } - ); - X.MapWindow(wid); + { depth: 0 + , wid: wid + , parent: root + , x: 10 + , y: 10 + , width: 400 + , height: 300 + , border_width: 1 + , _class: 1 + , visual: 0 + , value_mask: { BackPixel: white, EventMask: Exposure|PointerMotion } + }); + X.MapWindow({ window: wid }); var gc = X.AllocID(); - X.AllocColor(display.screen[0].default_colormap, 0xffff, 0, 0, function(redcolor) { + X.AllocColor({ cmap: display.screen[0].default_colormap, red: 0xffff, blue: 0, green: 0 }, function(redcolor) { // todo: it is possible for PolyLine to be called before CreateGC! console.log(redcolor); - X.CreateGC(gc, wid, { foreground: redcolor.pixel, background: white } ); + X.CreateGC({ cid: gc, drawable: wid, value_mask: { Foreground: redcolor.pixel, Background: white } }); }); X.on('event', function(ev) { - if (ev.type == 12) - { - if (pts.length > 4) - X.PolyLine(0, wid, gc, pts); - } else if (ev.type == 6) { - pts.push(ev.x); - pts.push(ev.y); - if (pts.length > 4) - X.PolyLine(0, wid, gc, pts.slice(-4)); + if (ev.type == 12 && pts.length > 1) X.PolyLine({ coordinate_mode: 0, drawable: wid, gc: gc, points: pts }); + else if (ev.type == 6) { + pts.push({ x: ev.x, y: ev.y }); + if (pts.length > 1) X.PolyLine({ coordinate_mode: 0, drawable: wid, gc: gc, points: pts.slice(-2) }); } }); diff --git a/test/atoms.js b/test/atoms.js index 0cd4ec6..21c1fdd 100644 --- a/test/atoms.js +++ b/test/atoms.js @@ -3,11 +3,12 @@ var x11 = require('../lib/x11'); var xclient = x11.createClient(); xclient.on('connect', function(display) { - var X = this; - var hello = 'Hello, node.js'; - X.InternAtom(false, hello, function(atomId) { - X.GetAtomName(atomId, function(str) { - console.log('Value for atom ' + atomId + ' is \"' + str + '\"'); - }); - }); + var X = this; + var hello = 'Hello, node.js'; + X.InternAtom({ only_if_exists: false, name: hello }, function(internResp) { + console.log(internResp) + X.GetAtomName({ atom: internResp.atom }, function(atomNameResp) { + console.log(atomNameResp); + }); + }); }); diff --git a/test/c-tests/Makefile b/test/c-tests/Makefile deleted file mode 100644 index 9b00c85..0000000 --- a/test/c-tests/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -LDFLAGS=-lX11 - -simplewin: simplewin.o diff --git a/test/c-tests/simplewin.c b/test/c-tests/simplewin.c deleted file mode 100644 index a3f3926..0000000 --- a/test/c-tests/simplewin.c +++ /dev/null @@ -1,42 +0,0 @@ -#include -#include -#include -#include - -int main(void) { - Display *d; - Window w, w1; - XEvent e; - char *msg = "Hello, world!"; - int s; - - d = XOpenDisplay(NULL); - if (d == NULL) { - fprintf(stderr, "Cannot open display\n"); - exit(1); - } - - s = DefaultScreen(d); - w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 100, 100, 1, - BlackPixel(d, s), WhitePixel(d, s)); - - w1 = XCreateSimpleWindow(d, RootWindow(d, s), 50, 50, 50, 50, 1, - BlackPixel(d, s), WhitePixel(d, s)); - XSelectInput(d, w, ExposureMask | KeyPressMask); - XSelectInput(d, w1, ExposureMask); - XMapWindow(d, w); - XMapWindow(d, w1); - - while (1) { - XNextEvent(d, &e); - if (e.type == Expose) { - XFillRectangle(e.xany.display, e.xany.window, DefaultGC(d, s), 20, 20, 10, 10); - XDrawString(e.xany.display, e.xany.window, DefaultGC(d, s), 10, 50, msg, strlen(msg)); - } - if (e.type == KeyPress) - break; - } - - XCloseDisplay(d); - return 0; -} diff --git a/test/changeprop.js b/test/changeprop.js index a70eb94..1b77f4a 100644 --- a/test/changeprop.js +++ b/test/changeprop.js @@ -10,13 +10,14 @@ xclient.on('connect', function(display) { var white = display.screen[0].white_pixel; var black = display.screen[0].black_pixel; - X.CreateWindow(wid, root, 10, 10, 400, 300, 1, 1, 0, { backgroundPixel: white, eventMask: PointerMotion }); - X.MapWindow(wid); + X.CreateWindow({ depth: 0, wid: wid, parent: root, x: 10, y: 10, width: 400, height: 300, border_width: 1, _class: 1, visual: 0, + value_mask: { BackPixel: white, EventMask: PointerMotion } }); + X.MapWindow({ window: wid }); // mode: 0 replace, 1 prepend, 2 append // mode, wid, name, type, format, data - X.ChangeProperty(0, wid, xclient.atoms.WM_NAME, xclient.atoms.STRING, 8, 'Hello, NodeJS'); + X.ChangeProperty({ mode: 0, window: wid, property: xclient.atoms.WM_NAME, type: xclient.atoms.STRING, format: 8, data: 'Hello, NodeJS' }); setInterval(function() { - X.ChangeProperty(0, wid, xclient.atoms.WM_NAME, xclient.atoms.STRING, 8, 'Hello, NodeJS ' + new Date()); + X.ChangeProperty({ mode: 0, window: wid, property: xclient.atoms.WM_NAME, type: xclient.atoms.STRING, format: 8, data: 'Hello, NodeJS ' + new Date() }); }, 100); -}); \ No newline at end of file +}); diff --git a/test/creategc.js b/test/creategc.js index d5b052b..7ca2867 100644 --- a/test/creategc.js +++ b/test/creategc.js @@ -11,7 +11,8 @@ xclient.on('connect', function(display) { 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: PointerMotion }); + X.CreateWindow({ depth: 0, wid: wid, parent: root, x: 10, y: 10, width: 400, height: 300, border_width: 1, _class: 1, visual: 0, + value_mask: { BackPixel: white, EventMask: PointerMotion } }); var cid = X.AllocID(); - X.CreateGC(cid, wid); -}); \ No newline at end of file + X.CreateGC({ cid: cid, drawable: wid }); +}); diff --git a/test/createwindow.js b/test/createwindow.js index 9bab395..75681f9 100644 --- a/test/createwindow.js +++ b/test/createwindow.js @@ -23,10 +23,11 @@ xclient.on('connect', function(display) { var white = display.screen[0].white_pixel; var black = display.screen[0].black_pixel; - X.CreateWindow(wid, root, 10, 10, 400, 300, 1, 1, 0, { backgroundPixel: white, eventMask: mask }); - X.MapWindow(wid); + X.CreateWindow({ depth: 0, wid: wid, parent: root, x: 10, y: 10, width: 400, height: 300, border_width: 1, _class: 1, visual: 0, + value_mask: { BackPixel: white, EventMask: mask } }); + X.MapWindow({ window: wid }); }); xclient.on('event', function(ev) { console.log(ev); -}); \ No newline at end of file +}); diff --git a/test/genstdatoms.js b/test/genstdatoms.js index 795a96e..08da4e4 100644 --- a/test/genstdatoms.js +++ b/test/genstdatoms.js @@ -8,13 +8,13 @@ xclient.on('connect', function(display) { { function getAtom(a) { - X.GetAtomName(a, function(str) { + X.GetAtomName({ atom: a }, function(str) { if (a == 1) console.log('module.exports = {') if (a != 68) - console.log(' %s: %d,', str, a); + console.log(' %s: %d,', str.name, a); else - console.log(' %s: %d\n}', str, a); + console.log(' %s: %d\n}', str.name, a); listAtoms(); }); } diff --git a/test/getkeyboardmapping.js b/test/getkeyboardmapping.js index 6def7af..8c68d51 100644 --- a/test/getkeyboardmapping.js +++ b/test/getkeyboardmapping.js @@ -7,27 +7,28 @@ for (var key in ks) var kk2Name = {}; x11.createClient(function(display) { - var X = display.client; - var min = display.min_keycode; - var max = display.max_keycode; - X.GetKeyboardMapping(min, max-min, function(list) { - for (var i=0; i < list.length; ++i) - { - var name = kk2Name[i+min] = []; - var sublist = list[i]; - for (var j =0; j < sublist.length; ++j) - name.push(ks2Name[sublist[j]]); - } + var X = display.client; + var min = display.min_keycode; + var max = display.max_keycode; + X.GetKeyboardMapping({ first_keycode: min, count: max-min }, function(list) { + console.log(list) + for (var i=0; i < list.length; ++i) + { + var name = kk2Name[i+min] = []; + var sublist = list[i]; + for (var j =0; j < sublist.length; ++j) name.push(ks2Name[sublist[j]]); + } - var root = display.screen[0].root; - var wid = X.AllocID(); - var white = display.screen[0].white_pixel; - var black = display.screen[0].black_pixel; - X.CreateWindow(wid, root, 10, 10, 400, 300, 1, 1, 0, { backgroundPixel: white, eventMask: x11.eventMask.KeyPress}); - X.MapWindow(wid); + var root = display.screen[0].root; + var wid = X.AllocID(); + var white = display.screen[0].white_pixel; + var black = display.screen[0].black_pixel; + X.CreateWindow({ depth: 0, wid: wid, parent: root, x: 10, y: 10, width: 400, height: 300, border_width: 1, _class: 1, visual: 0, + value_mask: { BackPixel: white, EventMask: x11.eventMask.KeyPress } }); + X.MapWindow({ window: wid }); - X.on('event', function(ev) { - console.log(kk2Name[ev.keycode]); - }); + X.on('event', function(ev) { + console.log(kk2Name[ev.keycode]); }); + }); }); diff --git a/test/getprop.js b/test/getprop.js index b350d00..bb35107 100644 --- a/test/getprop.js +++ b/test/getprop.js @@ -10,21 +10,21 @@ xclient.on('connect', function(display) { var white = display.screen[0].white_pixel; var black = display.screen[0].black_pixel; - X.CreateWindow(wid, root, 10, 10, 400, 300, 1, 1, 0, { backgroundPixel: white, eventMask: PropertyChange }); - X.MapWindow(wid); + X.CreateWindow({ depth: 0, wid: wid, parent: root, x: 10, y: 10, width: 400, height: 300, border_width: 1, _class: 1, visual: 0, + value_mask: { BackPixel: white, EventMask: PropertyChange } }); + X.MapWindow({ window: wid }); // mode: 0 replace, 1 prepend, 2 append // mode, wid, name, type, format, data - X.ChangeProperty(0, wid, xclient.atoms.WM_NAME, xclient.atoms.STRING, 8, 'Hello, NodeJS'); + X.ChangeProperty({ mode: 0, window: wid, property: xclient.atoms.WM_NAME, type: xclient.atoms.STRING, format: 8, data: 'Hello, NodeJS' }); setInterval(function() { - X.ChangeProperty(0, wid, xclient.atoms.WM_NAME, xclient.atoms.STRING, 8, 'Hello, NodeJS ' + new Date()); + X.ChangeProperty({ mode: 0, window: wid, property: xclient.atoms.WM_NAME, type: xclient.atoms.STRING, format: 8, data: 'Hello, NodeJS' + new Date() }); }, 1000); xclient.on('event', function(ev) { - X.GetProperty(0, wid, xclient.atoms.WM_NAME, xclient.atoms.STRING, 0, 10000000, function(prop) { - if (prop.type == xclient.atoms.STRING) - prop.data = prop.data.toString(); - console.log(prop.data); + X.GetProperty({ _delete: 0, window: wid, property: xclient.atoms.WM_NAME, type: xclient.atoms.STRING, long_offset: 0, long_length: 10000000 }, function(prop) { + if (prop.type == xclient.atoms.STRING) prop.data = prop.value.toString(); + console.log(prop.value); }); }); -}); \ No newline at end of file +}); diff --git a/test/hosts.js b/test/hosts.js new file mode 100644 index 0000000..3cd762d --- /dev/null +++ b/test/hosts.js @@ -0,0 +1,9 @@ +var x11 = require('../lib/x11'); + +var xclient = x11.createClient(); +xclient.on('connect', function(display) { + var X = this; + X.ListHosts(function(resp) { + console.log('ListHosts', JSON.stringify(resp, null, 2)) + }) +}); diff --git a/test/listext.js b/test/listext.js index 0ec2fe6..ae5f4fb 100644 --- a/test/listext.js +++ b/test/listext.js @@ -1,10 +1,10 @@ var x11 = require('../lib/x11'); var X = x11.createClient(); X.on('connect', function(display) { - X.ListExtensions(function(list) { - list.forEach(function(ext) { - console.log(ext); - }); - X.terminate(); + X.ListExtensions(function(list) { + list.names.forEach(function(ext) { + console.log(ext.name); }); + X.terminate(); + }); }); diff --git a/test/map_unmap.js b/test/map_unmap.js index 6ccf232..3750ac7 100644 --- a/test/map_unmap.js +++ b/test/map_unmap.js @@ -11,15 +11,19 @@ xclient.on('connect', function(display) { var white = display.screen[0].white_pixel; var black = display.screen[0].black_pixel; - X.CreateWindow(wid, root, 10, 10, 400, 300, 1, 1, 0, { backgroundPixel: white, eventMask: PointerMotion }); - X.MapWindow(wid); + X.CreateWindow({ depth: 0, wid: wid, parent: root, x: 10, y: 10, width: 400, height: 300, border_width: 1, _class: 1, visual: 0, + value_mask: { BackPixel: white, EventMask: PointerMotion } }); + X.MapWindow({ window: wid }); setInterval(function() { if (!mapped) { - X.MapWindow(wid); + X.MapWindow({window: wid }); } else { - X.UnmapWindow(wid); + X.UnmapWindow({ window: wid }); } mapped = !mapped; }, 1000); + X.QueryTree({ window: root }, function(resp) { + console.log('QueryTree', resp) + }) -}); \ No newline at end of file +}); diff --git a/test/polyfillrect.js b/test/polyfillrect.js index 6b2d70f..dab3a71 100644 --- a/test/polyfillrect.js +++ b/test/polyfillrect.js @@ -11,25 +11,27 @@ xclient.on('connect', function(display) { 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); + X.CreateWindow({ depth: 0, wid: wid, parent: root, x: 10, y: 10, width: 400, height: 300, border_width: 1, _class: 1, visual: 0, + value_mask: { BackPixel: white, EventMask: Exposure|PointerMotion } }); + X.MapWindow({ window: wid }); var gc = X.AllocID(); - X.CreateGC(gc, wid, { foreground: black, background: white } ); + X.CreateGC({ cid: gc, drawable: wid, value_mask: { Foreground: black, Background: white } }); + + var gc2 + X.AllocColor({ cmap: display.screen[0].default_colormap, red: 0xffff, blue: 0, green: 0 }, function(redcolor) { + gc2 = X.AllocID(); + X.CreateGC({ cid: gc2, drawable: wid, value_mask: { Foreground: redcolor.pixel, Background: white } }); + }) X.on('event', function(ev) { if (ev.type == 12) { - X.PolyFillRectangle(wid, gc, [20, 30, 50, 90]); - X.PolyFillRectangle(wid, gc, [40, 50, 90, 10]); - X.PolyFillRectangle(wid, gc, [20, 80, 50, 30]); + X.PolyFillRectangle({ drawable: wid, gc: gc, rectangles: + [ { x: 20, y: 30, width: 50, height: 90} + , { x: 40, y: 50, width: 90, height: 10} + ]}) + X.PolyFillRectangle({ drawable: wid, gc: gc2 || gc, rectangles: { x: 20, y: 80, width: 50, height: 30} }) } else if (ev.type == 6) { //console.log(ev.x, ev.y); @@ -40,4 +42,4 @@ xclient.on('connect', function(display) { X.on('error', function(e) { console.log(e); }); -}); \ No newline at end of file +}); diff --git a/test/polyline.js b/test/polyline.js index 1509ac0..22971dd 100644 --- a/test/polyline.js +++ b/test/polyline.js @@ -3,7 +3,7 @@ var x11 = require('../lib/x11'); var xclient = x11.createClient(); var Exposure = x11.eventMask.Exposure; var PointerMotion = x11.eventMask.PointerMotion; -var pts = [100, 1000, 10, 20, 10, 0, 0, 3]; +var pts = []; var prevPoint; @@ -14,30 +14,19 @@ xclient.on('connect', function(display) { 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); + X.CreateWindow({ depth: 0, wid: wid, parent: root, x: 10, y: 10, width: 400, height: 300, border_width: 1, _class: 1, visual: 0, + value_mask: { BackPixel: white, EventMask: Exposure|PointerMotion } }); + X.MapWindow({ window: wid }); var gc = X.AllocID(); - X.CreateGC(gc, wid, { foreground: black, background: white } ); + X.CreateGC({ cid: gc, drawable: wid, value_mask: { Foreground: black, Background: white } }); X.on('event', function(ev) { - if (ev.type == 12) - { - if (pts.length > 4) - X.PolyLine(0, wid, gc, pts); - } else if (ev.type == 6) { - pts.push(ev.x); - pts.push(ev.y); - if (pts.length > 4) - X.PolyLine(0, wid, gc, pts.slice(-4)); - } + if (ev.type == 12 && pts.length > 1) X.PolyLine({ coordinate_mode: 0, drawable: wid, gc: gc, points: pts }); + else if (ev.type == 6) { + pts.push({ x: ev.x, y: ev.y }); + if (pts.length > 1) X.PolyLine({ coordinate_mode: 0, drawable: wid, gc: gc, points: pts.slice(-2) }); + } }); X.on('error', function(e) { diff --git a/test/polypoint.js b/test/polypoint.js index d5764d1..fcdde0d 100644 --- a/test/polypoint.js +++ b/test/polypoint.js @@ -12,27 +12,19 @@ xclient.on('connect', function(display) { 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); + X.CreateWindow({ depth: 0, wid: wid, parent: root, x: 10, y: 10, width: 400, height: 300, border_width: 1, _class: 1, visual: 0, + value_mask: { BackPixel: white, EventMask: Exposure|PointerMotion } }); + X.MapWindow({ window: wid }); var gc = X.AllocID(); - X.CreateGC(gc, wid, { foreground: black, background: white } ); + X.CreateGC({ cid: gc, drawable: wid, value_mask: { Foreground: black, Background: white } }); X.on('event', function(ev) { if (ev.type == 12) { //X.PolyPoint(0, wid, gc, pts); } else if (ev.type == 6) { - //pts.push(ev.x); - //pts.push(ev.y); - X.PolyPoint(0, wid, gc, [ev.x, ev.y]); + X.PolyPoint({ coordinate_mode: 0, drawable: wid, gc: gc, points: { x: ev.x, y: ev.y} }); } }); diff --git a/test/query_ext.js b/test/query_ext.js index 52a539a..eb0a0fc 100644 --- a/test/query_ext.js +++ b/test/query_ext.js @@ -4,9 +4,10 @@ var numExt = 0; X.on('connect', function(display) { X.ListExtensions(function(list) { console.log(list); - list.forEach(function(ext) { + list.names.forEach(function(ext) { numExt++; - X.QueryExtension(ext, function(e) { + X.QueryExtension({ name: ext.name }, function(e) { + console.log(e) e.name = ext; console.log(e); if (--numExt == 0) diff --git a/test/query_pointer.js b/test/query_pointer.js index ccc18a2..18bef7c 100644 --- a/test/query_pointer.js +++ b/test/query_pointer.js @@ -5,10 +5,11 @@ X.on('connect', function(display) { var screen = display.screen[0]; var wid = X.AllocID(); - X.CreateWindow(wid, screen.root, 10, 10, 400, 300, 1, 1, 0, { backgroundPixel: screen.white_pixel }); - X.MapWindow(wid); + X.CreateWindow({ depth: 0, wid: wid, parent: screen.root, x: 10, y: 10, width: 400, height: 300, border_width: 1, _class: 1, visual: 0, + value_mask: { BackPixel: screen.white_pixel } }); + X.MapWindow({ window: wid }); setInterval( function() { - X.QueryPointer(wid, function(res) { + X.QueryPointer({ window: wid }, function(res) { console.log(res); }); }, 1000); diff --git a/test/rects.js b/test/rects.js new file mode 100644 index 0000000..ced1dca --- /dev/null +++ b/test/rects.js @@ -0,0 +1,58 @@ +var x11 = require('../lib/x11'); +x11.createClient().on('connect', function(display) { + var X = this + , rects = + [ { rect: { x: 50, y: 50, width: 100, height: 100 }, dir: 1, range: [0, 100] } + , { rect: { x: 100, y: 200, width: 90, height: 90 }, dir: 2, range: [80, 120] } + , { rect: { x: 20, y: 30, width: 15, height: 15 }, dir: 3, range: [10, 50] } + ] + , windows = [X.AllocID()] + , draw = [X.AllocID(), X.AllocID(), X.AllocID(), X.AllocID()] + , borderWidth = 5 + , width = 800 + , split = 400 + , dir = 5 + , screen = display.screen[0]; + + windows.forEach(function(window, i) { + X.CreateWindow( + { depth: 0 + , wid: window + , parent: screen.root + , x: 400 * (i % 2) + , y: 300 * Math.floor(i/2) + , width: 400 - borderWidth + , height: 300 - borderWidth + , border_width: borderWidth + , 'class': 1 + , value_mask: { BackPixel: screen.white_pixel, EventMask: x11.eventMask.PointerMotion } + }) + X.CreateGC({ cid: draw[i], drawable: window }) + setTimeout(function(){ + X.MapWindow({ window: window }) + }, 1000 * i + 1000) + }) + setInterval(function() { + windows.forEach(function(window, i) { + X.ClearArea( + { exposures: false + , window: window + , x: 0 + , y: 0 + , width: 400 + , height: 400}) + rects.forEach(function(rect, i) { + rect.rect.x += rect.dir + rect.rect.y += rect.dir + //rect.rect.width += rect.dir + //rect.rect.height += rect.dir + if (rect.rect.x >= rect.range[1] || rect.rect.x <= rect.range[0]) rect.dir *= -1 + }) + var rectList = rects.map(function(r) { return r.rect }) + X.PolyFillRectangle({ drawable: window, gc: draw[i], rectangles: rectList }) + }) + split += dir + if (split > 500 || split < 300) dir *= -1 + }, 100); + +})