Files
gio/app/internal/window/os_unix.go
T
Elias Naur 0181f22d01 app/internal/window: block Main until all windows are closed
With this change, the Wayland backend now supports multiple windows.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-16 11:01:19 +02:00

48 lines
1.0 KiB
Go

// SPDX-License-Identifier: Unlicense OR MIT
// +build linux,!android freebsd openbsd
package window
import (
"errors"
)
// windowCounter keeps track of the number of windows.
// A send of +1 or -1 represents a change in window count.
var windowCounter = make(chan int)
func Main() {
// Wait for first window
count := <-windowCounter
for count > 0 {
count += <-windowCounter
}
}
// instead of creating files with build tags for each combination of wayland +/- x11
// let each driver initialize these variables with their own version of createWindow.
var wlDriver, x11Driver func(Callbacks, *Options) error
func NewWindow(window Callbacks, opts *Options) error {
var errFirst, err error
if wlDriver != nil {
if err = wlDriver(window, opts); err == nil {
return nil
}
errFirst = err
}
if x11Driver != nil {
if err = x11Driver(window, opts); err == nil {
return nil
}
if errFirst == nil {
errFirst = err
}
}
if errFirst != nil {
return errFirst
}
return errors.New("app: no window driver available")
}