Skip to content

Commit

Permalink
fix(Core): use inputplumber for sending OSK keys and add open OSK button
Browse files Browse the repository at this point in the history
- Add 'launch_in_background' method to Launchmanager
  • Loading branch information
ShadowApex committed Dec 11, 2024
1 parent f169780 commit 708e9ee
Show file tree
Hide file tree
Showing 11 changed files with 522 additions and 53 deletions.
1 change: 0 additions & 1 deletion core/global/keyboard_instance.gd
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,3 @@ func set_context(ctx: KeyboardContext) -> void:
context = ctx
context_changed.emit(ctx)
ctx.entered.emit()

53 changes: 43 additions & 10 deletions core/global/launch_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ var _sandbox := Sandbox.get_sandbox()
var _current_app: RunningApp
var _pid_to_windows := {}
var _running: Array[RunningApp] = []
var _running_background: Array[RunningApp] = []
var _apps_by_pid: Dictionary = {}
var _apps_by_name: Dictionary = {}
var _data_dir: String = ProjectSettings.get_setting("OpenGamepadUI/data/directory")
Expand Down Expand Up @@ -135,7 +136,7 @@ func _init() -> void:
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)
_xwayland_game.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):
Expand Down Expand Up @@ -191,9 +192,39 @@ func _save_persist_data():
file.flush()


## Launches the given command on the target xwayland display. Returns a PID
## of the launched process.
## Launches the given application and switches to the in-game state. Returns a
## [RunningApp] instance of the application.
func launch(app: LibraryLaunchItem) -> RunningApp:
var running_app := _launch(app)

# Add the running app to our list and change to the IN_GAME state
_add_running(running_app)
state_machine.set_state([in_game_state])
_update_recent_apps(app)

return running_app


## Launches the given app in the background. Returns the [RunningApp] instance.
func launch_in_background(app: LibraryLaunchItem) -> RunningApp:
# Start the application
var running_app := _launch(app)

# Listen for app state changes
var on_app_state_changed := func(from: RunningApp.STATE, to: RunningApp.STATE):
if to != RunningApp.STATE.STOPPED:
return
logger.debug("Cleaning up pid {0}".format([running_app.pid]))
_running_background.erase(running_app)
logger.debug("Currently running background apps:", _running_background)
running_app.state_changed.connect(on_app_state_changed)
_running_background.append(running_app)

return running_app


## Launches the given app
func _launch(app: LibraryLaunchItem) -> RunningApp:
var cmd: String = app.command
var args: PackedStringArray = app.args
var env: Dictionary = app.env.duplicate()
Expand All @@ -220,7 +251,7 @@ func launch(app: LibraryLaunchItem) -> RunningApp:
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
var use_sandboxing := settings_manager.get_value(section, sandboxing_key, false) as bool

# Set the display environment if one was not set.
if not "DISPLAY" in env:
Expand Down Expand Up @@ -254,12 +285,7 @@ func launch(app: LibraryLaunchItem) -> RunningApp:
# Launch the application process
var running_app := RunningApp.spawn(app, env, exec, command)
logger.info("Launched with PID: {0}".format([running_app.pid]))

# Add the running app to our list and change to the IN_GAME state
_add_running(running_app)
state_machine.set_state([in_game_state])
_update_recent_apps(app)


return running_app


Expand Down Expand Up @@ -306,6 +332,11 @@ func get_running() -> Array[RunningApp]:
return _running.duplicate()


## Returns a list of currently running background apps
func get_running_background() -> Array[RunningApp]:
return _running_background.duplicate()


## Returns the running app from the given window id
func get_running_from_window_id(window_id: int) -> RunningApp:
for app in _running:
Expand Down Expand Up @@ -463,6 +494,8 @@ func check_running() -> void:
# Update the state of all running apps
for app in _running:
app.update()
for app in _running_background:
app.update()


# Updates our mapping of PIDs to Windows. This gives us a good view of what
Expand Down
1 change: 1 addition & 0 deletions core/global/library_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ func remove_library_launch_item(library_id: String, name: String) -> void:

## Loads the launch items from the given library
func load_library(library_id: String) -> void:
logger.debug("Loading library from provider:", library_id)
var library := get_library_by_id(library_id)
var items: Array = await library.get_library_launch_items()
for i in items:
Expand Down
263 changes: 263 additions & 0 deletions core/systems/input/events/event.gd
Original file line number Diff line number Diff line change
Expand Up @@ -740,3 +740,266 @@ static func capability_from_keycode(scancode: int) -> String:
return "Keyboard:KeyF24"
_:
return ""


