Skip to content

Commit d084f00

Browse files
authored
Add KDE support for scale factor (#302)
1 parent 1880cb4 commit d084f00

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/common/provider/ScaledSizeProvider.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,34 @@ qreal ScaledSizeProvider::scaleFactor()
6565
qreal ScaledSizeProvider::getScaleFactor()
6666
{
6767
#if defined(__linux__)
68-
if(isGnomeEnvironment()) {
68+
char env = getLinuxDesktopEnvironment();
69+
if (env == 'g') {
6970
auto screen = QApplication::primaryScreen();
7071
auto logicalDotsPerInch = (int) screen->logicalDotsPerInch();
7172
auto physicalDotsPerInch = (int) screen->physicalDotsPerInch();
7273
return (qreal)logicalDotsPerInch / (qreal)physicalDotsPerInch;
74+
} else if (env == 'k') {
75+
auto screen = QApplication::primaryScreen();
76+
return screen->devicePixelRatio();
7377
}
7478
#endif
7579

7680
return 1;
7781
}
7882

7983
#if defined(__linux__)
80-
bool ScaledSizeProvider::isGnomeEnvironment()
84+
char ScaledSizeProvider::getLinuxDesktopEnvironment()
8185
{
8286
auto currentDesktop = QString(qgetenv("XDG_CURRENT_DESKTOP"));
83-
return currentDesktop.contains(QLatin1String("gnome"), Qt::CaseInsensitive)
84-
|| currentDesktop.contains(QLatin1String("unity"), Qt::CaseInsensitive);
87+
if (currentDesktop.contains(QLatin1String("gnome"), Qt::CaseInsensitive)
88+
|| currentDesktop.contains(QLatin1String("unity"), Qt::CaseInsensitive)) {
89+
return 'g';
90+
} else if (currentDesktop.contains(QLatin1String("kde"), Qt::CaseInsensitive)) {
91+
return 'k';
92+
} else {
93+
return ' ';
94+
}
8595
}
8696
#endif
8797

88-
} // namespace kImageAnnotator
98+
} // namespace kImageAnnotator

src/common/provider/ScaledSizeProvider.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class ScaledSizeProvider
4747
static qreal getScaleFactor();
4848

4949
#if defined(__linux__)
50-
static bool isGnomeEnvironment();
50+
static char getLinuxDesktopEnvironment();
5151
#endif
5252

5353
ScaledSizeProvider() = default;

0 commit comments

Comments
 (0)