From 94148070705b93feba0a1244bd4771c33ec87d6e Mon Sep 17 00:00:00 2001 From: Utopiah Date: Wed, 25 Oct 2023 10:28:18 +0200 Subject: [PATCH] pointer move and click via xdotool with WebXR example --- examples/spasca-offline/engine/index.html | 73 +++++++++++++++++------ index.js | 8 ++- 2 files changed, 62 insertions(+), 19 deletions(-) diff --git a/examples/spasca-offline/engine/index.html b/examples/spasca-offline/engine/index.html index d1fe99b..57f17df 100644 --- a/examples/spasca-offline/engine/index.html +++ b/examples/spasca-offline/engine/index.html @@ -2201,10 +2201,6 @@ function highlight(code = `console.log("Here is your code."); var x = 5;`, langu return colorRange } -document.body.addEventListener( "highlighterready", (e) => { - fetch("colorme.js").then(r=>r.text()).then( page => { addCodeEditor( page ) }) -}, false); - function startExperience(){ //addCodeEditor(" \n\nqwe qwe qwe qwe qwe qwe qwe qweqweqwe\n\n\na", "") //addCodeEditor() @@ -3012,6 +3008,12 @@ let uws = {} // used for testing AFRAME.registerComponent('startfunctions', { init: function () { + + /* + document.body.addEventListener( "highlighterready", (e) => { + fetch("colorme.js").then(r=>r.text()).then( page => { addCodeEditor( page ) }) + }, false); + fetch('/unifiedworkspaces') .then( r => r.json() ) .then( r => { @@ -3024,13 +3026,47 @@ AFRAME.registerComponent('startfunctions', { ) }) } ) + */ + //startExperience() //doublePinchToScale() //emptyPinchToMove() //makeAnchorsVisibleOnTargets() //startMesher() - fetch('/routes/json').then(r=>r.json()).then(r=>r.filter(p=>p.match(/minimizeall|resolution/)).map(p=>addNewNote('jxr fetch("https://192.168.0.129:8082'+p+'")'))) + fetch('/routes/json').then(r=>r.json()).then(r=>r.filter(p=>p.match(/minimizeall|resolution/)).map(p=>addNewNote('jxr fetch("'+p+'")'))) + // assume served locally + + // could consider on end to click instead + + document.querySelector('[pinchprimary]').addEventListener('pinchstarted', event => { + console.log('pinchprimary pinchstarted') + if (selectedElement) return + fetch('/mouse/down').then( r => r.json() ).then( r => console.log(r) ) + }) + document.querySelector('[pinchprimary]').addEventListener('pinchended', event => { + console.log('pinchprimary pinchended') + if (selectedElement) return + fetch('/mouse/up').then( r => r.json() ).then( r => console.log(r) ) + }) + document.querySelector('[pinchprimary]').addEventListener('pinchmoved', event => { + console.log('pinchprimary pinchmoved') + if (selectedElement) return + let pos = event.detail.position.clone() + let mx = Math.round((0.5+pos.x)*2000) // should clamp + let my = Math.round((1.6-pos.y)*2000) + console.log(pos.x,pos.y) + console.log(mx,my) + // should remain positive values, could align on virtual monitor if found + // otherwise realistic offsets while sitting, e.g 0 0 at 0.5m on the left and 0.5m above + // note that y is going up, so should be flipped + // resolution can also be found via xrand query, could be use to scale accordingly + // a partly visible virtual touchpad could help + // position="0 1.6 -0.5" scale="1 0.5 0.01" + fetch('/mouse/move/?options='+mx+' '+ my) + .then( r => r.json() ) + .then( r => console.log(r) ) + }) } }) @@ -3044,8 +3080,9 @@ AFRAME.registerComponent('startfunctions', { - @@ -3073,6 +3110,9 @@ AFRAME.registerComponent('startfunctions', { + + + @@ -3084,10 +3124,12 @@ AFRAME.registerComponent('startfunctions', { - - + + - - - - - + --> + + diff --git a/index.js b/index.js index 4d2ff38..92d20e6 100644 --- a/index.js +++ b/index.js @@ -79,6 +79,8 @@ const utilsCmd = { // security risk but for now not accepting user input so safe format: res => res.toString().split('\n') }, 'mousemove' : { cmd: 'xdotool mousemove ', optionsPattern: /\d+ \d+/}, + 'mouseup' : { cmd: 'xdotool mouseup 1'}, + 'mousedown' : { cmd: 'xdotool mousedown 1'}, // per device specific (until adjustable per user) 'minimizeall' : { cmd: kwinmin}, //KWin script //'minimizeall' : { cmd: '/home/fabien/Prototypes/kwin-scripting/launch'}, //KWin script @@ -412,8 +414,10 @@ function getSshConfig(){ easier to revoke if need be */ -app.get('/mousemove', (req, res) => { - if( !req.query.options?.match(utilsCmd['mousemove']) ) { {res.json( {error: 'use /mousemove/set?options=100 2000'}); return}} +app.get('/mouse/up', (req, res) => { res.json( execConfiguredCommand('mouseup') ) }) +app.get('/mouse/down', (req, res) => { res.json( execConfiguredCommand('mousedown') ) }) +app.get('/mouse/move', (req, res) => { + if( !req.query.options?.match(utilsCmd['mousemove']) ) { {res.json( {error: 'use /mouse/move?options=100 2000'}); return}} res.json( execConfiguredCommand('mousemove',req.query.options) ) } ) app.get('/minimizeall', (req, res) => { res.json( execConfiguredCommand('minimizeall') ) })