From 505050e9367f5677eeced81d881a5fb8852aaeaa Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 8 Feb 2020 18:47:59 -0800 Subject: [PATCH] Fix high DPI check in 0437835b --- app/app.pro | 13 ++++++++++++- app/main.cpp | 6 +++++- app/utils.h | 5 +++++ app/wm.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 app/wm.cpp diff --git a/app/app.pro b/app/app.pro index 74412d93..da319e9a 100644 --- a/app/app.pro +++ b/app/app.pro @@ -104,6 +104,16 @@ unix:!macx { CONFIG += libdrm } } + + packagesExist(wayland-client) { + DEFINES += HAS_WAYLAND + PKGCONFIG += wayland-client + } + + packagesExist(x11) { + DEFINES += HAS_X11 + PKGCONFIG += x11 + } } win32 { LIBS += -llibssl -llibcrypto -lSDL2 -lSDL2_ttf -lavcodec -lavutil -lopus -ld3dx9 @@ -148,7 +158,8 @@ SOURCES += \ settings/mappingmanager.cpp \ gui/sdlgamepadkeynavigation.cpp \ streaming/video/overlaymanager.cpp \ - backend/systemproperties.cpp + backend/systemproperties.cpp \ + wm.cpp HEADERS += \ utils.h \ diff --git a/app/main.cpp b/app/main.cpp index 3f6a8294..1a7a0bc7 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -29,6 +29,7 @@ #include "cli/startstream.h" #include "cli/commandlineparser.h" #include "path.h" +#include "utils.h" #include "gui/computermodel.h" #include "gui/appmodel.h" #include "backend/autoupdatechecker.h" @@ -287,7 +288,10 @@ int main(int argc, char *argv[]) // Avoid using High DPI on EGLFS. It breaks font rendering. // https://bugreports.qt.io/browse/QTBUG-64377 - if (QGuiApplication::platformName() != "eglfs") { + // + // NB: We can't use QGuiApplication::platformName() here because it is only + // set once the QGuiApplication is created, which is too late to enable High DPI :( + if (WMUtils::isRunningWindowManager()) { // Enable High DPI support QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); diff --git a/app/utils.h b/app/utils.h index 8629e1b0..e2de9d42 100644 --- a/app/utils.h +++ b/app/utils.h @@ -3,3 +3,8 @@ #define THROW_BAD_ALLOC_IF_NULL(x) \ if ((x) == nullptr) throw std::bad_alloc() +namespace WMUtils { + bool isRunningX11(); + bool isRunningWayland(); + bool isRunningWindowManager(); +} diff --git a/app/wm.cpp b/app/wm.cpp new file mode 100644 index 00000000..3d622d20 --- /dev/null +++ b/app/wm.cpp @@ -0,0 +1,46 @@ +#include "utils.h" + +#ifdef HAS_X11 +#include +#endif + +#ifdef HAS_WAYLAND +#include +#endif + +bool WMUtils::isRunningX11() +{ +#ifdef HAS_WAYLAND + Display* display = XOpenDisplay(nullptr); + if (display != nullptr) { + XCloseDisplay(display); + return true; + } +#endif + + return false; +} + +bool WMUtils::isRunningWayland() +{ +#ifdef HAS_WAYLAND + struct wl_display* display = wl_display_connect(nullptr); + if (display != nullptr) { + wl_display_disconnect(display); + return true; + } +#endif + + return false; +} + +bool WMUtils::isRunningWindowManager() +{ +#if defined(Q_OS_WIN) || defined(Q_OS_DARWIN) + // Windows and macOS are always running a window manager + return true; +#else + // On Unix OSes, look for Wayland or X + return WMUtils::isRunningWayland() || WMUtils::isRunningX11(); +#endif +}