Skip to content

Commit 0462b4f

Browse files
committed
Prevent controller input when launching emulators directly
1 parent fb32dbc commit 0462b4f

10 files changed

+96
-9
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
extends Window
2+
3+
var pid := 0
4+
5+
func _process(delta):
6+
if not visible: return
7+
if pid >= 0 or not OS.is_process_running(pid):
8+
# Request focus, as we might not have it
9+
get_tree().root.move_to_foreground()
10+
_on_close_requested()
11+
12+
func _on_about_to_popup():
13+
RetroHub._prevent_controller_input = true
14+
15+
func _on_close_requested():
16+
hide()
17+
# 0 or -1 will kill ALL processes, at least on Linux.
18+
# We definitely do not want that.
19+
if pid > 0:
20+
OS.kill(pid)
21+
pid = 0
22+
RetroHub._prevent_controller_input = false
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[gd_scene load_steps=2 format=3 uid="uid://d0w7vab58e64a"]
2+
3+
[ext_resource type="Script" path="res://scenes/config/settings/EmulatorLaunchedPopup.gd" id="1_3nwfj"]
4+
5+
[node name="EmulatorLaunchedPopup" type="Window"]
6+
initial_position = 1
7+
size = Vector2i(624, 357)
8+
script = ExtResource("1_3nwfj")
9+
10+
[node name="Panel" type="Panel" parent="."]
11+
anchors_preset = 15
12+
anchor_right = 1.0
13+
anchor_bottom = 1.0
14+
grow_horizontal = 2
15+
grow_vertical = 2
16+
theme_type_variation = &"WindowPanel"
17+
18+
[node name="CenterContainer" type="CenterContainer" parent="Panel"]
19+
layout_mode = 1
20+
anchors_preset = 15
21+
anchor_right = 1.0
22+
anchor_bottom = 1.0
23+
grow_horizontal = 2
24+
grow_vertical = 2
25+
26+
[node name="Label" type="Label" parent="Panel/CenterContainer"]
27+
layout_mode = 2
28+
text = "The emulator is running...
29+
30+
To return to Retrohub, either close the emulator, or close
31+
this popup to kill the emulator process..."
32+
horizontal_alignment = 1
33+
vertical_alignment = 1
34+
35+
[connection signal="about_to_popup" from="." to="." method="_on_about_to_popup"]
36+
[connection signal="close_requested" from="." to="." method="_on_close_requested"]

scenes/config/settings/EmulatorSettings.gd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ extends Control
1313

1414
@onready var n_add_custom_info_popup := %AddCustomInfoPopup
1515
@onready var n_add_custom_core_info_popup := %AddCustomCoreInfoPopup
16+
@onready var n_emulator_launched_popup := %EmulatorLaunchedPopup
1617

1718
var sep_idx := -1
1819

@@ -178,3 +179,6 @@ func _on_EmulatorEditorsTab_focus_entered():
178179
get_current_emulator_editor().focus_node_from_bottom()
179180

180181

182+
func _on_emulator_launched(pid: int):
183+
n_emulator_launched_popup.pid = pid
184+
n_emulator_launched_popup.popup_centered()

scenes/config/settings/EmulatorSettings.tscn

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
[gd_scene load_steps=8 format=3 uid="uid://carj0e8mnxjvn"]
1+
[gd_scene load_steps=9 format=3 uid="uid://carj0e8mnxjvn"]
22

33
[ext_resource type="PackedScene" uid="uid://6yp7suicf3ib" path="res://scenes/config/settings/emulator/EmulatorEditor.tscn" id="1"]
44
[ext_resource type="Script" path="res://scenes/config/settings/EmulatorSettings.gd" id="2"]
55
[ext_resource type="PackedScene" uid="uid://dnlu06cgbfnex" path="res://scenes/config/settings/AddCustomInfo.tscn" id="3"]
66
[ext_resource type="PackedScene" uid="uid://60ylmuq3irmj" path="res://scenes/config/settings/emulator/RetroArchEmulatorEditor.tscn" id="4"]
77
[ext_resource type="Script" path="res://source/utils/ScrollHandler.gd" id="5"]
88
[ext_resource type="Script" path="res://scenes/ui_nodes/AccessibilityFocus.gd" id="6"]
9+
[ext_resource type="PackedScene" uid="uid://d0w7vab58e64a" path="res://scenes/config/settings/EmulatorLaunchedPopup.tscn" id="7_i3ta7"]
910

