Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
apprehensions committed Nov 2, 2023
1 parent 3305de5 commit a43d5a1
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 42 deletions.
6 changes: 3 additions & 3 deletions cmd/vinegar/vinegar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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())
Expand Down
60 changes: 27 additions & 33 deletions config/cardpick.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
6 changes: 3 additions & 3 deletions config/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
}
}
4 changes: 2 additions & 2 deletions splash/dialog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion splash/styles.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit a43d5a1

Please sign in to comment.