Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Gamescope toggle as an override for individual programs #3572

Merged
merged 5 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bottles/backend/managers/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ def get_programs(self, config: BottleConfig) -> List[dict]:
"vkd3d": _program.get("vkd3d"),
"dxvk_nvapi": _program.get("dxvk_nvapi"),
"fsr": _program.get("fsr"),
"gamescope": _program.get("gamescope"),
"pulseaudio_latency": _program.get("pulseaudio_latency"),
"virtual_desktop": _program.get("virtual_desktop"),
"removed": _program.get("removed"),
Expand Down
1 change: 1 addition & 0 deletions bottles/backend/models/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Samples:
"WINE_FULLSCREEN_FSR": ("fsr", True),
"WINE_FULLSCREEN_FSR_STRENGTH": ("fsr_sharpening_strength", 2),
"WINE_FULLSCREEN_FSR_MODE": ("fsr_quality_mode", "none"),
"GAMESCOPE": ("gamescope", False),
"DRI_PRIME": ("discrete_gpu", True),
"__NV_PRIME_RENDER_OFFLOAD": ("discrete_gpu", True),
"PULSE_LATENCY_MSEC": ("pulseaudio_latency", True),
Expand Down
6 changes: 6 additions & 0 deletions bottles/backend/wine/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def __init__(
program_vkd3d: Optional[bool] = None,
program_nvapi: Optional[bool] = None,
program_fsr: Optional[bool] = None,
program_gamescope: Optional[bool] = None,
program_virt_desktop: Optional[bool] = None,
):
logging.info("Launching an executable…")
Expand All @@ -64,6 +65,7 @@ def __init__(
self.pre_script = pre_script
self.post_script = post_script
self.monitoring = monitoring
self.use_gamescope = program_gamescope
self.use_virt_desktop = program_virt_desktop

env_dll_overrides = []
Expand Down Expand Up @@ -95,6 +97,9 @@ def __init__(
self.environment["WINE_FULLSCREEN_FSR_MODE"] = str(
self.config.Parameters.fsr_quality_mode
)

if program_gamescope is not None and program_gamescope != self.config.Parameters.gamescope:
self.environment["GAMESCOPE"] = "1" if program_gamescope else "0"

if env_dll_overrides:
if "WINEDLLOVERRIDES" in self.environment:
Expand All @@ -121,6 +126,7 @@ def run_program(cls, config: BottleConfig, program: dict, terminal: bool = False
program_vkd3d=program.get("vkd3d"),
program_nvapi=program.get("dxvk_nvapi"),
program_fsr=program.get("fsr"),
program_gamescope=program.get("gamescope"),
program_virt_desktop=program.get("virtual_desktop"),
).run()

Expand Down
12 changes: 8 additions & 4 deletions bottles/backend/wine/winecommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ def __init__(
self.arguments = arguments
self.cwd = self._get_cwd(cwd)
self.runner, self.runner_runtime = self._get_runner_info()
self.gamescope_activated = (
environment["GAMESCOPE"] == "1" if "GAMESCOPE" in environment
else self.config.Parameters.gamescope
)
mirkobrombin marked this conversation as resolved.
Show resolved Hide resolved
self.command = self.get_cmd(
command, pre_script, post_script, environment=_environment
)
Expand Down Expand Up @@ -330,7 +334,7 @@ def get_env(
if (
params.mangohud
and not self.minimal
and not (gamescope_available and params.gamescope)
and not (gamescope_available and self.gamescope_activated)
):
env.add("MANGOHUD", "1")
env.add("MANGOHUD_DLSYM", "1")
Expand Down Expand Up @@ -506,13 +510,13 @@ def get_cmd(
else:
command = f"gamemode {command}"

if mangohud_available and params.mangohud and not params.gamescope:
if mangohud_available and params.mangohud and not self.gamescope_activated:
if not return_steam_cmd:
command = f"{mangohud_available} {command}"
else:
command = f"mangohud {command}"

if gamescope_available and params.gamescope:
if gamescope_available and self.gamescope_activated:
gamescope_run = tempfile.NamedTemporaryFile(mode="w", suffix=".sh").name

# Create temporary sh script in /tmp where Gamescope will execute it
Expand Down Expand Up @@ -603,7 +607,7 @@ def _get_gamescope_cmd(self, return_steam_cmd: bool = False) -> str:
params = config.Parameters
gamescope_cmd = []

if gamescope_available and params.gamescope:
if gamescope_available and self.gamescope_activated:
gamescope_cmd = [gamescope_available]
if return_steam_cmd:
gamescope_cmd = ["gamescope"]
Expand Down
3 changes: 3 additions & 0 deletions bottles/frontend/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@ def run_program(self):
_program_vkd3d = None
_program_dxvk_nvapi = None
_program_fsr = None
_program_gamescope = None
_program_virt_desktop = None

mng = Manager(g_settings=self.settings, is_cli=True)
Expand Down Expand Up @@ -682,6 +683,7 @@ def run_program(self):
_program_vkd3d = program.get("vkd3d")
_program_dxvk_nvapi = program.get("dxvk_nvapi")
_program_fsr = program.get("fsr")
_program_gamescope = program.get("gamescope")
_program_virt_desktop = program.get("virtual_desktop")

_executable = _executable.replace("file://", "")
Expand All @@ -701,6 +703,7 @@ def run_program(self):
program_vkd3d=_program_vkd3d,
program_nvapi=_program_dxvk_nvapi,
program_fsr=_program_fsr,
program_gamescope=_program_gamescope,
program_virt_desktop=_program_virt_desktop,
).run_cli()

Expand Down
9 changes: 9 additions & 0 deletions bottles/frontend/ui/dialog-launch-options.blp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,15 @@ template LaunchOptionsDialog : .AdwWindow {
}
}

.AdwActionRow action_gamescope {
title: _("Gamescope");
activatable-widget: "switch_gamescope";

Switch switch_gamescope {
valign: center;
}
}

.AdwActionRow action_virt_desktop {
title: _("Virtual Desktop");
activatable-widget: "switch_virt_desktop";
Expand Down
15 changes: 15 additions & 0 deletions bottles/frontend/windows/launchoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ class LaunchOptionsDialog(Adw.Window):
switch_vkd3d = Gtk.Template.Child()
switch_nvapi = Gtk.Template.Child()
switch_fsr = Gtk.Template.Child()
switch_gamescope = Gtk.Template.Child()
switch_virt_desktop = Gtk.Template.Child()
action_dxvk = Gtk.Template.Child()
action_vkd3d = Gtk.Template.Child()
action_nvapi = Gtk.Template.Child()
action_fsr = Gtk.Template.Child()
action_gamescope = Gtk.Template.Child()
action_cwd = Gtk.Template.Child()
action_virt_desktop = Gtk.Template.Child()
# endregion
Expand Down Expand Up @@ -95,6 +97,7 @@ def __init__(self, parent, config, program, **kwargs):
self.toggled["vkd3d"] = False
self.toggled["dxvk_nvapi"] = False
self.toggled["fsr"] = False
self.toggled["gamescope"] = False
self.toggled["virtual_desktop"] = False

# connect signals
Expand All @@ -113,6 +116,7 @@ def __init__(self, parent, config, program, **kwargs):
self.global_vkd3d = program_vkd3d = config.Parameters.vkd3d
self.global_nvapi = program_nvapi = config.Parameters.dxvk_nvapi
self.global_fsr = program_fsr = config.Parameters.fsr
self.global_gamescope = program_gamescope = config.Parameters.gamescope
self.global_virt_desktop = program_virt_desktop = (
config.Parameters.virtual_desktop
)
Expand All @@ -129,6 +133,9 @@ def __init__(self, parent, config, program, **kwargs):
if self.program.get("fsr") is not None:
program_fsr = self.program.get("fsr")
self.action_fsr.set_subtitle(self.__msg_override)
if self.program.get("gamescope") is not None:
program_gamescope = self.program.get("gamescope")
self.action_gamescope.set_subtitle(self.__msg_override)
if self.program.get("virtual_desktop") is not None:
program_virt_desktop = self.program.get("virtual_desktop")
self.action_virt_desktop.set_subtitle(self.__msg_override)
Expand All @@ -137,6 +144,7 @@ def __init__(self, parent, config, program, **kwargs):
self.switch_vkd3d.set_active(program_vkd3d)
self.switch_nvapi.set_active(program_nvapi)
self.switch_fsr.set_active(program_fsr)
self.switch_gamescope.set_active(program_gamescope)
self.switch_virt_desktop.set_active(program_virt_desktop)

self.switch_dxvk.connect(
Expand All @@ -151,6 +159,9 @@ def __init__(self, parent, config, program, **kwargs):
self.switch_fsr.connect(
"state-set", self.__check_override, self.action_fsr, "fsr"
)
self.switch_gamescope.connect(
"state-set", self.__check_override, self.action_gamescope, "gamescope"
)
self.switch_virt_desktop.connect(
"state-set",
self.__check_override,
Expand Down Expand Up @@ -195,12 +206,14 @@ def __idle_save(self, *_args):
program_vkd3d = self.switch_vkd3d.get_state()
program_nvapi = self.switch_nvapi.get_state()
program_fsr = self.switch_fsr.get_state()
program_gamescope = self.switch_gamescope.get_state()
program_virt_desktop = self.switch_virt_desktop.get_state()

self.__set_override("dxvk", program_dxvk, self.global_dxvk)
self.__set_override("vkd3d", program_vkd3d, self.global_vkd3d)
self.__set_override("dxvk_nvapi", program_nvapi, self.global_nvapi)
self.__set_override("fsr", program_fsr, self.global_fsr)
self.__set_override("gamescope", program_gamescope, self.global_gamescope)
self.__set_override(
"virtual_desktop", program_virt_desktop, self.global_virt_desktop
)
Expand Down Expand Up @@ -331,11 +344,13 @@ def __reset_defaults(self, *_args):
self.switch_vkd3d.set_active(self.global_vkd3d)
self.switch_nvapi.set_active(self.global_nvapi)
self.switch_fsr.set_active(self.global_fsr)
self.switch_gamescope.set_active(self.global_gamescope)
self.switch_virt_desktop.set_active(self.global_virt_desktop)
self.action_dxvk.set_subtitle("")
self.action_vkd3d.set_subtitle("")
self.action_nvapi.set_subtitle("")
self.action_fsr.set_subtitle("")
self.action_gamescope.set_subtitle("")
self.action_virt_desktop.set_subtitle("")
self.__set_disabled_switches()
for name in self.toggled:
Expand Down
Loading