Skip to content

Commit

Permalink
fix(Full Session): loading menu fixes, launch fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowApex committed Nov 30, 2024
1 parent 5f5cedb commit a86b2ab
Show file tree
Hide file tree
Showing 16 changed files with 128 additions and 38 deletions.
33 changes: 23 additions & 10 deletions core/global/launch_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ var logger := Log.get_logger("LaunchManager", Log.LEVEL.DEBUG)

# Connect to Gamescope signals
func _init() -> void:
_load_persist_data()

# Get the window ID of OpenGamepadUI
if _xwayland_ogui:
var ogui_windows := _xwayland_ogui.get_windows_for_pid(PID)
Expand All @@ -77,6 +79,7 @@ func _init() -> void:
if from == to:
return
logger.info("Window focus changed from " + str(from) + " to: " + str(to))
self.check_running.call_deferred()
_xwayland_primary.focused_window_updated.connect(on_focus_changed)

# When focused app changes, update the current app and gamepad profile
Expand Down Expand Up @@ -115,6 +118,7 @@ func _init() -> void:
if from == to:
return
logger.debug("Focusable apps changed from", from, "to", to)
self.check_running.call_deferred()
# If focusable apps has changed and the currently focused app no longer exists,
# remove the manual focus
var baselayer_app := _xwayland_primary.baselayer_app
Expand All @@ -123,6 +127,14 @@ func _init() -> void:
_xwayland_primary.remove_baselayer_app()
_xwayland_primary.focusable_apps_updated.connect(on_focusable_apps_changed)

# Listen for signals from the secondary Gamescope XWayland
if _xwayland_game:
# Listen for window created/destroyed events
var on_window_created := func(window_id: int):
logger.debug("Window created:", window_id)
self.check_running.call_deferred()
_xwayland_ogui.window_created.connect(on_window_created)

# Whenever the in-game state is entered, set the gamepad profile
var on_game_state_entered := func(_from: State):
if _current_app:
Expand Down Expand Up @@ -152,6 +164,7 @@ func _init() -> void:
in_game_state.state_exited.connect(on_game_state_exited)
set_gamepad_profile("")


# Loads persistent data like recent games launched, etc.
func _load_persist_data():
# Create the data directory if it doesn't exist
Expand Down Expand Up @@ -189,20 +202,20 @@ func launch(app: LibraryLaunchItem) -> RunningApp:
# Override any parameters that may be in the user's config for this game
var section := ".".join(["game", app.name.to_lower()])
var cmd_key := ".".join(["command", app._provider_id])
var user_cmd = settings_manager.get_value(section, cmd_key)
if user_cmd and user_cmd is String:
var user_cmd = settings_manager.get_value(section, cmd_key, "")
if user_cmd and user_cmd is String and not (user_cmd as String).is_empty():
cmd = user_cmd
var args_key := ".".join(["args", app._provider_id])
var user_args = settings_manager.get_value(section, args_key)
if user_args and user_args is PackedStringArray:
var user_args = settings_manager.get_value(section, args_key, PackedStringArray())
if user_args and user_args is PackedStringArray and not (user_args as PackedStringArray).is_empty():
args = user_args
var cwd_key := ".".join(["cwd", app._provider_id])
var user_cwd = settings_manager.get_value(section, cwd_key)
if user_cwd and user_cwd is String:
var user_cwd = settings_manager.get_value(section, cwd_key, "")
if user_cwd and user_cwd is String and not (user_cwd as String).is_empty():
cwd = user_cwd
var env_key := ".".join(["env", app._provider_id])
var user_env = settings_manager.get_value(section, env_key)
if user_env and user_env is Dictionary:
var user_env = settings_manager.get_value(section, env_key, {})
if user_env and user_env is Dictionary and not (user_env as Dictionary).is_empty():
env = user_env
var sandboxing_key := ".".join(["use_sandboxing", app._provider_id])
var use_sandboxing := settings_manager.get_value(section, sandboxing_key, true) as bool
Expand Down Expand Up @@ -376,8 +389,8 @@ func set_gamepad_profile(path: String, target_gamepad: String = "") -> void:
logger.info("Setting target devices to: ", target_devices)
gamepad.set_target_devices(target_devices)

