Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Allow users to choose window's default size in Display settings. There are four options: 800x450 (default), 750x500, 825x550, 900x600.
  • Loading branch information
haanhvu committed Nov 19, 2024
1 parent 117540c commit 81bdb25
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 12 deletions.
44 changes: 42 additions & 2 deletions app/src/common/shared/com/igalia/wolvic/browser/SettingsStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,36 @@ SettingsStore getInstance(final @NonNull Context aContext) {
// The maximum size is computed so the resulting texture fits within 2560x2560.
public final static int MAX_WINDOW_WIDTH_DEFAULT = 1200;
public final static int MAX_WINDOW_HEIGHT_DEFAULT = 800;
public enum WindowSizePreset {
PRESET_0(WINDOW_WIDTH_DEFAULT, WINDOW_HEIGHT_DEFAULT),
PRESET_1(750, 500),
PRESET_2(825, 550),
PRESET_3(900, 600);

public final int width;
public final int height;

WindowSizePreset(int width, int height) {
this.width = width;
this.height = height;
}
public static WindowSizePreset fromId(int id) {
if (id >= 0 && id < values().length) {
return values()[id];
} else {
return WINDOW_SIZE_PRESET_DEFAULT;
}
}
public static WindowSizePreset fromValues(int width, int height) {
for (WindowSizePreset preset : values()) {
if (preset.width == width && preset.height == height) {
return preset;
}
}
return WINDOW_SIZE_PRESET_DEFAULT;
}
}
public final static WindowSizePreset WINDOW_SIZE_PRESET_DEFAULT = WindowSizePreset.PRESET_0;

public final static int POINTER_COLOR_DEFAULT_DEFAULT = Color.parseColor("#FFFFFF");
public final static int SCROLL_DIRECTION_DEFAULT = 0;
Expand Down Expand Up @@ -477,11 +507,21 @@ public void setDisplayDensity(float aDensity) {
}

public int getWindowWidth() {
return WINDOW_WIDTH_DEFAULT;
return mPrefs.getInt(
mContext.getString(R.string.settings_key_window_width), WINDOW_WIDTH_DEFAULT);
}

public int getWindowHeight() {
return WINDOW_HEIGHT_DEFAULT;
return mPrefs.getInt(
mContext.getString(R.string.settings_key_window_height), WINDOW_HEIGHT_DEFAULT);
}

public void setWindowSizePreset(int presetId) {
WindowSizePreset preset = WindowSizePreset.fromId(presetId);
SharedPreferences.Editor editor = mPrefs.edit();
editor.putInt(mContext.getString(R.string.settings_key_window_width), preset.width);
editor.putInt(mContext.getString(R.string.settings_key_window_height), preset.height);
editor.commit();
}

public float getWindowAspect() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
protected void updateLayout() {
post(() -> {
double width = Math.ceil(getWidth()/getContext().getResources().getDisplayMetrics().density);
boolean isNarrow = width < SettingsStore.WINDOW_WIDTH_DEFAULT;
boolean isNarrow = width < SettingsStore.getInstance(getContext()).getWindowWidth();

if (isNarrow != mViewModel.getIsNarrow().getValue().get()) {
mBookmarkAdapter.setNarrow(isNarrow);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
protected void updateLayout() {
post(() -> {
double width = Math.ceil(getWidth() / getContext().getResources().getDisplayMetrics().density);
boolean isNarrow = width < SettingsStore.WINDOW_WIDTH_DEFAULT;
boolean isNarrow = width < SettingsStore.getInstance(getContext()).getWindowWidth();

if (isNarrow != mViewModel.getIsNarrow().getValue().get()) {
mDownloadsAdapter.setNarrow(isNarrow);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ private void showHistory(List<VisitInfo> historyItems) {
protected void updateLayout() {
post(() -> {
double width = Math.ceil(getWidth() / getContext().getResources().getDisplayMetrics().density);
boolean isNarrow = width < SettingsStore.WINDOW_WIDTH_DEFAULT;
boolean isNarrow = width < SettingsStore.getInstance(getContext()).getWindowWidth();

if (isNarrow != mViewModel.getIsNarrow().getValue().get()) {
mHistoryAdapter.setNarrow(isNarrow);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
protected void updateLayout() {
post(() -> {
double width = Math.ceil(getWidth() / getContext().getResources().getDisplayMetrics().density);
boolean isNarrow = width < SettingsStore.WINDOW_WIDTH_DEFAULT;
boolean isNarrow = width < SettingsStore.getInstance(getContext()).getWindowWidth();

if (isNarrow != mViewModel.getIsNarrow().getValue().get()) {
mWebAppsAdapter.setNarrow(isNarrow);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public static float worldToWidgetRatio(@NonNull UIWidget widget) {

public static float worldToWindowRatio(Context aContext){
SettingsStore settingStore = SettingsStore.getInstance(aContext);
return (WidgetPlacement.floatDimension(aContext, R.dimen.window_world_width) / SettingsStore.WINDOW_WIDTH_DEFAULT /
return (WidgetPlacement.floatDimension(aContext, R.dimen.window_world_width) / SettingsStore.WINDOW_WIDTH_DEFAULT /
(settingStore.getDisplayDpi() / 100.0f) / settingStore.getDisplayDensity()) / WORLD_DPI_RATIO;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ public void centerFrontWindowIfNeeded() {
// default position
mWidgetPlacement.translationY = WidgetPlacement.unitFromMeters(getContext(), R.dimen.window_world_y);
// center vertically relative to the default position
mWidgetPlacement.translationY += (SettingsStore.WINDOW_HEIGHT_DEFAULT - mWidgetPlacement.height) / 2.0f;
mWidgetPlacement.translationY += (SettingsStore.getInstance(getContext()).getWindowHeight() - mWidgetPlacement.height) / 2.0f;
mWidgetManager.updateWidget(this);
mWidgetManager.updateVisibleWidgets();
}
Expand Down Expand Up @@ -1568,28 +1568,37 @@ public Pair<Float, Float> getMaxWorldSize() {
}

public Pair<Float, Float> getMinWorldSize() {
SettingsStore settings = SettingsStore.getInstance(getContext());
float minWidth = WidgetPlacement.floatDimension(getContext(), R.dimen.window_world_width) * MIN_SCALE;
float minHeight = minWidth * SettingsStore.WINDOW_HEIGHT_DEFAULT / SettingsStore.WINDOW_WIDTH_DEFAULT;
float minHeight = minWidth * settings.getWindowHeight() / settings.getWindowWidth();
return new Pair<>(minWidth, minHeight);
}

public Pair<Float, Float> getDefaultWorldSize() {
SettingsStore settings = SettingsStore.getInstance(getContext());
float defaultWidth = settings.getWindowWidth() * WidgetPlacement.worldToDpRatio(getContext());
float defaultHeight = settings.getWindowHeight() * WidgetPlacement.worldToDpRatio(getContext());
return new Pair<>(defaultWidth, defaultHeight);
}

public @NonNull Pair<Float, Float> getSizeForScale(float aScale, float aAspect) {
Pair<Float, Float> minWorldSize = getMinWorldSize();
Pair<Float, Float> maxWorldSize = getMaxWorldSize();
Pair<Float, Float> defaultWorldSize = getDefaultWorldSize();
Pair<Float,Float> mainAxisMinMax, crossAxisMinMax;
float mainAxisDefault, mainAxisTarget;
float mainCrossAspect;

boolean isHorizontal = aAspect >= 1.0;
if (isHorizontal) {
// horizontal orientation
mainAxisDefault = WidgetPlacement.floatDimension(getContext(), R.dimen.window_world_width);
mainAxisDefault = defaultWorldSize.first;
mainAxisMinMax = Pair.create(minWorldSize.first, maxWorldSize.first);
crossAxisMinMax = Pair.create(minWorldSize.second, maxWorldSize.second);
mainCrossAspect = aAspect;
} else {
// vertical orientation
mainAxisDefault = WidgetPlacement.floatDimension(getContext(), R.dimen.window_world_width) * aAspect;
mainAxisDefault = defaultWorldSize.second;
mainAxisMinMax = Pair.create(minWorldSize.second, maxWorldSize.second);
crossAxisMinMax = Pair.create(minWorldSize.first, maxWorldSize.first);
mainCrossAspect = 1 / aAspect;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ private void placeWindow(@NonNull WindowWidget aWindow, WindowPlacement aPositio
placement.translationY = WidgetPlacement.unitFromMeters(mContext, R.dimen.window_world_y);
if (centerWindow) {
// center the window vertically relative to its default position
placement.translationY += (SettingsStore.WINDOW_HEIGHT_DEFAULT - placement.height) / 2.0f;
placement.translationY += (SettingsStore.getInstance(mContext).getWindowHeight() - placement.height) / 2.0f;
}
placement.translationZ = WidgetPlacement.getWindowWorldZMeters(mContext);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import com.igalia.wolvic.ui.widgets.WidgetManagerDelegate;
import com.igalia.wolvic.ui.widgets.WidgetPlacement;

import java.util.ArrayList;
import java.util.List;

class DisplayOptionsView extends SettingsView {

private OptionsDisplayBinding mBinding;
Expand Down Expand Up @@ -72,6 +75,17 @@ protected void updateUI() {
mBinding.msaaRadio.setOnCheckedChangeListener(mMSSAChangeListener);
setMSAAMode(mBinding.msaaRadio.getIdForValue(msaaLevel), false);

List<String> windowSizePresets = new ArrayList<>();
for (SettingsStore.WindowSizePreset preset : SettingsStore.WindowSizePreset.values()) {
windowSizePresets.add(getContext().getString(R.string.window_size_preset, preset.width, preset.height));
}
mBinding.windowsSize.setOptions(windowSizePresets.toArray(new String[0]));
mBinding.windowsSize.setOnCheckedChangeListener(mWindowsSizeChangeListener);
int windowWidth = SettingsStore.getInstance(getContext()).getWindowWidth();
int windowHeight = SettingsStore.getInstance(getContext()).getWindowHeight();
SettingsStore.WindowSizePreset windowSizePreset = SettingsStore.WindowSizePreset.fromValues(windowWidth, windowHeight);
setWindowsSizePreset(windowSizePreset.ordinal(), false);

mBinding.autoplaySwitch.setOnCheckedChangeListener(mAutoplayListener);
setAutoplay(SettingsStore.getInstance(getContext()).isAutoplayEnabled(), false);

Expand Down Expand Up @@ -165,6 +179,10 @@ public boolean isEditing() {
setMSAAMode(checkedId, true);
};

private RadioGroupSetting.OnCheckedChangeListener mWindowsSizeChangeListener = (radioGroup, checkedId, doApply) -> {
setWindowsSizePreset(checkedId, true);
};

private SwitchSetting.OnCheckedChangeListener mAutoplayListener = (compoundButton, enabled, apply) -> {
setAutoplay(enabled, true);
};
Expand Down Expand Up @@ -249,6 +267,10 @@ public boolean isEditing() {
restart = true;
}

if (mBinding.windowsSize.getCheckedRadioButtonId() != SettingsStore.WINDOW_SIZE_PRESET_DEFAULT.ordinal()) {
setWindowsSizePreset(SettingsStore.WINDOW_SIZE_PRESET_DEFAULT.ordinal(), true);
}

float prevDensity = SettingsStore.getInstance(getContext()).getDisplayDensity();
restart = restart | setDisplayDensity(SettingsStore.DISPLAY_DENSITY_DEFAULT);
int prevDpi = SettingsStore.getInstance(getContext()).getDisplayDpi();
Expand Down Expand Up @@ -410,6 +432,14 @@ private void setMSAAMode(int checkedId, boolean doApply) {
}
}

private void setWindowsSizePreset(int checkedId, boolean doApply) {
mBinding.windowsSize.setOnCheckedChangeListener(null);
mBinding.windowsSize.setChecked(checkedId, doApply);
mBinding.windowsSize.setOnCheckedChangeListener(mWindowsSizeChangeListener);

SettingsStore.getInstance(getContext()).setWindowSizePreset(checkedId);
}

private boolean setDisplayDensity(float newDensity) {
mBinding.densityEdit.setOnClickListener(null);
boolean restart = false;
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/layout/options_display.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@
app:options="@array/developer_options_msaa"
app:values="@array/developer_options_msaa_mode_values" />

<com.igalia.wolvic.ui.views.settings.RadioGroupSetting
android:id="@+id/windows_size"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:description="Window's&#10;default size" />

<com.igalia.wolvic.ui.views.settings.SingleEditSetting
android:id="@+id/homepage_edit"
android:layout_width="match_parent"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/non_L10n.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
<string name="settings_key_speech_data_collection" translatable="false">settings_key_speech_data_collection</string>
<string name="settings_key_speech_data_collection_reviewed" translatable="false">settings_key_speech_data_collection_accept</string>
<string name="settings_key_window_distance" translatable="false">settings_window_distance</string>
<string name="settings_key_window_width" translatable="false">settings_window_width</string>
<string name="settings_key_window_height" translatable="false">settings_window_height</string>
<string name="settings_key_user_agent_version" translatable="false">settings_user_agent_version_v2</string>
<string name="settings_key_input_mode" translatable="false">settings_touch_mode</string>
<string name="settings_key_center_windows" translatable="false">settings_center_windows</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 @@ -607,6 +607,9 @@
<!-- This string is used to label the MSAA radio button that enables two times MSAA in Immersive Mode. -->
<string name="developer_options_msaa_4">4x</string>

<!-- This string is used to label the radio buttons for setting the default size of windows. -->
<string name="window_size_preset">%1$d×%2$d</string>

<!-- This string is used to label a set of radio buttons that allow the user to change the
User-Agent (UA) string of the browser. -->
<string name="developer_options_ua_mode">User-Agent Mode</string>
Expand Down

0 comments on commit 81bdb25

Please sign in to comment.