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