moved dpi handling out of helper file

This commit is contained in:
fourtf 2018-01-14 21:59:45 +01:00
parent e19a83679f
commit e0372a2453
2 changed files with 21 additions and 27 deletions

View file

@ -9,19 +9,6 @@
namespace chatterino { namespace chatterino {
namespace util { namespace util {
static bool tryHandleDpiChangedMessage(void *message, int &dpi)
{
MSG *msg = reinterpret_cast<MSG *>(message);
// WM_DPICHANGED
if (msg->message == 0x02E0) {
dpi = HIWORD(msg->wParam);
return true;
}
return false;
}
static boost::optional<UINT> getWindowDpi(quintptr ptr) static boost::optional<UINT> getWindowDpi(quintptr ptr)
{ {
typedef UINT(WINAPI * GetDpiForWindow)(HWND); typedef UINT(WINAPI * GetDpiForWindow)(HWND);
@ -44,20 +31,20 @@ class DpiNativeEventFilter : public QAbstractNativeEventFilter
public: public:
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override
{ {
// MSG *msg = reinterpret_cast<MSG *>(message); // MSG *msg = reinterpret_cast<MSG *>(message);
// if (msg->message == WM_NCCREATE) { // if (msg->message == WM_NCCREATE) {
// QLibrary user32("user32.dll", 0); // QLibrary user32("user32.dll", 0);
// { // {
// typedef BOOL(WINAPI * EnableNonClientDpiScaling)(HWND); // typedef BOOL(WINAPI * EnableNonClientDpiScaling)(HWND);
// EnableNonClientDpiScaling enableNonClientDpiScaling = // EnableNonClientDpiScaling enableNonClientDpiScaling =
// (EnableNonClientDpiScaling)user32.resolve("EnableNonClientDpiScaling"); // (EnableNonClientDpiScaling)user32.resolve("EnableNonClientDpiScaling");
// if (enableNonClientDpiScaling) // if (enableNonClientDpiScaling)
// enableNonClientDpiScaling(msg->hwnd); // enableNonClientDpiScaling(msg->hwnd);
// } // }
// } // }
return false; return false;
} }
}; };

View file

@ -7,6 +7,8 @@
#include <QDebug> #include <QDebug>
#include <QIcon> #include <QIcon>
#include <windows.h>
namespace chatterino { namespace chatterino {
namespace widgets { namespace widgets {
@ -60,10 +62,12 @@ void BaseWindow::leaveEvent(QEvent *)
#ifdef USEWINSDK #ifdef USEWINSDK
bool BaseWindow::nativeEvent(const QByteArray &eventType, void *message, long *result) bool BaseWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)
{ {
int dpi; MSG *msg = reinterpret_cast<MSG *>(message);
if (util::tryHandleDpiChangedMessage(message, dpi)) { // WM_DPICHANGED
if (msg->message == 0x02E0) {
qDebug() << "dpi changed"; qDebug() << "dpi changed";
int dpi = HIWORD(msg->wParam);
float oldDpiMultiplier = this->dpiMultiplier; float oldDpiMultiplier = this->dpiMultiplier;
this->dpiMultiplier = dpi / 96.f; this->dpiMultiplier = dpi / 96.f;
@ -73,10 +77,13 @@ bool BaseWindow::nativeEvent(const QByteArray &eventType, void *message, long *r
this->resize(static_cast<int>(this->width() * scale), this->resize(static_cast<int>(this->width() * scale),
static_cast<int>(this->height() * scale)); static_cast<int>(this->height() * scale));
return true;
} }
return QWidget::nativeEvent(eventType, message, result); return QWidget::nativeEvent(eventType, message, result);
} } // namespace widgets
#endif #endif
} // namespace widgets } // namespace widgets