NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.9k stars 13.95k forks source link

Icons in Telegram Desktop pixelated when using display scaling in KDE #239814

Open MaxMatti opened 1 year ago

MaxMatti commented 1 year ago

Describe the bug

Icons in Telegram Desktop pixelated when using display scaling in KDE

Steps To Reproduce

Steps to reproduce the behavior:

  1. go to kde display settings, set scaling to 150%
  2. reboot for changes to take effect
  3. start Telegram Desktop, look at any icon or picture

Expected behavior

high-res icons used

Screenshots

Screenshot_20230625_192245

Additional context

Starting Telegram by running QT_SCREEN_SCALE_FACTORS='' telegram-desktop in a terminal fixes this. Not sure if putting that into the .desktop-file is your preferred fix or just a workaround. By default the variable is set to eDP-1=1.5;HDMI-1=1.5;DP-1=1.5;DP-2=1.5;DP-3=1.5;DP-4=1.5;DP-5=1.5; on my system, likely by KDE.

Notify maintainers

@NickCao

Metadata

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.3.6, NixOS, 23.11 (Tapir), 23.11pre497285.3ae20aa58a6`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.15.1`
 - channels(root): `"nixos, nixpkgs"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
MaxMatti commented 1 year ago

Relevant issue in the KDE issue tracker: https://bugs.kde.org/show_bug.cgi?id=471443 It also contains links to the respective issues in the Telegram and Qt issue trackers.

NickCao commented 1 year ago

So AFAIK this is an upstream issue that we have little control over?

MaxMatti commented 1 year ago

It's an upstream issue that NixOS is able to provide a workaround for until it's fixed upstream.

NickCao commented 1 year ago

Would this break the scaling for others (who do rely on QT_SCREEN_SCALE_FACTORS)?

ilya-fedin commented 1 year ago

This will break scaling in any Qt application started by tdesktop itself (be it okular when clicking on a pdf file or KDE settings when clicking 'Open system settings' button in the tdesktop call settings). That's why I ended up with a Qt patch in tdesktop upstream, that's just completely broken by both Qt and KDE.

Actually, you can make KDE use the proper APIs for scaling by setting DPI in font settings instead of global scaling in monitor settings (use 96 * your scale factor). But this will make the scaling worse for KDE applications as scaling in Qt 5 is opt-in and KDE rarely opts-in to it in their applications, apparently due to that hack with environment variables which makes the problem hidden.

TL;DR use Wayland if you want non-buggy scaling on KDE. Every other way will lead to noticeable bugs.

LostAttractor commented 11 months ago

Same issues when using Gnome with Wayland when enabling Enable precise High DPI scaling in Telegram's Experimental settings. 图片 If you don't turn this option on, telegram seems to downsample after rendering at an integer multiple, which can lead to a certain degree of blurring. If this option is not turned on, telegram will show that it is displaying at 200% interface scale and display correctly at the scale factor set by my display (150%). 图片 After turning this option on, telegram will show that it is scaled to the scaling factor of my display and the text is noticeably clearer. So I guess this option is turned on whether to set the fractional scale factor or use downsampling.

ilya-fedin commented 11 months ago

Yeah, QT_SCREEN_SCALE_FACTORS that is set by KDE forces Qt to always act like this option is turned on.

LostAttractor commented 11 months ago

Yeah, QT_SCREEN_SCALE_FACTORS that is set by KDE forces Qt to always act like this option is turned on.

However, if this option is not turned on, the fonts will indeed become blurry (even on my 4k display), Although not obvious. I guess it is because downsampling will cause sub-pixel rendering to completely invalid. It may be necessary to wait for qt and telegram to support wp-fractional-scale-v1 before this problem can be truly solved.

ilya-fedin commented 11 months ago

Qt supports it. But Telegram is a legacy application in terms of HiDPI: it was developed in 2013, long before Qt got HiDPI support and is not compatible with Qt's HiDPI. At that point Telegram has thousands of lines of code implementing widgets and all these lines have to be rewritten to support fractional scaling and runtime scaling changes. It's clear this is not going to happen so if you need native fractional scaling support then you better trash tdesktop out and use something other e.g. Telegram Electron. tdesktop is likely to forever be blurry on other than integer scaling factors, support only one screen scaling (unless Qt gets in the way and rescales with ruining picture quality) and not to have support for runtime scale factor changes (again unless Qt gets in the way).