Skip to content

Commit

Permalink
Reset windows position when user tries to reorient via controllers
Browse files Browse the repository at this point in the history
Otherwise, it can be confusing to users if they have moved those windows
manually via our `Drag to move windows` feature before reorientation.

Signed-off-by: Songlin Jiang <[email protected]>
  • Loading branch information
HollowMan6 committed Jan 24, 2024
1 parent 89f1df3 commit b849543
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,15 @@ public void checkTogglePassthrough() {
}
}

@Keep
@SuppressWarnings("unused")
public void resetWindowsPosition() {
// Reset the position of the windows when we are not in headlock and window movement is enabled.
if (!mSettings.isHeadLockEnabled() && mSettings.isWindowMovementEnabled()) {
runOnUiThread(() -> mWindows.resetWindowsPosition());
}
}

@Keep
@SuppressWarnings("unused")
public boolean areLayersEnabled() {
Expand Down
15 changes: 10 additions & 5 deletions app/src/common/shared/com/igalia/wolvic/ui/widgets/Windows.java
Original file line number Diff line number Diff line change
Expand Up @@ -1058,20 +1058,25 @@ public void exitResizeMode() {
}
}

public void resetWindowsPosition() {
WindowWidget frontWindow = getFrontWindow();
if (frontWindow != null) {
placeWindow(frontWindow, WindowPlacement.FRONT);
}
updateViews();
}

private final SharedPreferences.OnSharedPreferenceChangeListener mPreferencesListener =
new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
WindowWidget frontWindow = getFrontWindow();

if (Objects.equals(key, mContext.getString(R.string.settings_key_window_movement))) {
boolean isWindowMovementEnabled = sharedPreferences.getBoolean(key, SettingsStore.WINDOW_MOVEMENT_DEFAULT);

// Reset the position of the windows when the setting becomes disabled.
if (frontWindow != null && !isWindowMovementEnabled) {
placeWindow(frontWindow, WindowPlacement.FRONT);
if (!sharedPreferences.getBoolean(key, SettingsStore.WINDOW_MOVEMENT_DEFAULT)) {
resetWindowsPosition();
}
updateViews();
}

if (!Objects.equals(key, mContext.getString(R.string.settings_key_window_distance)))
Expand Down
1 change: 1 addition & 0 deletions app/src/main/cpp/BrowserWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1973,6 +1973,7 @@ BrowserWorld::CreateSkyBox(const std::string& aBasePath, const std::string& aExt

void BrowserWorld::OnReorient() {
m.reorientRequested = true;
VRBrowser::ResetWindowsPosition();
}

} // namespace crow
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/cpp/VRBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const char* const kIsOverrideEnvPathEnabledName = "isOverrideEnvPathEnabled";
const char* const kIsOverrideEnvPathEnabledSignature = "()Z";
const char* const kCheckTogglePassthrough = "checkTogglePassthrough";
const char* const kCheckTogglePassthroughSignature = "()V";
const char* const kResetWindowsPosition = "resetWindowsPosition";
const char* const kResetWindowsPositionSignature = "()V";
const char* const kGetActiveEnvironment = "getActiveEnvironment";
const char* const kGetActiveEnvironmentSignature = "()Ljava/lang/String;";
const char* const kGetPointerColor = "getPointerColor";
Expand Down Expand Up @@ -93,6 +95,7 @@ jmethodID sRenderPointerLayer = nullptr;
jmethodID sGetStorageAbsolutePath = nullptr;
jmethodID sIsOverrideEnvPathEnabled = nullptr;
jmethodID sCheckTogglePassthrough = nullptr;
jmethodID sResetWindowsPosition = nullptr;
jmethodID sGetActiveEnvironment = nullptr;
jmethodID sGetPointerColor = nullptr;
jmethodID sAreLayersEnabled = nullptr;
Expand Down Expand Up @@ -142,6 +145,7 @@ VRBrowser::InitializeJava(JNIEnv* aEnv, jobject aActivity) {
sGetStorageAbsolutePath = FindJNIMethodID(sEnv, sBrowserClass, kGetStorageAbsolutePathName, kGetStorageAbsolutePathSignature);
sIsOverrideEnvPathEnabled = FindJNIMethodID(sEnv, sBrowserClass, kIsOverrideEnvPathEnabledName, kIsOverrideEnvPathEnabledSignature);
sCheckTogglePassthrough = FindJNIMethodID(sEnv, sBrowserClass, kCheckTogglePassthrough, kCheckTogglePassthroughSignature);
sResetWindowsPosition = FindJNIMethodID(sEnv, sBrowserClass, kResetWindowsPosition, kResetWindowsPositionSignature);
sGetActiveEnvironment = FindJNIMethodID(sEnv, sBrowserClass, kGetActiveEnvironment, kGetActiveEnvironmentSignature);
sGetPointerColor = FindJNIMethodID(sEnv, sBrowserClass, kGetPointerColor, kGetPointerColorSignature);
sAreLayersEnabled = FindJNIMethodID(sEnv, sBrowserClass, kAreLayersEnabled, kAreLayersEnabledSignature);
Expand Down Expand Up @@ -192,6 +196,7 @@ VRBrowser::ShutdownJava() {
sGetStorageAbsolutePath = nullptr;
sIsOverrideEnvPathEnabled = nullptr;
sCheckTogglePassthrough = nullptr;
sResetWindowsPosition = nullptr;
sGetActiveEnvironment = nullptr;
sGetPointerColor = nullptr;
sAreLayersEnabled = nullptr;
Expand Down Expand Up @@ -363,6 +368,13 @@ VRBrowser::CheckTogglePassthrough() {
CheckJNIException(sEnv, __FUNCTION__);
}

void
VRBrowser::ResetWindowsPosition() {
if (!ValidateMethodID(sEnv, sActivity, sResetWindowsPosition, __FUNCTION__)) { return; }
sEnv->CallVoidMethod(sActivity, sResetWindowsPosition);
CheckJNIException(sEnv, __FUNCTION__);
}

std::string
VRBrowser::GetActiveEnvironment() {
if (!ValidateMethodID(sEnv, sActivity, sGetActiveEnvironment, __FUNCTION__)) { return ""; }
Expand Down
1 change: 1 addition & 0 deletions app/src/main/cpp/VRBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ void RenderPointerLayer(jobject aSurface, const int32_t color, const std::functi
std::string GetStorageAbsolutePath(const std::string& aRelativePath);
bool isOverrideEnvPathEnabled();
void CheckTogglePassthrough();
void ResetWindowsPosition();
std::string GetActiveEnvironment();
int32_t GetPointerColor();
bool AreLayersEnabled();
Expand Down

0 comments on commit b849543

Please sign in to comment.