From a43d5a13a8ccb45a30caf57d0eebe86c0204a0c4 Mon Sep 17 00:00:00 2001 From: sewn Date: Thu, 2 Nov 2023 14:48:39 +0300 Subject: [PATCH] minor changes --- cmd/vinegar/vinegar.go | 6 ++--- config/cardpick.go | 60 +++++++++++++++++++----------------------- config/env.go | 6 ++--- splash/dialog.go | 4 +-- splash/styles.go | 2 +- 5 files changed, 36 insertions(+), 42 deletions(-) diff --git a/cmd/vinegar/vinegar.go b/cmd/vinegar/vinegar.go index 7b6906e7..2dec0a45 100644 --- a/cmd/vinegar/vinegar.go +++ b/cmd/vinegar/vinegar.go @@ -144,8 +144,8 @@ func Sysinfo(pfx *wine.Prefix) { } fmt.Println("* Cards:") - for _, c := range sysinfo.Cards { - fmt.Printf(" * Card %d: %s %s\n", c.Index, c.Driver, c.Path) + for i, c := range sysinfo.Cards { + fmt.Printf(" * Card %d: %s %s\n", i, c.Driver, c.Path) } } @@ -180,7 +180,7 @@ func (b *Binary) Main(args ...string) { select {} // wait for window to close } - // Technically this is 'initializing wineprefix', as SetDPI calls Wine which + // Technically this is 'initializing wineprefix', as SetDPI calls Wine which // automatically create the Wineprefix. if _, err := os.Stat(filepath.Join(b.Prefix.Dir(), "drive_c", "windows")); err != nil { log.Printf("Initializing wineprefix at %s", b.Prefix.Dir()) diff --git a/config/cardpick.go b/config/cardpick.go index d1f7c9e5..644baa37 100644 --- a/config/cardpick.go +++ b/config/cardpick.go @@ -3,39 +3,43 @@ package config import ( "errors" "fmt" + "log" "strconv" - "strings" "github.com/vinegarhq/vinegar/sysinfo" ) -// opt accepts the following values: -// aliases - "integrated", "prime-discrete" and "none": Equivalent to "0", "1" or empty. Enables an extra "prime" check. -// integer - GPU index -// empty - Skips logic and does nothing. func (b *Binary) pickCard() error { - aliases := map[string]string{ - "integrated": "0", - "prime-discrete": "1", - "none": "", + if b.ForcedGpu == "" { + return nil } - var ( - aIdx string - prime bool - ) + n := len(sysinfo.Cards) + idx := -1 + prime := false + aliases := map[string]int{ + "integrated": 0, + "prime-discrete": 1, + } - aIdx = b.ForcedGpu - if a, ok := aliases[b.ForcedGpu]; ok { - aIdx = a + if i, ok := aliases[b.ForcedGpu]; ok { + idx = i prime = true + } else { + i, err := strconv.Atoi(b.ForcedGpu) + if err != nil { + return err + } + idx = i } - if aIdx == "" { - return nil + if idx < 0 { + return errors.New("gpu index cannot be negative") } - n := len(sysinfo.Cards) + if n < idx+1 { + return errors.New("gpu not found") + } // Check if the system actually has PRIME offload and there's no ambiguity with the GPUs. if prime { @@ -54,26 +58,16 @@ func (b *Binary) pickCard() error { } } - idx, err := strconv.Atoi(aIdx) - if err != nil { - return err - } - - if idx < 0 { - return errors.New("gpu index cannot be negative") - } - if n < idx+1 { - return errors.New("gpu not found") - } - c := sysinfo.Cards[idx] + log.Printf("Using Card index: %d", idx) b.Env.Set("MESA_VK_DEVICE_SELECT_FORCE_DEFAULT_DEVICE", "1") - b.Env.Set("DRI_PRIME", aIdx) + b.Env.Set("DRI_PRIME", strconv.Itoa(idx)) - if strings.HasSuffix(c.Driver, "nvidia") { // Workaround for OpenGL in nvidia GPUs + if sysinfo.Cards[idx].Driver == "nvidia" { // Workaround for OpenGL in nvidia GPUs b.Env.Set("__GLX_VENDOR_LIBRARY_NAME", "nvidia") } else { b.Env.Set("__GLX_VENDOR_LIBRARY_NAME", "mesa") } + return nil } diff --git a/config/env.go b/config/env.go index 193e79cb..92aaea57 100644 --- a/config/env.go +++ b/config/env.go @@ -6,7 +6,7 @@ import ( type Environment map[string]string -// Set will only set the given environment key and value +// Set will only set the given environment key and value // if it isn't already set within Environment. func (e Environment) Set(key, value string) { if _, ok := e[key]; ok { @@ -15,10 +15,10 @@ func (e Environment) Set(key, value string) { e[key] = value } -// Setenv will apply the environment's variables onto the +// Setenv will apply the environment's variables onto the // global environment using os.Setenv. func (e Environment) Setenv() { for name, value := range e { os.Setenv(name, value) } -} \ No newline at end of file +} diff --git a/splash/dialog.go b/splash/dialog.go index 2abe1a2e..5520f3c0 100644 --- a/splash/dialog.go +++ b/splash/dialog.go @@ -40,8 +40,8 @@ func (ui *Splash) Dialog(title, msg string) { layout.UniformInset(18).Layout(gtx, func(gtx C) D { return layout.Flex{ - Axis: layout.Vertical, - Spacing: layout.SpaceBetween, + Axis: layout.Vertical, + Spacing: layout.SpaceBetween, }.Layout(gtx, layout.Rigid(material.Body2(ui.Theme, title).Layout), layout.Rigid(material.Body2(ui.Theme, msg).Layout), diff --git a/splash/styles.go b/splash/styles.go index dc728618..c2c51a54 100644 --- a/splash/styles.go +++ b/splash/styles.go @@ -40,7 +40,7 @@ func (ui *Splash) drawCompact(gtx C) D { Right: unit.Dp(18), }.Layout(gtx, func(gtx C) D { return layout.Flex{ - Axis: layout.Vertical, + Axis: layout.Vertical, }.Layout(gtx, layout.Rigid(func(gtx C) D { return layout.Flex{