Skip to content

Commit

Permalink
Make OpenXR optional
Browse files Browse the repository at this point in the history
  • Loading branch information
lvonasek committed Oct 22, 2024
1 parent 85ac1fe commit e6fd2e6
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/com/winlator/ContainersFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public final int getItemCount() {
}

private void runContainer(Container container) {
if (!XrActivity.isSupported()) {
if (!XrActivity.isEnabled(getContext())) {
Intent intent = new Intent(getContext(), XServerDisplayActivity.class);
intent.putExtra("container_id", container.id);
requireActivity().startActivity(intent);
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/winlator/SettingsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ public void onFailed(int reason) {
final CheckBox cbUseDRI3 = view.findViewById(R.id.CBUseDRI3);
cbUseDRI3.setChecked(preferences.getBoolean("use_dri3", true));

final CheckBox cbUseXR = view.findViewById(R.id.CBUseXR);
cbUseXR.setChecked(preferences.getBoolean("use_xr", true));
if (!XrActivity.isSupported()) {
cbUseXR.setVisibility(View.GONE);
}

final CheckBox cbEnableWineDebug = view.findViewById(R.id.CBEnableWineDebug);
cbEnableWineDebug.setChecked(preferences.getBoolean("enable_wine_debug", false));

Expand Down Expand Up @@ -237,6 +243,7 @@ public void onStopTrackingTouch(SeekBar seekBar) {}
editor.putString("box86_preset", Box86_64PresetManager.getSpinnerSelectedId(sBox86Preset));
editor.putString("box64_preset", Box86_64PresetManager.getSpinnerSelectedId(sBox64Preset));
editor.putBoolean("use_dri3", cbUseDRI3.isChecked());
editor.putBoolean("use_xr", cbUseXR.isChecked());
editor.putFloat("cursor_speed", sbCursorSpeed.getProgress() / 100.0f);
editor.putBoolean("enable_wine_debug", cbEnableWineDebug.isChecked());
editor.putBoolean("enable_box86_64_logs", cbEnableBox86_64Logs.isChecked());
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/winlator/ShortcutsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ else if (itemId == R.id.shortcut_add_to_home_screen) {
private void runFromShortcut(Shortcut shortcut) {
Activity activity = getActivity();

if (!XrActivity.isSupported()) {
if (!XrActivity.isEnabled(getContext())) {
Intent intent = new Intent(activity, XServerDisplayActivity.class);
intent.putExtra("container_id", shortcut.container.id);
intent.putExtra("shortcut_path", shortcut.file.getPath());
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/winlator/XServerDisplayActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void onCreate(Bundle savedInstanceState) {
if (enableLogs) ProcessHelper.addDebugCallback(debugDialog = new DebugDialog(this));
Menu menu = navigationView.getMenu();
menu.findItem(R.id.main_menu_logs).setVisible(enableLogs);
if (XrActivity.isSupported()) menu.findItem(R.id.main_menu_magnifier).setVisible(false);
if (XrActivity.isEnabled(this)) menu.findItem(R.id.main_menu_magnifier).setVisible(false);
navigationView.setNavigationItemSelectedListener(this);
navigationView.setPointerIcon(PointerIcon.getSystemIcon(this, PointerIcon.TYPE_ARROW));
navigationView.setOnFocusChangeListener((v, hasFocus) -> navigationFocused = hasFocus);
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/com/winlator/XrActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.app.Activity;
import android.app.ActivityOptions;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.text.Editable;
Expand Down Expand Up @@ -42,6 +43,7 @@ public enum ControllerButton {

private static boolean isDeviceDetectionFinished = false;
private static boolean isDeviceSupported = false;
private static boolean isEnabled = false;
private static boolean isImmersive = false;
private static boolean isSBS = false;
private static final KeyCharacterMap chars = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
Expand Down Expand Up @@ -128,6 +130,13 @@ public static boolean getSBS() {
return isSBS;
}

public static boolean isEnabled(Context context) {
if (context != null) {
isEnabled = PreferenceManager.getDefaultSharedPreferences(context).getBoolean("use_xr", true);
}
return isSupported() && isEnabled;
}

public static boolean isSupported() {
if (!isDeviceDetectionFinished) {
if (Build.MANUFACTURER.compareToIgnoreCase("META") == 0) {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/winlator/renderer/GLRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void onSurfaceCreated(GL10 gl, EGLConfig config) {

@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
if (XrActivity.isSupported()) {
if (XrActivity.isEnabled(null)) {
XrActivity activity = XrActivity.getInstance();
activity.init();
width = activity.getWidth();
Expand Down Expand Up @@ -115,7 +115,7 @@ public void onDrawFrame(GL10 gl) {
private void drawFrame() {
boolean xrFrame = false;
boolean xrImmersive = false;
if (XrActivity.isSupported()) {
if (XrActivity.isEnabled(null)) {
xrImmersive = XrActivity.getImmersive();
xrFrame = XrActivity.getInstance().beginFrame(xrImmersive, XrActivity.getSBS());
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/winlator/renderer/Texture.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void copyFromFramebuffer(int framebuffer, short width, short height) {
GLES20.glCopyTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 0, 0, width, height, 0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
if (XrActivity.isSupported()) XrActivity.getInstance().bindFramebuffer();
if (XrActivity.isEnabled(null)) XrActivity.getInstance().bindFramebuffer();
}

public void destroy() {
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/layout/settings_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,13 @@
android:layout_height="wrap_content"
android:text="@string/use_dri3_extension"
android:layout_marginTop="8dp" />

<CheckBox
android:id="@+id/CBUseXR"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/use_xr"
android:layout_marginTop="8dp" />
</LinearLayout>

<TextView
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@
<string name="do_you_want_to_reconfigure_wine">您想要在下一次启动时重新配置容器吗? 这将删除时间戳以触发Wine配置。</string>

<!-- OpenXR specific text -->
<string name="use_xr">使用 OpenXR 集成</string>
<string name="toggle_orientation">切换方向</string>
<string name="primary_controller">主控制器</string>
<string name="left_controller">左控制器</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@
<string name="do_you_want_to_reconfigure_wine">Do you want to reconfigure this container on the next startup? This will remove the timestamp to trigger Wine Configuration.</string>

<!-- OpenXR specific text -->
<string name="use_xr">Use OpenXR integration</string>
<string name="xr" translatable="false">XR</string>
<string name="primary_controller">Primary controller</string>
<string name="left_controller">Left controller</string>
Expand Down

0 comments on commit e6fd2e6

Please sign in to comment.