fixed size of the attachedwindow for the browser extension for scaling

This commit is contained in:
fourtf
2018-06-25 22:06:17 +02:00
parent 13d28d0d8b
commit 6375a902a0
8 changed files with 135 additions and 69 deletions
+32 -32
View File
@@ -10,46 +10,46 @@
namespace chatterino {
namespace util {
static boost::optional<UINT> getWindowDpi(quintptr ptr)
{
typedef UINT(WINAPI * GetDpiForWindow)(HWND);
QLibrary user32("user32.dll", 0);
// static boost::optional<UINT> getWindowDpi(quintptr ptr)
//{
// typedef UINT(WINAPI * GetDpiForWindow)(HWND);
// QLibrary user32("user32.dll", 0);
GetDpiForWindow getDpiForWindow = (GetDpiForWindow)user32.resolve("GetDpiForWindow");
// GetDpiForWindow getDpiForWindow = (GetDpiForWindow)user32.resolve("GetDpiForWindow");
if (getDpiForWindow) {
UINT value = getDpiForWindow((HWND)ptr);
// if (getDpiForWindow) {
// UINT value = getDpiForWindow((HWND)ptr);
return value == 0 ? boost::none : boost::optional<UINT>(value);
}
// return value == 0 ? boost::none : boost::optional<UINT>(value);
// }
return boost::none;
}
// return boost::none;
//}
#ifdef USEWINSDK
class DpiNativeEventFilter : public QAbstractNativeEventFilter
{
public:
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override
{
// MSG *msg = reinterpret_cast<MSG *>(message);
//#ifdef USEWINSDK
// class DpiNativeEventFilter : public QAbstractNativeEventFilter
//{
// public:
// bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override
// {
// // MSG *msg = reinterpret_cast<MSG *>(message);
// if (msg->message == WM_NCCREATE) {
// QLibrary user32("user32.dll", 0);
// {
// typedef BOOL(WINAPI * EnableNonClientDpiScaling)(HWND);
// // if (msg->message == WM_NCCREATE) {
// // QLibrary user32("user32.dll", 0);
// // {
// // typedef BOOL(WINAPI * EnableNonClientDpiScaling)(HWND);
// EnableNonClientDpiScaling enableNonClientDpiScaling =
// (EnableNonClientDpiScaling)user32.resolve("EnableNonClientDpiScaling");
// // EnableNonClientDpiScaling enableNonClientDpiScaling =
// // (EnableNonClientDpiScaling)user32.resolve("EnableNonClientDpiScaling");
// if (enableNonClientDpiScaling)
// enableNonClientDpiScaling(msg->hwnd);
// }
// }
return false;
}
};
#endif
// // if (enableNonClientDpiScaling)
// // enableNonClientDpiScaling(msg->hwnd);
// // }
// // }
// return false;
// }
//};
//#endif
} // namespace util
} // namespace chatterino
+38
View File
@@ -0,0 +1,38 @@
#include "windows_helper.hpp"
#ifdef USEWINSDK
namespace chatterino {
namespace util {
typedef enum MONITOR_DPI_TYPE {
MDT_EFFECTIVE_DPI = 0,
MDT_ANGULAR_DPI = 1,
MDT_RAW_DPI = 2,
MDT_DEFAULT = MDT_EFFECTIVE_DPI
} MONITOR_DPI_TYPE;
typedef HRESULT(CALLBACK *GetDpiForMonitor_)(HMONITOR, MONITOR_DPI_TYPE, UINT *, UINT *);
boost::optional<UINT> getWindowDpi(HWND hwnd)
{
static HINSTANCE shcore = LoadLibrary(L"Shcore.dll");
if (shcore != nullptr) {
if (auto getDpiForMonitor = GetDpiForMonitor_(GetProcAddress(shcore, "GetDpiForMonitor"))) {
HMONITOR monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
UINT xScale, yScale;
getDpiForMonitor(monitor, MDT_DEFAULT, &xScale, &yScale);
return xScale;
}
}
return boost::none;
}
} // namespace util
} // namespace chatterino
#endif
+16
View File
@@ -0,0 +1,16 @@
#pragma once
#ifdef USEWINSDK
#include <Windows.h>
#include <boost/optional.hpp>
namespace chatterino {
namespace util {
boost::optional<UINT> getWindowDpi(HWND hwnd);
} // namespace util
} // namespace chatterino
#endif