Skip to content

Commit

Permalink
fix(Full Session): Fix performance and gamepad issues.
Browse files Browse the repository at this point in the history
- Fixed or worked around issues with xwayland and gamescope doing the 'blur' effect.
- Worked around an issue with the x11 rust bindings not reporting timely app id focus switching.
  • Loading branch information
pastaq committed Dec 1, 2024
1 parent a86b2ab commit 2040d5e
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 22 deletions.
22 changes: 12 additions & 10 deletions core/global/launch_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ 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 _focused_app_id := 0


# Connect to Gamescope signals
Expand All @@ -83,23 +84,24 @@ func _init() -> void:
_xwayland_primary.focused_window_updated.connect(on_focus_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:
var on_focused_app_changed := func(_from: int, to: int) -> void:
if _focused_app_id == to:
return
logger.debug("Focused app changed from " + str(from) + " to " + str(to))

logger.debug("Focused app changed from " + str(_focused_app_id) + " to " + str(to))
_focused_app_id = to

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

# Find the running app for the given app id
var last_app := self._current_app
var detected_app: RunningApp
for app in _running:
if app.app_id == to:
detected_app = app

# If the running app was not launched by OpenGamepadUI, then detect it.
if not detected_app:
detected_app = _detect_running_app(to)
Expand Down Expand Up @@ -427,6 +429,7 @@ func _on_app_state_changed(from: RunningApp.STATE, to: RunningApp.STATE, app: Ru
logger.debug("App state changed from", from, "to", to, "for app:", app)
if to != RunningApp.STATE.STOPPED:
return
logger.debug("Cleaning up pid {0}".format([app.pid]))
_remove_running(app)
logger.debug("Currently running apps:", _running)
if state_machine.has_state(in_game_state) and _running.size() == 0:
Expand All @@ -438,11 +441,10 @@ func _on_app_state_changed(from: RunningApp.STATE, to: RunningApp.STATE, app: Ru

# Removes the given PID from our list of running apps
func _remove_running(app: RunningApp):
logger.info("Cleaning up pid {0}".format([app.pid]))
logger.info("Removing app", app, "from running apps.")
_running.erase(app)
_apps_by_name.erase(app.launch_item.name)
_apps_by_pid.erase(app.pid)

app_stopped.emit(app)


Expand All @@ -454,10 +456,10 @@ func check_running() -> void:
var root_id := _xwayland_game.root_window_id
if root_id < 0:
return

# Update our view of running processes and what windows they have
_update_pids(root_id)

# Update the state of all running apps
for app in _running:
app.update()
Expand Down
2 changes: 1 addition & 1 deletion core/ui/card_ui/card_ui.gd
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func _on_game_state_exited(to: State) -> void:
panel.visible = false
# Only blur if the focused GFX app is set
if _xwayland_primary:
var should_blur := settings_manager.get_value("display", "enable_overlay_blur", true) as bool
var should_blur := settings_manager.get_value("display", "enable_overlay_blur", false) as bool
if should_blur and _xwayland_primary.get_focused_app_gfx() != gamescope.OVERLAY_GAME_ID:
_set_blur(GamescopeXWayland.BLUR_MODE_ALWAYS)

Expand Down
1 change: 1 addition & 0 deletions core/ui/card_ui/card_ui.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ size_flags_vertical = 8
layout_mode = 2

[node name="ContextBar" parent="MenuContent/BottomMargin/VBoxContainer" instance=ExtResource("12_bstc8")]
visible = false
layout_mode = 2

[node name="MenuContainer" type="MarginContainer" parent="MenuContent"]
Expand Down
6 changes: 3 additions & 3 deletions core/ui/card_ui/gamepad/gamepad_settings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func _on_state_entered(_from: State) -> void:
if device.dbus_path == dbus_path:
self.gamepad = device
break

if self.gamepad == null:
logger.error("Unable to find CompositeDevice with path: " + dbus_path)
not_available.visible = true
Expand Down Expand Up @@ -152,10 +153,9 @@ func _on_state_entered(_from: State) -> void:
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_gamepad = settings_manager.get_library_value(self.library_item, "gamepad_profile_target", "") 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
Expand Down
12 changes: 12 additions & 0 deletions core/ui/card_ui/navigation/running_game_card.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var menu_state_machine := load("res://assets/state/state_machines/menu_state_mac
var popup_state_machine := load("res://assets/state/state_machines/popup_state_machine.tres") as StateMachine
var in_game_state := load("res://assets/state/states/in_game.tres") as State
var button_scene := load("res://core/ui/components/card_button.tscn") as PackedScene
var gamepad_state := load("res://assets/state/states/gamepad_settings.tres") as State

@export_category("Card")
@export var is_toggled := false:
Expand All @@ -38,6 +39,7 @@ var button_scene := load("res://core/ui/components/card_button.tscn") as PackedS
@onready var exit_button := $%ExitButton as CardButton
@onready var highlight_rect := $%HighlightTextureRect
@onready var focus_group := $%FocusGroup as FocusGroup
@onready var gamepad_button := $%GamepadButton

var tween: Tween
var running_app: RunningApp
Expand All @@ -54,6 +56,7 @@ func _ready() -> void:
focus_exited.connect(_on_unfocus)
button_up.connect(_on_button_up)
theme_changed.connect(_on_theme_changed)
gamepad_button.button_down.connect(_on_gampad_button_pressed)

# Find the parent theme and update if required
var effective_theme := ThemeUtils.get_effective_theme(self)
Expand Down Expand Up @@ -207,3 +210,12 @@ func _input(event: InputEvent) -> void:
#logger.debug("Consuming input event '{action}' for node {n}".format({"action": action, "n": str(self)}))
get_viewport().set_input_as_handled()
self.grab_focus()


## Ensure that the library item meta data is always set before opening the gamepad
## settings menu
func _on_gampad_button_pressed() -> void:
var library_item: LibraryItem = null
if running_app and running_app.launch_item:
library_item = LibraryItem.new_from_launch_item(running_app.launch_item)
gamepad_state.set_meta("item", library_item)
5 changes: 3 additions & 2 deletions core/ui/card_ui/navigation/running_game_card.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
[ext_resource type="Resource" uid="uid://cr544el0cqjlm" path="res://assets/state/state_machines/global_state_machine.tres" id="15_p4kr0"]
[ext_resource type="Resource" uid="uid://cv3vduo0ojk1u" path="res://assets/state/states/menu.tres" id="16_vmedb"]

[sub_resource type="Image" id="Image_2qj0k"]
[sub_resource type="Image" id="Image_geul6"]
data = {
"data": PackedByteArray(255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 231, 255, 94, 94, 54, 255, 94, 94, 57, 255, 93, 93, 233, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 231, 255, 94, 94, 54, 255, 94, 94, 57, 255, 93, 93, 233, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 93, 93, 233, 255, 93, 93, 232, 255, 93, 93, 41, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 93, 93, 233, 255, 93, 93, 232, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 44, 255, 255, 255, 0, 255, 97, 97, 42, 255, 97, 97, 42, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 44, 255, 255, 255, 0, 255, 97, 97, 42, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 235, 255, 94, 94, 234, 255, 95, 95, 43, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 235, 255, 94, 94, 234, 255, 95, 95, 43, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 235, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 233, 255, 95, 95, 59, 255, 96, 96, 61, 255, 93, 93, 235, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 233, 255, 95, 95, 59, 255, 96, 96, 61, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0),
"format": "RGBA8",
Expand All @@ -27,7 +27,7 @@ data = {
}

[sub_resource type="ImageTexture" id="ImageTexture_osglk"]
image = SubResource("Image_2qj0k")
image = SubResource("Image_geul6")

[node name="RunningGameCard" type="PanelContainer"]
anchors_preset = 10
Expand Down Expand Up @@ -160,6 +160,7 @@ layout_mode = 2
text = "Pause"

[node name="GamepadButton" parent="MarginContainer/VBoxContainer/ContentContainer" instance=ExtResource("8_ixs6g")]
unique_name_in_owner = true
layout_mode = 2
text = "Gamepad"

Expand Down
15 changes: 15 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 @@ -9,13 +9,15 @@ const qb_card_scene := preload("res://core/ui/card_ui/quick_bar/qb_card.tscn")
var launch_manager := load("res://core/global/launch_manager.tres") as LaunchManager
var quick_bar_menu_state := preload("res://assets/state/states/quick_bar_menu.tres") as State
var qb_focus := preload("res://core/ui/card_ui/quick_bar/quick_bar_menu_focus.tres") as FocusStack
var gamepad_state := load("res://assets/state/states/gamepad_settings.tres") as State

@onready var viewport: VBoxContainer = $%Viewport
@onready var focus_group := $%FocusGroup as FocusGroup
@onready var playing_container := $%PlayingNowContainer
@onready var game_label := $%GameNameLabel
@onready var notify_button := $%NotifyButton
@onready var notify_card := $%NotificationsCard
@onready var gamepad_button := $%GamepadButton


# Called when the node enters the scene tree for the first time.
Expand All @@ -24,6 +26,8 @@ func _ready() -> void:
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)
launch_manager.app_launched.connect(_on_app_focus_changed)
gamepad_button.button_down.connect(_on_gampad_button_pressed)

# Handle when the notifications button is pressed
var on_notify_pressed := func():
Expand All @@ -46,6 +50,10 @@ func _on_state_exited(_to: State) -> void:


func _on_app_switched(_from: RunningApp, to: RunningApp) -> void:
_on_app_focus_changed(to)


func _on_app_focus_changed(to: RunningApp) -> void:
if to == null:
playing_container.visible = false
return
Expand Down Expand Up @@ -90,3 +98,10 @@ func add_child_menu(qb_item: Control, icon: Texture2D, focus_node: Control = nul
focus_parent.add_child(focus_group)

viewport.add_child(qb_card)


## Ensure that the library item meta data is always set before opening the gamepad
## settings menu
func _on_gampad_button_pressed() -> void:
var library_item := launch_manager.get_current_app_library_item()
gamepad_state.set_meta("item", library_item)
1 change: 1 addition & 0 deletions core/ui/card_ui/quick_bar/quick_bar_menu.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ state = ExtResource("14_gr3i0")
on_signal = "button_up"

[node name="GamepadButton" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer/ButtonContainer" instance=ExtResource("9_6qs1m")]
unique_name_in_owner = true
custom_minimum_size = Vector2(26, 26)
layout_mode = 2
texture = ExtResource("15_0l0p5")
Expand Down
2 changes: 1 addition & 1 deletion core/ui/common/settings/display_settings_menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func _ready() -> void:
get_window().content_scale_factor = display_scale
scale_slider.value_changed.connect(_on_scale_changed)

var blur_enabled := settings_manager.get_value("display", "enable_overlay_blur", true) as bool
var blur_enabled := settings_manager.get_value("display", "enable_overlay_blur", false) as bool
blur_toggle.button_pressed = blur_enabled
blur_toggle.toggled.connect(_on_blur_toggled)

Expand Down
16 changes: 12 additions & 4 deletions core/ui/components/loading02.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ extends Control

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
if visible:
if is_visible_in_tree():
set_process(true)
animation_player.play("play")
else:
set_process(false)
animation_player.stop()
visibility_changed.connect(_on_visibility_changed)


func _on_visibility_changed() -> void:
if not animation_player:
return
if visible:
if is_visible_in_tree():
set_process(true)
animation_player.play("play")
return
Expand All @@ -26,5 +30,9 @@ func _on_visibility_changed() -> void:
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
var sprite_scale := 1 / (sprite.texture.get_height() / size.y)
sprite.offset = size / 2 / sprite_scale
sprite.scale = Vector2(sprite_scale, sprite_scale)
var new_offset := size / 2 / sprite_scale
if new_offset != sprite.offset:
sprite.offset = new_offset
var new_scale := Vector2(sprite_scale, sprite_scale)
if new_scale != sprite.scale:
sprite.scale = new_scale
2 changes: 1 addition & 1 deletion core/ui/components/loading02.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ script = ExtResource("1_1u2cn")
texture = ExtResource("1_jaecb")
offset = Vector2(128, 128)
hframes = 43
frame = 20
frame = 31

[node name="AnimationPlayer" type="AnimationPlayer" parent="Sprite2D"]
root_node = NodePath("../..")
Expand Down

0 comments on commit 2040d5e

Please sign in to comment.