8000 Implement keyboard in XServerScreen by LossyDragon · Pull Request #264 · oxters168/Pluvia · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Implement keyboard in XServerScreen #264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/main/java/com/OxGames/Pluvia/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class MainActivity : ComponentActivity() {

@SuppressLint("RestrictedApi")
override fun dispatchKeyEvent(event: KeyEvent): Boolean {
// Log.d("MainActivity$index", "dispatchKeyEvent(${event.keyCode}):\n$event")
// Timber.d("dispatchKeyEvent(${event.keyCode}):\n$event")

var eventDispatched = PluviaApp.events.emit(AndroidEvent.KeyEvent(event)) { keyEvent ->
keyEvent.any { it }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ class SteamService : Service(), IChallengeUrlChanged {
fun getOwnedAppDlc(appId: Int): Map<Int, DepotInfo> = getAppDlc(appId).filter {
getPkgInfoOf(it.value.dlcAppId)?.let { pkg ->
instance?.steamClient?.let { steamClient ->
pkg.ownerAccountId.contains(steamClient.steamID.accountID.toInt())
pkg.ownerAccountId.contains(steamClient.steamID!!.accountID.toInt())
}
} == true
}
Expand Down
329 changes: 253 additions & 76 deletions app/src/main/java/com/OxGames/Pluvia/ui/screen/xserver/XServerScreen.kt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
package com.OxGames.Pluvia.ui.screen.xserver

import com.winlator.container.Container
import com.winlator.core.KeyValueSet
import com.winlator.core.WineInfo

data class XServerState(
var winStarted: Boolean = false,
val dxwrapper: String = Container.DEFAULT_DXWRAPPER,
val dxwrapperConfig: KeyValueSet? = null,
val screenSize: String = Container.DEFAULT_SCREEN_SIZE,
val wineInfo: WineInfo = WineInfo.MAIN_WINE_VERSION,
val graphicsDriver: String = Container.DEFAULT_GRAPHICS_DRIVER,
val audioDriver: String = Container.DEFAULT_AUDIO_DRIVER,

val gameName: String = "",
val appId: Int = -1,
var firstTimeBoot: Boolean = false,
var taskAffinityMask: Int = 0,
var taskAffinityMaskWoW64: Int = 0,
)
package com.OxGames.Pluvia.ui.screen.xserver

import com.winlator.container.Container
import com.winlator.core.KeyValueSet
import com.winlator.core.WineInfo

data class XServerState(
var winStarted: Boolean = false,
val dxwrapper: String = Container.DEFAULT_DXWRAPPER,
val dxwrapperConfig: KeyValueSet? = null,
val screenSize: String = Container.DEFAULT_SCREEN_SIZE,
val wineInfo: WineInfo = WineInfo.MAIN_WINE_VERSION,
val graphicsDriver: String = Container.DEFAULT_GRAPHICS_DRIVER,
val audioDriver: String = Container.DEFAULT_AUDIO_DRIVER,

val currentTime: Long = 0L,

val gameName: String = "",
val appId: Int = -1,
var firstTimeBoot: Boolean = false,
var taskAffinityMask: Int = 0,
var taskAffinityMaskWoW64: Int = 0,
)
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,18 @@ import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext
import java.io.File
import javax.inject.Inject
import kotlin.time.Duration.Companion.seconds
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.delay
import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import org.json.JSONException
import org.json.JSONObject
Expand Down Expand Up @@ -119,12 +123,16 @@ class XServerViewModel @Inject constructor(
var handled = false
if (isGamepad) {
handled = xServerView!!.xServer.winHandler.onKeyEvent(it.event)
Timber.d("Gamepad Handled: $handled")
// handled = ExternalController.onKeyEvent(xServer.winHandler, it.event)
}
if (!handled && isKeyboard) {
handled = keyboard?.onKeyEvent(it.event) == true
Timber.d("Keyboard Handled: $handled")
}

Timber.d("isKeyboard: $isKeyboard, isGamepad: $isGamepad \n Handled KeyEvent in XServer: (${it.event.keyCode}) with $handled")

handled
}

Expand Down Expand Up @@ -196,6 +204,14 @@ class XServerViewModel @Inject constructor(
} else {
Timber.w("Did not find existing container")
}

viewModelScope.launch {
while (isActive) {
_state.update { it.copy(currentTime = System.currentTimeMillis()) }
ensureActive()
delay(1.seconds)
}
}
}

override fun onCleared() {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/winlator/xserver/Keyboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private void triggerOnKeyRelease(byte keycode) {
public static boolean isKeyboardDevice(InputDevice device) {
if (device == null) return false;
int sources = device.getSources();
return !device.isVirtual() && ((sources & InputDevice.SOURCE_KEYBOARD) == InputDevice.SOURCE_KEYBOARD);
return (sources & InputDevice.SOURCE_KEYBOARD) == InputDevice.SOURCE_KEYBOARD;
}

public boolean onKeyEvent(KeyEvent event) {
Expand Down Expand Up @@ -364,4 +364,4 @@ else if (keycode == XKeycode.KEY_NUM_LOCK.getId()) {
public static boolean isModifierSticky(byte keycode) {
return keycode == XKeycode.KEY_CAPS_LOCK.getId() || keycode == XKeycode.KEY_NUM_LOCK.getId();
}
}
}
2 changes: 1 addition & 1 deletion app/src/main/res/values-da/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
<string name="dialog_message_delete_app">Er du sikker på, at du vil slette denne app?\n\n\tStørrelse på disk: %1$s</string>
<string name="dialog_message_download_app">Den app, der installeres, har følgende pladskrav. Vil du fortsætte?\nDownloadstørrelse: %1$s\nStørrelse på disk: %2$s\nTilgængelig plads: %3$s</string>
<string name="dialog_message_download_install_fs">Ubuntu Isoen skal downloades og installeres, før du kan redigere konfigurationen. Denne handling kan tage et par minutter. Vil du fortsætte?</string>
<string name="dialog_message_exit_game">"Er du sikker på, at du vil lukke spillet "</string>
<string name="dialog_message_exit_game">"Er du sikker på, at du vil lukke spillet %1$s?"</string>
<string name="dialog_message_friend_block">Er du sikker på, at du vil blokere %1$s?</string>
<string name="dialog_message_friend_favorite">Er du sikker på, at du vil sætte %1$s som favorit?</string>
<string name="dialog_message_friend_no_past_aliases">Ingen tidligere aliaser fundet</string>
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,9 @@

<!-- XServer -->
<string name="xserver_no_game_name">your game</string>
<string name="xserver_drawer_show_keyboard">Show Keyboard</string>
<string name="xserver_drawer_close_drawer">Close Drawer</string>
<string name="xserver_drawer_exit_game">Exit Game</string>

<!-- Login -->
<string name="login_fab_credential">Credential Sign In</string>
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots") } // JavaSteam
maven { url = uri("https://central.sonatype.com/repository/maven-snapshots/") } // JavaSteam
}
}

Expand Down
0