mirror of
https://github.com/danbulant/node-x11
synced 2026-06-14 12:11:26 +00:00
open correct socket on local OSX display
This commit is contained in:
parent
37a2ce9e3a
commit
f5a65e5a42
1 changed files with 36 additions and 31 deletions
|
|
@ -1,3 +1,12 @@
|
|||
if (process.platform == 'darwin') {
|
||||
// some strage dns related errors in core node libs on OSX (node v0.6.5)
|
||||
// skip them at the moment
|
||||
process.on('uncaughtException', function (err) {
|
||||
console.log(err);
|
||||
console.log('Caught exception: ' + err);
|
||||
});
|
||||
}
|
||||
|
||||
var util = require('util'); // util.inherits
|
||||
var net = require('net');
|
||||
|
||||
|
|
@ -62,30 +71,12 @@ function XClient(stream, displayNum, screenNum)
|
|||
this.seq2stack = {}; // debug: map seq_num to stack at the moment request was issued
|
||||
|
||||
// in/out packets indexed by sequence ID
|
||||
//this.requests = {};
|
||||
this.replies = {};
|
||||
//this.events = {};
|
||||
this.atoms = stdatoms;
|
||||
this.event_consumers = {}; // maps window id to eventemitter TODO: bad name
|
||||
|
||||
this.importRequestsFromTemplates(this, coreRequests);
|
||||
// TODO: this is potentially async and probably has to be synchronised with 'connect' event
|
||||
/*
|
||||
// import available extentions
|
||||
// TODO: lazy import on first call?
|
||||
this.ext = {};
|
||||
this.ListExtensions( function(err, extentionsList ) {
|
||||
for (ext in extentionsList) {
|
||||
try {
|
||||
X.QueryExtension(ext, function(e) {
|
||||
var extRequests = require('./ext/' + extentionsList[ext]);
|
||||
importRequestsFromTemplates(this, extRequests);
|
||||
});
|
||||
} catch (e) {
|
||||
// do not import if module not defined
|
||||
}
|
||||
}
|
||||
});
|
||||
*/
|
||||
|
||||
this.startHandshake();
|
||||
}
|
||||
util.inherits(XClient, EventEmitter);
|
||||
|
|
@ -102,12 +93,13 @@ XClient.prototype.importRequestsFromTemplates = function(target, reqs)
|
|||
for (r in reqs)
|
||||
{
|
||||
// r is request name
|
||||
target[r] = (function(reqName) {
|
||||
target[r] = (function(reqName) {
|
||||
|
||||
var reqFunc = function req_proxy() {
|
||||
client.seq_num++; // TODO: handle overflow (seq should be last 15 (?) bits of the number
|
||||
|
||||
var err = new Error;
|
||||
err.name = r;
|
||||
err.name = reqName;
|
||||
Error.captureStackTrace(err, arguments.callee);
|
||||
client.seq2stack[client.seq_num] = err.stack;
|
||||
|
||||
|
|
@ -324,11 +316,14 @@ XClient.prototype.require = function(extName, callback)
|
|||
ext.requireExt(this.display, callback);
|
||||
}
|
||||
|
||||
var platformDefaultTransport = {
|
||||
var platformLocalTransport = {
|
||||
win32: 'tcp',
|
||||
win64: 'tcp',
|
||||
cygwin: 'tcp',
|
||||
linux: 'unix'
|
||||
linux: 'unix',
|
||||
|
||||
// OSX
|
||||
darwin: 'unix'
|
||||
// TODO: check process.platform on SmartMachine solaris box
|
||||
}
|
||||
|
||||
|
|
@ -343,6 +338,7 @@ module.exports.createClient = function(initCb, display)
|
|||
var host = displayMatch[1];
|
||||
if (!host)
|
||||
host = '127.0.0.1';
|
||||
|
||||
var displayNum = displayMatch[2];
|
||||
if (!displayNum)
|
||||
displayNum = 0;
|
||||
|
|
@ -352,13 +348,22 @@ module.exports.createClient = function(initCb, 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' || host != '127.0.0.1')
|
||||
stream = net.createConnection(6000 + parseInt(displayNum), host);
|
||||
if (defaultTransportName == 'unix' && host == '127.0.0.1')
|
||||
stream = net.createConnection('/tmp/.X11-unix/X' + displayNum);
|
||||
|
||||
var socketPath;
|
||||
if ( process.platform.match(/win/).length > 0 )
|
||||
{
|
||||
if (process.platform == 'darwin')
|
||||
{
|
||||
if (display[0] == '/') // local socket
|
||||
{
|
||||
socketPath = display;
|
||||
}
|
||||
} else if(host == '127.0.0.1')
|
||||
socketPath = '/tmp/.X11-unix/X' + displayNum;
|
||||
}
|
||||
if(socketPath)
|
||||
stream = net.createConnection(socketPath);
|
||||
else
|
||||
stream = net.createConnection(6000 + parseInt(displayNum), host);
|
||||
var client = new XClient(stream, displayNum, screenNum);
|
||||
if (initCb)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue