fixed size of the attachedwindow for the browser extension for scaling
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#ifdef USEWINSDK
|
||||
#include "util/windows_helper.hpp"
|
||||
|
||||
#include "Windows.h"
|
||||
// don't even think about reordering these
|
||||
#include "Psapi.h"
|
||||
@@ -177,12 +179,24 @@ void AttachedWindow::updateWindowRect_(void *_attachedPtr)
|
||||
::SetWindowPos(hwnd, next ? next : HWND_TOPMOST, 0, 0, 0, 0,
|
||||
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
|
||||
|
||||
float scale = 1.f;
|
||||
if (auto dpi = util::getWindowDpi(attached)) {
|
||||
scale = dpi.get() / 96.f;
|
||||
|
||||
// for (auto w : this->ui_.split->findChildren<BaseWidget *>()) {
|
||||
// w->setOverrideScale(scale);
|
||||
// }
|
||||
// this->ui_.split->setOverrideScale(scale);
|
||||
}
|
||||
|
||||
if (this->height_ == -1) {
|
||||
::MoveWindow(hwnd, rect.right - this->width_ - 8, rect.top + this->yOffset_ - 8,
|
||||
this->width_, rect.bottom - rect.top - this->yOffset_, false);
|
||||
// ::MoveWindow(hwnd, rect.right - this->width_ - 8, rect.top + this->yOffset_ - 8,
|
||||
// this->width_, rect.bottom - rect.top - this->yOffset_, false);
|
||||
} else {
|
||||
::MoveWindow(hwnd, rect.right - this->width_ - 8, rect.bottom - this->height_ - 8,
|
||||
this->width_, this->height_, false);
|
||||
::MoveWindow(hwnd, //
|
||||
int(rect.right - this->width_ * scale - 8), //
|
||||
int(rect.bottom - this->height_ * scale - 8), //
|
||||
int(this->width_ * scale), int(this->height_ * scale), true);
|
||||
}
|
||||
|
||||
// ::MoveWindow(hwnd, rect.right - 360, rect.top + 82, 360 - 8, rect.bottom -
|
||||
|
||||
@@ -28,6 +28,10 @@ BaseWidget::~BaseWidget()
|
||||
|
||||
float BaseWidget::getScale() const
|
||||
{
|
||||
if (this->overrideScale) {
|
||||
return this->overrideScale.get();
|
||||
}
|
||||
|
||||
BaseWidget *baseWidget = dynamic_cast<BaseWidget *>(this->window());
|
||||
|
||||
if (baseWidget == nullptr) {
|
||||
@@ -37,6 +41,17 @@ float BaseWidget::getScale() const
|
||||
return baseWidget->scale;
|
||||
}
|
||||
|
||||
void BaseWidget::setOverrideScale(boost::optional<float> value)
|
||||
{
|
||||
this->overrideScale = value;
|
||||
this->setScale(this->getScale());
|
||||
}
|
||||
|
||||
boost::optional<float> BaseWidget::getOverrideScale() const
|
||||
{
|
||||
return this->overrideScale;
|
||||
}
|
||||
|
||||
QSize BaseWidget::getScaleIndependantSize() const
|
||||
{
|
||||
return this->scaleIndependantSize;
|
||||
@@ -120,8 +135,8 @@ void BaseWidget::setScale(float value)
|
||||
// update scale value
|
||||
this->scale = value;
|
||||
|
||||
this->scaleChangedEvent(value);
|
||||
this->scaleChanged.invoke(value);
|
||||
this->scaleChangedEvent(this->getScale());
|
||||
this->scaleChanged.invoke(this->getScale());
|
||||
|
||||
this->setScaleIndependantSize(this->getScaleIndependantSize());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include <boost/optional.hpp>
|
||||
#include <pajlada/signals/signal.hpp>
|
||||
|
||||
namespace chatterino {
|
||||
@@ -23,6 +24,9 @@ public:
|
||||
virtual float getScale() const;
|
||||
pajlada::Signals::Signal<float> scaleChanged;
|
||||
|
||||
void setOverrideScale(boost::optional<float>);
|
||||
boost::optional<float> getOverrideScale() const;
|
||||
|
||||
QSize getScaleIndependantSize() const;
|
||||
int getScaleIndependantWidth() const;
|
||||
int getScaleIndependantHeight() const;
|
||||
@@ -46,6 +50,7 @@ protected:
|
||||
private:
|
||||
void init();
|
||||
float scale = 1.f;
|
||||
boost::optional<float> overrideScale = boost::none;
|
||||
QSize scaleIndependantSize;
|
||||
|
||||
std::vector<BaseWidget *> widgets;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "singletons/windowmanager.hpp"
|
||||
#include "util/nativeeventhelper.hpp"
|
||||
#include "util/posttothread.hpp"
|
||||
#include "util/windows_helper.hpp"
|
||||
#include "widgets/helper/rippleeffectlabel.hpp"
|
||||
#include "widgets/helper/shortcut.hpp"
|
||||
#include "widgets/label.hpp"
|
||||
@@ -29,15 +30,6 @@
|
||||
//#include <ShellScalingApi.h>
|
||||
#pragma comment(lib, "Dwmapi.lib")
|
||||
|
||||
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 *);
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
@@ -78,7 +70,7 @@ BaseWindow::BaseWindow(QWidget *parent, Flags _flags)
|
||||
|
||||
float BaseWindow::getScale() const
|
||||
{
|
||||
return this->scale;
|
||||
return this->getOverrideScale().value_or(this->scale);
|
||||
}
|
||||
|
||||
BaseWindow::Flags BaseWindow::getFlags()
|
||||
@@ -448,25 +440,9 @@ bool BaseWindow::nativeEvent(const QByteArray &eventType, void *message, long *r
|
||||
return true;
|
||||
}
|
||||
case WM_SHOWWINDOW: {
|
||||
// if (IsWindows8Point1OrGreater()) {
|
||||
|
||||
static HINSTANCE shcore = LoadLibrary(L"Shcore.dll");
|
||||
if (shcore != nullptr) {
|
||||
if (auto getDpiForMonitor =
|
||||
GetDpiForMonitor_(GetProcAddress(shcore, "GetDpiForMonitor"))) {
|
||||
HMONITOR monitor = MonitorFromWindow(msg->hwnd, MONITOR_DEFAULTTONEAREST);
|
||||
|
||||
UINT xScale, yScale;
|
||||
|
||||
getDpiForMonitor(monitor, MDT_DEFAULT, &xScale, &yScale);
|
||||
|
||||
// GetDpiForMonitor(monitor, MDT_DEFAULT, &xScale, &yScale);
|
||||
|
||||
float scale = xScale / 96.f;
|
||||
|
||||
this->nativeScale_ = scale;
|
||||
this->updateScale();
|
||||
}
|
||||
if (auto dpi = util::getWindowDpi(msg->hwnd)) {
|
||||
this->nativeScale_ = dpi.get() / 96.f;
|
||||
this->updateScale();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user