Skip to content

Commit

Permalink
fix(Overlay Mode): Overlay Mode Fixes
Browse files Browse the repository at this point in the history
- Temporary workaround for resource loading of SettingsManager and InputIconManager.
- Fixed loading and saving default target gamepad.
- Fixed loading the gamepad profile on startup in Overlay Mode, enabling
  opening overlay window.
- Added missing children to overlay_mode_card_ui.
  • Loading branch information
pastaq committed Nov 23, 2024
1 parent 3e066d2 commit 2d7b941
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 93 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ assets/crypto/keys/opengamepadui.pub: assets/crypto/keys/opengamepadui.key

.PHONY: deploy
deploy: dist-archive $(SSH_MOUNT_PATH)/.mounted ## Build, deploy, and tunnel to a remote device
cp dist/opengamepadui.tar.gz $(SSH_MOUNT_PATH)
scp dist/opengamepadui.tar.gz $(SSH_USER)@$(SSH_HOST):$(SSH_DATA_PATH)
cd $(SSH_MOUNT_PATH) #&& tar xvfz opengamepadui.tar.gz
ssh -t $(SSH_USER)@$(SSH_HOST) tar xvfz "$(SSH_DATA_PATH)/opengamepadui.tar.gz"

Expand Down
30 changes: 7 additions & 23 deletions core/global/launch_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ func _init() -> void:

# Listen for signals from the primary Gamescope XWayland
if _xwayland_primary:
# When window focus changes, update the current app and gamepad profile
# Debug print when the focused window changes
var on_focus_changed := func(from: int, to: int):
if from == to:
return
logger.info("Window focus changed from " + str(from) + " to: " + str(to))
_xwayland_primary.focused_window_updated.connect(on_focus_changed)

# Debug print when the focused app changed
# When focused app changes, update the current app and gamepad profile
var on_focused_app_changed := func(from: int, to: int) -> void:
if from == to:
return
Expand Down Expand Up @@ -150,7 +150,7 @@ func _init() -> void:

in_game_state.state_entered.connect(on_game_state_entered)
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():
Expand Down Expand Up @@ -345,26 +345,10 @@ func set_gamepad_profile(path: String, target_gamepad: String = "") -> void:
# If no profile was specified, unset the gamepad profiles
if path == "":
# Try check to see if there is a global gamepad setting
var profile_path := settings_manager.get_value("input", "gamepad_profile", InputPlumber.DEFAULT_GLOBAL_PROFILE) as String
if not profile_path.ends_with(".json") or not FileAccess.file_exists(profile_path):
profile_path = InputPlumber.DEFAULT_GLOBAL_PROFILE
logger.info("Loading global gamepad profile: " + profile_path)

for gamepad in input_plumber.get_composite_devices():
InputPlumber.load_target_modified_profile(gamepad, profile_path, profile_modifier)

# Set the target gamepad if one was specified
if not target_gamepad.is_empty():
var target_devices := PackedStringArray([target_gamepad, "keyboard", "mouse"])
match target_gamepad:
"xb360", "xbox-series", "xbox-elite", "gamepad":
target_devices.append("touchpad")
_:
logger.debug(target_gamepad, "needs no additional target devices.")
logger.info("Setting target devices to: ", target_devices)
gamepad.set_target_devices(target_devices)

return
path = settings_manager.get_value("input", "gamepad_profile", InputPlumber.DEFAULT_GLOBAL_PROFILE) as String
# Verify we loaded a valid profile, or fallback.
if not path.ends_with(".json") or not FileAccess.file_exists(path):
path = InputPlumber.DEFAULT_GLOBAL_PROFILE

