From 2910c768eb036ca38ff3c12b35144c694ddc13bf Mon Sep 17 00:00:00 2001 From: gucio321 Date: Sun, 1 Oct 2023 15:20:21 +0200 Subject: [PATCH 1/3] change mainthread library should fix #700 because it fixes mainthread handling for macos --- Context.go | 2 -- MasterWindow.go | 4 ++-- go.mod | 3 ++- go.sum | 7 +++++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Context.go b/Context.go index ee4e7ce5..7cde56da 100644 --- a/Context.go +++ b/Context.go @@ -30,8 +30,6 @@ type state struct { type context struct { backend imgui.Backend[imgui.GLFWWindowFlags] - // TODO: should be handled by mainthread tbh - // see https://github.com/faiface/mainthread/pull/4 isRunning bool widgetIndexCounter int diff --git a/MasterWindow.go b/MasterWindow.go index 08f6831b..f513e602 100644 --- a/MasterWindow.go +++ b/MasterWindow.go @@ -6,7 +6,7 @@ import ( "runtime" imgui "github.com/AllenDang/cimgui-go" - "github.com/faiface/mainthread" + "golang.design/x/hotkey/mainthread" "golang.org/x/image/colornames" ) @@ -230,7 +230,7 @@ func (w *MasterWindow) render() { // Run should be called at the end of main function, after setting // up the master window. func (w *MasterWindow) Run(loopFunc func()) { - mainthread.Run(func() { + mainthread.Init(func() { Context.isRunning = true w.updateFunc = loopFunc diff --git a/go.mod b/go.mod index 748b6c78..5be31749 100644 --- a/go.mod +++ b/go.mod @@ -5,12 +5,12 @@ go 1.21 require ( github.com/AllenDang/cimgui-go v0.0.0-20230918114712-675654f053d9 github.com/AllenDang/go-findfont v0.0.0-20200702051237-9f180485aeb8 - github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3 github.com/mazznoer/csscolorparser v0.1.3 github.com/napsy/go-css v0.0.0-20221107082635-4ed403047a64 github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 github.com/sahilm/fuzzy v0.1.0 github.com/stretchr/testify v1.8.4 + golang.design/x/hotkey v0.4.1 golang.org/x/image v0.12.0 gopkg.in/eapache/queue.v1 v1.1.0 ) @@ -19,6 +19,7 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/kylelemons/godebug v1.1.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + golang.design/x/mainthread v0.3.0 // indirect golang.org/x/sys v0.5.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index b7763ca1..7c3096ac 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,6 @@ github.com/AllenDang/go-findfont v0.0.0-20200702051237-9f180485aeb8 h1:dKZMqib/y github.com/AllenDang/go-findfont v0.0.0-20200702051237-9f180485aeb8/go.mod h1:b4uuDd0s6KRIPa84cEEchdQ9ICh7K0OryZHbSzMca9k= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3 h1:baVdMKlASEHrj19iqjARrPbaRisD7EuZEVJj6ZMLl1Q= -github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3/go.mod h1:VEPNJUlxl5KdWjDvz6Q1l+rJlxF2i6xqDeGuGAxa87M= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/mazznoer/csscolorparser v0.1.3 h1:vug4zh6loQxAUxfU1DZEu70gTPufDPspamZlHAkKcxE= @@ -21,6 +19,10 @@ github.com/sahilm/fuzzy v0.1.0/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8 github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +golang.design/x/hotkey v0.4.1 h1:zLP/2Pztl4WjyxURdW84GoZ5LUrr6hr69CzJFJ5U1go= +golang.design/x/hotkey v0.4.1/go.mod h1:M8SGcwFYHnKRa83FpTFQoZvPO5vVT+kWPztFqTQKmXA= +golang.design/x/mainthread v0.3.0 h1:UwFus0lcPodNpMOGoQMe87jSFwbSsEY//CA7yVmu4j8= +golang.design/x/mainthread v0.3.0/go.mod h1:vYX7cF2b3pTJMGM/hc13NmN6kblKnf4/IyvHeu259L0= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/image v0.12.0 h1:w13vZbU4o5rKOFFR8y7M+c4A5jXDC0uXTdHYRP8X2DQ= @@ -35,6 +37,7 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201022201747-fb209a7c41cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= From ae9753deabf5327af0882646e5eb482756ee6699 Mon Sep 17 00:00:00 2001 From: gucio321 Date: Wed, 18 Oct 2023 23:28:17 +0200 Subject: [PATCH 2/3] mainthread: use build constraints to choose right mainthread library --- MasterWindow.go | 3 +-- go.mod | 1 + go.sum | 2 ++ mainthread_all.go | 10 ++++++++++ mainthread_mac.go | 10 ++++++++++ 5 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 mainthread_all.go create mode 100644 mainthread_mac.go diff --git a/MasterWindow.go b/MasterWindow.go index f513e602..4fbc1b26 100644 --- a/MasterWindow.go +++ b/MasterWindow.go @@ -6,7 +6,6 @@ import ( "runtime" imgui "github.com/AllenDang/cimgui-go" - "golang.design/x/hotkey/mainthread" "golang.org/x/image/colornames" ) @@ -230,7 +229,7 @@ func (w *MasterWindow) render() { // Run should be called at the end of main function, after setting // up the master window. func (w *MasterWindow) Run(loopFunc func()) { - mainthread.Init(func() { + mainthreadCallPlatform(func() { Context.isRunning = true w.updateFunc = loopFunc diff --git a/go.mod b/go.mod index 5be31749..e7935269 100644 --- a/go.mod +++ b/go.mod @@ -17,6 +17,7 @@ require ( require ( github.com/davecgh/go-spew v1.1.1 // indirect + github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3 // indirect github.com/kylelemons/godebug v1.1.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect golang.design/x/mainthread v0.3.0 // indirect diff --git a/go.sum b/go.sum index 7c3096ac..5ab061f5 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ github.com/AllenDang/go-findfont v0.0.0-20200702051237-9f180485aeb8 h1:dKZMqib/y github.com/AllenDang/go-findfont v0.0.0-20200702051237-9f180485aeb8/go.mod h1:b4uuDd0s6KRIPa84cEEchdQ9ICh7K0OryZHbSzMca9k= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3 h1:baVdMKlASEHrj19iqjARrPbaRisD7EuZEVJj6ZMLl1Q= +github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3/go.mod h1:VEPNJUlxl5KdWjDvz6Q1l+rJlxF2i6xqDeGuGAxa87M= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/mazznoer/csscolorparser v0.1.3 h1:vug4zh6loQxAUxfU1DZEu70gTPufDPspamZlHAkKcxE= diff --git a/mainthread_all.go b/mainthread_all.go new file mode 100644 index 00000000..d6f2233d --- /dev/null +++ b/mainthread_all.go @@ -0,0 +1,10 @@ +//go:build !darwin +// +build !darwin + +package giu + +import "github.com/faiface/mainthread" + +func mainthreadCallPlatform(c func()) { + mainthread.Run(c) +} diff --git a/mainthread_mac.go b/mainthread_mac.go new file mode 100644 index 00000000..14448510 --- /dev/null +++ b/mainthread_mac.go @@ -0,0 +1,10 @@ +//go:build darwin +// +build darwin + +package giu + +import "golang.design/x/hotkey/mainthread" + +func mainthreadCall(c func()) { + mainthread.init(c) +} From 43f2cca1f4587076b7d2a09aecf25bc542d8bb37 Mon Sep 17 00:00:00 2001 From: gucio321 Date: Wed, 18 Oct 2023 23:43:15 +0200 Subject: [PATCH 3/3] macos: use right function name --- mainthread_mac.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mainthread_mac.go b/mainthread_mac.go index 14448510..793dd76f 100644 --- a/mainthread_mac.go +++ b/mainthread_mac.go @@ -5,6 +5,6 @@ package giu import "golang.design/x/hotkey/mainthread" -func mainthreadCall(c func()) { - mainthread.init(c) +func mainthreadCallPlatform(c func()) { + mainthread.Call(c) }