Skip to content

Commit

Permalink
Update scaling logic for OLED
Browse files Browse the repository at this point in the history
  • Loading branch information
CryoByte33 committed Nov 25, 2023
1 parent d642a6e commit 51d4d7d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 43 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ Scripts and utilities to improve performance and manage storage on the Steam Dec

## Update

### Notes on the Steam Deck OLED
The latest update resolves the scaling issues on the new OLED Deck, and I figured I should provide an update here:
1. **This (CU2) is still fully compatible with the new OLED models.**
2. Performance improvements should be similar (or possibly slightly better) than on the LCD model (thorough testing pending)

### General Linux Compatibility
As of the latest update, this _should_ be compatible with most Linux systems, with the following limitations:
1. This will not operate on swap partitions, only files.
Expand Down Expand Up @@ -55,7 +60,7 @@ new features and how they work.
* Storage Manager
* Sync shadercache and compatdata to the same location the game is installed
* Delete shadercache and compatdata for whichever games you select
* **NEW** Delete the shadercache and compatdata for all uninstalled games with a single click
* Delete the shadercache and compatdata for all uninstalled games with a single click
* Full CLI mode

Look below for common questions and answers, or go check out my [YouTube Channel](https://www.youtube.com/@cryobyte33)
Expand All @@ -66,7 +71,8 @@ for examples on how to use this and what performance you can expect.
### Simple

[Download this link](https://raw.githubusercontent.com/CryoByte33/steam-deck-utilities/main/InstallCryoUtilities.desktop)
to your desktop (right click and save file) on your Steam Deck, then double-click it.
to your desktop (right click and save file) on your Steam Deck, remove the `.download` from the end of the file name,
then double-click it.

This will install the program, create desktop icons, and create menu entries.

Expand Down
2 changes: 1 addition & 1 deletion internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

// CurrentVersionNumber Version number to build with, Fyne can't support build flags just yet.
var CurrentVersionNumber = "2.2.0"
var CurrentVersionNumber = "2.2.1"

// Get home Directory
var HomeDirectory, _ = os.UserHomeDir()
Expand Down
59 changes: 24 additions & 35 deletions internal/ui_screen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,15 @@

package internal

/*
#cgo LDFLAGS: -lX11
#include <X11/Xlib.h>
*/
import "C"
import (
"fmt"
"github.com/go-gl/glfw/v3.3/glfw"
"os"
)

const (
smallScreen = 1280
mediumScreen = 1920
)

const (
defaultSteamDeckScreenWidth = 1280
defaultSteamDeckScreenHeight = 800
smallScreenSize = 100
mediumScreenSize = 200
)

const scaleEnvKey = "FYNE_SCALE"
Expand All @@ -44,8 +35,8 @@ type ScreenSizer struct {
}

type screen struct {
name string
width, height int
name string
widthPhysical, heightPhysical int
}

func NewScreenSizer() *ScreenSizer {
Expand All @@ -54,40 +45,38 @@ func NewScreenSizer() *ScreenSizer {

func getDefaultScreen() screen {

display := C.XOpenDisplay(nil)
if display == nil {
CryoUtils.InfoLog.Println("Can't get info on display")
return screen{name: defaultScreenName, width: defaultSteamDeckScreenWidth, height: defaultSteamDeckScreenHeight}
}
defer C.XCloseDisplay(display)

displayScreen := C.XDefaultScreenOfDisplay(display)
displayScreenName := C.GoString(C.XDisplayString(display))
width := int(C.XWidthOfScreen(displayScreen))
height := int(C.XHeightOfScreen(displayScreen))
if width == 0 || height == 0 {
CryoUtils.InfoLog.Println("Default monitor not detected")
return screen{name: defaultScreenName, width: defaultSteamDeckScreenWidth, height: defaultSteamDeckScreenHeight}
var primaryScreen screen

err := glfw.Init()
if err != nil {
return defaultScreen()
}
return screen{displayScreenName, width, height}
defer glfw.Terminate()

monitor := glfw.GetPrimaryMonitor()
primaryScreen.name = monitor.GetName()
primaryScreen.widthPhysical, primaryScreen.heightPhysical = monitor.GetPhysicalSize()
return primaryScreen
}

func (s ScreenSizer) UpdateScaleForActiveMonitor() {
defaultScreen := getDefaultScreen()

if defaultScreen.width <= smallScreen {
if s.screen.widthPhysical <= smallScreenSize {
s.setScale(0.25)
} else if defaultScreen.width > smallScreen && defaultScreen.width <= mediumScreen {
} else if s.screen.widthPhysical > smallScreenSize && s.screen.widthPhysical <= mediumScreenSize {
s.setScale(0.75)
} else if s.screen.widthPhysical > mediumScreenSize {
s.setScale(1)
} else if defaultScreen.width > mediumScreen {
s.setScale(2)
}
}

func (s ScreenSizer) setScale(f float32) {
err := os.Setenv(scaleEnvKey, fmt.Sprintf("%f", f))
CryoUtils.InfoLog.Printf("Setting scale %f", f)
if err != nil {
CryoUtils.ErrorLog.Println(err)
}
}

func defaultScreen() screen {
return screen{name: defaultScreenName, widthPhysical: 60, heightPhysical: 100}
}
5 changes: 0 additions & 5 deletions launcher.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
#!/bin/bash
# Author: CryoByte33 and contributors to the CryoUtilities project

if [ "$(xrandr | grep -c ' connected')" -eq 1 ]; then
export FYNE_SCALE=0.25
fi

"$HOME/.cryo_utilities/cryo_utilities" gui

0 comments on commit 51d4d7d

Please sign in to comment.