description and source-codecreateClient = function (options, initCb)
{
if (typeof options === 'function') {
initCb = options;
options = {};
}
if (!options) options = {};
var display = options.display;
if (!display)
display = (process.env.DISPLAY) ? process.env.DISPLAY : ':0';
var displayMatch = display.match(/^(?:[^:]*?\/)?(.*):(\d+)(?:.(\d+))?$/);
if (!displayMatch)
throw new Error("Cannot parse display");
var host = displayMatch[1];
var displayNum = displayMatch[2];
if (!displayNum)
displayNum = 0;
var screenNum = displayMatch[3];
if (!screenNum)
screenNum = 0;
// open stream
var stream;
var connected = false;
var cbCalled = false;
var socketPath;
// try local socket on non-windows platforms
if ( ['cygwin', 'win32', 'win64'].indexOf(process.platform) < 0 )
{
if (process.platform == 'darwin' || process.platform == 'mac')
{
// socket path on OSX is /tmp/launch-(some id)/org.x:0
if (display[0] == '/')
{
socketPath = display;
}
} else if(!host)
socketPath = '/tmp/.X11-unix/X' + displayNum;
}
var client = new XClient(displayNum, screenNum, options);
var connectStream = function() {
if (socketPath) {
stream = net.createConnection(socketPath);
} else {
stream = net.createConnection(6000 + parseInt(displayNum), host);
}
stream.on('connect', function() {
connected = true;
client.init(stream);
});
stream.on('error', function(err) {
if (!connected && socketPath && err.code === 'ENOENT') {
// Retry connection with TCP on localhost
socketPath = null;
host = 'localhost';
connectStream();
} else if (initCb && !cbCalled) {
cbCalled = true;
initCb(err);
} else {
client.emit('error', err);
}
});
};
connectStream();
if (initCb)
{
client.on('connect', function(display) {
// opt-in BigReq
if (!options.disableBigRequests) {
client.require('big-requests', function(err, BigReq) {
if (err)
return initCb(err)
BigReq.Enable(function(err, maxLen) {
display.max_request_length = maxLen;
cbCalled = true;
initCb(undefined, display);
});
});
} else {
cbCalled = true;
initCb(undefined, display);
}
});
}
return client;
}
example usage...
```js
var x11 = require('x11');
var Exposure = x11.eventMask.Exposure;
var PointerMotion = x11.eventMask.PointerMotion;
x11.createClient(function(err, display) {
if (!err) {
var X = display.client;
var root = display.screen[0].root;
var wid = X.AllocID();
X.CreateWindow(
wid, root, // new window id, parent
0, 0, 100, 100, // x, y, w, h
...