mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 18:05:35 +00:00
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>
This commit is contained in:
@@ -8,10 +8,16 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
var mainDone = make(chan struct{})
|
// 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() {
|
func Main() {
|
||||||
<-mainDone
|
// Wait for first window
|
||||||
|
count := <-windowCounter
|
||||||
|
for count > 0 {
|
||||||
|
count += <-windowCounter
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// instead of creating files with build tags for each combination of wayland +/- x11
|
// instead of creating files with build tags for each combination of wayland +/- x11
|
||||||
|
|||||||
@@ -179,13 +179,18 @@ func newWLWindow(window Callbacks, opts *Options) error {
|
|||||||
d.destroy()
|
d.destroy()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// Increment window counter.
|
||||||
|
windowCounter <- +1
|
||||||
w.w = window
|
w.w = window
|
||||||
go func() {
|
go func() {
|
||||||
|
defer func() {
|
||||||
|
// Decrement window counter.
|
||||||
|
windowCounter <- -1
|
||||||
|
}()
|
||||||
w.w.SetDriver(w)
|
w.w.SetDriver(w)
|
||||||
w.loop()
|
w.loop()
|
||||||
w.destroy()
|
w.destroy()
|
||||||
d.destroy()
|
d.destroy()
|
||||||
close(mainDone)
|
|
||||||
}()
|
}()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -422,12 +422,16 @@ func newX11Window(gioWin Callbacks, opts *Options) error {
|
|||||||
// make the window visible on the screen
|
// make the window visible on the screen
|
||||||
C.XMapWindow(dpy, win)
|
C.XMapWindow(dpy, win)
|
||||||
|
|
||||||
|
// Increment window counter.
|
||||||
|
windowCounter <- +1
|
||||||
go func() {
|
go func() {
|
||||||
|
defer func() {
|
||||||
|
windowCounter <- -1
|
||||||
|
}()
|
||||||
w.w.SetDriver(w)
|
w.w.SetDriver(w)
|
||||||
w.setStage(system.StageRunning)
|
w.setStage(system.StageRunning)
|
||||||
w.loop()
|
w.loop()
|
||||||
w.destroy()
|
w.destroy()
|
||||||
close(mainDone)
|
|
||||||
}()
|
}()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user