From ae863cc6132552a0d8458cb19470d78bf675fa58 Mon Sep 17 00:00:00 2001 From: The412Banner Date: Wed, 23 Sep 2026 22:20:04 -0400 Subject: [PATCH] Controller profiles for every desktop emulator; PC keyboard under half the screen bannerlator-pad-defaults now covers DuckStation, PCSX2, Dolphin (GameCube and Wii), Cemu, melonDS, PPSSPP and RetroArch as well as RPCS3, from each project's source: files an emulator would otherwise fill with keyboard-only defaults are seeded when missing (Dolphin, Cemu, PPSSPP, RPCS3), or given SDL bindings in the config the emulator wrote itself when nothing binds a controller yet (DuckStation, PCSX2 with its SettingsVersion, melonDS). RetroArch gets an Xbox 360 profile for its sdl2 driver and is moved off udev, which finds no pads in the runtime. The desktop re-runs it every 30 s, so an emulator's first config is covered for its next start. The PC keyboard takes 47% of the screen height, header included. --- .../com/droiddeck/launcher/ui/PcKeyboard.kt | 19 +- tools/linuxfs/desktop/droiddeck-desktop | 5 +- .../usr/local/bin/bannerlator-pad-defaults | 353 +++++++++++++++++- 3 files changed, 365 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/ui/PcKeyboard.kt b/app/src/main/java/com/droiddeck/launcher/ui/PcKeyboard.kt index 34a67980b7..ad3b34405e 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/PcKeyboard.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/PcKeyboard.kt @@ -143,19 +143,20 @@ fun PcKeyboard( } LaunchedEffect(Unit) { runCatching { firstKey.requestFocus() } } - Box(Modifier.fillMaxSize(), contentAlignment = Alignment.BottomCenter) { - BoxWithConstraints( + BoxWithConstraints(Modifier.fillMaxSize(), contentAlignment = Alignment.BottomCenter) { + // Slightly under half the screen, header included, so the program stays in view above it: + // six rows share what is left of 47% after the header, the gaps and the padding. + val rowHeight = ((maxHeight * 0.47f - 24.dp - 3.dp * 6 - 10.dp) / 6).coerceIn(24.dp, 44.dp) + Box( Modifier.fillMaxWidth() .background(Color(0xE6101418), RoundedCornerShape(topStart = 14.dp, topEnd = 14.dp)) .border(1.dp, pal.line2, RoundedCornerShape(topStart = 14.dp, topEnd = 14.dp)) // Touches on the keyboard stop here; the program underneath never sees them. .pointerInput(Unit) { awaitEachGesture { awaitFirstDown().consume(); waitForUpOrCancellation()?.consume() } } - .padding(horizontal = 8.dp, vertical = 6.dp), + .padding(horizontal = 8.dp, vertical = 5.dp), ) { - // About half the screen on a phone-shaped panel: the program stays visible above it. - val rowHeight = (maxWidth / 26f).coerceIn(30.dp, 44.dp) - Column(verticalArrangement = Arrangement.spacedBy(4.dp)) { - Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth().height(28.dp)) { + Column(verticalArrangement = Arrangement.spacedBy(3.dp)) { + Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth().height(24.dp)) { Text("PC keyboard", fontSize = 12.sp, fontWeight = FontWeight.SemiBold, color = colors.onSurfaceVariant) Spacer(Modifier.weight(1f)) HeaderButton("Android keyboard", onAndroidKeyboard) @@ -163,7 +164,7 @@ fun PcKeyboard( HeaderButton("Hide ✕", onClose) } ROWS.forEachIndexed { r, row -> - Row(horizontalArrangement = Arrangement.spacedBy(4.dp), modifier = Modifier.fillMaxWidth().height(rowHeight)) { + Row(horizontalArrangement = Arrangement.spacedBy(3.dp), modifier = Modifier.fillMaxWidth().height(rowHeight)) { row.forEachIndexed { i, key -> val state = mods[key.code] ?: MOD_OFF val lit = state != MOD_OFF || (key.code == 58 && capsOn) @@ -228,7 +229,7 @@ private fun RowScope.KeyCap( .focusable(interactionSource = src), ) { Text( - label, fontSize = if (label.length > 2) 12.sp else 16.sp, fontWeight = FontWeight.SemiBold, + label, fontSize = if (label.length > 2) 11.sp else 15.sp, fontWeight = FontWeight.SemiBold, color = Color.White, textAlign = TextAlign.Center, maxLines = 1, ) } diff --git a/tools/linuxfs/desktop/droiddeck-desktop b/tools/linuxfs/desktop/droiddeck-desktop index d371980b97..1f4c018b47 100644 --- a/tools/linuxfs/desktop/droiddeck-desktop +++ b/tools/linuxfs/desktop/droiddeck-desktop @@ -101,8 +101,11 @@ export BL_DESKTOP=1 ln -sf /usr/local/bin/bannerlator-steam-launch /usr/local/bin/steamdeck-steam 2>/dev/null ln -sf /usr/local/bin/bannerlator-steam-shim /usr/local/bin/steam 2>/dev/null python3 /usr/local/bin/bannerlator-desktop-games 2>&1 | sed 's/^/[games] /' -# Player 1 on the controller in every emulator that has no profile of its own yet. +# Player 1 on the controller in every emulator that has no profile of its own yet - now, and again +# every half minute: an emulator started for the first time writes its own config, which is then +# given the controller for its next start without waiting for the next desktop. python3 /usr/local/bin/bannerlator-pad-defaults 2>&1 | sed 's/^/[pads] /' +( while sleep 30; do python3 /usr/local/bin/bannerlator-pad-defaults 2>&1 | sed 's/^/[pads] /'; done ) & # Games and emulators from the menu run through droiddeck-gpu (their own gamescope on the app's # compositor) while the desktop is on pixman, where they could not draw with the GPU. # BL_DESKTOP_GPU=on/off overrides; each entry keeps "Run in a desktop window" either way. diff --git a/tools/linuxfs/overlay/usr/local/bin/bannerlator-pad-defaults b/tools/linuxfs/overlay/usr/local/bin/bannerlator-pad-defaults index 82370a7deb..2c016d1008 100755 --- a/tools/linuxfs/overlay/usr/local/bin/bannerlator-pad-defaults +++ b/tools/linuxfs/overlay/usr/local/bin/bannerlator-pad-defaults @@ -70,8 +70,357 @@ def rpcs3(): seed(os.path.join(CONFIG, "rpcs3/input_configs/global/Default.yml"), RPCS3_PLAYER1, "RPCS3") -for step in (rpcs3,): +# ---- ini helpers (DuckStation and PCSX2 share one ini dialect, keys may repeat) ------------- + +def ini_section(lines, name): + """(start, end) line indices of [name]'s body, or None.""" + start = None + for i, l in enumerate(lines): + t = l.strip() + if t.startswith("[") and t.endswith("]"): + if start is not None: + return start, i + if t[1:-1].strip() == name: + start = i + 1 + return (start, len(lines)) if start is not None else None + + +def patch_ini_section(path, section, body, what, needle="SDL-", require=None): + """Add body's lines to [section] of an ini the emulator wrote itself, unless the section + already binds a controller (needle). Missing file: nothing - the emulator writes its own + defaults on first run and this runs again.""" + if not os.path.isfile(path): + return + with open(path, encoding="utf-8", errors="replace") as f: + text = f.read() + if require and require not in text: + return + lines = text.splitlines() + span = ini_section(lines, section) + if span and any(needle in l for l in lines[span[0]:span[1]]): + return + new = body.strip("\n").splitlines() + if span: + # The controller type the emulator already wrote stays; only bindings are added. + have = {l.split("=", 1)[0].strip() for l in lines[span[0]:span[1]] if "=" in l} + new = [l for l in new if not (l.split("=", 1)[0].strip() == "Type" and "Type" in have)] + end = span[1] + while end > span[0] and not lines[end - 1].strip(): + end -= 1 + lines[end:end] = new + else: + lines += ["", f"[{section}]"] + new + with open(path + ".tmp", "w", encoding="utf-8") as f: + f.write("\n".join(lines) + "\n") + os.replace(path + ".tmp", path) + print(f"bannerlator-pad-defaults: {what}: Player 1 on the controller ({path})") + + +# DuckStation: SDL-/, axes signed (src/util/sdl_input_source.cpp); Pad1 keys from +# src/core/analog_controller.cpp. Its defaults bind the keyboard only (settings.cpp). +DUCKSTATION_PAD1 = """Type = AnalogController +Up = SDL-0/DPadUp +Down = SDL-0/DPadDown +Left = SDL-0/DPadLeft +Right = SDL-0/DPadRight +Cross = SDL-0/A +Circle = SDL-0/B +Square = SDL-0/X +Triangle = SDL-0/Y +Select = SDL-0/Back +Start = SDL-0/Start +Analog = SDL-0/Guide +L1 = SDL-0/LeftShoulder +R1 = SDL-0/RightShoulder +L2 = SDL-0/+LeftTrigger +R2 = SDL-0/+RightTrigger +L3 = SDL-0/LeftStick +R3 = SDL-0/RightStick +LLeft = SDL-0/-LeftX +LRight = SDL-0/+LeftX +LUp = SDL-0/-LeftY +LDown = SDL-0/+LeftY +RLeft = SDL-0/-RightX +RRight = SDL-0/+RightX +RUp = SDL-0/-RightY +RDown = SDL-0/+RightY +LargeMotor = SDL-0/LargeMotor +SmallMotor = SDL-0/SmallMotor +""" + + +def duckstation(): + for d in (os.path.join(CONFIG, "duckstation"), os.path.join(HOME, ".local/share/duckstation")): + patch_ini_section(os.path.join(d, "settings.ini"), "Pad1", DUCKSTATION_PAD1, "DuckStation") + + +# PCSX2: FaceSouth/... names (pcsx2/Input/SDLInputSource.cpp), keys from SIO/Pad/PadDualshock2.cpp. +# An ini without [UI] SettingsVersion is thrown away and rebuilt, so only a complete one is patched. +PCSX2_PAD1 = """Type = DualShock2 +Up = SDL-0/DPadUp +Right = SDL-0/DPadRight +Down = SDL-0/DPadDown +Left = SDL-0/DPadLeft +Triangle = SDL-0/FaceNorth +Circle = SDL-0/FaceEast +Cross = SDL-0/FaceSouth +Square = SDL-0/FaceWest +Select = SDL-0/Back +Start = SDL-0/Start +L1 = SDL-0/LeftShoulder +R1 = SDL-0/RightShoulder +L2 = SDL-0/+LeftTrigger +R2 = SDL-0/+RightTrigger +L3 = SDL-0/LeftStick +R3 = SDL-0/RightStick +Analog = SDL-0/Guide +LUp = SDL-0/-LeftY +LRight = SDL-0/+LeftX +LDown = SDL-0/+LeftY +LLeft = SDL-0/-LeftX +RUp = SDL-0/-RightY +RRight = SDL-0/+RightX +RDown = SDL-0/+RightY +RLeft = SDL-0/-RightX +LargeMotor = SDL-0/LargeMotor +SmallMotor = SDL-0/SmallMotor +""" + + +def pcsx2(): + patch_ini_section(os.path.join(CONFIG, "PCSX2/inis/PCSX2.ini"), "Pad1", PCSX2_PAD1, "PCSX2", + require="SettingsVersion") + + +# Dolphin: SDL//; control names from InputCommon/.../SDL/SDLGamepad.h (Left Y+ +# is up). A section that exists is taken whole - keys it lacks are unbound - so both are complete. +DOLPHIN_GC = """[GCPad1] +Device = SDL/0/Xbox 360 Controller +Buttons/A = `Button S` +Buttons/B = `Button W` +Buttons/X = `Button E` +Buttons/Y = `Button N` +Buttons/Z = `Shoulder R` +Buttons/Start = `Start` +Main Stick/Up = `Left Y+` +Main Stick/Down = `Left Y-` +Main Stick/Left = `Left X-` +Main Stick/Right = `Left X+` +C-Stick/Up = `Right Y+` +C-Stick/Down = `Right Y-` +C-Stick/Left = `Right X-` +C-Stick/Right = `Right X+` +Triggers/L = `Trigger L` +Triggers/R = `Trigger R` +Triggers/L-Analog = `Trigger L` +Triggers/R-Analog = `Trigger R` +D-Pad/Up = `Pad N` +D-Pad/Down = `Pad S` +D-Pad/Left = `Pad W` +D-Pad/Right = `Pad E` +Rumble/Motor = `Motor` +""" +DOLPHIN_WII = """[Wiimote1] +Device = SDL/0/Xbox 360 Controller +Source = 1 +Buttons/A = `Button S` +Buttons/B = `Trigger R` +Buttons/1 = `Button W` +Buttons/2 = `Button N` +Buttons/- = `Back` +Buttons/+ = `Start` +Buttons/Home = `Guide` +D-Pad/Up = `Pad N` +D-Pad/Down = `Pad S` +D-Pad/Left = `Pad W` +D-Pad/Right = `Pad E` +IR/Up = `Right Y+` +IR/Down = `Right Y-` +IR/Left = `Right X-` +IR/Right = `Right X+` +Shake/X = `Button E` +Shake/Y = `Button E` +Shake/Z = `Button E` +Rumble/Motor = `Motor` +Extension = Nunchuk +Nunchuk/Buttons/C = `Shoulder L` +Nunchuk/Buttons/Z = `Trigger L` +Nunchuk/Stick/Up = `Left Y+` +Nunchuk/Stick/Down = `Left Y-` +Nunchuk/Stick/Left = `Left X-` +Nunchuk/Stick/Right = `Left X+` +""" + + +def dolphin(): + d = os.path.join(CONFIG, "dolphin-emu") + seed(os.path.join(d, "GCPadNew.ini"), DOLPHIN_GC, "Dolphin (GameCube)") + seed(os.path.join(d, "WiimoteNew.ini"), DOLPHIN_WII, "Dolphin (Wii)") + + +# Cemu: an SDLController profile for the GamePad. The uuid is "_" and SDL's GUID +# carries a CRC of the device name; this is the one SDL reports for the session's pad +# ("Xbox 360 Controller (0)", 045e:028e - read from RPCS3's SDL log on the device). Mapping ids +# from VPADController.h, values from Controller.h, Cemu's own SDL default layout plus Home. +CEMU_MAP = [(1, 1), (2, 0), (3, 3), (4, 2), (5, 9), (6, 10), (7, 42), (8, 43), (9, 6), (10, 4), + (11, 11), (12, 12), (13, 13), (14, 14), (15, 7), (16, 8), (17, 45), (18, 39), (19, 44), + (20, 38), (21, 47), (22, 41), (23, 46), (24, 40), (27, 5)] +CEMU_XML = """ + +\tWii U GamePad +\t0 +\t +\t\tSDLController +\t\t0_03005e615e0400008e02000010010000 +\t\tXbox 360 Controller +\t\t0.5 +\t\t +""" + "".join(f"\t\t\t\n\t\t\t\t{m}\n\t\t\t\t\n\t\t\t\n" for m, b in CEMU_MAP) + """\t\t +\t + +""" + + +def cemu(): + seed(os.path.join(CONFIG, "Cemu/controllerProfiles/controller0.xml"), CEMU_XML, "Cemu") + + +# melonDS 1.x: raw SDL joystick indices. The session's pad has the kernel's Xbox 360 layout +# (buttons A B X Y LB RB Back Start Guide LS RS = 0..10, hat 0 for the d-pad); the d-pad values +# also take the left stick (EmuInstanceInput.cpp; encoding InputConfig/MapButton.h). +MELONDS_JOY = """[Instance0.Joystick] +A = 1 +B = 0 +X = 3 +Y = 2 +L = 4 +R = 5 +Select = 6 +Start = 7 +Up = 17891585 +Down = 16843012 +Left = 1114376 +Right = 65794 +""" + + +def melonds(): + path = os.path.join(CONFIG, "melonDS/melonDS.toml") + if not os.path.isfile(path): + seed(path, "[Instance0]\nJoystickID = 0\n\n" + MELONDS_JOY, "melonDS") + return + with open(path, encoding="utf-8", errors="replace") as f: + text = f.read() + try: + import tomllib + joy = tomllib.loads(text).get("Instance0", {}).get("Joystick", {}) + except Exception: + return + if any(isinstance(v, int) and v != -1 for v in joy.values()): + return # something is bound already + # Replace melonDS's own all-unbound table with ours (a TOML table can be defined only once). + out, skipping = [], False + for line in text.splitlines(): + t = line.strip() + if t.startswith("["): + skipping = t == "[Instance0.Joystick]" + if not skipping: + out.append(line) + with open(path + ".tmp", "w", encoding="utf-8") as f: + f.write("\n".join(out).rstrip("\n") + "\n\n" + MELONDS_JOY) + os.replace(path + ".tmp", path) + print(f"bannerlator-pad-defaults: melonDS: Player 1 on the controller ({path})") + + +# PPSSPP (SDL): its pad defaults leave the shoulders, the right stick and the triggers unbound on +# SDL builds (SDLJoystick.cpp codes vs KeyMapDefaults.cpp); a [ControlMapping] that exists replaces +# every default, so this one is complete, keyboard included (device 1 keyboard, 10 pad). +PPSSPP_CONTROLS = """[ControlMapping] +Up = 1-19,10-19 +Down = 1-20,10-20 +Left = 1-21,10-21 +Right = 1-22,10-22 +Cross = 1-54,10-189 +Circle = 1-52,10-190 +Square = 1-29,10-191 +Triangle = 1-47,10-188 +Start = 1-62,10-197 +Select = 1-66,10-196 +L = 1-45,10-193 +R = 1-51,10-192 +An.Up = 1-37,10-4003 +An.Down = 1-39,10-4002 +An.Left = 1-38,10-4001 +An.Right = 1-40,10-4000 +RightAn.Up = 10-4007 +RightAn.Down = 10-4006 +RightAn.Left = 10-4005 +RightAn.Right = 10-4004 +Pause = 1-111,10-4 +""" + + +def ppsspp(): + seed(os.path.join(CONFIG, "ppsspp/PSP/SYSTEM/controls.ini"), PPSSPP_CONTROLS, "PPSSPP") + + +# RetroArch: the udev joypad driver finds nothing here (no udev database in the runtime); sdl2 +# does, and matches this profile by vendor/product (task_autodetect.c). +RETROARCH_PROFILE = """input_driver = "sdl2" +input_device = "Xbox 360 Controller" +input_vendor_id = "1118" +input_product_id = "654" +input_b_btn = "0" +input_a_btn = "1" +input_y_btn = "2" +input_x_btn = "3" +input_select_btn = "4" +input_menu_toggle_btn = "5" +input_start_btn = "6" +input_l3_btn = "7" +input_r3_btn = "8" +input_l_btn = "9" +input_r_btn = "10" +input_up_btn = "11" +input_down_btn = "12" +input_left_btn = "13" +input_right_btn = "14" +input_l2_axis = "+4" +input_r2_axis = "+5" +input_l_x_plus_axis = "+0" +input_l_x_minus_axis = "-0" +input_l_y_plus_axis = "+1" +input_l_y_minus_axis = "-1" +input_r_x_plus_axis = "+2" +input_r_x_minus_axis = "-2" +input_r_y_plus_axis = "+3" +input_r_y_minus_axis = "-3" +""" + + +def retroarch(): + d = os.path.join(CONFIG, "retroarch") + seed(os.path.join(d, "autoconfig/sdl2/Xbox 360 Controller.cfg"), RETROARCH_PROFILE, "RetroArch (profile)") + cfg = os.path.join(d, "retroarch.cfg") + if not os.path.isfile(cfg): + seed(cfg, 'input_joypad_driver = "sdl2"\ninput_autodetect_enable = "true"\n', "RetroArch") + return + with open(cfg, encoding="utf-8", errors="replace") as f: + lines = f.read().splitlines() + changed = False + for i, l in enumerate(lines): + if l.replace(" ", "").startswith('input_joypad_driver="udev"'): + lines[i] = 'input_joypad_driver = "sdl2"' + changed = True + if changed: + with open(cfg + ".tmp", "w", encoding="utf-8") as f: + f.write("\n".join(lines) + "\n") + os.replace(cfg + ".tmp", cfg) + print(f"bannerlator-pad-defaults: RetroArch: joypad driver udev -> sdl2 ({cfg})") + + +for step in (rpcs3, duckstation, pcsx2, dolphin, cemu, melonds, ppsspp, retroarch): try: step() - except OSError as e: + except Exception as e: print(f"bannerlator-pad-defaults: {step.__name__}: {e}")