helloSystem / KWin

KWin.app
3 stars 2 forks source link

Does not obey QT_SCALE_FACTOR, hence breaks HiDPI #3

Open probonopd opened 3 years ago

probonopd commented 3 years ago

We are exporting QT_SCALE_FACTOR=2 to switch into HiDPI mode.

However, KWin does not obey this. In fact, looking at the source code, it seems to me it intentionally unsets this variable?

https://github.com/KDE/kwin/blob/9f41691684ffa2f42f09cfb8a24ec23fc146fe27/src/main_x11.cpp#L416

As a result, title bars and other window decorations do not scale; unlike the rest of Qt.

https://phabricator.kde.org/D20234 confirms the suspicion that it intentionally does not follow QT_SCALE_FACTOR since

Qt scaling and kwin on X11 is never going to work so it is disabled.

Why is it working for all of Qt but not for KWin?

probonopd commented 3 years ago

A (very crude and cumbersome) workaround would be to scale all of BreezeEnhanced by the QT_SCALE_FACTOR:

FreeBSD% git diff
diff --git a/breezedecoration.cpp b/breezedecoration.cpp
index 66a09c2..6dbbe0e 100644
--- a/breezedecoration.cpp
+++ b/breezedecoration.cpp
@@ -46,6 +46,9 @@
 #include <QTimer>
 #include <QVariantAnimation>

+#include <QProcessEnvironment>
+#include <QDebug>
+ 
 #if BREEZE_HAVE_X11
 #include <QX11Info>
 #endif
@@ -404,7 +407,17 @@ namespace Breeze
         if( hideTitleBar() ) top = bottom;
         else {

-            top = 22; // probono: Absolute height of the title bar in pixels
+            float scaleFactor;
+            scaleFactor = 1.0;
+            qDebug() << QProcess::systemEnvironment();
+            if(getenv("QT_SCALE_FACTOR")) {
+                qDebug() << "Using QT_SCALE_FACTOR as scaleFactor";
+                QString floatString = qgetenv("QT_SCALE_FACTOR");
+                QTextStream floatTextStream(&floatString);
+                floatTextStream >> scaleFactor;
+            }
+            qDebug() << "Using scaleFactor" << scaleFactor;
+            top = 22 * scaleFactor; // probono: Absolute height of the title bar in pixels

         }

and many other places...

It may even be necessary to binary-patch KWin so that it doesn't unset this variable and BreezeEnhanced gets a chance at reading it.

There must certainly be a better way?

probonopd commented 3 years ago

According to #kwin IRC,

kdeglobals > KScreen > ScaleFactor

for X11, and Wayland will "know automatically". So there is no way to use an environment variable, we must live-patch the kdeglobals file depending on the autodetected resolution? That is very unlike the rest of Qt.

And

[KScreen]
ScaleFactor=2

in ~/.config/kdeglobals does not seem to make any difference for me...

probonopd commented 3 years ago

According to #kwin IRC,

honestly trying to configure kwin without kscreen going is a bad idea user-facing configuration is exposed through the kscreen kcm kcmshell5 kcm_kscreen or systemsettings5 kcm_kscreen

probonopd commented 3 years ago

I was also pointed at

https://github.com/KDE/kscreen/blob/0f5d8dd52b3d02afe7fc57f6be60d69134fe3f42/kcm/kcm.cpp#L362-L385

but I don't know what to make of it.

In helloSystem, we set font sizes to exact point sizes and the only factor that shall influence what gets rendered is QT_SCALE_FACTOR.

probonopd commented 3 years ago

A (very crude and cumbersome) workaround

Probably not as the KWin architects intended, but applying a BREEZE_SCALE_FACTOR that is the same as QT_SCALE_FACTOR in BreezeEnhanced allows us to achieve more or less the desired outcome:

image

Some fine tuning may definitely be required, and if anyone knows a proper way to get KWin to obey QT_SCALE_FACTOR please let us know.