         @on_key_up? and window.addEventListener 'keyup', @_on_key_up
         @on_wheel? and root.addEventListener 'wheel', @_on_wheel_listener
         # @on_click? and addListener root, 'click', @on_click
+        document.addEventListener 'pointerlockchange', @_pointerlockchange, false
+
 
     _destroy_events: ->
         root = @_root
+        if @locked
+            @unlock_pointer()
         options = if supports_passive_events then {passive: false} else false
         if @on_pointer_over?
             removeListener root, 'pointerover', @_on_pointer_over, options


{vec3} = require 'vmath'
# Force usage of spur-events' polyfill even when there is pointer event support
# to avoid some problems in Chrome
window.PointerEvent = undefined
{addListener, removeListener} = require 'spur-events'
{set_immediate} = require './main_loop'

supports_passive_events = false # changed at the end

            if @_menu_prevent_default?
                @_root.addEventListener 'contextmenu', @_menu_prevent_default
            @_enabled = true
        return this

    disable: ->
        if @_enabled
