veandco / go-sdl2

SDL2 binding for Go
https://godoc.org/github.com/veandco/go-sdl2
BSD 3-Clause "New" or "Revised" License
2.21k stars 221 forks source link

Clicking outside window, minimizes the window #408

Open pouryatorabi opened 5 years ago

pouryatorabi commented 5 years ago

I have created a window in my secondary monitor, when I click in my Main monitor, the created window will minimize. This is my code:

sdl.Init(sdl.INIT_EVERYTHING)

Num,_ :=sdl.GetNumVideoDisplays()

var rect sdl.Rect

rect,_ = sdl.GetDisplayBounds(0)

winWidth,winHeight := 1920,1080

for i:=Num-1;i>=0;i--{
    Mod , _:=sdl.GetDisplayMode(i,0)
    if Mod.W ==int32(winWidth) && Mod.H==int32(winHeight){
        rect,_ = sdl.GetDisplayBounds(i)
        break
    }
}

window, _ := sdl.CreateWindow("Title", rect.X, rect.Y,rect.W, rect.H, sdl.WINDOW_FULLSCREEN)
window.SetBordered(false)
window.SetFullscreen(1)
renderer, _ := sdl.CreateRenderer(window, -1, sdl.RENDERER_ACCELERATED)

renderer.Clear()
renderer.SetDrawColor(0, 0, 0, 255)
renderer.FillRect(&sdl.Rect{0, 0, int32(winWidth), int32(winHeight)})
renderer.Present()

sdl.ShowCursor(0)

for{
    time.Sleep(time.Millisecond*30)
    for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
        fmt.Println(event)
        switch event.(type) {
        case *sdl.QuitEvent:
            fmt.Println("Quit")
            //info.Running = false
        case *sdl.MouseButtonEvent:
            fmt.Println("Mouse")
        }
    }
}
pouryatorabi commented 5 years ago

If I omit the pollevent loop, it won't minimize but my mouse cursor would show a busy indicator, only on windows.

veeableful commented 5 years ago

Hi @pouryatorabi, have you tried setting SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS environment variable to 0?

For example, could you try running the following command and see if it still minimize?

SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS=0 [the program]

pouryatorabi commented 5 years ago

I just made an environmental variable, SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS, and put the value to 0. I tested again but still have problem. Another thing bothering me is that if I don't handle the events, my mouse cursor would show a busy indicator in Windows, but I don't have this problem on Ubuntu, is there anyway to solve it?

veeableful commented 5 years ago

Hmm I see. Perhaps it only works on Linux. Have you tried using sdl.WINDOW_FULLSCREEN_DESKTOP instead of sdl.WINDOW_FULLSCREEN in your sdl.CreateWindow() function?

pouryatorabi commented 5 years ago

I have tested them all, no luck.