Skip to content

Commit

Permalink
fix(Overlay Mode): Focus and Profile Fixes
Browse files Browse the repository at this point in the history
- Fix bug where an app type couldn't be detected if it was started by Steam.
- Only change Steam overlay status if it was the overlay.
- Also ignore window ID 1, Chimera App sets Steam to this for some reason.
  • Loading branch information
pastaq committed Dec 21, 2024
1 parent 9d825ab commit 9fd0fc9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
11 changes: 6 additions & 5 deletions core/global/launch_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var _persist_path: String = "/".join([_data_dir, "launcher.json"])
var _persist_data: Dictionary = {"version": 1}
var _ogui_window_id := 0
var should_manage_overlay := true
var logger := Log.get_logger("LaunchManager", Log.LEVEL.DEBUG)
var logger := Log.get_logger("LaunchManager", Log.LEVEL.INFO)
var _focused_app_id := 0


Expand Down Expand Up @@ -93,7 +93,7 @@ func _init() -> void:
_focused_app_id = to

# If OGUI was focused, set the global gamepad profile
if to in [gamescope.OVERLAY_GAME_ID, 0]:
if to in [gamescope.OVERLAY_GAME_ID, 0, 1]:
set_gamepad_profile("")
return

Expand Down Expand Up @@ -577,7 +577,7 @@ func _is_app_id_running(app_id) -> bool:

# Identifies the running app from the given window_id. If none is found,
# creates a new RunningApp instance.
func _detect_running_app(_app_id: int) -> RunningApp:
func _detect_running_app(app_id: int) -> RunningApp:
logger.debug("No known running app in focused window. Attempting to detect the running app.")

# Get the currently focused window id
Expand Down Expand Up @@ -620,12 +620,12 @@ func _detect_running_app(_app_id: int) -> RunningApp:
return null

logger.debug("Found app name : " + app_name)
return _make_running_app_from_process(app_name, pid, window_id)
return _make_running_app_from_process(app_name, pid, window_id, app_id)


# Creates a new RunningApp instance from a given name, PID, and window_id. Used
# when an app launch is detcted that wasn't launched by an OGUI library.
func _make_running_app_from_process(name: String, pid: int, window_id: int) -> RunningApp:
func _make_running_app_from_process(name: String, pid: int, window_id: int, app_id: int) -> RunningApp:
logger.debug("Creating running app from process")

# Create a dummy LibraryLaunchItem to make our RunningApp.
Expand All @@ -646,6 +646,7 @@ func _make_running_app_from_process(name: String, pid: int, window_id: int) -> R
if _xwayland_game:
display = _xwayland_game.name
var running_app: RunningApp = _make_running_app(launch_item, pid, display)
running_app.app_id = app_id
running_app.window_id = window_id
running_app.state = RunningApp.STATE.RUNNING
running_app.is_ogui_managed = false
Expand Down
8 changes: 6 additions & 2 deletions core/ui/card_ui_overlay_mode/card_ui_overlay_mode.gd
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var managed_states: Array[State] = [quick_bar_state, settings_state, gamepad_sta
var xwayland_primary := gamescope.get_xwayland(gamescope.XWAYLAND_TYPE_PRIMARY)
var xwayland_ogui := gamescope.get_xwayland(gamescope.XWAYLAND_TYPE_OGUI)
var overlay_window_id := 0
var set_steam_overlay_focus := false

# Process
var PID: int = OS.get_process_id()
Expand Down Expand Up @@ -300,7 +301,8 @@ func _on_base_state_entered(_from: State) -> void:

# Manage overlay
xwayland_ogui.set_overlay(overlay_window_id, 0)
xwayland_ogui.set_overlay(underlay_window_id, 1)
if self.set_steam_overlay_focus:
xwayland_ogui.set_overlay(underlay_window_id, 1)


## Called when a the base state is exited.
Expand All @@ -315,8 +317,10 @@ func _on_base_state_exited(_to: State) -> void:
logger.error("Unable to set STEAM_INPUT_FOCUS atom!")

# Manage overlay
self.set_steam_overlay_focus = xwayland_ogui.get_overlay(underlay_window_id) == 1
xwayland_ogui.set_overlay(overlay_window_id, 1)
xwayland_ogui.set_overlay(underlay_window_id, 0)
if self.set_steam_overlay_focus:
xwayland_ogui.set_overlay(underlay_window_id, 0)


## Verifies steam is still running by checking for the steam overlay, closes otherwise.
Expand Down

0 comments on commit 9fd0fc9

Please sign in to comment.