diff --git a/CHANGELOG.md b/CHANGELOG.md index 28cc1143..9f6db794 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ - bug fixes - regression breaking touch move events on desktop touchscreens +- misc + - change noFocus client option behavior: the defalt client window now doesn't take the focus at all, even when a text input is clicked. + +- scripting + - add `setFocusable()` function to change the focusability of the window on the fly (allows renabling focus temporarely to interact with a text widget using a dedicated toggle buttonfor example) + + ## 1.19.1 - bug fixes diff --git a/resources/docs/docs/client-options.md b/resources/docs/docs/client-options.md index 6bf42f81..31f874e0 100644 --- a/resources/docs/docs/client-options.md +++ b/resources/docs/docs/client-options.md @@ -13,7 +13,7 @@ Client options can be set either with the server's `--client-options` option, or | consoleLength | number | 300 | sets the maximum number of log messages in the client's console | | id | string | *random_id* | client's unique id (use with caution: two clients should never have the same id) | | usePercents | 1 / 0 | 0 | sets the editor's "relative units" option | -| noFocus | 1 / 0 | 0 | (built-in client only) prevent the client window from taking focus unless a text input or a dropdown is clicked | +| noFocus | 1 / 0 | 0 | (built-in client only) prevent the client window from taking focus | | clientSync | 1 / 0 | 1 | set to 0 to prevent the client from syncing with other clients | | altTraversing | 1 / 0 | 0 | set to 1 to enable an alternative traversing behavior for toggle buttons (traversing gestures on toggle buttons will change their values in only one way depending on the first touched button's state) | | virtualKeyboard | 1 / 0 | 0 | (desktop only) set to 1 to enable the virtual keyboard by default | diff --git a/resources/docs/docs/widgets/scripting.md b/resources/docs/docs/widgets/scripting.md index 86f9d41b..898ee47f 100644 --- a/resources/docs/docs/widgets/scripting.md +++ b/resources/docs/docs/widgets/scripting.md @@ -288,6 +288,14 @@ Gives focus to a widget (ie input widget). ---- +#### `setFocusable(focusable)` + +- `focusable`: `0` or `1` + +*Built-in client only*: define whether the client window can be focused or not. Text inputs cannot be interacted with when the window is not focusable. + +---- + #### `getScroll(id)` - `id`: widget `id` as a string. diff --git a/src/client/events/click.js b/src/client/events/click.js index aa4d17b1..92150779 100644 --- a/src/client/events/click.js +++ b/src/client/events/click.js @@ -38,7 +38,7 @@ function mouseToFastClick(event) { DOM.dispatchEvent(e.target, name, e) - if (ENV.nofocus && !editor.enabled && e.target.tagName !== 'INPUT' && e.target.tagName !== 'TEXTAREA' && e.target.tagName !== 'SELECT') { + if (!FOCUSABLE && e.target.tagName !== 'INPUT' && e.target.tagName !== 'TEXTAREA' && e.target.tagName !== 'SELECT') { console.debug('ELECTRON.BLUR()') } diff --git a/src/client/globals.js b/src/client/globals.js index e204fb1f..fe12c67d 100644 --- a/src/client/globals.js +++ b/src/client/globals.js @@ -34,6 +34,9 @@ window.TOGGLE_ALT_TRAVERSING = !!ENV.altTraversing window.VIRTUAL_KEYBOARD = !!ENV.virtualKeyboard +window.FOCUSABLE = !ENV.noFocus +if (!FOCUSABLE) console.debug('ELECTRON.SETFOCUSABLE(0)') +else console.debug('ELECTRON.SETFOCUSABLE(1)') window.JSON.parseFlex = require('json5').parse diff --git a/src/client/widgets/scripts/script-vm.js b/src/client/widgets/scripts/script-vm.js index c6262123..5127ec77 100644 --- a/src/client/widgets/scripts/script-vm.js +++ b/src/client/widgets/scripts/script-vm.js @@ -470,6 +470,14 @@ class ScriptVm extends Vm { } + this.sandbox.contentWindow.setFocusable = (focusable)=>{ + + this.checkContext('setFocusable') + FOCUSABLE = !!focusable + console.debug('ELECTRON.SETFOCUSABLE('+(focusable ? 1 : 0)+')') + + } + this.sandbox.contentWindow.toolbar = (...args)=>{ this.checkContext('toolbar') @@ -525,7 +533,7 @@ class ScriptVm extends Vm { this.sandbox.contentWindow.Image = Image for (var imports of ['set', 'get', 'getProp', 'getIndex', 'updateProp', 'send', 'httpGet', 'stateGet', 'stateSet', 'storage', - 'setInterval', 'clearInterval', 'setTimeout', 'clearTimeout', 'setFocus', 'unfocus', 'setScroll', 'getScroll', 'toolbar', + 'setInterval', 'clearInterval', 'setTimeout', 'clearTimeout', 'setFocus', 'unfocus' , 'setFocusable', 'setScroll', 'getScroll', 'toolbar', 'openUrl', 'getVar', 'setVar', 'runAs', 'Image', 'updateCanvas']) { this.sanitize(this.sandbox.contentWindow[imports]) } diff --git a/src/server/electron-window.js b/src/server/electron-window.js index 3e054136..46bfef27 100644 --- a/src/server/electron-window.js +++ b/src/server/electron-window.js @@ -25,6 +25,7 @@ module.exports = function(options={}) { }) + // default geometry var currentScreen = screen.getDisplayNearestPoint(screen.getCursorScreenPoint()), screenSize = currentScreen.size, @@ -102,6 +103,14 @@ module.exports = function(options={}) { if (level === 0 && message === 'ELECTRON.BLUR()') window.blur() if (level === 0 && message === 'ELECTRON.FOCUS()') window.focus() + if (level === 0 && message === 'ELECTRON.SETFOCUSABLE(1)') { + window.setFocusable(true) + window.focus() + } + if (level === 0 && message === 'ELECTRON.SETFOCUSABLE(0)') { + window.setFocusable(false) + window.blur() + } }) @@ -161,6 +170,9 @@ module.exports = function(options={}) { }) } + window.setFocusable(!options.noFocus) + + return window } diff --git a/src/server/index.js b/src/server/index.js index baa9ec6d..9261dc8d 100644 --- a/src/server/index.js +++ b/src/server/index.js @@ -62,7 +62,13 @@ function openClient() { var address = settings.appAddresses()[0] var launch = ()=>{ - var win = require('./electron-window')({address:address, shortcuts:true, fullscreen: settings.read('fullscreen'), id: 'client'}) + var win = require('./electron-window')({ + address:address, + shortcuts:true, + fullscreen: settings.read('fullscreen'), + noFocus: settings.read('client-options') && settings.read('client-options').some(x=>x.match(/nofocus=1/i)), + id: 'client' + }) win.on('error', ()=>{ console.log('ERR') })