Jump to content

[ Solved ] Error Change Full SCreen to Mode Windows.


Go to solution Solved by Yue,

Recommended Posts

Posted

On my screen resolution change the application starts in windowed mode, if I switch to full window it works fine, but if I switch back to windowed mode, although the resolution data is the same, the window occupies the entire surface of the desktop.

image.thumb.png.cbab6c4858baf3875634a6d10b41a1a5.png

 

image.thumb.png.7bdb4684f02c5331a35669784a37e8a5.png

 

Switch to full screen and back without changing resolution.

I attach the project via inbox.  File Windows.lua

image.thumb.png.58c3375560660171ead4e800f5e3993f.png


 

 local title = title or "Ventana"
    local x = x or 0
    local y = y or 0
    local display = display or GetDisplays()[1]
 
    -- 🌟 Cargar configuración
    local settings = SettingsManager:New():Load()
 
    -- 📏 Si existe resolución guardada, usarla
    if settings["resolution"] then
        local w, h = settings["resolution"]:match("(%d+)%s*x%s*(%d+)")
        if w and h then
            width = tonumber(w)
            height = tonumber(h)
            Print("📐 Resolución cargada desde archivo: " .. width .. "x" .. height)
        else
            width = width or 800
            height = height or 600
        end
    else
        width = width or 800
        height = height or 600
    end
 
    -- 🖥️ Determinar si usar pantalla completa o modo ventana
    local fullscreen = false
    local fs = settings["fullscreen"]
    if fs then
        fs = fs:lower()
        if fs == "true" or fs == "1" or fs == "yes" then
            fullscreen = true
        end
    end
 
    if fullscreen then
        style = WINDOW_FULLSCREEN | WINDOW_CENTER
        Print("🖥️ Modo pantalla completa activado.")
    else
        style = WINDOW_TITLEBAR | WINDOW_CENTER
        Print("🪟 Modo ventana activado.")
    end
 
    -- 🪟 Crear ventana y framebuffer
    local window = CreateWindow(title, 0, 0, width, height, display, style)
    local framebuffer = CreateFramebuffer(window)

 

 

 

Astrocuco.thumb.png.c76e0fb3de2d6e437e7dca099625e11e.png

  • Yue changed the title to [ Solved ] Error Change Full SCreen to Mode Windows.
  • Solution
Posted

Topic: Resolution Issue When Switching Between Fullscreen and Windowed Mode

Description of the problem:

When switching between fullscreen and windowed mode, I encountered unexpected behavior: when the application entered fullscreen mode, the system resolution was adjusted to the resolution of the window. However, when switching back to windowed mode, the desktop resolution was not restored to its original value. Instead, the application continued using the fullscreen resolution, resulting in inconsistencies in display and issues with the graphical interface.

Cause:

This behavior is caused by how the Leadwerks engine handles fullscreen mode. When fullscreen is activated, the operating system changes the screen resolution to match the game window's resolution. When switching back to windowed mode, the engine does not automatically restore the original desktop resolution, causing the error.

Solution:

To resolve this issue, I implemented an approach in Lua to explicitly save the original desktop resolution before switching to fullscreen and then restore it when switching back to windowed mode. Below is the implemented code to handle this behavior correctly:

 
-- Last update: April 6, 2025

Window = {}
Window.__index = Window

function Window:New(title, x, y, width, height, display, style)
    local this = setmetatable({}, Window)
   
    local title = title or "Window"
    local x = x or 0
    local y = y or 0
    local display = display or GetDisplays()[1]
    
    -- Save the original desktop resolution
    local originalWidth, originalHeight = display:GetSize().x, display:GetSize().y
    local savedWidth, savedHeight = width, height

    -- Load settings
    local settings = SettingsManager:New():Load()
    if settings["resolution"] then
        local w, h = settings["resolution"]:match("(%d+)%s*x%s*(%d+)")
        if w and h then
            savedWidth = tonumber(w)
            savedHeight = tonumber(h)
        end
    end

    -- Check if fullscreen mode is enabled
    local fullscreen = false
    local fs = settings["fullscreen"]
    if fs then
        fs = fs:lower()
        if fs == "true" or fs == "1" or fs == "yes" then
            fullscreen = true
        end
    end

    -- Set the window style based on fullscreen or windowed mode
    if fullscreen then
        style = WINDOW_FULLSCREEN 
    else
        style = WINDOW_TITLEBAR
    end

    -- Create the window with the appropriate resolution
    local window = CreateWindow(title, 1920/2-(savedWidth/2), 1080/2-(savedHeight/2), savedWidth, savedHeight, display, style)
    local framebuffer = CreateFramebuffer(window)

    -- Method to restore the original resolution when switching back to windowed mode
    function this:RestoreOriginalResolution()
        if not fullscreen then
            window:SetSize(originalWidth, originalHeight)  -- Restore the original resolution
        end
    end

    return this
end

return Window

 

Explanation:

  1. Saving the original resolution: Before creating the window, the original desktop resolution is saved using display:GetSize().

  2. Loading the saved resolution: If the configuration includes a saved resolution, it is used. If not, the default resolution is applied.

  3. Detecting fullscreen mode: It checks if fullscreen mode is enabled in the settings and adjusts the window style accordingly.

  4. Restoring the original resolution: I implemented the RestoreOriginalResolution() method that restores the desktop resolution when switching back to windowed mode.

With this solution, the application now correctly handles the resolution change between fullscreen and windowed modes, maintaining the original desktop resolution.

Conclusion:

This behavior is not a bug in the engine but a common feature in many graphics engines that handle fullscreen as an "exclusive mode." By implementing this custom logic, I was able to resolve the issue and restore the original system resolution when switching between modes

  • Like 1

 

 

Astrocuco.thumb.png.c76e0fb3de2d6e437e7dca099625e11e.png

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...