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.contacts.Contact;
import com.ts3client.contacts.ContactStore;
@@ -8,7 +10,6 @@ import com.ts3client.contacts.NicknameDisplay;
import com.ts3client.teamspeak.TeamSpeakSettingsDb;
import com.ts3client.text.TsLink;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
@@ -99,7 +100,7 @@ final class ContactsDialog extends JDialog {
private final JCheckBox ignoreAway = new JCheckBox("Hide away message");
private final JRadioButton allowWhisper = new JRadioButton("Allow whisper");
private final JRadioButton denyWhisper = new JRadioButton("Deny whisper");
private final JPanel details = new JPanel(new BorderLayout(0, 8));
private final JPanel details = new JPanel(new BorderLayout(0, UIScale.scale(8)));
/** Set while the fields are being filled from a contact, so that does not count as an edit. */
private boolean filling;
@@ -110,22 +111,22 @@ final class ContactsDialog extends JDialog {
this.settings = settings;
buildTree();
JPanel left = new JPanel(new BorderLayout(0, 4));
left.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 4));
JPanel left = new JPanel(new BorderLayout(0, UIScale.scale(4)));
left.setBorder(new ScaledEmptyBorder(8, 8, 8, 4));
JLabel hint = new JLabel("Drag & Drop users here");
hint.setForeground(Theme.chatSystem());
left.add(hint, BorderLayout.NORTH);
JScrollPane scroll = new JScrollPane(tree);
scroll.setPreferredSize(new Dimension(300, 340));
scroll.setPreferredSize(UIScale.scale(new Dimension(300, 340)));
left.add(scroll, BorderLayout.CENTER);
details.setBorder(BorderFactory.createEmptyBorder(8, 4, 8, 8));
details.setBorder(new ScaledEmptyBorder(8, 4, 8, 8));
details.add(buildNicknameRow(), BorderLayout.NORTH);
details.add(buildPages(), BorderLayout.CENTER);
JPanel buttons = new JPanel(new BorderLayout());
buttons.setBorder(BorderFactory.createEmptyBorder(0, 8, 8, 8));
JPanel leftButtons = new JPanel(new FlowLayout(FlowLayout.LEFT, 6, 0));
buttons.setBorder(new ScaledEmptyBorder(0, 8, 8, 8));
JPanel leftButtons = new JPanel(new FlowLayout(FlowLayout.LEFT, UIScale.scale(6), 0));
JButton defaults = new JButton("Set Defaults");
defaults.setToolTipText("Set default display, ignore and hide options");
defaults.addActionListener(e -> new ContactDefaultsDialog(this, settings).setVisible(true));
@@ -160,7 +161,7 @@ final class ContactsDialog extends JDialog {
Dialogs.closeOnEscape(this);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
pack();
setMinimumSize(new Dimension(620, 400));
setMinimumSize(UIScale.scale(new Dimension(620, 400)));
setLocationRelativeTo(owner);
}
@@ -172,7 +173,7 @@ final class ContactsDialog extends JDialog {
root.add(neutral);
tree.setRootVisible(false);
tree.setShowsRootHandles(true);
tree.setRowHeight(20);
tree.setRowHeight(UIScale.scale(20));
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.setCellRenderer(new ContactRenderer());
tree.addTreeSelectionListener(e -> showSelected());
@@ -301,7 +302,7 @@ final class ContactsDialog extends JDialog {
private JComponent buildNicknameRow() {
JPanel row = 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.gridy = 0;
c.gridx = 0;
@@ -325,7 +326,7 @@ final class ContactsDialog extends JDialog {
JTabbedPane pages = new JTabbedPane();
pages.addTab("General", page(
radioGroup(neutralRadio, blockedRadio, friendRadio),
Box.createVerticalStrut(8),
Box.createVerticalStrut(UIScale.scale(8)),
labelled("Phonetic Nickname:", phoneticField)));
neutralRadio.setToolTipText("Mark as neutral");
blockedRadio.setToolTipText("Mark as blocked");
@@ -375,7 +376,7 @@ final class ContactsDialog extends JDialog {
private static JPanel page(Component... rows) {
JPanel p = new JPanel();
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
p.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
p.setBorder(new ScaledEmptyBorder(10, 10, 10, 10));
for (Component row : rows) {
if (row instanceof JComponent) ((JComponent) row).setAlignmentX(Component.LEFT_ALIGNMENT);
p.add(row);
@@ -397,7 +398,7 @@ final class ContactsDialog extends JDialog {
}
private static JPanel labelled(String label, JComponent field) {
JPanel p = new JPanel(new BorderLayout(6, 0));
JPanel p = new JPanel(new BorderLayout(UIScale.scale(6), 0));
p.add(new JLabel(label), BorderLayout.WEST);
p.add(field, BorderLayout.CENTER);
p.setMaximumSize(new Dimension(Integer.MAX_VALUE, field.getPreferredSize().height));