Add mouse-warping support. . Reference: /n/atom/patch/applied/9wd-mousewarp Date: Fri May 23 21:43:17 CES 2014 Signed-off-by: root@davidrhoskin.com --- /usr/web/9wd/js/util/array.js Fri May 23 21:42:29 2014 +++ /usr/web/9wd/js/util/array.js Fri May 23 21:42:31 2014 @@ -82,3 +82,22 @@ max: this.getPoint() } } + +ArrayIterator.prototype.strtoul = function(){ + var spc = " ".charCodeAt(0); + var oh = "0".charCodeAt(0); + var nine = "9".charCodeAt(0); + var x = 0; + + for(; this.index < this.array.length; ++this.index){ + if(this.array[this.index] != spc) + break; + } + for(; this.index < this.array.length; ++this.index){ + if(this.array[this.index] >= oh && this.array[this.index] <= nine) + x = (x * 10) + (this.array[this.index] - oh); + else + break; + } + return x; +} --- /usr/web/9wd/js/draw/draw9p.js Fri May 23 21:42:34 2014 +++ /usr/web/9wd/js/draw/draw9p.js Fri May 23 21:42:36 2014 @@ -251,6 +251,8 @@ }else{ if(qid.path == QCONSCTL){ return; + }else if(qid.path == QMOUSE){ + return mouse.handlewarp(data); }else if(qid.path == QCURSOR){ return mouse.cursor.write(data); }else if(qid.path == QLABEL){ --- /usr/web/9wd/js/mouse.js Fri May 23 21:42:39 2014 +++ /usr/web/9wd/js/mouse.js Fri May 23 21:42:40 2014 @@ -17,6 +17,20 @@ buf = buf.concat(pad11(this.timestamp)); return buf; } + State.prototype.bound = function(){ + if(this.position.x > Draw9p.rootcanvas.width){ + this.position.x = Draw9p.rootcanvas.width; + } + if(this.position.x < 0){ + this.position.x = 0; + } + if(this.position.y > Draw9p.rootcanvas.height){ + this.position.y = Draw9p.rootcanvas.height; + } + if(this.position.y < 0){ + this.position.y = 0; + } + } this.states = {down: 1, up: 0}; this.state = new State({x: 0, y: 0}, 0); @@ -50,6 +64,9 @@ this.state.buttons = (this.state.buttons& ~(1< Draw9p.rootcanvas.width){ - this.state.position.x = Draw9p.rootcanvas.width; - } - if(this.state.position.x < 0){ - this.state.position.x = 0; - } + this.state.position.y += e.movementY || e.mozMovementY || e.webkitMovementY || 0; - if(this.state.position.y > Draw9p.rootcanvas.height){ - this.state.position.y = Draw9p.rootcanvas.height; - } - if(this.state.position.y < 0){ - this.state.position.y = 0; - } - this.cursor.goto(this.state.position); + this.state.bound(); this.generatemovement(this.state); return false; } + this.handlewarp = function(data){ + var ai = new ArrayIterator(data); + + if(ai.getChar() != "m".charCodeAt(0)){ + throw("bad mouse write"); + } + var x = ai.strtoul(); + var y = ai.strtoul(); + + this.state.position.x = x; + this.state.position.y = y; + this.state.bound(); + + this.generatemovement(this.state); + return data.length; + } + this.generatemovement = function(state){ - cons.write("m " + state.position.x + ", " + state.position.y + - " : " + state.buttons); + //cons.write("m " + state.position.x + ", " + state.position.y + + // " : " + state.buttons); + this.cursor.goto(this.state.position); this.buf.push(this.state.copy()); this.flushcallbacks(); }