Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/common/provider/ScaledSizeProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,24 @@ qreal ScaledSizeProvider::scaleFactor()
qreal ScaledSizeProvider::getScaleFactor()
{
#if defined(__linux__)
DesktopEnvironmentChecker desktopEnvironmentChecker;
auto environment = desktopEnvironmentChecker.getDesktopEnvironment();

if (environment == DesktopEnvironmentType::Gnome) {
if(isGnomeEnvironment()) {
auto screen = QApplication::primaryScreen();
auto logicalDotsPerInch = (int) screen->logicalDotsPerInch();
auto physicalDotsPerInch = (int) screen->physicalDotsPerInch();
return (qreal)logicalDotsPerInch / (qreal)physicalDotsPerInch;
} else if (environment == DesktopEnvironmentType::Kde) {
auto screen = QApplication::primaryScreen();
return screen->devicePixelRatio();
}
#endif

return 1;
}

#if defined(__linux__)
bool ScaledSizeProvider::isGnomeEnvironment()
{
auto currentDesktop = QString(qgetenv("XDG_CURRENT_DESKTOP"));
return currentDesktop.contains(QLatin1String("gnome"), Qt::CaseInsensitive)
|| currentDesktop.contains(QLatin1String("unity"), Qt::CaseInsensitive);
}
#endif

} // namespace kImageAnnotator
4 changes: 4 additions & 0 deletions src/common/provider/ScaledSizeProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class ScaledSizeProvider
static qreal scaleFactor();
static qreal getScaleFactor();

#if defined(__linux__)
static bool isGnomeEnvironment();
#endif

ScaledSizeProvider() = default;
~ScaledSizeProvider() = default;
};
Expand Down