diff --git a/src/main.cpp b/src/main.cpp index bd8ee1582..b33264096 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,36 +10,11 @@ #include "util/networkmanager.hpp" #ifdef USEWINSDK -#include "windows.h" +#include "util/nativeeventhelper.hpp" #endif namespace { -#ifdef USEWINSDK -class DpiNativeEventFilter : public QAbstractNativeEventFilter -{ -public: - bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override - { - MSG *msg = reinterpret_cast(message); - - if (msg->message == WM_NCCREATE) { - QLibrary user32("user32.dll", NULL); - { - typedef BOOL(WINAPI * EnableNonClientDpiScaling)(HWND); - - EnableNonClientDpiScaling enableNonClientDpiScaling = - (EnableNonClientDpiScaling)user32.resolve("EnableNonClientDpiScaling"); - - // if (enableNonClientDpiScaling) - // enableNonClientDpiScaling(msg->hwnd); - } - } - return false; - } -}; -#endif - inline bool initSettings(bool portable) { QString settingsPath; @@ -73,8 +48,9 @@ int main(int argc, char *argv[]) QApplication::setAttribute(Qt::AA_UseSoftwareOpenGL, true); QApplication a(argc, argv); +// Install native event handler for hidpi on windows #ifdef USEWINSDK - a.installNativeEventFilter(new DpiNativeEventFilter); + a.installNativeEventFilter(new chatterino::util::DpiNativeEventFilter); #endif // Options diff --git a/src/util/nativeeventhelper.hpp b/src/util/nativeeventhelper.hpp index b6df01e4d..844b451fa 100644 --- a/src/util/nativeeventhelper.hpp +++ b/src/util/nativeeventhelper.hpp @@ -4,6 +4,7 @@ #include #include +#include #include namespace chatterino { @@ -36,6 +37,32 @@ static boost::optional getWindowDpi(quintptr ptr) return boost::none; } + +#ifdef USEWINSDK +class DpiNativeEventFilter : public QAbstractNativeEventFilter +{ +public: + bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override + { + MSG *msg = reinterpret_cast(message); + + if (msg->message == WM_NCCREATE) { + QLibrary user32("user32.dll", NULL); + { + typedef BOOL(WINAPI * EnableNonClientDpiScaling)(HWND); + + EnableNonClientDpiScaling enableNonClientDpiScaling = + (EnableNonClientDpiScaling)user32.resolve("EnableNonClientDpiScaling"); + + // if (enableNonClientDpiScaling) + // enableNonClientDpiScaling(msg->hwnd); + } + } + return false; + } +}; +#endif + } // namespace util } // namespace chatterino