SimulaVR / Simula

Linux VR Desktop
MIT License
2.91k stars 87 forks source link

XWayland surfaces often (but not always) launch as misaligned #94

Closed georgewsinger closed 4 years ago

georgewsinger commented 4 years ago

Consider for example xfce4-terminal and vim running in xfce4-terminal:

Fortunately, this never happens with firefox and google-chrome-stable.

Code responsible for adjusting window dimensions. We only started seeing this problem when forcing windows to launch as squares. See our call to adjustDimensions:

updateSimulaViewSprite :: GodotSimulaViewSprite -> IO ()
updateSimulaViewSprite gsvs = do
  adjustDimensions gsvs 768 768
  useSimulaCanvasItemToDrawSubsurfaces gsvs
  setExtents gsvs
  where adjustDimensions :: GodotSimulaViewSprite -> Int -> Int -> IO ()
        adjustDimensions gsvs w h = do
          gsci <- readTVarIO (gsvs ^. gsvsSimulaCanvasItem)
          renderTarget <- readTVarIO (gsci ^. gsciViewport)
          simulaView <- readTVarIO (gsvs ^. gsvsView)
          let eitherSurface = (simulaView ^. svWlrEitherSurface)
          wlrSurface <- getWlrSurface eitherSurface
          dimensions@(originalWidth, originalHeight) <- getBufferDimensions wlrSurface
          let d'@(w',h') = if (originalWidth > 450 || originalHeight > 450)
                then (w,h)
                else (originalWidth, originalHeight)

          v <- toLowLevel (V2 (fromIntegral w') (fromIntegral h'))

          case eitherSurface of
            Left wlrXdgSurface -> return ()-- G.set_size wlrXdgSurface v
            Right wlrXWaylandSurface -> do G.set_size wlrXWaylandSurface v
                                            -- G.set_maximized wlrXWaylandSurface True -- Doesn't fix the issue

          pixelDimensionsOfWlrSurface <- toGodotVector2 d'
          G.set_size renderTarget pixelDimensionsOfWlrSurface

        setExtents :: GodotSimulaViewSprite -> IO ()
        setExtents gsvs = do
          simulaView <- readTVarIO (gsvs ^. gsvsView)
          let eitherSurface = simulaView ^. svWlrEitherSurface
          sprite <- atomically $ readTVar (_gsvsSprite gsvs)
          aabb <- G.get_aabb sprite
          size <- godot_aabb_get_size aabb
          shape <- atomically $ readTVar (_gsvsShape gsvs)

          size' <- godot_vector3_operator_divide_scalar size 2
          (V3 x y z)  <- fromLowLevel size'
          G.set_extents shape size'

and note that when we stop calling adjustDimensions, the problem goes away:

Also: sometimes we can launch programs like xfce4-terminal and terminus as squares (via adjustDimensions) and they aren't misaligned, but this is relatively rare: