Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

termux-app: Make font size setting be per display #16

Merged
merged 1 commit into from
Jun 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions termux-app/src/main/java/com/termux/app/TermuxPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.content.SharedPreferences;
import android.util.TypedValue;
import android.view.Display;

public class TermuxPreferences {

Expand All @@ -18,9 +19,11 @@ public class TermuxPreferences {


private final SharedPreferences prefs;
private final Context context;

TermuxPreferences(TermuxActivity activity) {
prefs = activity.getPreferences(Context.MODE_PRIVATE);
context = activity;
setupFontSizeDefaults(activity);
}

Expand Down Expand Up @@ -64,8 +67,17 @@ public boolean toggleShowTerminalToolbar() {
return newValue;
}

/**
* Use different font sizes on different displays.
*/
private String fontSizePrefName() {
var display = context.getDisplay();
var displayId = (display == null) ? Display.DEFAULT_DISPLAY : display.getDisplayId();
return PREF_FONT_SIZE + ((displayId == Display.DEFAULT_DISPLAY) ? "" : Integer.toString(displayId));
}

public int getFontSize() {
return prefs.getInt(PREF_FONT_SIZE, defaultFontSize);
return prefs.getInt(fontSizePrefName(), defaultFontSize);
}

public int changeFontSize(boolean increase) {
Expand All @@ -74,7 +86,7 @@ public int changeFontSize(boolean increase) {
fontSize += (increase ? 1 : -1) * 2;
fontSize = Math.max(minFontSize, Math.min(fontSize, maxFontSize));

prefs.edit().putInt(PREF_FONT_SIZE, fontSize).apply();
prefs.edit().putInt(fontSizePrefName(), fontSize).apply();
return fontSize;
}

Expand Down