From 2720bfb5d8ffe7efae7b28437aa0f1486afd3e8b Mon Sep 17 00:00:00 2001 From: Shane McGovern Date: Wed, 26 Aug 2026 22:45:09 +0100 Subject: [PATCH] feat(ui): scope on-screen VirtualKeyboard to Linux handhelds and restore L2/R2 trigger scrolling --- src/core/GamepadMap.lua | 4 ++- src/import/RomImporter.lua | 54 +++++++++++++++++++++++++++++++++- src/ui/kit/Kit.lua | 3 +- src/ui/kit/VirtualKeyboard.lua | 17 +++++++++++ 4 files changed, 75 insertions(+), 3 deletions(-) diff --git a/src/core/GamepadMap.lua b/src/core/GamepadMap.lua index fe1fe88c..a7a75604 100644 --- a/src/core/GamepadMap.lua +++ b/src/core/GamepadMap.lua @@ -40,8 +40,10 @@ GamepadMap.NX_RAW_BUTTON_BINDINGS = { -- Raw index -> gamepad button *name* for RomImporter (then NX face swap applies). GamepadMap.RAW_TO_GAMEPAD_BUTTON = { - [1] = "a", [2] = "b", + [1] = "a", [2] = "b", [3] = "x", [4] = "y", + [5] = "leftshoulder", [6] = "rightshoulder", [7] = "back", [8] = "start", [9] = "back", [10] = "start", + [11] = "triggerleft", [12] = "triggerright", } GamepadMap.NX_RAW_TO_GAMEPAD_BUTTON = { diff --git a/src/import/RomImporter.lua b/src/import/RomImporter.lua index 5c5970f3..1e15166b 100644 --- a/src/import/RomImporter.lua +++ b/src/import/RomImporter.lua @@ -3193,8 +3193,13 @@ function RomImporter:gamepadpressed(_, button) return end - -- Select button: toggle Virtual Keyboard + -- Select button: toggle Virtual Keyboard on handhelds if button == "back" or button == "select" or action == "select" then + local isHandheld = os.getenv("HANDHELD") == "1" or os.getenv("PORTMASTER") == "1" + or os.getenv("POKEPORT_HANDHELD") == "1" or os.getenv("TRIMUI") == "1" + or os.getenv("MUOS") == "1" or os.getenv("KNULLI") == "1" + or os.getenv("POKEPORT_SBC") == "1" or os.getenv("ANBERNIC") == "1" + if not isHandheld then return end if okKit and Kit.VirtualKeyboard then if Kit.VirtualKeyboard.active then Kit.VirtualKeyboard.close(false) @@ -3277,6 +3282,17 @@ function RomImporter:gamepadpressed(_, button) return end + -- Triggers (L2 / R2): fast scroll content / lists up and down + if button == "triggerleft" or button == "lefttrigger" or button == "l2" + or action == "triggerleft" or action == "l2" then + require("src.import.LauncherView").wheelmoved(self, 0, 4) + return + elseif button == "triggerright" or button == "righttrigger" or button == "r2" + or action == "triggerright" or action == "r2" then + require("src.import.LauncherView").wheelmoved(self, 0, -4) + return + end + -- Start button: Play / Choose ROM if button == "start" then if self.workState == "working" then return end @@ -3353,6 +3369,24 @@ function RomImporter:gamepadaxis(_, axis, value) elseif axis == "lefty" and math.abs(value) <= PAD_DEAD then self._padStickCentered = true end + elseif axis == "triggerleft" or axis == "lefttrigger" then + if value > 0.4 then + if not self._l2TriggerActive then + require("src.import.LauncherView").wheelmoved(self, 0, 4) + self._l2TriggerActive = true + end + elseif value < 0.2 then + self._l2TriggerActive = false + end + elseif axis == "triggerright" or axis == "righttrigger" then + if value > 0.4 then + if not self._r2TriggerActive then + require("src.import.LauncherView").wheelmoved(self, 0, -4) + self._r2TriggerActive = true + end + elseif value < 0.2 then + self._r2TriggerActive = false + end end end @@ -3380,6 +3414,24 @@ function RomImporter:joystickaxis(joystick, axis, value) self:gamepadaxis(joystick, "leftx", value) elseif axis == 2 then self:gamepadaxis(joystick, "lefty", value) + elseif axis == 3 or axis == 5 then + if value > 0.4 then + if not self._l2RawActive then + require("src.import.LauncherView").wheelmoved(self, 0, 4) + self._l2RawActive = true + end + elseif value < 0.2 then + self._l2RawActive = false + end + elseif axis == 4 or axis == 6 then + if value > 0.4 then + if not self._r2RawActive then + require("src.import.LauncherView").wheelmoved(self, 0, -4) + self._r2RawActive = true + end + elseif value < 0.2 then + self._r2RawActive = false + end end end diff --git a/src/ui/kit/Kit.lua b/src/ui/kit/Kit.lua index e00ea4b6..fe1a9424 100644 --- a/src/ui/kit/Kit.lua +++ b/src/ui/kit/Kit.lua @@ -934,9 +934,10 @@ function Kit.textfield(id, x, y, w, h, value, placeholder) local isHandheld = os.getenv("HANDHELD") == "1" or os.getenv("PORTMASTER") == "1" or os.getenv("POKEPORT_HANDHELD") == "1" or os.getenv("TRIMUI") == "1" or os.getenv("MUOS") == "1" or os.getenv("KNULLI") == "1" + or os.getenv("POKEPORT_SBC") == "1" or os.getenv("ANBERNIC") == "1" local clickedOrActivated = (Kit._activateId == id) or (isHandheld and Kit.press(x, y, w, h)) - if clickedOrActivated and not mobile() then + if isHandheld and clickedOrActivated and not mobile() then VirtualKeyboard.open({ text = value, targetId = id, diff --git a/src/ui/kit/VirtualKeyboard.lua b/src/ui/kit/VirtualKeyboard.lua index 669e3fa2..63f65f77 100755 --- a/src/ui/kit/VirtualKeyboard.lua +++ b/src/ui/kit/VirtualKeyboard.lua @@ -48,7 +48,23 @@ local ROWS_SYM = { { { id = "url_https", label = "https://", w = 3 }, { id = "url_http", label = "http://", w = 2 }, { id = "url_json", label = ".json", w = 2 }, { id = "url_zip", label = ".zip", w = 2 }, { id = "clear", label = "Clear", w = 3 } }, } +local function isLinuxHandheld() + return os.getenv("HANDHELD") == "1" + or os.getenv("PORTMASTER") == "1" + or os.getenv("POKEPORT_HANDHELD") == "1" + or os.getenv("TRIMUI") == "1" + or os.getenv("MUOS") == "1" + or os.getenv("KNULLI") == "1" + or os.getenv("POKEPORT_SBC") == "1" + or os.getenv("ANBERNIC") == "1" +end + +function VirtualKeyboard.isSupported() + return isLinuxHandheld() +end + function VirtualKeyboard.open(opts) + if not isLinuxHandheld() then return false end opts = opts or {} VirtualKeyboard.active = true VirtualKeyboard.text = tostring(opts.text or "") @@ -58,6 +74,7 @@ function VirtualKeyboard.open(opts) VirtualKeyboard.row = 1 VirtualKeyboard.col = 1 VirtualKeyboard.mode = 1 + return true end function VirtualKeyboard.close(confirmed)