var notify := Notification.new("Using gamepad profile: " + profile.name)
notification_manager.show(notify)
#var notify := Notification.new("Using gamepad profile: " + profile.name)
#notification_manager.show(notify)


## Sets the given running app as the current app
Expand Down
7 changes: 6 additions & 1 deletion core/global/platform.gd
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ enum PLATFORM {
STEAMOS,
MANJARO,
ARCH_LIKE,
NIXOS,
}

var hardware_manager := load("res://core/systems/hardware/hardware_manager.tres") as HardwareManager

## Detected Operating System information
var os_info := _detect_os()
## The OS platform provider detected
var os: PlatformProvider
var os: OSPlatform
## The hardware platform provider detected
var platform: PlatformProvider
var logger := Log.get_logger("Platform", Log.LEVEL.INFO)
Expand Down Expand Up @@ -127,6 +128,8 @@ func _init() -> void:
os = load("res://core/platform/os/chimeraos.tres")
if PLATFORM.MANJARO in flags:
os = load("res://core/platform/os/manjaro.tres")
if PLATFORM.NIXOS in flags:
os = load("res://core/platform/os/nixos.tres")

if os:
for action in os.startup_actions:
Expand Down Expand Up @@ -286,6 +289,8 @@ func _read_os() -> Array[PLATFORM]:
flags.append(PLATFORM.MANJARO)
if os_info.id_like == "arch":
flags.append(PLATFORM.ARCH_LIKE)
if os_info.id == "nixos":
flags.append(PLATFORM.NIXOS)

return flags

Expand Down
23 changes: 23 additions & 0 deletions core/platform/os/nixos.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
extends OSPlatform
class_name PlatformNixOS


func _init() -> void:
logger.set_name("PlatformNixOS")
logger.set_level(Log.LEVEL.INFO)
logger.info("Detected NixOS platform")


## NixOS typically cannot execute regular binaries, so downloaded binaries will
## be run with 'steam-run'.
func get_binary_compatibility_cmd(cmd: String, args: PackedStringArray) -> Array[String]:
# Hack for steam plugin running steamcmd on NixOS
var command: Array[String] = []
if not cmd.ends_with("steamcmd.sh"):
return command

command.push_back("steam-run")
command.push_back(cmd)
command.append_array(args)

return command
10 changes: 10 additions & 0 deletions core/platform/os/nixos.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[gd_resource type="Resource" script_class="PlatformNixOS" load_steps=3 format=3 uid="uid://byxeetkb11b3e"]

[ext_resource type="Script" path="res://core/platform/os/nixos.gd" id="1_h88kc"]
[ext_resource type="Script" path="res://core/platform/actions/platform_action.gd" id="2_tc12v"]

[resource]
script = ExtResource("1_h88kc")
name = ""
startup_actions = Array[ExtResource("2_tc12v")]([])
shutdown_actions = Array[ExtResource("2_tc12v")]([])
8 changes: 8 additions & 0 deletions core/platform/os/os_platform.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ class_name OSPlatform

@export_category("Images")
@export var logo: Texture2D ## Logo of the OS


## If the OS requires running regular binaries through a compatibility tool,
## this method should return the given command/args prepended with the compatibility
## tool to use.
func get_binary_compatibility_cmd(cmd: String, args: PackedStringArray) -> Array[String]:
var result: Array[String] = []
return result
1 change: 0 additions & 1 deletion core/systems/debug/log_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,3 @@ func get_available_loggers() -> PackedStringArray:
var logger_names := loggers_by_name.keys()
mutex.unlock()
return logger_names

