hajimehoshi / ebiten

Ebitengine - A dead simple 2D game engine for Go
https://ebitengine.org
Apache License 2.0
11.06k stars 662 forks source link

Undecorated windows are offset by an invisible margin #3162

Open rdnt opened 6 hours ago

rdnt commented 6 hours ago

Ebitengine Version

v2.8.4

Operating System

Go Version (go version)

go version go1.23.0 windows/amd64

What steps will reproduce the problem?

What is the expected result?

What happens instead?

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 commented 2 hours ago

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,