Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed zooming bug in native-host-ext [Chrome] #1936

Merged
merged 12 commits into from
Jul 25, 2021
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Bugfix: Fixed "smiley" emotes being unable to be "Tabbed" with autocompletion, introduced in v2.3.3. (#3010)
- Bugfix: Copy buttons in usercard now show properly in light mode (#3057)
- Bugfix: Fixed comma appended to username completion when not at the beginning of the message. (#3060)
- Bugfix: Fixed bug misplacing chat when zooming on Chrome with Chatterino Native Host extension (#1936)
- Dev: Ubuntu packages are now available (#2936)
- Dev: Disabled update checker on Flatpak. (#3051)
- Dev: Add logging for HTTP requests (#2991)
Expand Down
16 changes: 11 additions & 5 deletions src/singletons/NativeMessaging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ void NativeMessagingServer::ReceiverThread::handleMessage(
const QJsonObject &root)
{
auto app = getApp();

QString action = root.value("action").toString();

if (action.isNull())
Expand All @@ -211,13 +210,20 @@ void NativeMessagingServer::ReceiverThread::handleMessage(
AttachedWindow::GetArgs args;
args.winId = root.value("winId").toString();
args.yOffset = root.value("yOffset").toInt(-1);
args.x = root.value("size").toObject().value("x").toInt(-1);
args.width = root.value("size").toObject().value("width").toInt(-1);
args.height = root.value("size").toObject().value("height").toInt(-1);

{
const auto sizeObject = root.value("size").toObject();
args.x = sizeObject.value("x").toDouble(-1.0);
args.pixelRatio = sizeObject.value("pixelRatio").toDouble(-1.0);
args.width = sizeObject.value("width").toInt(-1);
args.height = sizeObject.value("height").toInt(-1);
}

args.fullscreen = attachFullscreen;

qCDebug(chatterinoNativeMessage)
<< args.x << args.width << args.height << args.winId;
<< args.x << args.pixelRatio << args.width << args.height
<< args.winId;

if (_type.isNull() || args.winId.isNull())
{
Expand Down
12 changes: 11 additions & 1 deletion src/widgets/AttachedWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ AttachedWindow *AttachedWindow::get(void *target, const GetArgs &args)
window->fullscreen_ = args.fullscreen;

window->x_ = args.x;
window->pixelRatio_ = args.pixelRatio;

if (args.height != -1)
{
Expand Down Expand Up @@ -276,7 +277,16 @@ void AttachedWindow::updateWindowRect(void *_attachedPtr)
// offset
int o = this->fullscreen_ ? 0 : 8;

if (this->x_ != -1)
if (this->pixelRatio_ != -1.0)
{
::MoveWindow(
hwnd,
int(rect.left + this->x_ * scale * this->pixelRatio_ + o - 2),
int(rect.bottom - this->height_ * scale - o),
int(this->width_ * scale), int(this->height_ * scale), true);
}
//support for old extension version 1.3
else if (this->x_ != -1.0)
{
::MoveWindow(hwnd, int(rect.left + this->x_ * scale + o),
int(rect.bottom - this->height_ * scale - o),
Expand Down
6 changes: 4 additions & 2 deletions src/widgets/AttachedWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class AttachedWindow : public QWidget
struct GetArgs {
QString winId;
int yOffset = -1;
int x = -1;
double x = -1;
double pixelRatio = -1;
int width = -1;
int height = -1;
bool fullscreen = false;
Expand Down Expand Up @@ -54,7 +55,8 @@ class AttachedWindow : public QWidget
void *target_;
int yOffset_;
int currentYOffset_;
int x_ = -1;
double x_ = -1;
double pixelRatio_ = -1;
int width_ = 360;
int height_ = -1;
bool fullscreen_ = false;
Expand Down