Keyboard in the drawer, and GE-Proton / proton-cachyos on request

A session had no way to type without a hardware keyboard. The drawer's Keyboard
opens the soft keyboard onto an invisible host View whose InputConnection turns
what the IME commits into the key events that would have typed it, and the
key path carries Bannerlator's two soft-keyboard fixes: a symbol key with no
scan code is worked back from the character it stands for, and a capital gets
the Shift a soft keyboard reports but never sends — not a hardware one, whose
own Shift would be released early by a second.

Compatibility tools, on the main screen and in the drawer, queues a GE-Proton
or proton-cachyos install as a line in the runtime's ~/.bl-proton-extra, which
the session script hands to bannerlator-proton-extra before the client starts;
it shows what is installed and removes a build.
This commit is contained in:
The412Banner committed 2026-09-20 01:07:09 -04:00
1 parent b74aa97996
commit af25620316
9 files changed
+388 -6

No files matched your search

@@ -69,4 +69,41 @@ public final class EvdevKeys {
default: return -1;
}
}
/**
* The character a key carries when Shift is not held, for a character that needs it - so '@'
* gives '2' and 'A' gives 'a'. Returns 0 when the character is typed without Shift, which is
* also the answer for anything this layout does not place on a key. US layout, which is what
* the session's keymap is.
*/
public static int unshiftedChar(int ch) {
if (ch >= 'A' && ch <= 'Z') return Character.toLowerCase(ch);
int at = SHIFTED_CHARS.indexOf(ch);
return at >= 0 ? PLAIN_CHARS.charAt(at) : 0;
}
// Index-aligned: the symbol, and the key it shares with Shift held.
private static final String SHIFTED_CHARS = "!@#$%^&*()_+{}|:\"<>?~";
private static final String PLAIN_CHARS = "1234567890-=[]\\;',./`";
/** The Android key code that carries an unshifted character, or 0 when nothing does. */
public static int keycodeForChar(int ch) {
if (ch >= 'a' && ch <= 'z') return KeyEvent.KEYCODE_A + (ch - 'a');
if (ch >= '0' && ch <= '9') return KeyEvent.KEYCODE_0 + (ch - '0');
switch (ch) {
case '-': return KeyEvent.KEYCODE_MINUS;
case '=': return KeyEvent.KEYCODE_EQUALS;
case '[': return KeyEvent.KEYCODE_LEFT_BRACKET;
case ']': return KeyEvent.KEYCODE_RIGHT_BRACKET;
case '\\': return KeyEvent.KEYCODE_BACKSLASH;
case ';': return KeyEvent.KEYCODE_SEMICOLON;
case '\'': return KeyEvent.KEYCODE_APOSTROPHE;
case ',': return KeyEvent.KEYCODE_COMMA;
case '.': return KeyEvent.KEYCODE_PERIOD;
case '/': return KeyEvent.KEYCODE_SLASH;
case '`': return KeyEvent.KEYCODE_GRAVE;
case ' ': return KeyEvent.KEYCODE_SPACE;
default: return 0;
}
}
}
@@ -0,0 +1,123 @@
package com.steamdeck.launcher.input
import android.app.Activity
import android.content.Context
import android.text.InputType
import android.view.KeyCharacterMap
import android.view.KeyEvent
import android.view.View
import android.view.inputmethod.BaseInputConnection
import android.view.inputmethod.EditorInfo
import android.view.inputmethod.InputConnection
import android.view.inputmethod.InputMethodManager
/**
* A place for the soft keyboard to land. Steam's UI and the games under it are X11 clients of
* gamescope and know nothing of Wayland text input, so everything the keyboard produces has to
* become key events: what the IME commits as text is turned into the key presses that would have
* typed it (Shift included, from the key character map), and handed to the activity, whose key
* path turns them into evdev codes for the compositor. Backspace, Enter and the keys an IME sends
* directly go the same way.
*
* Invisible and unfocusable until asked for: a focused View would take D-pad and stick motion
* away from the pad.
*/
class KeyboardHost(private val activity: Activity) : View(activity) {
private val imm = activity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
private val map: KeyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD)
var shown = false
private set
init {
isFocusable = false
isFocusableInTouchMode = false
visibility = VISIBLE // present in the tree, draws nothing
layoutParams = android.widget.FrameLayout.LayoutParams(1, 1)
}
override fun onCheckIsTextEditor(): Boolean = shown
override fun onCreateInputConnection(outAttrs: EditorInfo): InputConnection? {
if (!shown) return null
// No suggestions and no autocorrect: the keyboard sends what was pressed, key by key, which
// is what a password field on the other side needs.
outAttrs.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS or
InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
outAttrs.imeOptions = EditorInfo.IME_ACTION_NONE or EditorInfo.IME_FLAG_NO_FULLSCREEN or
EditorInfo.IME_FLAG_NO_EXTRACT_UI
return KeyConnection()
}
fun toggle() = if (shown) hide() else show()
fun show() {
shown = true
isFocusable = true
isFocusableInTouchMode = true
requestFocus()
imm.restartInput(this)
imm.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT)
}
fun hide() {
shown = false
imm.hideSoftInputFromWindow(windowToken, 0)
isFocusable = false
isFocusableInTouchMode = false
clearFocus()
}
private inner class KeyConnection : BaseInputConnection(this, false) {
override fun commitText(text: CharSequence?, newCursorPosition: Int): Boolean {
if (text.isNullOrEmpty()) return true
// The key events that type this text on a US layout - a capital arrives as Shift
// down, the letter, Shift up. Characters the map cannot place are sent as a bare
// key event carrying the character, which the activity's key path works back from.
val events = map.getEvents(text.toString().toCharArray())
if (events != null) {
for (event in events) activity.dispatchKeyEvent(event)
} else {
for (ch in text) {
val t = System.currentTimeMillis()
val down = KeyEvent(t, t, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_UNKNOWN, 0, 0,
KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0, 0)
activity.dispatchKeyEvent(CharKeyEvent(down, ch))
activity.dispatchKeyEvent(CharKeyEvent(KeyEvent.changeAction(down, KeyEvent.ACTION_UP), ch))
}
}
return true
}
override fun setComposingText(text: CharSequence?, newCursorPosition: Int): Boolean = true
override fun finishComposingText(): Boolean = true
override fun deleteSurroundingText(beforeLength: Int, afterLength: Int): Boolean {
repeat(beforeLength) { tap(KeyEvent.KEYCODE_DEL) }
repeat(afterLength) { tap(KeyEvent.KEYCODE_FORWARD_DEL) }
return true
}
override fun sendKeyEvent(event: KeyEvent): Boolean = activity.dispatchKeyEvent(event)
override fun performEditorAction(actionCode: Int): Boolean {
tap(KeyEvent.KEYCODE_ENTER)
return true
}
private fun tap(keyCode: Int) {
val t = System.currentTimeMillis()
activity.dispatchKeyEvent(KeyEvent(t, t, KeyEvent.ACTION_DOWN, keyCode, 0))
activity.dispatchKeyEvent(KeyEvent(t, t, KeyEvent.ACTION_UP, keyCode, 0))
}
override fun getTextBeforeCursor(n: Int, flags: Int): CharSequence = ""
override fun getTextAfterCursor(n: Int, flags: Int): CharSequence = ""
override fun getSelectedText(flags: Int): CharSequence? = null
}
/** A key event that carries a character the key map could not place. */
private class CharKeyEvent(origin: KeyEvent, private val ch: Char) : KeyEvent(origin) {
override fun getUnicodeChar(): Int = ch.code
override fun getUnicodeChar(metaState: Int): Int = ch.code
}
}