generated from SteamDeckHomebrew/decky-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.py
82 lines (56 loc) · 2.5 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"""
vibrantDeck - Adjust color vibrancy of Steam Deck output
Copyright (C) 2022,2023 Sefa Eyeoglu <[email protected]> (https://scrumplex.net)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import os
import sys
import struct
import subprocess
from typing import Iterable
# Takes 0.0..1.0, 0.5 being sRGB 0.5..1.0 being "boosted"
SDR_GAMUT_PROP = "GAMESCOPE_COLOR_SDR_GAMUT_WIDENESS"
def float_to_long(x: float) -> int:
return struct.unpack("!I", struct.pack("!f", x))[0]
def long_to_float(x: int) -> float:
return struct.unpack("!f", struct.pack("!I", x))[0]
def set_cardinal_prop(prop_name: str, values: Iterable[int]):
param = ",".join(map(str, values))
command = ["xprop", "-root", "-f", prop_name,
"32c", "-set", prop_name, param]
if "DISPLAY" not in os.environ:
command.insert(1, ":1")
command.insert(1, "-display")
completed = subprocess.run(command, stderr=sys.stderr, stdout=sys.stdout)
return completed.returncode == 0
class Plugin:
async def set_vibrancy(self, vibrancy: float):
vibrancy = max(vibrancy, 0.0)
vibrancy = min(vibrancy, 1.0)
return set_cardinal_prop(SDR_GAMUT_PROP, [float_to_long(vibrancy)])
async def get_vibrancy(self) -> float:
command = ["xprop", "-root", SDR_GAMUT_PROP]
if "DISPLAY" not in os.environ:
command.insert(1, ":1")
command.insert(1, "-display")
completed = subprocess.run(command, capture_output=True)
stdout = completed.stdout.decode("utf-8")
# Good output: "GAMESCOPE_COLOR_SDR_GAMUT_WIDENESS(CARDINAL) = 1065353216"
# Bad output: "GAMESCOPE_COLOR_SDR_GAMUT_WIDENESS: not found."
if "=" in stdout:
# "1065353216"
wideness_param = stdout.split("=")[1]
# 1065353216
wideness_param = int(wideness_param)
# 1.0
return round(long_to_float(wideness_param), 2)
return 1.0