From f40eb4e3d27b86b0c11f8fb148afe92ec0f434ed Mon Sep 17 00:00:00 2001 From: Andrey Sidorov Date: Thu, 31 May 2012 11:06:46 +1000 Subject: [PATCH] XC-MISC extension --- lib/x11/ext/xc-misc.js | 68 ++++++++++++++++++++++++++++++++++++++++++ test/xcmisc.js | 19 ++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 lib/x11/ext/xc-misc.js create mode 100644 test/xcmisc.js diff --git a/lib/x11/ext/xc-misc.js b/lib/x11/ext/xc-misc.js new file mode 100644 index 0000000..c15fb8d --- /dev/null +++ b/lib/x11/ext/xc-misc.js @@ -0,0 +1,68 @@ +// http://www.x.org/releases/X11R7.6/doc/xcmiscproto/xc-misc.pdf + +var x11 = require('..'); +// TODO: move to templates + +exports.requireExt = function(display, callback) +{ + var X = display.client; + X.QueryExtension('XC-MISC', function(err, ext) { + + if (!ext.present) + callback(new Error('extension not available')); + + ext.QueryVersion = function(clientMaj, clientMin, cb) + { + X.seq_num++; + X.pack_stream.pack('CCSSS', [ext.majorOpcode, 0, 2, clientMaj, clientMin]); + X.replies[X.seq_num] = [ + function(buf, opt) { + var res = buf.unpack('SS'); + return res; + }, + cb + ]; + X.pack_stream.flush(); + } + + ext.GetXIDRange = function(cb) + { + X.seq_num++; + X.pack_stream.pack('CCS', [ext.majorOpcode, 1, 1]); + X.replies[X.seq_num] = [ + function(buf, opt) { + var res = buf.unpack('LL'); + return { + startId: res[0], + count: res[1] + }; + }, + cb + ]; + X.pack_stream.flush(); + } + + ext.GetXIDList = function( count, cb ) + { + X.seq_num++; + X.pack_stream.pack('CCSL', [ext.majorOpcode, 2, 2, count]); + X.replies[X.seq_num] = [ + function(buf, opt) { + var numIds = buf.unpack('L')[0]; + var res = []; + for (var i = 0; i < numIds; ++i) + res.push(buf.unpack('L', 24+i*4)); + return res; + }, + cb + ]; + X.pack_stream.flush(); + } + + ext.QueryVersion(1, 1, function(err, vers) { + ext.major = vers[0]; + ext.minor = vers[1]; + callback(ext); + }); + }); +} diff --git a/test/xcmisc.js b/test/xcmisc.js new file mode 100644 index 0000000..ea4573e --- /dev/null +++ b/test/xcmisc.js @@ -0,0 +1,19 @@ +var x11 = require('../lib/x11'); + +x11.createClient(function(display) { + var X = display.client; + var root = display.screen[0].root; + X.require('xc-misc', function(Misc) { + var xid = X.AllocID(); + console.log("first ID from connection: " + xid); + debugger; + Misc.GetXIDRange(function(err, range) { + console.log("ID range from GetIDRange: [start:" + range.startId + ", count: " + range.count + "]"); + }); + Misc.GetXIDList(100, function(err, list) { + console.log("ID list from GetIDList(100) : " + list); + }); + }); + X.on('error', function(err) { console.log("Error", err); }); + +});