go-sdl2 icon indicating copy to clipboard operation
go-sdl2 copied to clipboard

Clicking outside window, minimizes the window

Open pouryatorabi opened this issue 5 years ago • 5 comments

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 avatar May 11 '19 11:05 pouryatorabi

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

pouryatorabi avatar May 11 '19 11:05 pouryatorabi

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]

veeableful avatar May 12 '19 16:05 veeableful

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?

pouryatorabi avatar May 13 '19 05:05 pouryatorabi

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?

veeableful avatar May 15 '19 15:05 veeableful

I have tested them all, no luck.

pouryatorabi avatar May 16 '19 06:05 pouryatorabi