UNPKG

neo-neo-bblessed

Version:

A fork of neo-blessed (which is a fork of blessed) with bug fixes and maintenance.

3 lines (2 loc) 2.36 kB
var l=require("net"),s=require("fs"),c=require("events").EventEmitter,E=!1,b=1,I=2,M=4,x=8,h=32,L=128,w=3,G=256,k=1198550348,p="/dev/gpmctl";function g(n,t,f){var r;E?(r=new Buffer(20),r.writeUInt32LE(k,0),r.writeUInt16LE(t.eventMask,4),r.writeUInt16LE(t.defaultMask,6),r.writeUInt16LE(t.minMod,8),r.writeUInt16LE(t.maxMod,10),r.writeInt16LE(process.pid,12),r.writeInt16LE(t.vc,16)):(r=new Buffer(16),r.writeUInt16LE(t.eventMask,0),r.writeUInt16LE(t.defaultMask,2),r.writeUInt16LE(t.minMod,4),r.writeUInt16LE(t.maxMod,6),r.writeInt16LE(t.pid,8),r.writeInt16LE(t.vc,12)),n.write(r,function(){f&&f()})}function P(n){var t={};return t.buttons=n[0],t.modifiers=n[1],t.vc=n.readUInt16LE(2),t.dx=n.readInt16LE(4),t.dy=n.readInt16LE(6),t.x=n.readInt16LE(8),t.y=n.readInt16LE(10),t.type=n.readInt16LE(12),t.clicks=n.readInt32LE(16),t.margin=n.readInt32LE(20),t.wdx=n.readInt16LE(24),t.wdy=n.readInt16LE(26),t}function o(n){if(!(this instanceof o))return new o(n);c.call(this);var t=process.pid,f;try{f=s.readlinkSync("/proc/"+t+"/fd/0")}catch(m){}var r=f?/tty[0-9]+$/.exec(f):null,d;r&&(r=r[0],d=+/[0-9]+$/.exec(r)[0]);var i=this;r&&s.stat(p,function(m,y){if(!(m||!y.isSocket())){var u={eventMask:65535,defaultMask:b|G,minMod:0,maxMod:65535,pid:t,vc:d},a=l.createConnection(p);this.gpm=a,a.on("connect",function(){g(a,u,function(){u.pid=0,u.vc=w})}),a.on("data",function(v){var e=P(v);switch(e.type&15){case b:(e.dx||e.dy)&&i.emit("move",e.buttons,e.modifiers,e.x,e.y),(e.wdx||e.wdy)&&i.emit("mousewheel",e.buttons,e.modifiers,e.x,e.y,e.wdx,e.wdy);break;case I:(e.dx||e.dy)&&i.emit("drag",e.buttons,e.modifiers,e.x,e.y),(e.wdx||e.wdy)&&i.emit("mousewheel",e.buttons,e.modifiers,e.x,e.y,e.wdx,e.wdy);break;case M:i.emit("btndown",e.buttons,e.modifiers,e.x,e.y),e.type&h&&i.emit("dblclick",e.buttons,e.modifiers,e.x,e.y);break;case x:i.emit("btnup",e.buttons,e.modifiers,e.x,e.y),e.type&L||i.emit("click",e.buttons,e.modifiers,e.x,e.y);break}}),a.on("error",function(){i.stop()})}})}o.prototype.__proto__=c.prototype,o.prototype.stop=function(){this.gpm&&this.gpm.end(),delete this.gpm},o.prototype.ButtonName=function(n){return n&4?"left":n&2?"middle":n&1?"right":""},o.prototype.hasShiftKey=function(n){return n&1},o.prototype.hasCtrlKey=function(n){return n&4},o.prototype.hasMetaKey=function(n){return n&8},module.exports=o; //# sourceMappingURL=gpmclient.js.map