fix: would crash if no gpm installed

This commit is contained in:
Mario GLiewe 2015-02-01 13:15:41 +01:00
parent 96a19b8523
commit db435b179d
1 changed files with 53 additions and 49 deletions

View File

@ -102,63 +102,67 @@ function GpmClient(options) {
vc=/[0-9]+$/.exec(tty)[0];
}
var self=this;
if (tty) {
fs.stat(GPM_SOCKET, function(err, stat) {
if (err || !stat.isSocket())
return;
var conf = {
eventMask: 0xffff,
defaultMask: GPM_MOVE|GPM_HARD,
minMod: 0,
maxMod: 0xffff,
pid: pid,
vc: vc
};
var conf = {
eventMask: 0xffff,
defaultMask: GPM_MOVE|GPM_HARD,
minMod: 0,
maxMod: 0xffff,
pid: pid,
vc: vc
};
var gpm=net.createConnection(GPM_SOCKET);
this.gpm=gpm;
var gpm=net.createConnection(GPM_SOCKET);
this.gpm=gpm;
gpm.on('connect', function() {
send_config(gpm, conf, function() {
conf.pid=0;
conf.vc=GPM_REQ_NOPASTE;
//send_config(gpm, conf);
gpm.on('connect', function() {
send_config(gpm, conf, function() {
conf.pid=0;
conf.vc=GPM_REQ_NOPASTE;
//send_config(gpm, conf);
});
});
});
var self=this;
gpm.on('data', function(packet) {
var evnt=parseEvent(packet);
switch(evnt.type & 15) {
case GPM_MOVE:
if (evnt.dx || evnt.dy) self.emit('move', evnt.buttons, evnt.modifiers, evnt.x, evnt.y)
if (evnt.wdx || evnt.wdy) self.emit('mousewheel', evnt.buttons, evnt.modifiers, evnt.x, evnt.y, evnt.wdx, evnt.wdy)
gpm.on('data', function(packet) {
var evnt=parseEvent(packet);
switch(evnt.type & 15) {
case GPM_MOVE:
if (evnt.dx || evnt.dy) self.emit('move', evnt.buttons, evnt.modifiers, evnt.x, evnt.y)
if (evnt.wdx || evnt.wdy) self.emit('mousewheel', evnt.buttons, evnt.modifiers, evnt.x, evnt.y, evnt.wdx, evnt.wdy)
break;
case GPM_DRAG:
if (evnt.dx || evnt.dy) self.emit('drag', evnt.buttons, evnt.modifiers, evnt.x, evnt.y)
if (evnt.wdx || evnt.wdy) self.emit('mousewheel', evnt.buttons, evnt.modifiers, evnt.x, evnt.y, evnt.wdx, evnt.wdy)
break;
case GPM_DOWN:
self.emit('btndown', evnt.buttons, evnt.modifiers, evnt.x, evnt.y)
if (evnt.type & GPM_DOUBLE) {
self.emit('dblclick', evnt.buttons, evnt.modifiers, evnt.x, evnt.y)
}
break;
case GPM_DRAG:
if (evnt.dx || evnt.dy) self.emit('drag', evnt.buttons, evnt.modifiers, evnt.x, evnt.y)
if (evnt.wdx || evnt.wdy) self.emit('mousewheel', evnt.buttons, evnt.modifiers, evnt.x, evnt.y, evnt.wdx, evnt.wdy)
case GPM_UP:
self.emit('btnup', evnt.buttons, evnt.modifiers, evnt.x, evnt.y)
if (!(evnt.type & GPM_MFLAG)) {
self.emit('click', evnt.buttons, evnt.modifiers, evnt.x, evnt.y)
}
break;
case GPM_DOWN:
self.emit('btndown', evnt.buttons, evnt.modifiers, evnt.x, evnt.y)
if (evnt.type & GPM_DOUBLE) {
self.emit('dblclick', evnt.buttons, evnt.modifiers, evnt.x, evnt.y)
}
break;
case GPM_UP:
self.emit('btnup', evnt.buttons, evnt.modifiers, evnt.x, evnt.y)
if (!(evnt.type & GPM_MFLAG)) {
self.emit('click', evnt.buttons, evnt.modifiers, evnt.x, evnt.y)
}
break;
}
})
gpm.on('error', function(err) {
console.log('GPM ERROR', err);
self.stop();
})
gpm.on('error', function(err) {
console.log('GPM ERROR', err);
self.stop();
});
});
}
}
GpmClient.prototype=new EventEmitter();
GpmClient.prototype.stop=function() {