now focus handling/locking is global...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-08-26 23:58:52 +03:00
parent 984de33b1e
commit e8194e6965
7 changed files with 111 additions and 57 deletions

View File

@ -133,6 +133,16 @@ body {
box-shadow: none; box-shadow: none;
} }
.viewer .lock-clicks {
position: absolute;
display: block;
width: 100%;
height: 100%;
background: transparent;
cursor: auto;
z-index: 10000;
}
/*********************************************************************/ /*********************************************************************/

View File

@ -74,6 +74,7 @@ var CollectionActions = actions.Actions({
set collection(value){ set collection(value){
this.loadCollection(value) }, this.loadCollection(value) },
// XXX should this check consistency???
get collection_order(){ get collection_order(){
if(this.collections == null){ if(this.collections == null){
return null return null

View File

@ -2152,7 +2152,7 @@ var FileSystemWriterUIActions = actions.Actions({
// XXX this needs feedback... // XXX this needs feedback...
// XXX should this return a promise??? // XXX should this return a promise???
saveIndexHere: ['File/Save', saveIndexHere: ['File/$Save',
function(){ function(){
if(this.location.path){ if(this.location.path){
this.saveIndex() this.saveIndex()
@ -2172,10 +2172,10 @@ var FileSystemWriterUIActions = actions.Actions({
.saveIndexHere()}], .saveIndexHere()}],
// XXX need to be able to make dirs... // XXX need to be able to make dirs...
browseExportIndex: ['File/Export/Export Index to...', browseExportIndex: ['File/Export/Export Index...',
makeBrowseProxy('exportIndex')], makeBrowseProxy('exportIndex')],
// XXX need to be able to make dirs... // XXX need to be able to make dirs...
browseExportDirs: ['File/Export/Export Images to...', browseExportDirs: ['File/Export/Export Images...',
makeBrowseProxy('exportDirs')], makeBrowseProxy('exportDirs')],
@ -2351,7 +2351,7 @@ var FileSystemWriterUIActions = actions.Actions({
}, },
}, },
// XXX indicate export state: index, crop, image... // XXX indicate export state: index, crop, image...
exportDialog: ['File/Export/Export optioons...', exportDialog: ['File/Export/$Export...',
widgets.makeUIDialog(function(){ widgets.makeUIDialog(function(){
var that = this var that = this

View File

@ -84,6 +84,7 @@ core.ImageGridFeatures.Feature('viewer-testing', [
// features... // features...
'ui-cursor', 'ui-cursor',
'ui-unfocused-lock',
'ui-single-image', 'ui-single-image',

View File

@ -1736,8 +1736,7 @@ module.ContextActionMenu = core.ImageGridFeatures.Feature({
event.preventDefault() event.preventDefault()
event.stopPropagation() event.stopPropagation()
that.focused that.browseActions()
&& that.browseActions()
}) })
}], }],
], ],

View File

@ -10,6 +10,7 @@
* - ui-url-hash * - ui-url-hash
* handle .location.hash * handle .location.hash
* - ui-cursor * - ui-cursor
- ui-unfocused-lock
* - ui-control * - ui-control
* touch/mouse control mechanics * touch/mouse control mechanics
* *
@ -154,10 +155,6 @@ module.ViewerActions = actions.Actions({
// transition. // transition.
'resize-done-timeout': 300, 'resize-done-timeout': 300,
// The timeout to wait after window focus before setting .focused
// to true.
'window-focus-timeout': 200,
// Theme to set on startup... // Theme to set on startup...
'theme': null, 'theme': null,
@ -232,14 +229,6 @@ module.ViewerActions = actions.Actions({
} }
}, },
// Focus...
//
// This is true when window is focused and false when not + 200ms
// after focusing.
// This enables the used to ignore events that lead to window focus.
get focused(){
return !!this.__focus_lock.state },
// Scaling... // Scaling...
// //
// NOTE: .screenwidth / .screenheight are measured in square image blocks... // NOTE: .screenwidth / .screenheight are measured in square image blocks...
@ -748,35 +737,6 @@ module.Viewer = core.ImageGridFeatures.Feature({
} }
}], }],
// focus-lock...
['start',
function(){
var that = this
var focus_lock = this.__focus_lock = this.__focus_lock || {}
var focused = focus_lock.state = focus_lock.state || document.hasFocus()
var unlock = focus_lock.unlock = focus_lock.unlock
|| function(){ setTimeout(
function(){ focus_lock.state = true },
that.config['window-focus-timeout'] || 0) }
var lock = focus_lock.lock = focus_lock.lock
|| function(){ focus_lock.state = false }
$(window)
.focus(unlock)
.blur(lock)
}],
['stop',
function(){
var focus_lock = this.__focus_lock = this.__focus_lock || {}
var unlock = focus_lock.unlock
var lock = focus_lock.lock
unlock
&& $(window).off('focus', unlock)
lock
&& $(window).off('blur', lock)
}],
/*/ force browser to redraw images after resize... /*/ force browser to redraw images after resize...
// NOTE: this fixes a bug where images are not always updated // NOTE: this fixes a bug where images are not always updated
// when off-screen... // when off-screen...
@ -1271,6 +1231,94 @@ module.Cursor = core.ImageGridFeatures.Feature({
/*********************************************************************/
// Lock mouse when unfocused...
var LockUnfocusedActions = actions.Actions({
config: {
'lock-unfocused': 'on',
// The timeout to wait after window focus before setting .focused
// to true.
'window-focus-timeout': 200,
},
// Focus...
//
// This is true when window is focused and false when not + 200ms
// after focusing.
// This enables the used to ignore events that lead to window focus.
get focused(){
return that.dom.find('.lock-clicks').length > 0 },
toggleUnfocusedLock: ['Interface/Lock unfocused viewer',
core.doc`Toggle unfocused viewer locking...
NOTE: this defines the handlers on window.`,
core.makeConfigToggler('lock-unfocused',
['off', 'on'],
function(state){
var that = this
var handlers = this.__focus_lock_handlers = this.__focus_lock_handlers || {}
var unlock = handlers.unlock = handlers.unlock
|| function(){
setTimeout(function(){
that.dom.find('.lock-clicks').remove()
}, that.config['window-focus-timeout'] || 0) }
var lock = handlers.lock = handlers.lock
|| function(){
that.dom.find('.lock-clicks').length == 0
&& that.dom
.append($('<div>')
.addClass('lock-clicks')
.on('click contextmenu',function(evt){
evt.stopPropagation()
evt.preventDefault()
})) }
// we reset the handlers to avoid multiple triggers...
$(window)
.off('focus', unlock)
.off('blur', lock)
// setup...
if(state == 'on'){
$(window)
.focus(unlock)
.blur(lock)
// setup initial state...
document.hasFocus() ? unlock() : lock()
// tare down...
} else {
unlock()
delete this.__focus_lock_handlers
}
})],
})
var LockUnfocused =
module.LockUnfocused = core.ImageGridFeatures.Feature({
title: '',
doc: '',
tag: 'ui-unfocused-lock',
depends: [
'ui'
],
actions: LockUnfocusedActions,
handlers: [
['start',
function(){
this.toggleUnfocusedLock('!') }],
],
})
/*********************************************************************/ /*********************************************************************/
// Touch/Control... // Touch/Control...
// //
@ -1514,11 +1562,6 @@ var ControlActions = actions.Actions({
var clicked_image = isImageClicked(event, img) var clicked_image = isImageClicked(event, img)
// ignore clicks when focusing window...
if(!that.focused){
return
}
var inner = function(){ var inner = function(){
focus ? focus ?
that[blockEvt] that[blockEvt]

View File

@ -22,14 +22,14 @@
"fs-walk": "^0.0.1", "fs-walk": "^0.0.1",
"glob": "^4.0.6", "glob": "^4.0.6",
"guarantee-events": "^1.0.0", "guarantee-events": "^1.0.0",
"ig-actions": "^3.5.4", "ig-actions": "^3.5.5",
"ig-features": "^3.2.6", "ig-features": "^3.2.7",
"ig-object": "^1.0.1", "ig-object": "^1.0.2",
"openseadragon": "^2.3.0", "openseadragon": "^2.3.0",
"preact": "^8.2.1", "preact": "^8.2.4",
"react": "^15.6.1", "react": "^15.6.1",
"react-dom": "^15.6.1", "react-dom": "^15.6.1",
"requirejs": "^2.3.4", "requirejs": "^2.3.5",
"requirejs-plugins": "^1.0.2", "requirejs-plugins": "^1.0.2",
"sharp": "^0.17.3", "sharp": "^0.17.3",
"wildglob": "^0.1.1" "wildglob": "^0.1.1"