Skip to content

Commit

Permalink
Rework default dimensions for DPI Awareness on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
achhabra2 committed Jan 3, 2022
1 parent 0ee145f commit 56a5273
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 14 deletions.
2 changes: 1 addition & 1 deletion frontend/dist/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion frontend/dist/bundle.js.map

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions internal/settings/dimensions_darwin.go
@@ -0,0 +1,5 @@
package settings

func GetAppDefaultDimensions() (int, int) {
return 480, 400
}
42 changes: 42 additions & 0 deletions internal/settings/dimensions_windows.go
@@ -0,0 +1,42 @@
package settings

import (
"syscall"
)

var (
user32 = syscall.NewLazyDLL("User32.dll")
getSystemMetrics = user32.NewProc("GetSystemMetrics")
getDpiForSystem = user32.NewProc("GetDpiForSystem")
)

func GetSystemMetrics(nIndex int) int {
index := uintptr(nIndex)
ret, _, _ := getSystemMetrics.Call(index)
return int(ret)
}

func GetDpiForSystem() int {
ret, _, _ := getDpiForSystem.Call()
return int(ret)
}

const (
SM_CXSCREEN = 0
SM_CYSCREEN = 1
)

func GetResolution() (int, int) {
return GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)
}

func GetAppDefaultDimensions() (int, int) {
w := 528.0
h := 440.0
baseDpi := 96.0
currentDpi := float64(GetDpiForSystem())
scalingFactor := currentDpi / baseDpi
w2 := int(w * scalingFactor)
h2 := int(h * scalingFactor)
return w2, h2
}
13 changes: 1 addition & 12 deletions main.go
Expand Up @@ -6,7 +6,6 @@ import (
"log"
"os"
"path/filepath"
goruntime "runtime"

"github.com/wailsapp/wails/v2/pkg/options/mac"

Expand Down Expand Up @@ -47,7 +46,7 @@ func main() {
// Create an instance of the app structure
app := NewApp(loggerPath)

width, height := GetAppDefaultDimensions()
width, height := settings.GetAppDefaultDimensions()
// Create application with options
err := wails.Run(&options.App{
Title: "RiftShare",
Expand Down Expand Up @@ -96,13 +95,3 @@ func main() {
}
}

func GetAppDefaultDimensions() (int, int) {
switch goruntime.GOOS {
case "windows":
return 660, 550
case "darwin":
return 480, 400
default:
return 480, 400
}
}

0 comments on commit 56a5273

Please sign in to comment.