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

Undecorated windows are offset by an invisible margin #3162

Closed
1 of 11 tasks
rdnt opened this issue Nov 16, 2024 · 10 comments
Closed
1 of 11 tasks

Undecorated windows are offset by an invisible margin #3162

rdnt opened this issue Nov 16, 2024 · 10 comments

Comments

@rdnt
Copy link

rdnt commented Nov 16, 2024

Ebitengine Version

v2.8.4

Operating System

  • Windows
  • macOS
  • Linux
  • FreeBSD
  • OpenBSD
  • Android
  • iOS
  • Nintendo Switch
  • PlayStation 5
  • Xbox
  • Web Browsers

Go Version (go version)

go version go1.23.0 windows/amd64

What steps will reproduce the problem?

  • Configure ebiten with ebiten.SetWindowDecorated(false)
  • Start a window having the same resolution as the monitor

What is the expected result?

  • The window should cover the entirety of the screen

What happens instead?

  • The window is offset by an invisible margin
    • On a 4k screen with 150% scaling, it is 34px high

image

Anything else you feel useful to add?

I have found that if the isInitWindowDecorated check is added on the last lines of the adjustWindowPosition function, then the window is properly positioned. I am unsure if it is a valid fix or more work is needed to configure it (e.g. if window decorations are enabled/disabled during runtime).

func (u *UserInterface) adjustWindowPosition(x, y int, monitor *Monitor) (int, int) {
    
    ...
    
    //if y < my+int(t) {
    if u.isInitWindowDecorated() && y < my+int(t) { // i.e. if decorated && y above the expected bottom of the title bar
        y = my + int(t)
    }
    return x, y
}

I am aware that if I use SetFullscreen then it can become a true fullscreen, but my usecase is around a transparent, click-pass-through, fullscreen overlay.

@hajimehoshi
Copy link
Owner

hajimehoshi commented Nov 17, 2024

I failed to reproduce this:

package main

import (
	"image/color"

	"github.com/hajimehoshi/ebiten/v2"
)

type Game struct {
}

func (g *Game) Update() error {
	if ebiten.IsKeyPressed(ebiten.KeyEscape) {
		return ebiten.Termination
	}
	return nil
}

func (g *Game) Draw(screen *ebiten.Image) {
	screen.Fill(color.RGBA{0x80, 0x80, 0x80, 0xff})
}

func (g *Game) Layout(width, height int) (int, int) {
	return width, height
}

func main() {
	ebiten.SetWindowDecorated(false)
	ebiten.SetWindowPosition(0, 0)
	ebiten.SetWindowSize(ebiten.Monitor().Size())
	if err := ebiten.RunGame(&Game{}); err != nil {
		panic(err)
	}
}

Could you show me a minimized code to reproduce your issue? Thanks,

@rdnt
Copy link
Author

rdnt commented Nov 17, 2024

Hi @hajimehoshi thanks for the quick response!

The example code you posted perfectly manages to reproduce the issue on my machine:
image

It has to be something setup-specific, I assume.

image

It wouldn't surprise me if this is a GPU thing, even. If I use a floating, transparent overlay at exactly the monitor's resolution, the GPU performs optimizations that remove the transparency, as if it's a full screen game of sorts.

So, for completeness:

Windows version: 11 (x64)
GPU: AMD 6900XT
CPU: AMD Ryzen 9 5900X

@hajimehoshi
Copy link
Owner

Hmm, that's pretty odd. In your machine, does u.window.GetAttrib(glfw.Decorated) in adjustWindowPosition return glfw.True, even though you call ebiten.SetWindowDecorated(false)?

@rdnt
Copy link
Author

rdnt commented Nov 17, 2024

u.window.GetAttrib(glfw.Decorated) called within adjustWindowPosition returns 0 <nil>.

@hajimehoshi
Copy link
Owner

hajimehoshi commented Nov 17, 2024

Thanks. In this case, didn't this return at the early return?

	if d == glfw.False {
		return x, y, nil
	}

I have found that if the isInitWindowDecorated check is added on the last lines of the adjustWindowPosition function, then the window is properly positioned.

I'm skeptical about this since this should not be reached.

@rdnt
Copy link
Author

rdnt commented Nov 17, 2024

Something like this?

func (u *UserInterface) adjustWindowPosition(x, y int, monitor *Monitor) (int, int) {
	if microsoftgdk.IsXbox() {
		return x, y
	}
	
	d, err := u.window.GetAttrib(glfw.Decorated)
	if err != nil {
		panic(err)
	}

	mx := monitor.boundsInGLFWPixels.Min.X
	my := monitor.boundsInGLFWPixels.Min.Y
	// As the video width/height might be wrong,
	// adjust x/y at least to enable to handle the window (#328)
	if x < mx {
		x = mx
	}
	t, err := _GetSystemMetrics(_SM_CYCAPTION)
	if err != nil {
		panic(err)
	}

	if d == glfw.False {
		return x, y
	}

	if y < my+int(t) {
		y = my + int(t)
	}

	return x, y
}

If yes then it properly renders in full screen on my machine.

Edit: I am not sure if the snippet you posted is existing code, if it is can you mention the file:line?

@hajimehoshi
Copy link
Owner

hajimehoshi commented Nov 17, 2024

Ah, I'm sorry but I was looking at the main branch, not the 2.8 branch. This means this was already fixed by 8b0c930

EDIT: What I was looking at was

// If a window is not decorated, the window should be able to reach the top of the screen (#3118).
d, err := u.window.GetAttrib(glfw.Decorated)
if err != nil {
return 0, 0, err
}
if d == glfw.False {
return x, y, nil
}

@hajimehoshi
Copy link
Owner

As there are multiple reports for the same issue, I'll cherry-pick the fix to 2.8. Let me close this issue later as a duplication with #3118.

hajimehoshi added a commit that referenced this issue Nov 17, 2024
@hajimehoshi hajimehoshi closed this as not planned Won't fix, can't repro, duplicate, stale Nov 17, 2024
@hajimehoshi
Copy link
Owner

hajimehoshi commented Nov 17, 2024

Please try

go get github.com/hajimehoshi/ebiten/v2@53090f31055ee868f1eb2f0c68860fbc4c6f3a2f

go get github.com/hajimehoshi/ebiten/v2@ec57d482f2d20d125def084d9fd982a2236df2b0

I'll tag v2.8.5 a few days later.

hajimehoshi added a commit that referenced this issue Nov 17, 2024
@rdnt
Copy link
Author

rdnt commented Nov 17, 2024

Can confirm the issue is no longer present on main. Lovely!
Apologies for having missed the original issue. Thanks for looking into it.

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

No branches or pull requests

2 participants