1011
[sub_resource type="StyleBoxEmpty" id="1"]
1112

@@ -155,6 +156,10 @@ visible = false
155156
unique_name_in_owner = true
156157
visible = false
157158

159+
[node name="EmulatorLaunchedPopup" parent="." instance=ExtResource("7_i3ta7")]
160+
unique_name_in_owner = true
161+
visible = false
162+
158163
[connection signal="visibility_changed" from="." to="." method="_on_EmulatorSettings_visibility_changed"]
159164
[connection signal="item_selected" from="VBoxContainer/HBoxContainer/EmulatorSelection" to="." method="_on_EmulatorSelection_item_selected"]
160165
[connection signal="pressed" from="VBoxContainer/HBoxContainer/Save" to="." method="save_changes"]
@@ -165,7 +170,9 @@ visible = false
165170
[connection signal="focus_entered" from="VBoxContainer/HSeparatorTop" to="." method="_on_HSeparatorTop_focus_entered"]
166171
[connection signal="focus_entered" from="VBoxContainer/EmulatorEditorsTab" to="." method="_on_EmulatorEditorsTab_focus_entered"]
167172
[connection signal="change_ocurred" from="VBoxContainer/EmulatorEditorsTab/ScrollContainer/EmulatorEditor" to="." method="_on_EmulatorEditor_change_ocurred"]
173+
[connection signal="emulator_launched" from="VBoxContainer/EmulatorEditorsTab/ScrollContainer/EmulatorEditor" to="." method="_on_emulator_launched"]
168174
[connection signal="change_ocurred" from="VBoxContainer/EmulatorEditorsTab/ScrollContainer2/RetroArchEmulatorEditor" to="." method="_on_EmulatorEditor_change_ocurred"]
175+
[connection signal="emulator_launched" from="VBoxContainer/EmulatorEditorsTab/ScrollContainer2/RetroArchEmulatorEditor" to="." method="_on_emulator_launched"]
169176
[connection signal="request_add_core" from="VBoxContainer/EmulatorEditorsTab/ScrollContainer2/RetroArchEmulatorEditor" to="." method="_on_RetroArchEmulatorEditor_request_add_core"]
170177
[connection signal="identifier_picked" from="AddCustomInfoPopup" to="." method="_on_AddCustomInfoPopup_identifier_picked"]
171178
[connection signal="identifier_picked" from="AddCustomCoreInfoPopup" to="." method="_on_AddCustomCoreInfoPopup_identifier_picked"]

scenes/config/settings/emulator/EmulatorEditor.gd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
extends Control
22

33
signal change_ocurred
4+
signal emulator_launched(pid)
45

56
var curr_emulator : Dictionary: set = set_curr_emulator
67

@@ -71,4 +72,5 @@ func _on_LoadPath_pressed():
7172

7273
func _on_run_emulator_pressed():
7374
var path : String = n_path.text
74-
OS.create_process(path, [])
75+
var pid := OS.create_process(path, [])
76+
emulator_launched.emit(pid)

scenes/config/settings/emulator/RetroArchEmulatorEditor.gd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ extends Control
22

33
signal change_ocurred
44
signal request_add_core
5+
signal emulator_launched(pid: int)
56

67
var curr_emulator : Dictionary: set = set_curr_emulator
78
var cores : Array
@@ -164,3 +165,9 @@ func _on_RemoveCore_pressed():
164165

165166
func _on_AddCore_pressed():
166167
emit_signal("request_add_core")
168+
169+
170+
func _on_run_emulator_pressed():
171+
var path : String = n_path.text
172+
var pid := OS.create_process(path, [])
173+
emulator_launched.emit(pid)

scenes/config/settings/emulator/RetroArchEmulatorEditor.tscn

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
[gd_scene load_steps=4 format=3 uid="uid://60ylmuq3irmj"]
1+
[gd_scene load_steps=5 format=3 uid="uid://60ylmuq3irmj"]
22

33
[ext_resource type="Script" path="res://scenes/config/settings/emulator/RetroArchEmulatorEditor.gd" id="1"]
44
[ext_resource type="Texture2D" uid="uid://dydir8kskmsc6" path="res://assets/icons/load.svg" id="2"]
55
[ext_resource type="Script" path="res://scenes/ui_nodes/AccessibilityFocus.gd" id="3"]
6+
[ext_resource type="Texture2D" uid="uid://d1jo22nh3m8ge" path="res://assets/icons/run.svg" id="4_v08bo"]
67

78
[node name="RetroArchEmulatorEditor" type="VBoxContainer"]
89
anchors_preset = 15
910
anchor_right = 1.0
1011
anchor_bottom = 1.0
11-
pivot_offset = Vector2(177, 407)
12+
grow_horizontal = 2
13+
grow_vertical = 2
1214
size_flags_horizontal = 3
1315
size_flags_vertical = 3
1416
script = ExtResource("1")
@@ -91,6 +93,11 @@ layout_mode = 2
9193
text = "Load"
9294
icon = ExtResource("2")
9395

96+
[node name="RunEmulator" type="Button" parent="HBoxContainer4"]
97+
layout_mode = 2
98+
text = "Launch"
99+
icon = ExtResource("4_v08bo")
100+
94101
[node name="HBoxContainer9" type="HBoxContainer" parent="."]
95102
layout_mode = 2
96103

@@ -321,6 +328,7 @@ next = NodePath("../../../Label")
321328
[connection signal="text_changed" from="HBoxContainer3/Name" to="." method="_on_item_change"]
322329
[connection signal="text_changed" from="HBoxContainer4/Path" to="." method="_on_item_change"]
323330
[connection signal="pressed" from="HBoxContainer4/LoadPath" to="." method="_on_LoadPath_pressed"]
331+
[connection signal="pressed" from="HBoxContainer4/RunEmulator" to="." method="_on_run_emulator_pressed"]
324332
[connection signal="text_changed" from="HBoxContainer9/CorePath" to="." method="_on_item_change"]
325333
[connection signal="pressed" from="HBoxContainer9/LoadCorePath" to="." method="_on_LoadCorePath_pressed"]
326334
[connection signal="text_changed" from="HBoxContainer5/Command" to="." method="_on_item_change"]

scenes/config/settings/input/ControllerLayout.gd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ func reset():
299299

300300
func start():
301301
# Disable custom controller handler while this popup is visible
302-
RetroHub._is_input_remap_utility = true
302+
RetroHub._prevent_controller_input = true
303303
joy_guid = Input.get_joy_guid(0)
304304
joy_name = Input.get_joy_name(0)
305305
Input.remove_joy_mapping(joy_guid)
@@ -379,7 +379,7 @@ func _on_ControllerLayout_about_to_show():
379379

380380
func _on_DoneButton_pressed():
381381
hide()
382-
RetroHub._is_input_remap_utility = false
382+
RetroHub._prevent_controller_input = false
383383

384384
func _on_ResetButton_pressed():
385385
reset()
@@ -393,4 +393,4 @@ func _on_PreviousButton_pressed():
393393

394394
func _on_close_requested():
395395
hide()
396-
RetroHub._is_input_remap_utility = false
396+
RetroHub._prevent_controller_input = false

source/RetroHub.gd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var launched_emulator : Dictionary = {}
2929

3030
var _is_echo := false
3131
@warning_ignore("unused_private_class_variable")
32-
var _is_input_remap_utility := false
32+
var _prevent_controller_input := false
3333
var _theme_processing_done := false
3434

3535
const version_major := 1
@@ -55,6 +55,7 @@ func _ready():
5555
func _notification(what):
5656
match what:
5757
NOTIFICATION_APPLICATION_FOCUS_IN:
58+
print(get_signal_connection_list("app_received_focus"))
5859
emit_signal("app_received_focus")
5960
NOTIFICATION_APPLICATION_FOCUS_OUT:
6061
emit_signal("app_lost_focus")

source/utils/InputHandler.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func _on_joypad_echo_delay_timeout():
4747
Input.parse_input_event(_joypad_last_event)
4848

4949
func _raw_input(event):
50-
if RetroHub._is_input_remap_utility:
50+
if RetroHub._prevent_controller_input:
5151
return;
5252
ControllerIcons._input(event)
5353
_event_handled = false

0 commit comments

Comments
 (0)