Skip to content

Commit 6e6edb8

Browse files
committed
Fix usability issues with OSK
1 parent 9c7acf2 commit 6e6edb8

File tree

6 files changed

+30
-11
lines changed

6 files changed

+30
-11
lines changed

addons/onscreenkeyboard/onscreen_keyboard.gd

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
extends PopupPanel
1+
extends Window
22

33
enum Direction {
44
UP,
@@ -32,9 +32,11 @@ signal layoutChanged
3232

3333
func _enter_tree():
3434
get_tree().get_root().size_changed.connect(size_changed)
35-
popup_hide.connect(hide)
3635
focus_exited.connect(hide)
3736
visible = false
37+
transient = true
38+
exclusive = true
39+
borderless = true
3840

3941
func _ready():
4042
RetroHubConfig.config_ready.connect(on_config_ready)
@@ -126,16 +128,23 @@ func _initKeyboard(config_value: String):
126128
###########################
127129

128130
var focused_control : Control = null
131+
var focused_window : Window = null
129132

130133
func show_keyboard(focused_control: Control):
131134
self.focused_control = focused_control
132135
visible = true
136+
137+
# Set window transience
138+
focused_window = focused_control.get_viewport().get_window()
133139
_showKeyboard()
134140
# Skip current frame to avoid double input when opening the keyboard
135141

136142
func hide_keyboard():
137143
await _hideKeyboard()
144+
if focused_window:
145+
focused_window.grab_focus()
138146
focused_control = null
147+
focused_window = null
139148

140149
func _hideKeyboard(keyData=null,x=null,y=null,steal_focus=null):
141150
var tween := create_tween().set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_SINE)
@@ -359,6 +368,9 @@ func _createKeyboard(layoutData):
359368
layoutContainer.tooltip_text = layout.get("name")
360369
layouts.push_back(layoutContainer)
361370
add_child(layoutContainer)
371+
layoutContainer.set_anchors_preset(Control.PRESET_FULL_RECT, true)
372+
layoutContainer.size_flags_horizontal = Control.SIZE_EXPAND_FILL
373+
layoutContainer.size_flags_vertical = Control.SIZE_EXPAND_FILL
362374

363375
var baseVbox = VBoxContainer.new()
364376
baseVbox.size_flags_horizontal = Control.SIZE_EXPAND_FILL

addons/onscreenkeyboard/plugin_node.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ extends EditorPlugin
44
func _enter_tree():
55
# Initialization of the plugin goes here
66
# Add the new type with a name, a parent type, a script and an icon
7-
add_custom_type("OnscreenKeyboard", "PopupPanel", preload("onscreen_keyboard.gd"), preload("control_icon.png"))
7+
add_custom_type("OnscreenKeyboard", "Window", preload("onscreen_keyboard.gd"), preload("control_icon.png"))
88

99
func _exit_tree():
1010
# Clean-up of the plugin goes here

project.godot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ config_version=5
1212

1313
config/name="RetroHub"
1414
run/main_scene="res://scenes/root/Root.tscn"
15-
config/features=PackedStringArray("4.1")
15+
config/features=PackedStringArray("4.2")
1616
boot_splash/bg_color=Color(0.188235, 0.235294, 0.290196, 1)
1717
boot_splash/image="res://assets/icons/app/splash.png"
1818
config/icon="res://icon.png"

scenes/root/Root.gd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ func _enter_tree():
1919

2020
func _raw_input(event: InputEvent):
2121
if not RetroHub._running_game:
22-
if event.is_action_pressed("rh_menu") and not RetroHubConfig.config.is_first_time:
22+
if event.is_action_pressed("rh_menu") and not RetroHubConfig.config.is_first_time \
23+
and not RetroHubUI.is_virtual_keyboard_visible():
2324
if not $ConfigPopup.visible:
2425
get_viewport().set_input_as_handled()
2526
$ConfigPopup.open_config()
@@ -35,6 +36,7 @@ func _ready():
3536
RetroHubConfig.config_updated.connect(_on_config_updated)
3637

3738
# Add popups to UI singleton
39+
RetroHubUI._n_theme_viewport = n_viewport
3840
RetroHubUI._n_config_popup = n_config_popup
3941
RetroHubUI._n_virtual_keyboard = n_keyboard_popup
4042

scenes/root/Root.tscn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ handle_input_locally = false
5858
visible = false
5959
content_scale_aspect = 4
6060

61-
[node name="Keyboard" type="PopupPanel" parent="."]
61+
[node name="Keyboard" type="Window" parent="."]
6262
unique_name_in_owner = true
6363
position = Vector2i(0, 348)
6464
size = Vector2i(1152, 300)

source/UI.gd

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
extends Control
22

3+
var _n_theme_viewport : Viewport
34
var _n_filesystem_popup : FileDialog: set = _set_filesystem_popup
4-
var _n_virtual_keyboard : PopupPanel: set = _set_virtual_keyboard
5+
var _n_virtual_keyboard : Window: set = _set_virtual_keyboard
56
var _n_config_popup : Window: set = _set_config_popup
67
var _n_warning_popup : AcceptDialog: set = _set_warning_popup
78

@@ -60,7 +61,7 @@ func _set_filesystem_popup(popup: FileDialog):
6061
#warning-ignore:return_value_discarded
6162
_n_filesystem_popup.visibility_changed.connect(_on_visibility_changed)
6263

63-
func _set_virtual_keyboard(keyboard: PopupPanel):
64+
func _set_virtual_keyboard(keyboard: Window):
6465
_n_virtual_keyboard = keyboard
6566

6667
func _set_config_popup(config_popup: Window):
@@ -150,7 +151,7 @@ func show_warning(text: String):
150151
_n_warning_popup.get_ok_button().grab_focus()
151152

152153
func get_focused_window() -> Window:
153-
var win_id := DisplayServer.get_focused_window_or_popup()
154+
var win_id := DisplayServer.get_top_popup_or_focused_window()
154155
var win : Window = instance_from_id(win_id)
155156
return win
156157

@@ -162,9 +163,13 @@ func get_true_focused_control() -> Control:
162163

163164
# Find currently focused "embedded" window viewport
164165
var viewport := win.get_viewport()
166+
# Handle theme viewport as well
167+
if viewport == get_tree().get_root().get_viewport():
168+
viewport = _n_theme_viewport
169+
165170
while viewport:
166-
if viewport.get_focused_window_or_popup() == null:
171+
if viewport.get_top_popup_or_focused_window() == null:
167172
# Found the innermost viewport
168173
return viewport.gui_get_focus_owner()
169-
viewport = viewport.get_focused_window_or_popup().get_viewport()
174+
viewport = viewport.get_top_popup_or_focused_window().get_viewport()
170175
return get_viewport().gui_get_focus_owner()

0 commit comments

Comments
 (0)