Scale the interface fractionally on Linux

Java2D on X11 (and so under XWayland) truncates its scale to a whole
number, drawing 150 % at 100 %. On Linux, pin Java2D to 1 and hand the
full factor to FlatLaf, taken from XSETTINGS Xft/DPI, KWin's Xwayland
scale or GDK_SCALE, or chosen in Options → Design.

The client's own sizes now go through UIScale: borders, gaps, dialog and
row sizes, icons (rendered at the scaled size, so they stay crisp),
custom-painted components and font sizes in the HTML views.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-23 22:33:27 +00:00
co-authored by Claude Opus 5.5
parent 1fddae3f0b
commit 9d996f48a2
57 changed files with 643 additions and 311 deletions
@@ -1,5 +1,7 @@
package com.ts3client.ui;
import com.formdev.flatlaf.util.ScaledEmptyBorder;
import com.formdev.flatlaf.util.UIScale;
import com.ts3client.config.Settings;
import com.ts3client.gfx.IconPack;
@@ -24,14 +26,15 @@ import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.io.File;
import java.util.Arrays;
/**
* Options page for how the client looks: the light or dark look-and-feel, and the icon
* pack the user interface is drawn with — where to look for more of them, and a viewer
* showing everything the active pack contains.
* Options page for how the client looks: the light or dark look-and-feel, the interface
* scale, and the icon pack the user interface is drawn with — where to look for more of
* them, and a viewer showing everything the active pack contains.
*
* <p>Both apply right away so the change can be seen in the window behind the dialog;
* cancelling puts the previous ones back.
* <p>Theme and pack apply right away so the change can be seen in the window behind the
* dialog; cancelling puts the previous ones back. The scale is only read at startup.
*/
final class DesignPanel extends JPanel {
@@ -42,6 +45,9 @@ final class DesignPanel extends JPanel {
/** Stands for "no pack": the icons the client draws itself. */
private static final String BUILT_IN = "Built-in icons";
/** The scale factors offered besides following the desktop (0). */
private static final double[] SCALES = {0, 1, 1.25, 1.5, 1.75, 2, 2.5, 3};
private final Settings settings;
private final String originalPackId;
private final String originalPackDir;
@@ -49,6 +55,7 @@ final class DesignPanel extends JPanel {
private final JComboBox<Settings.Appearance> appearanceCombo =
new JComboBox<>(Settings.Appearance.values());
private final JComboBox<Double> scaleCombo = new JComboBox<>();
private final JComboBox<Object> packCombo = new JComboBox<>();
private final JLabel packInfo = new JLabel();
private final JTextField packDirField;
@@ -56,14 +63,14 @@ final class DesignPanel extends JPanel {
private final JList<String> preview = new JList<>(previewModel);
DesignPanel(Settings settings) {
super(new BorderLayout(0, 8));
super(new BorderLayout(0, UIScale.scale(8)));
this.settings = settings;
this.originalPackId = settings.iconPack;
this.originalPackDir = settings.iconPackDir;
this.originalAppearance = settings.appearance;
this.packDirField = new JTextField(settings.iconPackDir, 18);
setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
setBorder(new ScaledEmptyBorder(12, 12, 12, 12));
add(buildHeader(), BorderLayout.NORTH);
add(buildPreview(), BorderLayout.CENTER);
@@ -73,6 +80,7 @@ final class DesignPanel extends JPanel {
/** Copies the chosen appearance and pack into the settings; the caller saves them. */
void apply() {
settings.appearance = selectedAppearance();
if (scaleCombo.getSelectedItem() instanceof Double scale) settings.uiScale = scale;
settings.iconPackDir = packDirField.getText().trim();
Object selected = packCombo.getSelectedItem();
settings.iconPack = selected instanceof IconPack pack ? pack.id() : "";
@@ -94,7 +102,7 @@ final class DesignPanel extends JPanel {
private JComponent buildHeader() {
JPanel p = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(2, 2, 2, 2);
c.insets = UIScale.scale(new Insets(2, 2, 2, 2));
c.anchor = GridBagConstraints.WEST;
c.fill = GridBagConstraints.HORIZONTAL;
@@ -125,13 +133,17 @@ final class DesignPanel extends JPanel {
int row = 0;
addRow(p, c, row++, new JLabel("Theme:"), appearanceCombo);
if (DisplayScale.isManaged()) {
buildScaleCombo();
addRow(p, c, row++, new JLabel("Interface scale:"), scaleCombo);
}
addRow(p, c, row++, new JLabel("Icon pack:"), packCombo);
c.gridx = 1;
c.gridy = row++;
packInfo.setEnabled(false);
p.add(packInfo, c);
JPanel dirRow = new JPanel(new BorderLayout(6, 0));
JPanel dirRow = new JPanel(new BorderLayout(UIScale.scale(6), 0));
JButton browse = new JButton("Browse…");
browse.addActionListener(e -> browseForPackFolder());
dirRow.add(packDirField, BorderLayout.CENTER);
@@ -141,18 +153,42 @@ final class DesignPanel extends JPanel {
return p;
}
private void buildScaleCombo() {
for (double scale : SCALES) scaleCombo.addItem(scale);
if (settings.uiScale > 0 && Arrays.stream(SCALES).noneMatch(s -> s == settings.uiScale)) {
scaleCombo.addItem(settings.uiScale);
}
scaleCombo.setSelectedItem(Math.max(0, settings.uiScale));
scaleCombo.setToolTipText("Size of text, icons and controls; takes effect after a restart");
scaleCombo.setRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index,
boolean selected, boolean focus) {
super.getListCellRendererComponent(list, value, index, selected, focus);
double scale = value instanceof Double d ? d : 0;
setText(scale > 0 ? percent(scale)
: "Automatic (" + percent(DisplayScale.detected()) + ")");
return this;
}
});
}
private static String percent(double scale) {
return Math.round(scale * 100) + "%";
}
private JComponent buildPreview() {
preview.setLayoutOrientation(JList.HORIZONTAL_WRAP);
preview.setVisibleRowCount(-1);
preview.setFixedCellWidth(TILE);
preview.setFixedCellHeight(TILE);
preview.setFixedCellWidth(UIScale.scale(TILE));
preview.setFixedCellHeight(UIScale.scale(TILE));
preview.setCellRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index,
boolean selected, boolean focus) {
super.getListCellRendererComponent(list, value, index, selected, focus);
String key = String.valueOf(value);
ImageIcon icon = Icons.of(key, PREVIEW_SIZE);
ImageIcon icon = Icons.of(key, UIScale.scale(PREVIEW_SIZE));
setText("");
setIcon(icon);
setToolTipText(key);
@@ -162,7 +198,7 @@ final class DesignPanel extends JPanel {
});
JScrollPane scroll = new JScrollPane(preview);
scroll.setPreferredSize(new Dimension(360, 200));
scroll.setPreferredSize(UIScale.scale(new Dimension(360, 200)));
scroll.setBorder(BorderFactory.createTitledBorder("Icons in this pack"));
return scroll;
}