Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repeatedly toggling fullscreen behaves strangely #2157

Open
Endaris opened this issue Feb 20, 2025 · 2 comments
Open

Repeatedly toggling fullscreen behaves strangely #2157

Endaris opened this issue Feb 20, 2025 · 2 comments
Labels

Comments

@Endaris
Copy link

Endaris commented Feb 20, 2025

Reproduced on Debian 12 and a 1920x1080 monitor with the AppImage for commit 1462bd4 for both OpenGL / Vulkan.
Here is a repro for the initial issue based on the project I noticed this with:

local canvasX, canvasY = 640, 380
local canvasScale = 1
local canvasWidth = 1280
local canvasHeight = 720

local canvas = love.graphics.newCanvas(canvasWidth, canvasHeight)

function love.load()
  love.graphics.setBackgroundColor(0.5, 0.5, 0.5, 1)
  love.window.updateMode(1280, 760, {resizable = true})
  --love.window.maximize()
end

function love.update(dt)
end

function love.keypressed(key, scancode)
  if key == "f" then
    toggleFullscreen()
  end
end

function love.draw()
  love.graphics.setCanvas(canvas)
  love.graphics.clear(0, 0, 0, 1)

  for i = 0, canvasWidth / 16 do
    for j = 0, canvasWidth / 36 do
      if j % 2 == 0 then
        love.graphics.setColor(0.1, 0.1, 0.8, 1)
      else
        love.graphics.setColor(0.7, 0.2, 0.7, 1)
      end
      love.graphics.rectangle("fill", i * 16, j * 36, 16, 36)
    end
  end

  love.graphics.setCanvas()

  love.graphics.setBlendMode("alpha", "premultiplied")
  love.graphics.draw(canvas, canvasX, canvasY, 0, canvasScale, canvasScale, canvasWidth / 2, canvasHeight / 2)
  love.graphics.setBlendMode("alpha", "alphamultiply")

  printScaleInfo()
end


function love.resize(w, h)
  print("love.resize called with width " .. w .. ", height " .. h)
  updateCanvasScale(w, h)
end

function toggleFullscreen()
  local fullscreen = love.window.getFullscreen()
  print("Toggling fullscreen " .. (not fullscreen and "on" or "off"))
  love.window.setFullscreen(not fullscreen, "desktop")
  fullscreen = not fullscreen

  local w, h = love.graphics.getDimensions()
  print("new graphics dimensions are width " .. w .. ", height " .. h)
  updateCanvasScale(w, h)
end

function updateCanvasScale(newWindowWidth, newWindowHeight)
  canvasX = math.floor(newWindowWidth / 2)
  canvasY = math.floor(newWindowHeight / 2)

  local availableScales = {1, 1.5, 2, 2.5, 3}
  for i= #availableScales, 1, -1 do
    local scale = availableScales[i]
    if (newWindowWidth >= canvas:getWidth() * scale and newWindowHeight >= canvas:getHeight() * scale) then
      canvasScale = scale
      break
    end
  end
end

function printScaleInfo()
  love.graphics.setColor(0, 1, 0, 1)
  local scaleString = "Scale: " .. canvasScale .. " (" .. canvasWidth * canvasScale .. " x " .. canvasHeight * canvasScale .. ")"
  love.graphics.print(scaleString, 10, 10)
  local renderer = love.graphics.getRendererInfo()
  love.graphics.print(renderer, 10, 30)
  love.graphics.setColor(1, 1, 1, 1)
end

When maximize is commented out like here, the following happens:

Graphically, the first fullscreen toggle yields scale 1.5 on my screen size as expected but toggling fullscreen off keeps the dimensions at the fullscreen resolution, no love.resize fires. Toggling it on has the expected result but toggling it off again moves the window handle offscreen.
When using love 11.5 instead, each fullscreen toggle resizes back to the previous window size with the weird side effect of moving down the window handle by a little each time.

If the maximize is added in love.load, openGL and Vulkan exhibit slightly different behaviours with love 12:
Vulkan in particular seems to squash the graphics vertically when not fullscreen whereas openGL will introduce some kind of offset.

@slime73 slime73 added the Linux label Feb 27, 2025
@slime73
Copy link
Member

slime73 commented Mar 2, 2025

Do you mind re-testing with the latest 12.0 build? It uses an updated version of SDL3.

@Endaris
Copy link
Author

Endaris commented Mar 3, 2025

Issue is still present, also recorded a video this time:

2025-03-03.23-08-46.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants