Skip to content

Commit

Permalink
Change window distance with the moving bar
Browse files Browse the repository at this point in the history
Users can now modify the distante to the browser window when dragging
the moving bar widget by moving the controller/hand closer or further
away.

As this can be done with a gesture now there is no need to have a
dedicated widget in the settings for that.
  • Loading branch information
svillar committed Jan 14, 2025
1 parent 0fcb501 commit ed83245
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 28 deletions.
11 changes: 11 additions & 0 deletions app/src/common/shared/com/igalia/wolvic/VRBrowserActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2247,6 +2247,17 @@ public void reject() {
@Override
public boolean isEyeTrackingSupported() { return mIsEyeTrackingSupported; }

@Keep
@SuppressWarnings("unused")
private void changeWindowDistance(float aDelta) {
// First we need to adapt the range of movement of the hand/controller to the actual range
// of movement of the window in space. We use 40cm for arm length
float windowWorldZRange = Math.abs(WidgetPlacement.floatDimension(getApplicationContext(), R.dimen.window_world_z_max) - WidgetPlacement.floatDimension(getApplicationContext(), R.dimen.window_world_z_min));
float conversionRatio = windowWorldZRange / 0.4f;
float clamped = Math.max(0.0f, Math.min(mSettings.getWindowDistance() + aDelta * conversionRatio, 1.0f));
mSettings.setWindowDistance(clamped);
}

private native void addWidgetNative(int aHandle, WidgetPlacement aPlacement);
private native void updateWidgetNative(int aHandle, WidgetPlacement aPlacement);
private native void updateVisibleWidgetsNative();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ protected void updateUI() {
mBinding.centerWindowsSwitch.setOnCheckedChangeListener(mCenterWindowsListener);
setCenterWindows(SettingsStore.getInstance(getContext()).isCenterWindows(), false);

float windowDistance = SettingsStore.getInstance(getContext()).getWindowDistance();
mBinding.windowDistanceSlider.setOnValueChangeListener(mWindowDistanceListener);
setWindowDistance(windowDistance, false);

int uaMode = SettingsStore.getInstance(getContext()).getUaMode();
mBinding.uaRadio.setOnCheckedChangeListener(mUaModeListener);
setUaMode(mBinding.uaRadio.getIdForValue(uaMode), false);
Expand Down Expand Up @@ -168,10 +164,6 @@ public boolean isEditing() {
return editing;
}

private SliderSetting.OnValueChangeListener mWindowDistanceListener = (slider, value, doApply) -> {
setWindowDistance(value, true);
};

private RadioGroupSetting.OnCheckedChangeListener mUaModeListener = (radioGroup, checkedId, doApply) -> {
setUaMode(checkedId, true);
};
Expand Down Expand Up @@ -288,7 +280,6 @@ public boolean isEditing() {
setSoundEffect(SettingsStore.AUDIO_ENABLED, true);
setLatinAutoComplete(SettingsStore.LATIN_AUTO_COMPLETE_ENABLED, true);
setCenterWindows(SettingsStore.CENTER_WINDOWS_DEFAULT, true);
setWindowDistance(SettingsStore.WINDOW_DISTANCE_DEFAULT, true);

if (mBinding.startWithPassthroughSwitch.isChecked() != SettingsStore.shouldStartWithPassthrougEnabled()) {
setStartWithPassthrough(SettingsStore.shouldStartWithPassthrougEnabled());
Expand Down Expand Up @@ -394,14 +385,6 @@ private void setHomepage(String newHomepage) {
mBinding.homepageEdit.setOnClickListener(mHomepageListener);
}

private void setWindowDistance(float value, boolean doApply) {
mBinding.windowDistanceSlider.setOnValueChangeListener(null);
mBinding.windowDistanceSlider.setValue(value, doApply);
mBinding.windowDistanceSlider.setOnValueChangeListener(mWindowDistanceListener);

SettingsStore.getInstance(getContext()).setWindowDistance(mBinding.windowDistanceSlider.getValue());
}

private void setUaMode(int checkId, boolean doApply) {
mBinding.uaRadio.setOnCheckedChangeListener(null);
mBinding.uaRadio.setChecked(checkId, doApply);
Expand Down
10 changes: 9 additions & 1 deletion app/src/main/cpp/BrowserWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ const vrb::Color kPointerColorSelected = vrb::Color(0.32f, 0.56f, 0.88f);
// How big is the pointer target while in hand-tracking mode
const float kPointerSize = 3.0;

// When moving windows, the minimum amount of movement required to start moving the window
float kWindowMoveZThreshold = 0.01;

class SurfaceObserver;
typedef std::shared_ptr<SurfaceObserver> SurfaceObserverPtr;

Expand Down Expand Up @@ -209,7 +212,7 @@ struct BrowserWorld::State {
double lastBatteryLevelUpdate = -1.0;
bool reorientRequested = false;
LockMode lockMode = LockMode::NO_LOCK;
vrb::Matrix lockModeLastTransform;
std::optional<vrb::Matrix> lockModeLastTransform;
#if HVR
bool wasButtonAppPressed = false;
#elif defined(OCULUSVR) && defined(STORE_BUILD)
Expand Down Expand Up @@ -1230,6 +1233,11 @@ BrowserWorld::StartFrame() {
} else {
m.prevReorient = vrb::Quaternion(reorientTransform);
}
auto delta = reorientTransform.GetTranslation().Magnitude() - m.lockModeLastTransform->GetTranslation().Magnitude();
if (abs(delta) > kWindowMoveZThreshold) {
m.lockModeLastTransform = reorientTransform;
VRBrowser::ChangeWindowDistance(delta);
}
}
m.device->Reorient(reorientTransform);
}
Expand Down
13 changes: 12 additions & 1 deletion app/src/main/cpp/VRBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ const char* const kSetHandTrackingSupported = "setHandTrackingSupported";
const char* const kSetHandTrackingSupportedSignature = "(Z)V";
const char* const kOnControllersAvailable = "onControllersAvailable";
const char* const kOnControllersAvailableSignature = "()V";

const char* const kChangeWindowDistance = "changeWindowDistance";
const char* const kChangeWindowDistanceSignature = "(F)V";

JNIEnv* sEnv = nullptr;
jclass sBrowserClass = nullptr;
Expand Down Expand Up @@ -117,6 +118,7 @@ jmethodID sOnAppFocusChanged = nullptr;
jmethodID sSetEyeTrackingSupported = nullptr;
jmethodID sSetHandTrackingSupported = nullptr;
jmethodID sOnControllersAvailable = nullptr;
jmethodID sChangeWindowDistance = nullptr;

} // namespace

Expand Down Expand Up @@ -171,6 +173,7 @@ VRBrowser::InitializeJava(JNIEnv* aEnv, jobject aActivity) {
sSetEyeTrackingSupported = FindJNIMethodID(sEnv, sBrowserClass, kSetEyeTrackingSupported, kSetEyeTrackingSupportedSignature);
sSetHandTrackingSupported = FindJNIMethodID(sEnv, sBrowserClass, kSetHandTrackingSupported, kSetHandTrackingSupportedSignature);
sOnControllersAvailable = FindJNIMethodID(sEnv, sBrowserClass, kOnControllersAvailable, kOnControllersAvailableSignature);
sChangeWindowDistance = FindJNIMethodID(sEnv, sBrowserClass, kChangeWindowDistance, kChangeWindowDistanceSignature);
}

JNIEnv * VRBrowser::Env()
Expand Down Expand Up @@ -220,6 +223,7 @@ VRBrowser::ShutdownJava() {
sDisableLayers = nullptr;
sEnv = nullptr;
sAppendAppNotesToCrashReport = nullptr;
sChangeWindowDistance = nullptr;
}

void
Expand Down Expand Up @@ -506,4 +510,11 @@ VRBrowser::OnControllersAvailable() {

}

void
VRBrowser::ChangeWindowDistance(jfloat aDelta) {
if (!ValidateMethodID(sEnv, sActivity, sChangeWindowDistance, __FUNCTION__)) { return; }
sEnv->CallVoidMethod(sActivity, sChangeWindowDistance, aDelta);
CheckJNIException(sEnv, __FUNCTION__);
}

} // namespace crow
1 change: 1 addition & 0 deletions app/src/main/cpp/VRBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void OnAppFocusChanged(const bool aIsFocused);
void SetEyeTrackingSupported(bool aIsSupported);
void SetHandTrackingSupported(bool aIsSupported);
void OnControllersAvailable();
void ChangeWindowDistance(jfloat aDelta);
} // namespace VRBrowser;

} // namespace crow
Expand Down
9 changes: 0 additions & 9 deletions app/src/main/res/layout/options_display.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,6 @@
app:hintTextColor="@color/iron_blur"
app:highlightedTextColor="@color/fog" />

<com.igalia.wolvic.ui.views.settings.SliderSetting
android:id="@+id/window_distance_slider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:description="@string/display_options_windows_distance"
app:stepSize="0.1"
app:valueFrom="0.0"
app:valueTo="1.0" />

<com.igalia.wolvic.ui.views.settings.SwitchSetting
android:id="@+id/center_windows_switch"
android:layout_width="match_parent"
Expand Down

0 comments on commit ed83245

Please sign in to comment.