## Convert the given key scancode into a target keyboard event string
static func virtual_key_from_keycode(scancode: int) -> String:
match scancode:
KEY_ESCAPE:
return "KEY_ESC"
KEY_1:
return "KEY_1"
KEY_2:
return "KEY_2"
KEY_3:
return "KEY_3"
KEY_4:
return "KEY_4"
KEY_5:
return "KEY_5"
KEY_6:
return "KEY_6"
KEY_7:
return "KEY_7"
KEY_8:
return "KEY_8"
KEY_9:
return "KEY_9"
KEY_0:
return "KEY_0"
KEY_MINUS:
return "KEY_MINUS"
KEY_EQUAL:
return "KEY_EQUAL"
KEY_BACKSPACE:
return "KEY_BACKSPACE"
KEY_TAB:
return "KEY_TAB"
KEY_Q:
return "KEY_Q"
KEY_W:
return "KEY_W"
KEY_E:
return "KEY_E"
KEY_R:
return "KEY_R"
KEY_T:
return "KEY_T"
KEY_Y:
return "KEY_Y"
KEY_U:
return "KEY_U"
KEY_I:
return "KEY_I"
KEY_O:
return "KEY_O"
KEY_P:
return "KEY_P"
KEY_BRACELEFT:
return "KEY_LEFTBRACE"
KEY_BRACERIGHT:
return "KEY_RIGHTBRACE"
KEY_ENTER:
return "KEY_ENTER"
KEY_CTRL:
return "KEY_LEFTCTRL"
KEY_A:
return "KEY_A"
KEY_S:
return "KEY_S"
KEY_D:
return "KEY_D"
KEY_F:
return "KEY_F"
KEY_G:
return "KEY_G"
KEY_H:
return "KEY_H"
KEY_J:
return "KEY_J"
KEY_K:
return "KEY_K"
KEY_L:
return "KEY_L"
KEY_SEMICOLON:
return "KEY_SEMICOLON"
KEY_APOSTROPHE:
return "KEY_APOSTROPHE"
KEY_ASCIITILDE:
return "KEY_GRAVE"
KEY_SHIFT:
return "KEY_LEFTSHIFT"
KEY_BACKSLASH:
return "KEY_BACKSLASH"
KEY_Z:
return "KEY_Z"
KEY_X:
return "KEY_X"
KEY_C:
return "KEY_C"
KEY_V:
return "KEY_V"
KEY_B:
return "KEY_B"
KEY_N:
return "KEY_N"
KEY_M:
return "KEY_M"
KEY_COMMA:
return "KEY_COMMA"
KEY_PERIOD:
return "KEY_DOT"
KEY_SLASH:
return "KEY_SLASH"
KEY_SHIFT:
return "KEY_SHIFT"
KEY_ASTERISK:
return "KEY_ASTERISK"
KEY_ALT:
return "KEY_ALT"
KEY_SPACE:
return "KEY_SPACE"
KEY_CAPSLOCK:
return "KEY_CAPSLOCK"
KEY_F1:
return "KEY_F1"
KEY_F2:
return "KEY_F2"
KEY_F3:
return "KEY_F3"
KEY_F4:
return "KEY_F4"
KEY_F5:
return "KEY_F5"
KEY_F6:
return "KEY_F6"
KEY_F7:
return "KEY_F7"
KEY_F8:
return "KEY_F8"
KEY_F9:
return "KEY_F9"
KEY_F10:
return "KEY_F10"
KEY_NUMLOCK:
return "KEY_NUMLOCK"
KEY_SCROLLLOCK:
return "KEY_SCROLLLOCK"
KEY_KP_7:
return "KEY_KP7"
KEY_KP_8:
return "KEY_KP8"
KEY_KP_9:
return "KEY_KP9"
KEY_KP_SUBTRACT:
return "KEY_KPMINUS"
KEY_KP_4:
return "KEY_KP4"
KEY_KP_5:
return "KEY_KP5"
KEY_KP_6:
return "KEY_KP6"
KEY_KP_ADD:
return "KEY_KPPLUS"
KEY_KP_1:
return "KEY_KP1"
KEY_KP_2:
return "KEY_KP2"
KEY_KP_3:
return "KEY_KP3"
KEY_KP_0:
return "KEY_KP0"
KEY_KP_PERIOD:
return "KEY_KPDOT"
KEY_F11:
return "KEY_F11"
KEY_F12:
return "KEY_F12"
KEY_JIS_KANA:
return "KEY_KATAKANAHIRAGANA"
KEY_KP_ENTER:
return "KEY_KPENTER"
KEY_CTRL:
return "KEY_CTRL"
KEY_KP_DIVIDE:
return "KEY_KPSLASH"
KEY_SYSREQ:
return "KEY_SYSREQ"
KEY_ALT:
return "KEY_ALT"
KEY_HOME:
return "KEY_HOME"
KEY_UP:
return "KEY_UP"
KEY_PAGEUP:
return "KEY_PAGEUP"
KEY_LEFT:
return "KEY_LEFT"
KEY_RIGHT:
return "KEY_RIGHT"
KEY_END:
return "KEY_END"
KEY_DOWN:
return "KEY_DOWN"
KEY_PAGEDOWN:
return "KEY_PAGEDOWN"
KEY_INSERT:
return "KEY_INSERT"
KEY_DELETE:
return "KEY_DELETE"
KEY_VOLUMEMUTE:
return "KEY_VOLUMEMUTE"
KEY_VOLUMEDOWN:
return "KEY_VOLUMEDOWN"
KEY_VOLUMEUP:
return "KEY_VOLUMEUP"
KEY_PAUSE:
return "KEY_PAUSE"
KEY_YEN:
return "KEY_YEN"
KEY_META:
return "KEY_LEFTMETA"
KEY_STOP:
return "KEY_STOP"
KEY_HELP:
return "KEY_HELP"
KEY_BACK:
return "KEY_BACK"
KEY_FORWARD:
return "KEY_FORWARD"
KEY_MEDIANEXT:
return "KEY_MEDIANEXT"
KEY_MEDIAPLAY:
return "KEY_MEDIAPLAY"
KEY_MEDIAPREVIOUS:
return "KEY_MEDIAPREVIOUS"
KEY_MEDIASTOP:
return "KEY_MEDIASTOP"
KEY_REFRESH:
return "KEY_REFRESH"
KEY_F13:
return "KEY_F13"
KEY_F14:
return "KEY_F14"
KEY_F15:
return "KEY_F15"
KEY_F16:
return "KEY_F16"
KEY_F17:
return "KEY_F17"
KEY_F18:
return "KEY_F18"
KEY_F19:
return "KEY_F19"
KEY_F20:
return "KEY_F20"
KEY_F21:
return "KEY_F21"
KEY_F22:
return "KEY_F22"
KEY_F23:
return "KEY_F23"
KEY_F24:
return "KEY_F24"
_:
return ""
Loading

0 comments on commit 708e9ee

Please sign in to comment.