aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts
diff options
context:
space:
mode:
authorStephen Blott2014-12-14 15:17:01 +0000
committerStephen Blott2014-12-14 15:17:01 +0000
commitd5cdffe53c78f21b49ef27d590199d3a453922ac (patch)
treedaf15a9192a463410fa84c188f04c6f0e4da8d17 /content_scripts
parent99e387f9cb6654d88ba0fe5de1059b9d0df481b5 (diff)
parent69c117102eb419baa649cccc770bffea5177b1e1 (diff)
downloadvimium-d5cdffe53c78f21b49ef27d590199d3a453922ac.tar.bz2
Merge branch 'hideMouseOnLinux' of https://github.com/mrmr1993/vimium into mrmr1993-hideMouseOnLinux
Diffstat (limited to 'content_scripts')
-rw-r--r--content_scripts/vimium_frontend.coffee31
1 files changed, 31 insertions, 0 deletions
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index ebdbb9aa..aeb74dcd 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -201,6 +201,7 @@ initializeOnDomReady = ->
# Tell the background page we're in the dom ready state.
chrome.runtime.connect({ name: "domReady" })
+ CursorHider.init()
registerFrame = ->
# Don't register frameset containers; focusing them is no use.
@@ -1085,6 +1086,36 @@ Tween =
value = (elapsed / state.duration) * (state.to - state.from) + state.from
state.onUpdate(value)
+CursorHider =
+ #
+ # Hides the cursor when the browser scrolls, and prevent mouse from hovering while invisible
+ #
+ cursorHideStyle: null
+ isScrolling: false
+
+ showCursor: ->
+ @cursorHideStyle.remove() if @cursorHideStyle.parentElement
+ hideCursor: ->
+ document.head.appendChild @cursorHideStyle unless @cursorHideStyle.parentElement
+
+ onMouseMove: (event) ->
+ if CursorHider.isScrolling # This event was caused by scrolling, don't show the cursor.
+ CursorHider.isScrolling = false
+ else
+ CursorHider.showCursor()
+ onScroll: (event) ->
+ CursorHider.isScrolling = true
+ CursorHider.hideCursor()
+
+ init: ->
+ @cursorHideStyle = document.createElement("style")
+ @cursorHideStyle.innerHTML = """
+ body * {pointer-events: none !important; cursor: none !important;}
+ body {cursor: none !important;}
+ """
+ window.addEventListener "mousemove", @onMouseMove
+ window.addEventListener "scroll", @onScroll
+
initializePreDomReady()
window.addEventListener("DOMContentLoaded", registerFrame)
window.addEventListener("unload", unregisterFrame)