3 changes: 3 additions & 0 deletions core/systems/input/input_plumber.gd
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ func _init() -> void:
var file := FileAccess.open(DEFAULT_PROFILE, FileAccess.READ)
var content := file.get_as_text()
file.close()
if DirAccess.make_dir_recursive_absolute(PROFILES_DIR) != OK:
var logger := Log.get_logger("InputPlumber", Log.LEVEL.DEBUG)
logger.error("Failed to create gamepad profiles directory")
var new_file := FileAccess.open(DEFAULT_GLOBAL_PROFILE, FileAccess.WRITE)
new_file.store_string(content)
new_file.close()
Expand Down
16 changes: 10 additions & 6 deletions core/systems/launcher/interactive_process.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,23 @@ var pty: Pty
var cmd: String
var args: PackedStringArray = []
var pid: int
var platform := load("res://core/global/platform.tres") as Platform
var registry := load("res://core/systems/resource/resource_registry.tres") as ResourceRegistry
var lines_mutex := Mutex.new()
var lines_buffer := PackedStringArray()
var logger := Log.get_logger("InteractiveProcess", Log.LEVEL.INFO)


func _init(command: String, cmd_args: PackedStringArray = []) -> void:
# Hack for steam plugin running steamcmd on NixOS
#if command.ends_with("steamcmd.sh"):
#cmd = "steam-run"
#args = PackedStringArray([command])
#args.append_array(cmd_args)
#return
# Check to see if this OS requires running the command through a binary
# compatibility tool.
if platform and platform.os:
var compatibility_cmd := platform.os.get_binary_compatibility_cmd(command, cmd_args)
if not compatibility_cmd.is_empty():
logger.debug("Using binary compatibility tool")
self.cmd = compatibility_cmd.pop_front()
self.args = PackedStringArray(compatibility_cmd)
return

self.cmd = command
self.args = cmd_args
Expand Down
10 changes: 7 additions & 3 deletions core/systems/launcher/launcher.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ func _init() -> void:
launch_manager._load_persist_data()


# TODO: Replace this with dbus signaling. This is super shitty.
func _process(delta) -> void:
launch_manager.check_running()
func _ready() -> void:
var timer := Timer.new()
timer.autostart = true
timer.one_shot = false
timer.wait_time = 1
timer.timeout.connect(launch_manager.check_running)
add_child(timer)
4 changes: 2 additions & 2 deletions core/systems/launcher/reaper.gd
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static func get_pid_status(pid: int) -> Dictionary:
var status_file: FileAccess = FileAccess.open(status_path, FileAccess.READ)
if not status_file:
var logger := Log.get_logger("Reaper")
logger.error("Unable to check status for pid: {0}".format([pid]))
logger.debug("Unable to check status for pid: {0}".format([pid]))
return {}

# Parse the status output
Expand Down Expand Up @@ -215,7 +215,7 @@ static func is_gamescope_pid(pid: int) -> bool:
var status: Dictionary = get_pid_status(pid)
if not "Name" in status:
var logger := Log.get_logger("Reaper")
logger.error("No name was found in pid status!")
logger.debug("No name was found in pid status!")
return false
if status["Name"] == "gamescope-wl":
return true
Expand Down
3 changes: 2 additions & 1 deletion core/systems/library/library_launch_item.gd
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,6 @@ func get_app_id() -> int:

# In all other cases, use the hash of the app name for its app id
var app_id := hash(self.name)
const MAX_APP_ID := 800483647

return app_id
return app_id % MAX_APP_ID
17 changes: 7 additions & 10 deletions core/ui/card_ui/card_ui.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,15 @@ instance = ExtResource("5_wmkau")

[node name="DesktopLibrary" parent="." instance=ExtResource("3_68bes")]

[node name="Launcher" type="Node" parent="."]
process_thread_group = 2
process_thread_group_order = 0
process_thread_messages = 0
script = ExtResource("14_fs00k")

[node name="PluginManager" parent="." instance=ExtResource("5_dv70s")]

[node name="PowerManager" type="Node" parent="."]
script = ExtResource("10_opsp8")
instance = ExtResource("11_nk5v7")

[node name="Launcher" type="Node" parent="."]
script = ExtResource("14_fs00k")

[node name="PowerSaver" parent="." instance=ExtResource("8_hyc1j")]

[node name="PowerStation" type="Node" parent="."]
Expand All @@ -130,6 +127,10 @@ one_shot = true
[node name="ResourceProcessor" type="ResourceProcessor" parent="."]
registry = ExtResource("15_ne50o")

[node name="GameLoading" parent="." instance=ExtResource("22_morxu")]
visible = false
layout_mode = 1

