diff --git a/backends/x/event.go b/backends/x/event.go index 3ef6e74..d170a43 100644 --- a/backends/x/event.go +++ b/backends/x/event.go @@ -12,7 +12,7 @@ func (backend *Backend) Run () { backend.callbackManager.RunStart() backend.Draw() xevent.Main(backend.connection) - backend.shutDown() + backend.callbackManager.RunQuit() } func (backend *Backend) handleConfigureNotify ( @@ -125,7 +125,3 @@ func (backend *Backend) compressConfigureNotify ( return } - -func (backend *Backend) shutDown () { - backend.callbackManager.RunQuit() -} diff --git a/backends/x/factory.go b/backends/x/factory.go index dfd7ce7..bf0728b 100644 --- a/backends/x/factory.go +++ b/backends/x/factory.go @@ -115,7 +115,7 @@ func factory ( // attatch graceful close handler backend.window.WMGracefulClose (func (window *xwindow.Window) { backend.window.Destroy() - backend.shutDown() + xevent.Quit(backend.connection) }) // attatch event handlers diff --git a/examples/color/main.go b/examples/color/main.go index 2c84fbc..fab929b 100644 --- a/examples/color/main.go +++ b/examples/color/main.go @@ -10,7 +10,7 @@ import _ "git.tebibyte.media/sashakoshka/stone/backends/x" var application = &stone.Application { } func main () { - application.SetTitle("hellorld") + application.SetTitle("color demo") application.SetSize(12, 7) iconFile16, err := os.Open("assets/scaffold16.png") @@ -26,21 +26,19 @@ func main () { application.SetIcon([]image.Image { icon16, icon32 }) - channel, err := application.Run() - if err != nil { panic(err) } + application.OnStart(onStart) + application.OnResize(onResize) + err = application.Run() + if err != nil { panic(err) } +} + +func onStart () { redraw() +} - for { - event := <- channel - switch event.(type) { - case stone.EventQuit: - os.Exit(0) - - case stone.EventResize: - redraw() - } - } +func onResize () { + redraw() } func redraw () { @@ -69,6 +67,4 @@ func redraw () { application.SetRune(x, height - 1, '=') application.SetColor(x, height - 1, stone.ColorRed) } - - application.Draw() } diff --git a/examples/draw/main.go b/examples/draw/main.go index 98d3fee..3bab734 100644 --- a/examples/draw/main.go +++ b/examples/draw/main.go @@ -29,7 +29,6 @@ func main () { application.OnPress(onPress) application.OnRelease(onRelease) application.OnMouseMove(onMouseMove) - application.OnQuit(onQuit) err = application.Run() if err != nil { panic(err) } @@ -56,7 +55,3 @@ func onMouseMove (x, y int) { if mousePressed { application.Draw() } } - -func onQuit () { - os.Exit(0) -} diff --git a/examples/hello/main.go b/examples/hello/main.go index 896a779..1df4772 100644 --- a/examples/hello/main.go +++ b/examples/hello/main.go @@ -10,7 +10,6 @@ import _ "git.tebibyte.media/sashakoshka/stone/backends/x" var application = &stone.Application { } var currentTime = time.Time { } -var tickPing = make(chan(struct { })) func main () { application.SetTitle("hellorld") @@ -29,27 +28,20 @@ func main () { application.SetIcon([]image.Image { icon16, icon32 }) - channel, err := application.Run() - if err != nil { panic(err) } + application.OnStart(onStart) + application.OnResize(onResize) + err = application.Run() + if err != nil { panic(err) } +} + +func onStart () { redraw() go tick() +} - for { - select { - case <- tickPing: - redraw() - - case event := <- channel: - switch event.(type) { - case stone.EventQuit: - os.Exit(0) - - case stone.EventResize: - redraw() - } - } - } +func onResize () { + redraw() } func redraw () { @@ -70,13 +62,12 @@ func redraw () { application.SetRune(5, 1, ':') application.SetRune(6, 1, rune(second / 10 + 48)) application.SetRune(7, 1, rune(second % 10 + 48)) - - application.Draw() } func tick () { for { - tickPing <- struct { } { } + redraw() + application.Draw() time.Sleep(time.Second) } }