public WindowInputHandler setWindow(Window window) {
   if (this.window != null) {
     this.window.setKeyCallback(null);
   }
   this.window = window;
   if (window != null) {
     ByteBuffer buf = BufferUtils.createByteBuffer(16);
     buf.limit(8);
     ByteBuffer bufX = buf.slice();
     buf.limit(16);
     buf.position(8);
     ByteBuffer bufY = buf.slice();
     window.getCursorPos(bufX.asDoubleBuffer(), bufY.asDoubleBuffer());
     mouseX = bufX.getDouble();
     mouseY = window.getViewport().getHeight() - bufY.getDouble();
     setImmediateMode(immediateMode);
   }
   return this;
 }