diff --git a/lib/x11/xcore.js b/lib/x11/xcore.js index 4278a62..04bd379 100644 --- a/lib/x11/xcore.js +++ b/lib/x11/xcore.js @@ -288,18 +288,26 @@ var platformDefaultTransport = { // TODO: check process.platform on SmartMachine solaris box } -module.exports.createClient = function() +module.exports.createClient = function(initCb) { - // TODO: parse $DISPLAY - - // open stream - var stream; - var defaultTransportName = platformDefaultTransport[process.platform]; - // use tcp if stated explicitly or if not defined at all - if (!defaultTransportName || defaultTransportName == 'tcp') - stream = net.createConnection(6000); - if (defaultTransportName == 'unix') - stream = net.createConnection('/tmp/.X11-unix/X0'); + // TODO: parse $DISPLAY + + // open stream + var stream; + var defaultTransportName = platformDefaultTransport[process.platform]; + // use tcp if stated explicitly or if not defined at all + if (!defaultTransportName || defaultTransportName == 'tcp') + stream = net.createConnection(6000); + if (defaultTransportName == 'unix') + stream = net.createConnection('/tmp/.X11-unix/X0'); - return new XClient(stream); + var client = new XClient(stream); + if (initCb) + { + client.on('connect', function(display) { + display.client = client; + initCb(display); + }); + } + return client; }