[node name="Panel" type="Panel" parent="."]
unique_name_in_owner = true
layout_mode = 1
Expand Down Expand Up @@ -245,10 +246,6 @@ layout_mode = 2
visible = false
layout_mode = 2

[node name="GameLoading" parent="." instance=ExtResource("22_morxu")]
visible = false
layout_mode = 1

[node name="AlwaysVisibleContent" type="MarginContainer" parent="."]
editor_description = "Anything in this container will always be visible, even during in-game states.
"
Expand Down
6 changes: 6 additions & 0 deletions core/ui/card_ui/quick_bar/quick_bar_menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func _ready() -> void:
quick_bar_menu_state.state_entered.connect(_on_state_entered)
quick_bar_menu_state.state_exited.connect(_on_state_exited)
launch_manager.app_switched.connect(_on_app_switched)
launch_manager.app_stopped.connect(_on_app_stopped)

# Handle when the notifications button is pressed
var on_notify_pressed := func():
Expand Down Expand Up @@ -54,6 +55,11 @@ func _on_app_switched(_from: RunningApp, to: RunningApp) -> void:
# TODO: Implement fetching game icon and setting it


func _on_app_stopped(app: RunningApp) -> void:
if launch_manager.get_running().is_empty():
playing_container.visible = false


# Adds the given Control menu to the quick bar. A focus node can be given which will
# be the first node to focus
func add_child_menu(qb_item: Control, icon: Texture2D, focus_node: Control = null, title: String = ""):
Expand Down
2 changes: 1 addition & 1 deletion core/ui/card_ui/settings/library_settings_menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extends ScrollContainer

var settings_manager := load("res://core/global/settings_manager.tres") as SettingsManager
var library_manager := load("res://core/global/library_manager.tres") as LibraryManager
var state_machine := load("res://assets/state/state_machines/global_state_machine.tres") as StateMachine
var state_machine := load("res://assets/state/state_machines/menu_state_machine.tres") as StateMachine
var settings_state := load("res://assets/state/states/settings.tres") as State
var game_settings_state := preload("res://assets/state/states/game_settings.tres") as State
var button_scene := load("res://core/ui/components/card_button.tscn") as PackedScene
Expand Down
17 changes: 16 additions & 1 deletion core/ui/common/game/game_loading.gd
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
extends Control

var launch_manager := load("res://core/global/launch_manager.tres") as LaunchManager
var state_machine := (
preload("res://assets/state/state_machines/global_state_machine.tres") as StateMachine
)
var menu_state := preload("res://assets/state/states/menu.tres") as State
var popup_state := preload("res://assets/state/states/popup.tres") as State
var in_game_state := preload("res://assets/state/states/in_game.tres") as State
var game_launching := false


# Called when the node enters the scene tree for the first time.
func _ready() -> void:
launch_manager.app_launched.connect(_on_app_launched)

var on_state_changed := func(_from: State, to: State):
if not game_launching:
visible = false
return
visible = to in [in_game_state, popup_state]
state_machine.state_changed.connect(on_state_changed)


func _on_app_launched(app: RunningApp):
visible = true
game_launching = true
app.app_type_detected.connect(_on_window_created, CONNECT_ONE_SHOT)
app.app_killed.connect(_on_window_created, CONNECT_ONE_SHOT)


func _on_window_created() -> void:
game_launching = false
visible = false
6 changes: 4 additions & 2 deletions core/ui/components/volume_indicator.gd
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ func _on_volume_changed(value: float) -> void:
visible = true
level_indicator.value = value * 100
timer.start()
gamescope.set_notification(overlay_window_id, 1)
var xwayland := gamescope.get_xwayland(gamescope.XWAYLAND_TYPE_OGUI)
xwayland.set_notification(overlay_window_id, 1)


func _on_timeout() -> void:
visible = false
gamescope.set_notification(overlay_window_id, 0)
var xwayland := gamescope.get_xwayland(gamescope.XWAYLAND_TYPE_OGUI)
xwayland.set_notification(overlay_window_id, 0)

0 comments on commit a86b2ab

Please sign in to comment.