Skip to content
Open
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
58 changes: 58 additions & 0 deletions app/src/main/java/app/gamenative/PluviaApp.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package app.gamenative

import android.hardware.display.DisplayManager
import android.os.Build
import android.os.StrictMode
import android.util.DisplayMetrics
import android.view.Display
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
Expand Down Expand Up @@ -51,6 +55,7 @@ class PluviaApp : SplitCompatApplication() {

override fun onCreate() {
super.onCreate()
instance = this

preloadSystemLibraries()

Expand Down Expand Up @@ -199,6 +204,9 @@ class PluviaApp : SplitCompatApplication() {
val events: EventDispatcher = EventDispatcher()
internal var onDestinationChangedListener: NavChangedListener? = null

private lateinit var instance: PluviaApp
private var cachedDefaultScreenSize: String? = null

// TODO: find a way to make this saveable, this is terrible (leak that memory baby)
internal var xEnvironment: XEnvironment? = null
internal var xServerView: XServerRendererView? = null
Expand Down Expand Up @@ -262,6 +270,56 @@ class PluviaApp : SplitCompatApplication() {

fun isManualSuspendMode(): Boolean = activeSuspendPolicy.equals(Container.SUSPEND_POLICY_MANUAL, ignoreCase = true)

fun getDefaultScreenSize(): String {
cachedDefaultScreenSize?.let { return it }

return try {
val displayManager = instance.getSystemService(DISPLAY_SERVICE) as? DisplayManager
Comment thread
coderabbitai[bot] marked this conversation as resolved.
val display = displayManager?.getDisplay(Display.DEFAULT_DISPLAY)
if (display != null) {
val width : Int
val height : Int

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val mode = display.mode
width = mode.physicalWidth
height = mode.physicalHeight
} else {
// API < 30 - Use deprecated Display API
val displayMetrics = DisplayMetrics()
@Suppress("DEPRECATION")
display.getRealMetrics(displayMetrics)
width = displayMetrics.widthPixels
height = displayMetrics.heightPixels
}

// Calculate aspect ratio (always use landscape orientation for calculation)
val aspectRatio = maxOf(width, height).toFloat() / minOf(width, height).toFloat()

// Aspect ratio thresholds:
// 4:3 = 1.33
// 16:10 = 1.6
// 16:9 = 1.77

val result = when {
aspectRatio < 1.5f -> Container.DEFAULT_SCREEN_SIZE_4_3 // 4:3 aspect ratio devices
aspectRatio < 1.7f -> Container.DEFAULT_SCREEN_SIZE_16_10 // 16:10 aspect ratio devices
else -> Container.DEFAULT_SCREEN_SIZE_16_9 // 16:9 and wider aspect ratio devices
}
cachedDefaultScreenSize = result
result
} else {
val fallback = Container.DEFAULT_SCREEN_SIZE_16_9 // Fallback to default
cachedDefaultScreenSize = fallback
fallback
}
} catch (e: Exception) {
Timber.e(e, "Failed to get device screen size")
val fallback = Container.DEFAULT_SCREEN_SIZE_16_9 // Fallback to default
cachedDefaultScreenSize = fallback
fallback
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/app/gamenative/PrefManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ object PrefManager {
/* Container Default Settings */
private val SCREEN_SIZE = stringPreferencesKey("screen_size")
var screenSize: String
get() = getPref(SCREEN_SIZE, Container.DEFAULT_SCREEN_SIZE)
get() = getPref(SCREEN_SIZE, PluviaApp.getDefaultScreenSize())
Comment thread
joshuatam marked this conversation as resolved.
set(value) {
setPref(SCREEN_SIZE, value)
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/app/gamenative/ui/data/XServerState.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app.gamenative.ui.data

import androidx.compose.runtime.saveable.mapSaver
import app.gamenative.PluviaApp
import com.winlator.container.Container
import com.winlator.core.DXVKHelper
import com.winlator.core.KeyValueSet
Expand All @@ -10,7 +11,7 @@ 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 screenSize: String = PluviaApp.getDefaultScreenSize(),
val wineInfo: WineInfo = WineInfo.MAIN_WINE_VERSION,
val graphicsDriver: String = Container.DEFAULT_GRAPHICS_DRIVER,
val graphicsDriverVersion: String = "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app.gamenative.utils

import android.content.Context
import android.content.Intent
import app.gamenative.PluviaApp
import app.gamenative.PrefManager
import app.gamenative.data.GameSource
import com.winlator.container.Container
Expand Down Expand Up @@ -189,7 +190,7 @@ object IntentLaunchManager {
// Only include non-default values to avoid overriding existing container settings
val config = ContainerData(
name = if (json.has("name")) json.getString("name") else "",
screenSize = if (json.has("screenSize")) json.getString("screenSize") else Container.DEFAULT_SCREEN_SIZE,
screenSize = if (json.has("screenSize")) json.getString("screenSize") else PluviaApp.getDefaultScreenSize(),
envVars = if (json.has("envVars")) json.getString("envVars") else Container.DEFAULT_ENV_VARS,
graphicsDriver = if (json.has("graphicsDriver")) json.getString("graphicsDriver") else Container.DEFAULT_GRAPHICS_DRIVER,
graphicsDriverVersion = if (json.has("graphicsDriverVersion")) json.getString("graphicsDriverVersion") else "",
Expand Down Expand Up @@ -259,7 +260,7 @@ object IntentLaunchManager {

return ContainerData(
name = override.name.ifEmpty { base.name },
screenSize = if (override.screenSize != Container.DEFAULT_SCREEN_SIZE) {
screenSize = if (override.screenSize != base.screenSize) {
override.screenSize
} else {
base.screenSize
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/com/winlator/container/Container.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public enum XrControllerMapping {
public static final String DEFAULT_EXTERNAL_DISPLAY_MODE = EXTERNAL_DISPLAY_MODE_OFF;

public static final String DEFAULT_ENV_VARS = "WRAPPER_MAX_IMAGE_COUNT=0 ZINK_DESCRIPTORS=lazy ZINK_DEBUG=compact,deck_emu MESA_SHADER_CACHE_DISABLE=false MESA_SHADER_CACHE_MAX_SIZE=512MB mesa_glthread=true WINEESYNC=1 MESA_VK_WSI_PRESENT_MODE=mailbox TU_DEBUG=noconform VKD3D_SHADER_MODEL=6_0 PULSE_LATENCY_MSEC=144";
public static final String DEFAULT_SCREEN_SIZE = "1280x720";
public static final String DEFAULT_SCREEN_SIZE_16_9 = "1280x720";
public static final String DEFAULT_SCREEN_SIZE_16_10 = "1280x800";
public static final String DEFAULT_SCREEN_SIZE_4_3 = "1280x960";
public static final String DEFAULT_GRAPHICS_DRIVER = DefaultVersion.DEFAULT_GRAPHICS_DRIVER;
public static final String DEFAULT_AUDIO_DRIVER = "pulseaudio";
public static final String DEFAULT_EMULATOR = "FEXCore";
Expand Down Expand Up @@ -75,7 +77,7 @@ public enum XrControllerMapping {
public static final byte MAX_DRIVE_LETTERS = 8;
public final String id;
private String name;
private String screenSize = DEFAULT_SCREEN_SIZE;
private String screenSize = DEFAULT_SCREEN_SIZE_16_9;
private String envVars = DEFAULT_ENV_VARS;
private String graphicsDriver = DEFAULT_GRAPHICS_DRIVER;
private String dxwrapper = DEFAULT_DXWRAPPER;
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/winlator/container/ContainerData.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.winlator.container

import androidx.compose.runtime.saveable.mapSaver
import app.gamenative.PluviaApp
import com.winlator.box86_64.Box86_64Preset
import com.winlator.core.DefaultVersion
import com.winlator.core.WineInfo
Expand All @@ -11,7 +12,7 @@ import kotlin.String

data class ContainerData(
val name: String = "",
val screenSize: String = Container.DEFAULT_SCREEN_SIZE,
val screenSize: String = PluviaApp.getDefaultScreenSize(),
val envVars: String = Container.DEFAULT_ENV_VARS,
val graphicsDriver: String = Container.DEFAULT_GRAPHICS_DRIVER,
val graphicsDriverVersion: String = "",
Expand Down
46 changes: 0 additions & 46 deletions app/src/main/java/com/winlator/container/ContainerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,52 +95,6 @@ public void createContainerAsync(String containerId, final JSONObject data, Call
public Future<Container> createContainerFuture(String containerId, final JSONObject data) {
return Executors.newSingleThreadExecutor().submit(() -> createContainer(containerId, data));
}
public Future<Container> createDefaultContainerFuture(WineInfo wineInfo, String containerId) {
String name = "container_" + containerId;
Log.d("XServerScreen", "Creating container $name");
String screenSize = Container.DEFAULT_SCREEN_SIZE;
String envVars = Container.DEFAULT_ENV_VARS;
String graphicsDriver = Container.DEFAULT_GRAPHICS_DRIVER;
String dxwrapper = Container.DEFAULT_DXWRAPPER;
String dxwrapperConfig = "";
String audioDriver = Container.DEFAULT_AUDIO_DRIVER;
String wincomponents = Container.DEFAULT_WINCOMPONENTS;
String drives = "";
Boolean showFPS = false;
String cpuList = Container.getFallbackCPUList();
String cpuListWoW64 = Container.getFallbackCPUListWoW64();
Boolean wow64Mode = WineInfo.isMainWineVersion(wineInfo.identifier());
// Boolean wow64Mode = false;
Byte startupSelection = Container.STARTUP_SELECTION_ESSENTIAL;
String box86Preset = Box86_64Preset.COMPATIBILITY;
String box64Preset = Box86_64Preset.COMPATIBILITY;
String desktopTheme = WineThemeManager.DEFAULT_DESKTOP_THEME;

JSONObject data = new JSONObject();
try {
data.put("name", name);
data.put("screenSize", screenSize);
data.put("envVars", envVars);
data.put("cpuList", cpuList);
data.put("cpuListWoW64", cpuListWoW64);
data.put("graphicsDriver", graphicsDriver);
data.put("dxwrapper", dxwrapper);
data.put("dxwrapperConfig", dxwrapperConfig);
data.put("audioDriver", audioDriver);
data.put("wincomponents", wincomponents);
data.put("drives", drives);
data.put("showFPS", showFPS);
data.put("wow64Mode", wow64Mode);
data.put("startupSelection", startupSelection);
data.put("box86Preset", box86Preset);
data.put("box64Preset", box64Preset);
data.put("desktopTheme", desktopTheme);
} catch (JSONException e) {
throw new RuntimeException(e);
}

return createContainerFuture(containerId, data);
}

public void duplicateContainerAsync(Container container, Runnable callback) {
final Handler handler = new Handler();
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<item>1024x768 (4:3)</item>
<item>1280x720 (16:9)</item>
<item>1280x800 (16:10)</item>
<item>1280x960 (4:3)</item>
Comment thread
joshuatam marked this conversation as resolved.
<item>1280x1024 (5:4)</item>
<item>1366x768 (16:9)</item>
<item>1440x900 (16:10)</item>
Expand Down
Loading