Skip to content

Commit

Permalink
fix(LaunchManager): disable STEAM_OVERLAY while game is running and o…
Browse files Browse the repository at this point in the history
…verlay is not focused for performance-sensitive devices
  • Loading branch information
ShadowApex authored and Derek J. Clark committed Mar 6, 2024
1 parent bf35e11 commit 65f51fb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 49 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ deploy-ext: dist-ext ## Build and deploy systemd extension to remote device
.PHONY: enable-debug
enable-debug: ## Set OpenGamepadUI command to use remote debug on target device
ssh $(SSH_USER)@$(SSH_HOST) mkdir -p .config/environment.d
echo 'OGUICMD="opengamepadui --remote-debug tcp://127.0.0.1:6007"' | \
echo 'CLIENTCMD="opengamepadui --remote-debug tcp://127.0.0.1:6007"' | \
ssh $(SSH_USER)@$(SSH_HOST) bash -c \
'cat > .config/environment.d/opengamepadui-session.conf'

Expand Down
64 changes: 16 additions & 48 deletions core/global/launch_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -80,34 +80,8 @@ func _init() -> void:
if not should_manage_overlay:
return

# Check to see if the overlay property needs updating
var focusable_apps := Gamescope.get_focusable_apps()
if _should_set_overlay(focusable_apps):
var ogui_window_id = Gamescope.get_window_id(PID, Gamescope.XWAYLAND.OGUI)
Gamescope.set_overlay(ogui_window_id, 1)
return

Gamescope.focused_window_updated.connect(on_focus_changed)

# Ensure that the overlay property is set when other apps are launched.
var on_focusable_apps_changed := func(from: PackedInt32Array, to: PackedInt32Array):
# If we don't want LaunchManager to manage overlay (I.E. overlay mode), return false always.
if not should_manage_overlay:
return

# Check to see if the overlay property needs updating
logger.debug("Apps changed from " + str(from) + " to " + str(to))
var ogui_window_id = Gamescope.get_window_id(PID, Gamescope.XWAYLAND.OGUI)
if _should_set_overlay(to):
logger.debug("Other focusable apps exist. Enabling STEAM_OVERLAY.")
Gamescope.set_overlay(ogui_window_id, 1)
return

logger.debug("No other focusable apps. Removing STEAM_OVERLAY.")
Gamescope.set_overlay(ogui_window_id, 0)

Gamescope.focusable_apps_updated.connect(on_focusable_apps_changed)

# Debug print when the focused app changed
var on_focused_app_changed := func(from: int, to: int) -> void:
logger.debug("Focused app changed from " + str(from) + " to " + str(to))
Expand All @@ -118,31 +92,25 @@ func _init() -> void:
if _current_app:
set_app_gamepad_profile(_current_app)

in_game_state.state_entered.connect(on_game_state_entered)


# Returns true if the 'STEAM_OVERLAY' prop should be set. This property should
# ALWAYS be set to '1' if there are any other windows/apps. Only when OGUI
# is the last remaining app should it be disabled.
func _should_set_overlay(focusable_apps: PackedInt32Array) -> bool:
# If there are no focusable apps, then the overlay property should be disabled.
if focusable_apps.size() == 0:
return false

var ogui_window_id = Gamescope.get_window_id(PID, Gamescope.XWAYLAND.OGUI)
var focused_window := Gamescope.get_focused_window()
# If we don't want LaunchManager to manage overlay (I.E. overlay mode), return false always.
if not should_manage_overlay:
return

# If the focused app is 769 (Steam), but its window is different, overlay should be enabled.
# This means that Steam was launched and is focused.
if focusable_apps.size() == 1 and focusable_apps[0] == Gamescope.OVERLAY_GAME_ID and focused_window != ogui_window_id:
logger.debug("Steam appears to be focused.")
return true
logger.debug("Enabling STEAM_OVERLAY.")
var ogui_window_id = Gamescope.get_window_id(PID, Gamescope.XWAYLAND.OGUI)
Gamescope.set_overlay(ogui_window_id, 0)

var on_game_state_exited := func(_to: State):
# If we don't want LaunchManager to manage overlay (I.E. overlay mode), return false always.
if not should_manage_overlay:
return

# If OGUI is the only focused and remaining app, overlay should be disabled.
if focusable_apps.size() == 1 and focusable_apps[0] == Gamescope.OVERLAY_GAME_ID and focused_window == ogui_window_id:
return false
logger.debug("Removing STEAM_OVERLAY.")
var ogui_window_id = Gamescope.get_window_id(PID, Gamescope.XWAYLAND.OGUI)
Gamescope.set_overlay(ogui_window_id, 1)

return true
in_game_state.state_entered.connect(on_game_state_entered)
in_game_state.state_exited.connect(on_game_state_exited)


# Loads persistent data like recent games launched, etc.
Expand Down

0 comments on commit 65f51fb

Please sign in to comment.