diff --git a/ui (gen4)/lib/keyboard.js b/ui (gen4)/lib/keyboard.js index f7e2e93c..ee08f20d 100755 --- a/ui (gen4)/lib/keyboard.js +++ b/ui (gen4)/lib/keyboard.js @@ -180,6 +180,50 @@ function normalizeModifiers(c, m, a, s){ } +// Event handler wrapper that will drop identical keys repeating at rate +// greater than max_rate +// +// NOTE: this will only limit repeating key combinations thus no lag is +// introduced... +var dropRepeatingkeys = +module.dropRepeatingkeys = +function dropRepeatingkeys(handler, max_rate){ + var _timeout = null + + var key = null + + var ctrl = null + var meta = null + var alt = null + var shift = null + + return function(evt){ + if(_timeout != null + && key == evt.keyCode + && ctrl == evt.ctrlKey + && meta == evt.metaKey + && alt == evt.altKey + && shift == evt.shiftKey){ + return + } + + key = evt.keyCode + ctrl = evt.ctrlKey + meta = evt.metaKey + alt = evt.altKey + shift = evt.shiftKey + + _timeout = setTimeout(function(){ + _timeout = null + }, + // XXX is this the right way to go??? + typeof(max_rate) == typeof(123) ? max_rate : max_rate()) + + return handler(evt) + } +} + + /* Key handler getter * * For doc on format see makeKeyboardHandler(...) diff --git a/ui (gen4)/package.json b/ui (gen4)/package.json index 84fba41a..0e742bc2 100755 --- a/ui (gen4)/package.json +++ b/ui (gen4)/package.json @@ -1,9 +1,9 @@ { - "name": "ImageGrid.Viewer", + "name": "ImageGrid.Viewer (gen4)", "main": "index.html", "version": "0.0.1", "window": { - "title": "ImageGrid.Viewer", + "title": "ImageGrid.Viewer (gen4)", "position": "center", "width": 900, "height": 700, diff --git a/ui (gen4)/ui.js b/ui (gen4)/ui.js index b3c35232..7fdec5d8 100755 --- a/ui (gen4)/ui.js +++ b/ui (gen4)/ui.js @@ -61,6 +61,9 @@ var overlay = require('lib/widget/overlay') /*********************************************************************/ +// XXX move this to config... +module.MAX_KEY_REPEAT_RATE = 100 + // XXX add this to the global doc... module.GLOBAL_KEYBOARD = { 'Global bindings': { @@ -229,7 +232,6 @@ module.GLOBAL_KEYBOARD = { - /*********************************************************************/ $(function(){ @@ -278,12 +280,17 @@ $(function(){ // setup base keyboard for devel, in case something breaks... $(document) .keydown( - keyboard.makeKeyboardHandler( - module.GLOBAL_KEYBOARD, - function(k){ - window.DEBUG && console.log(k) - }, - a)) + keyboard.dropRepeatingkeys( + keyboard.makeKeyboardHandler( + module.GLOBAL_KEYBOARD, + function(k){ + window.DEBUG && console.log(k) + }, + a), + function(){ + // XXX get this from config... + return module.MAX_KEY_REPEAT_RATE + })) }) diff --git a/ui (gen4)/viewer.js b/ui (gen4)/viewer.js index 7a243a96..cd4a2aab 100755 --- a/ui (gen4)/viewer.js +++ b/ui (gen4)/viewer.js @@ -2547,17 +2547,17 @@ module.ImageBookmarks = features.Feature(ImageGridFeatures, { var AppControlActions = actions.Actions({ // XXX revise these... - close: ['Cloase viewer', + close: ['File|Interface/Cloase viewer', function(){ // XXX should we do anything else here like auto-save??? window.close() }], - toggleFullScreen: ['', + toggleFullScreen: ['Interface/Toggle full screen mode', function(){ // XXX where should toggleFullscreenMode(..) be defined... toggleFullscreenMode() }], - showDevTools: ['', + showDevTools: ['Interface|Development/Show Dev Tools', function(){ if(window.showDevTools != null){ showDevTools()