mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
fixed dpi not initializing when the window shows
This commit is contained in:
parent
14511e10ef
commit
206a3518b0
6 changed files with 46 additions and 9 deletions
12
src/main.cpp
12
src/main.cpp
|
@ -22,14 +22,16 @@ public:
|
||||||
MSG *msg = reinterpret_cast<MSG *>(message);
|
MSG *msg = reinterpret_cast<MSG *>(message);
|
||||||
|
|
||||||
if (msg->message == WM_NCCREATE) {
|
if (msg->message == WM_NCCREATE) {
|
||||||
typedef BOOL(WINAPI * EnableNonClientDpiScaling)(HWND);
|
|
||||||
QLibrary user32("user32.dll", NULL);
|
QLibrary user32("user32.dll", NULL);
|
||||||
|
{
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifdef USEWINSDK
|
#ifdef USEWINSDK
|
||||||
#include "windows.h"
|
#include <windows.h>
|
||||||
|
#include <boost/optional.hpp>
|
||||||
|
|
||||||
|
#include <QLibrary>
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
namespace util {
|
namespace util {
|
||||||
|
@ -17,7 +20,23 @@ static bool tryHandleDpiChangedMessage(void *message, int &dpi)
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static boost::optional<UINT> getWindowDpi(quintptr ptr)
|
||||||
|
{
|
||||||
|
typedef UINT(WINAPI * GetDpiForWindow)(HWND);
|
||||||
|
QLibrary user32("user32.dll", NULL);
|
||||||
|
|
||||||
|
GetDpiForWindow getDpiForWindow = (GetDpiForWindow)user32.resolve("GetDpiForWindow");
|
||||||
|
|
||||||
|
if (getDpiForWindow) {
|
||||||
|
UINT value = getDpiForWindow((HWND)ptr);
|
||||||
|
|
||||||
|
return value == 0 ? boost::none : boost::optional<UINT>(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return boost::none;
|
||||||
}
|
}
|
||||||
}
|
} // namespace util
|
||||||
|
} // namespace chatterino
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -51,6 +51,17 @@ void BaseWidget::init()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BaseWidget::initAsWindow()
|
||||||
|
{
|
||||||
|
#ifdef USEWINSDK
|
||||||
|
auto dpi = util::getWindowDpi(this->winId());
|
||||||
|
|
||||||
|
if (dpi) {
|
||||||
|
this->dpiMultiplier = dpi.value() / 96.f;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void BaseWidget::refreshTheme()
|
void BaseWidget::refreshTheme()
|
||||||
{
|
{
|
||||||
// Do any color scheme updates here
|
// Do any color scheme updates here
|
||||||
|
|
|
@ -32,6 +32,7 @@ protected:
|
||||||
#ifdef USEWINSDK
|
#ifdef USEWINSDK
|
||||||
virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
|
virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
|
||||||
#endif
|
#endif
|
||||||
|
void initAsWindow();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float dpiMultiplier = 1.f;
|
float dpiMultiplier = 1.f;
|
||||||
|
|
|
@ -16,6 +16,8 @@ EmotePopup::EmotePopup(ColorScheme &colorScheme, EmoteManager &emoteManager,
|
||||||
: BaseWidget(colorScheme, 0)
|
: BaseWidget(colorScheme, 0)
|
||||||
, emoteManager(emoteManager)
|
, emoteManager(emoteManager)
|
||||||
{
|
{
|
||||||
|
this->initAsWindow();
|
||||||
|
|
||||||
QHBoxLayout *layout = new QHBoxLayout(this);
|
QHBoxLayout *layout = new QHBoxLayout(this);
|
||||||
this->setLayout(layout);
|
this->setLayout(layout);
|
||||||
layout->setMargin(0);
|
layout->setMargin(0);
|
||||||
|
@ -69,5 +71,5 @@ void EmotePopup::loadChannel(std::shared_ptr<Channel> _channel)
|
||||||
|
|
||||||
this->view->setChannel(emoteChannel);
|
this->view->setChannel(emoteChannel);
|
||||||
}
|
}
|
||||||
}
|
} // namespace widgets
|
||||||
}
|
} // namespace chatterino
|
||||||
|
|
|
@ -26,6 +26,8 @@ MainWindow::MainWindow(ChannelManager &_channelManager, ColorScheme &_colorSchem
|
||||||
, dpi(this->getDpiMultiplier())
|
, dpi(this->getDpiMultiplier())
|
||||||
// , windowGeometry("/windows/0/geometry")
|
// , windowGeometry("/windows/0/geometry")
|
||||||
{
|
{
|
||||||
|
this->initAsWindow();
|
||||||
|
|
||||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||||
|
|
||||||
// add titlebar
|
// add titlebar
|
||||||
|
|
Loading…
Reference in a new issue