logger.info("Loading gamepad profile: " + path)
if not FileAccess.file_exists(path):
Expand Down
2 changes: 0 additions & 2 deletions core/systems/input/input_icon_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,6 @@ func _get_matching_event(path: String, input_type: InputType) -> Array[InputEven
## Set the last input type to the given value and emit a signal
func set_last_input_type(_last_input_type: InputType):
last_input_type = _last_input_type
if not self.disabled:
input_type_changed.emit(_last_input_type)


## Signal whenever a gamepad is connected/disconnected
Expand Down
4 changes: 4 additions & 0 deletions core/systems/input/input_icon_processor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ func _input(event: InputEvent) -> void:
"InputEventJoypadMotion":
if abs(event.axis_value) > DEADZONE:
input_type = InputIconManager.InputType.GAMEPAD
var refresh := false
if input_type != icon_manager.last_input_type:
icon_manager.set_last_input_type(input_type)
refresh = true
if device_name != icon_manager.last_input_device:
icon_manager.last_input_device = device_name
refresh = true
if refresh:
icon_manager.refresh()
83 changes: 38 additions & 45 deletions core/ui/card_ui/gamepad/gamepad_settings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,18 @@ func _ready() -> void:
self.gamepad_type_selected = item_selected
if self.profile:
var gamepad_type := self.get_selected_target_gamepad()
profile_gamepad = InputPlumberProfile.get_target_device_string(gamepad_type)
logger.debug("Setting gamepad to " + profile_gamepad)
self.profile_gamepad = InputPlumberProfile.get_target_device_string(gamepad_type)
logger.debug("Setting gamepad to " + self.profile_gamepad)
else:
logger.debug("No profile, unable to set gamepad type.")
self._update_mapping_elements()
gamepad_type_dropdown.item_selected.connect(on_gamepad_selected)

# Load the default profile
var profile_path = settings_manager.get_value("input", "gamepad_profile", "")
profile_gamepad = settings_manager.get_value("input", "gamepad_profile_target", "")
for gamepad in input_plumber.get_composite_devices():
_set_gamepad_profile(gamepad, profile_path)
self.profile_gamepad = settings_manager.get_value("input", "gamepad_profile_target", "")
for composite_device in input_plumber.get_composite_devices():
_set_gamepad_profile(composite_device, profile_path)

# Grab focus when the mapper exits
var on_state_changed := func(_from: State, to: State):
Expand Down Expand Up @@ -103,7 +103,7 @@ func _on_state_entered(_from: State) -> void:
main_container.visible = true

# Read from the state to determine which gamepad is being configured
gamepad = null
self.gamepad = null
if !gamepad_state.has_meta("dbus_path"):
logger.error("No gamepad was set to configure!")
# Make menu empty, unable to find gamepad to configure
Expand All @@ -116,56 +116,48 @@ func _on_state_entered(_from: State) -> void:
# Find the composite device to configure
for device: CompositeDevice in input_plumber.get_composite_devices():
if device.dbus_path == dbus_path:
gamepad = device
self.gamepad = device
break
if gamepad == null:
if self.gamepad == null:
logger.error("Unable to find CompositeDevice with path: " + dbus_path)
not_available.visible = true
main_container.visible = false
$ServiceNotAvailableContainer/Label.text = "No gamepad to configure"
return

logger.debug("Configuring gamepad '" + gamepad.name + "': " + dbus_path)
logger.debug("Configuring gamepad '" + self.gamepad.name + "': " + dbus_path)

# Set the gamepad name label
gamepad_label.text = gamepad.name
gamepad_label.text = self.gamepad.name

# Populate the menu with the source inputs for the given gamepad
populate_mappings_for(gamepad)
populate_mappings_for(self.gamepad)

# Set the library item, if one exists
library_item = null
profile = null
self.library_item = null
self.profile = null
if gamepad_state.has_meta("item"):
library_item = gamepad_state.get_meta("item") as LibraryItem
self.library_item = gamepad_state.get_meta("item") as LibraryItem

# If no library item was set, but there's a running app, try to see if
# there is a library item for it instead.
if not library_item:
library_item = launch_manager.get_current_app_library_item()
if not self.library_item:
self.library_item = launch_manager.get_current_app_library_item()

# If no library item was set with the state, then configure the OGUI profile
if not library_item:
profile_label.text = "Global"
@warning_ignore("confusable_local_declaration")
var profile_path := settings_manager.get_value("input", "gamepad_profile", InputPlumber.DEFAULT_GLOBAL_PROFILE) as String
var profile_target_gamepad := settings_manager.get_value("input", "gamepad_profile_target", "") as String
profile = _load_profile(profile_path)
profile_gamepad = profile_target_gamepad
_update_mapping_elements()
return

# Set the profile text to the game name
profile_label.text = library_item.name


# Check to see if the given game has a gamepad profile
var profile_path := settings_manager.get_library_value(library_item, "gamepad_profile", "") as String
var profile_target_gamepad := settings_manager.get_library_value(library_item, "gamepad_profile_target", "") as String
profile = _load_profile(profile_path)
profile_gamepad = profile_target_gamepad
_update_mapping_elements()
var profile_path: String
if not self.library_item:
self.profile_label.text = "Global"
profile_path = settings_manager.get_value("input", "gamepad_profile", InputPlumber.DEFAULT_GLOBAL_PROFILE) as String
else:
self.profile_label.text = self.library_item.name
profile_path = settings_manager.get_library_value(self.library_item, "gamepad_profile", "") as String

self.profile = _load_profile(profile_path)
self.profile_gamepad = settings_manager.get_library_value(self.library_item, "gamepad_profile_target", "") as String

_update_mapping_elements()

# Clear focus
mapping_focus_group.current_focus = null

Expand Down Expand Up @@ -402,8 +394,8 @@ func _update_mapping_elements() -> void:
profile_label.text = profile.name

# Update the dropdown based on the profile's target gamepad type
if not profile_gamepad.is_empty():
var target_device := InputPlumberProfile.get_target_device(profile_gamepad)
if not self.profile_gamepad.is_empty():
var target_device := InputPlumberProfile.get_target_device(self.profile_gamepad)
var gamepad_text := self.get_target_gamepad_text(target_device)
var i := 0
var idx := 0
Expand Down Expand Up @@ -612,16 +604,16 @@ func _set_gamepad_profile(gamepad: CompositeDevice, profile_path: String = "") -
profile_path = settings_manager.get_library_value(library_item, "gamepad_profile", "")

logger.debug("Setting " + gamepad.name + " to profile: " + profile_path)
InputPlumber.load_target_modified_profile(gamepad, profile_path, profile_gamepad)
InputPlumber.load_target_modified_profile(gamepad, profile_path, self.profile_gamepad)

# Set the target gamepad if one was specified
if not profile_gamepad.is_empty():
var target_devices := PackedStringArray([profile_gamepad, "keyboard", "mouse"])
match profile_gamepad:
if not self.profile_gamepad.is_empty():
var target_devices := PackedStringArray([self.profile_gamepad, "keyboard", "mouse"])
match self.profile_gamepad:
"xb360", "xbox-series", "xbox-elite", "gamepad":
target_devices.append("touchpad")
_:
logger.debug(profile_gamepad, "needs no additional target devices.")
logger.debug(self.profile_gamepad, "needs no additional target devices.")
logger.debug("Setting target devices to: ", target_devices)
gamepad.set_target_devices(target_devices)

Expand All @@ -645,8 +637,9 @@ func _save_profile() -> void:
return

# Update the game settings to use this global profile
self.logger.info("Saving gamepad profile at", path, "and gamepad target", self.profile_gamepad)
settings_manager.set_value("input", "gamepad_profile", path)
settings_manager.set_value("input", "gamepad_profile_target", profile_gamepad)
settings_manager.set_value("input", "gamepad_profile_target", self.profile_gamepad)

for gamepad in input_plumber.get_composite_devices():
_set_gamepad_profile(gamepad, path)
Expand All @@ -668,7 +661,7 @@ func _save_profile() -> void:
# Update the game settings to use this gamepad profile
var section := "game.{0}".format([library_item.name.to_lower()])
settings_manager.set_value(section, "gamepad_profile", path)
settings_manager.set_value(section, "gamepad_profile_target", profile_gamepad)
settings_manager.set_value(section, "gamepad_profile_target", self.profile_gamepad)
logger.debug("Saved gamepad profile to: " + path)
notify.text = "Gamepad profile saved"
notification_manager.show(notify)
Expand Down
19 changes: 3 additions & 16 deletions core/ui/card_ui_overlay_mode/card_ui_overlay_mode.gd
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ func _ready() -> void:

# Set the theme if one was set
var theme_path := settings_manager.get_value("general", "theme", "res://assets/themes/card_ui-dracula.tres") as String
if theme_path.is_empty():
logger.error("Failed to load theme from settings manager.")
return
logger.debug("Setting theme to: " + theme_path)
var loaded_theme = load(theme_path)
if loaded_theme != null:
Expand Down Expand Up @@ -252,7 +255,6 @@ func _find_underlay_window_id() -> void:
if xwayland_ogui.has_notification(window):
underlay_window_id = window
logger.info("Found steam! " + str(underlay_window_id))
xwayland_primary.focused_app_updated.connect(_on_app_focus_changed)
break

# If we didn't find the window_id, set up a tiemr to loop back and try again.
Expand Down Expand Up @@ -306,18 +308,3 @@ func _check_exit() -> void:
return
logger.debug("Steam closed. Shutting down.")
get_tree().quit()


func _on_app_focus_changed(from: int, to: int) -> void:
# On focus to the steam overlay, ensure the default profile is used.
logger.warn("Changed window focus from", from, "to app ID:", to)
if to in [gamescope.OVERLAY_GAME_ID, 0]:
launch_manager.set_gamepad_profile("")
return

# On focus back to the game, ensure the game profile is set
var _current_app := launch_manager.get_current_app()
if not _current_app:
logger.error("Unable to set gamepad profile. Current app is NULL and we aren't focused")
return
launch_manager.set_app_gamepad_profile(_current_app)
26 changes: 25 additions & 1 deletion core/ui/card_ui_overlay_mode/card_ui_overlay_mode.tscn
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
[gd_scene load_steps=9 format=3 uid="uid://b13lnfkjbafkj"]
[gd_scene load_steps=16 format=3 uid="uid://b13lnfkjbafkj"]

[ext_resource type="Theme" uid="uid://ehplgpp70vxa" path="res://assets/themes/card_ui-dracula.tres" id="1_0qmlq"]
[ext_resource type="Script" path="res://core/ui/card_ui_overlay_mode/card_ui_overlay_mode.gd" id="2_3ptao"]
[ext_resource type="PackedScene" uid="uid://bxnb8t7i08vma" path="res://core/systems/input/overlay_mode_input_manager.tscn" id="3_klhmb"]
[ext_resource type="Script" path="res://core/systems/input/input_icon_processor.gd" id="4_6rltg"]
[ext_resource type="Script" path="res://core/systems/launcher/launcher.gd" id="4_o0rva"]
[ext_resource type="PackedScene" uid="uid://d2jiecrd5sw4s" path="res://core/ui/card_ui/settings/settings_menu.tscn" id="5_4sdt1"]
[ext_resource type="Script" path="res://core/systems/gamescope/gamescope.gd" id="5_sgddx"]
[ext_resource type="GamescopeInstance" uid="uid://chd0nc6gbfnw0" path="res://core/systems/gamescope/gamescope.tres" id="6_jj3bv"]
[ext_resource type="PackedScene" uid="uid://cwarv58ju0sow" path="res://core/ui/card_ui/gamepad/gamepad_settings.tscn" id="6_oddte"]
[ext_resource type="PackedScene" uid="uid://hroo3ll4inrb" path="res://core/ui/card_ui/quick_bar/quick_bar_menu.tscn" id="7_e54f8"]
[ext_resource type="Script" path="res://core/systems/plugin/plugin_manager.gd" id="7_qqh0e"]
[ext_resource type="Script" path="res://core/systems/performance/power_station.gd" id="8_kxe4b"]
[ext_resource type="PackedScene" uid="uid://eqqk1uve143x" path="res://core/ui/components/dialog.tscn" id="8_otm5f"]
[ext_resource type="ResourceRegistry" uid="uid://bsr58xihnpn1j" path="res://core/systems/resource/resource_registry.tres" id="9_4si0w"]
[ext_resource type="PowerStationInstance" uid="uid://c2mmrnh3rcs58" path="res://core/systems/performance/power_station.tres" id="9_nw6s5"]

[node name="CardUIOverlayMode" type="Control" groups=["main"]]
layout_mode = 3
Expand All @@ -21,9 +28,26 @@ script = ExtResource("2_3ptao")

[node name="InputManager" parent="." instance=ExtResource("3_klhmb")]

[node name="InputIconProcessor" type="Node" parent="."]
script = ExtResource("4_6rltg")

[node name="Gamescope" type="Node" parent="."]
script = ExtResource("5_sgddx")
instance = ExtResource("6_jj3bv")

[node name="Launcher" type="Node" parent="."]
script = ExtResource("4_o0rva")

[node name="PluginManager" type="Node" parent="."]
script = ExtResource("7_qqh0e")

[node name="PowerStation" type="Node" parent="."]
script = ExtResource("8_kxe4b")
instance = ExtResource("9_nw6s5")

[node name="ResourceProcessor" type="ResourceProcessor" parent="."]
registry = ExtResource("9_4si0w")

[node name="MenuContent" type="MarginContainer" parent="."]
unique_name_in_owner = true
layout_mode = 1
Expand Down
9 changes: 4 additions & 5 deletions core/ui/components/input_icon.gd
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ var internal_children: Array[Node] = []
self.textures = input_icons.parse_path(path, force_mapping, force_type - 1)
else:
self.textures = input_icons.parse_path(path, force_mapping)

# If no textures are found, become invisible
self.visible = !self.textures.is_empty()

# Remove old children
for child in internal_children.duplicate():
_remove_internal_child(child)
internal_children.clear()

# Add new children
var i := 0
for texture in self.textures:
Expand Down Expand Up @@ -123,8 +123,7 @@ func _on_input_type_changed(input_type: InputIconManager.InputType):
(show_only == 2 and input_type == InputIconManager.InputType.GAMEPAD):
self.visible = true
self.path = path
var width := self.max_width
self.max_width = width
self.max_width = max_width
else:
self.visible = false

Expand Down
4 changes: 4 additions & 0 deletions entrypoint.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ var args := OS.get_cmdline_args()
var child_pid := -1
var logger := Log.get_logger("Entrypoint")

# We don't need this here, except we do. For some reason it won't load properly
# after the entrypoint anymore and I don't care why. Don't touch this.
var settings_manager := load("res://core/global/settings_manager.tres") as SettingsManager
var input_icons := load("res://core/systems/input/input_icon_manager.tres") as InputIconManager

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
Expand Down

0 comments on commit 2d7b941

Please sign in to comment.