Skip to content

Commit

Permalink
Setting to open new tabs in the background or foreground
Browse files Browse the repository at this point in the history
Add a new switch to Options / Display that allows the user to
choose whether new tabs will be activated immediately or they
will remain in the background.

By default, new tabs will be open in the background.

For now, this setting only affects the contextual menu.
  • Loading branch information
felipeerias committed Feb 4, 2025
1 parent 07821ef commit eb466aa
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 3 deletions.
12 changes: 12 additions & 0 deletions app/src/common/shared/com/igalia/wolvic/browser/SettingsStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public static WindowSizePreset fromValues(int width, int height) {
private final static long CRASH_RESTART_DELTA = 2000;
public final static boolean AUTOPLAY_ENABLED = false;
public final static boolean HEAD_LOCK_DEFAULT = false;
public final static boolean OPEN_TABS_IN_BACKGROUND_DEFAULT = true;
public final static boolean DEBUG_LOGGING_DEFAULT = BuildConfig.DEBUG;
public final static boolean POP_UPS_BLOCKING_DEFAULT = true;
public final static boolean WEBXR_ENABLED_DEFAULT = true;
Expand Down Expand Up @@ -398,6 +399,17 @@ public void setHeadLockEnabled(boolean isEnabled) {
editor.apply();
}

public boolean isOpenTabsInBackgroundEnabled() {
return mPrefs.getBoolean(
mContext.getString(R.string.settings_key_open_tabs_in_background), OPEN_TABS_IN_BACKGROUND_DEFAULT);
}

public void setOpenTabsInBackgroundEnabled(boolean isEnabled) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(mContext.getString(R.string.settings_key_open_tabs_in_background), isEnabled);
editor.apply();
}

@TabsLocation
public int getTabsLocation() {
return mPrefs.getInt(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import androidx.annotation.StringRes;

import com.igalia.wolvic.R;
import com.igalia.wolvic.browser.SettingsStore;
import com.igalia.wolvic.browser.api.WSession;
import com.igalia.wolvic.downloads.DownloadJob;
import com.igalia.wolvic.telemetry.TelemetryService;
Expand Down Expand Up @@ -101,7 +102,11 @@ public void setContextElement(WSession.ContentDelegate.ContextElement aContextEl
// Open link in a new tab
mItems.add(new MenuWidget.MenuItem(getContext().getString(R.string.context_menu_open_link_new_tab_1), 0, () -> {
if (!StringUtils.isEmpty(aContextElement.linkUri)) {
widgetManager.openNewTab(aContextElement.linkUri);
if (SettingsStore.getInstance(getContext()).isOpenTabsInBackgroundEnabled()) {
widgetManager.openNewTab(aContextElement.linkUri);
} else {
widgetManager.openNewTabForeground(aContextElement.linkUri);
}
TelemetryService.Tabs.openedCounter(TelemetryService.Tabs.TabSource.CONTEXT_MENU);
}
onDismiss();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.igalia.wolvic.browser.SettingsStore;
import com.igalia.wolvic.databinding.OptionsDisplayBinding;
import com.igalia.wolvic.ui.views.settings.RadioGroupSetting;
import com.igalia.wolvic.ui.views.settings.SliderSetting;
import com.igalia.wolvic.ui.views.settings.SwitchSetting;
import com.igalia.wolvic.ui.widgets.WidgetManagerDelegate;
import com.igalia.wolvic.ui.widgets.WidgetPlacement;
Expand Down Expand Up @@ -99,6 +98,9 @@ protected void updateUI() {
mBinding.headLockSwitch.setOnCheckedChangeListener(mHeadLockListener);
setHeadLock(SettingsStore.getInstance(getContext()).isHeadLockEnabled(), false);

mBinding.openTabsInBackgroundSwitch.setOnCheckedChangeListener(mOpenTabsInBackgroundListener);
setOpenTabsInBackground(SettingsStore.getInstance(getContext()).isOpenTabsInBackgroundEnabled(), false);

@SettingsStore.TabsLocation int tabsLocation = SettingsStore.getInstance(getContext()).getTabsLocation();
mBinding.tabsLocationRadio.setOnCheckedChangeListener(mTabsLocationChangeListener);
setTabsLocation(mBinding.tabsLocationRadio.getIdForValue(tabsLocation), false);
Expand Down Expand Up @@ -188,6 +190,10 @@ public boolean isEditing() {
setHeadLock(value, true);
};

private SwitchSetting.OnCheckedChangeListener mOpenTabsInBackgroundListener = (compoundButton, value, doApply) -> {
setOpenTabsInBackground(value, true);
};

private RadioGroupSetting.OnCheckedChangeListener mTabsLocationChangeListener = (radioGroup, checkedId, doApply) -> {
setTabsLocation(checkedId, true);
};
Expand Down Expand Up @@ -347,6 +353,17 @@ private void setHeadLock(boolean value, boolean doApply) {
}
}

private void setOpenTabsInBackground(boolean value, boolean doApply) {
mBinding.openTabsInBackgroundSwitch.setOnCheckedChangeListener(null);
mBinding.openTabsInBackgroundSwitch.setValue(value, false);
mBinding.openTabsInBackgroundSwitch.setOnCheckedChangeListener(mOpenTabsInBackgroundListener);

SettingsStore settingsStore = SettingsStore.getInstance(getContext());
if (doApply) {
settingsStore.setOpenTabsInBackgroundEnabled(value);
}
}

private void setTabsLocation(int checkedId, boolean doApply) {
mBinding.tabsLocationRadio.setOnCheckedChangeListener(null);
mBinding.tabsLocationRadio.setChecked(checkedId, doApply);
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 @@ -84,6 +84,12 @@
android:layout_height="wrap_content"
app:description="@string/display_options_latin_auto_complete" />

<com.igalia.wolvic.ui.views.settings.SwitchSetting
android:id="@+id/openTabsInBackgroundSwitch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:description="@string/display_options_open_tabs_in_background" />

<com.igalia.wolvic.ui.views.settings.RadioGroupSetting
android:id="@+id/tabs_location_radio"
android:layout_width="match_parent"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/dimen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@
<dimen name="privacy_options_height">490dp</dimen>

<!-- Display settings -->
<dimen name="display_options_height">420dp</dimen>
<dimen name="display_options_height">450dp</dimen>

<!-- Language and voice settings -->
<dimen name="language_options_height">400dp</dimen>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/non_L10n.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<string name="settings_key_start_with_passthrough" translatable="false">settings_start_with_passthrough</string>
<string name="settings_key_latin_auto_complete" translatable="false">settings_latin_auto_complete</string>
<string name="settings_key_head_lock" translatable="false">settings_head_lock</string>
<string name="settings_key_open_tabs_in_background" translatable="false">settings_open_tabs_in_background</string>
<string name="settings_key_window_movement" translatable="false">settings_window_movement</string>
<string name="settings_key_environment_override" translatable="false">settings_environment_override</string>
<string name="settings_key_performance_monitor" translatable="false">settings_performance_monitor</string>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,10 @@
and is used to customize the windows distance. -->
<string name="display_options_windows_distance">Windows Distance</string>

<!-- This string labels an On/Off switch in the 'Display Options' dialog and is used to choose
whether new tabs will be activated immediately or they will remain in the background. -->
<string name="display_options_open_tabs_in_background">Open new tabs in the background</string>

<!-- This string labels an On/Off switch in the developer options dialog
and is used to customize background environments of the app. -->
<string name="developer_options_env_override">Enable Environment Override</string>
Expand Down

0 comments on commit eb466aa

Please sign in to comment.