From e5f3bc9f3fcc0971f0e63102316ee8b72025abdf Mon Sep 17 00:00:00 2001 From: Matthew Marlow <44077383+mfmarlow@users.noreply.github.com> Date: Sat, 1 Aug 2020 06:42:56 -0700 Subject: [PATCH] Improve Chatterino extension positioning (#1825) This adds support for left-side chat --- src/singletons/NativeMessaging.cpp | 3 ++- src/widgets/AttachedWindow.cpp | 21 +++++++++++++++++---- src/widgets/AttachedWindow.hpp | 2 ++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/singletons/NativeMessaging.cpp b/src/singletons/NativeMessaging.cpp index 51d1cedcc..94700257f 100644 --- a/src/singletons/NativeMessaging.cpp +++ b/src/singletons/NativeMessaging.cpp @@ -198,11 +198,12 @@ 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); args.fullscreen = attachFullscreen; - qDebug() << args.width << args.height << args.winId; + qDebug() << args.x << args.width << args.height << args.winId; if (_type.isNull() || args.winId.isNull()) { diff --git a/src/widgets/AttachedWindow.cpp b/src/widgets/AttachedWindow.cpp index 7c84d2b99..b97abb789 100644 --- a/src/widgets/AttachedWindow.cpp +++ b/src/widgets/AttachedWindow.cpp @@ -91,6 +91,8 @@ AttachedWindow *AttachedWindow::get(void *target, const GetArgs &args) window->fullscreen_ = args.fullscreen; + window->x_ = args.x; + if (args.height != -1) { if (args.height == 0) @@ -269,10 +271,21 @@ void AttachedWindow::updateWindowRect(void *_attachedPtr) // offset int o = this->fullscreen_ ? 0 : 8; - ::MoveWindow(hwnd, int(rect.right - this->width_ * scale - o), - int(rect.bottom - this->height_ * scale - o), - int(this->width_ * scale), int(this->height_ * scale), - true); + if (this->x_ != -1) + { + ::MoveWindow(hwnd, int(rect.left + this->x_ * scale + o), + int(rect.bottom - this->height_ * scale - o), + int(this->width_ * scale), int(this->height_ * scale), + true); + } + //support for old extension version 1.2 + else + { + ::MoveWindow(hwnd, int(rect.right - this->width_ * scale - o), + int(rect.bottom - this->height_ * scale - o), + int(this->width_ * scale), int(this->height_ * scale), + true); + } } // if (this->fullscreen_) diff --git a/src/widgets/AttachedWindow.hpp b/src/widgets/AttachedWindow.hpp index 0a910774d..4ecefa11c 100644 --- a/src/widgets/AttachedWindow.hpp +++ b/src/widgets/AttachedWindow.hpp @@ -17,6 +17,7 @@ public: struct GetArgs { QString winId; int yOffset = -1; + int x = -1; int width = -1; int height = -1; bool fullscreen = false; @@ -53,6 +54,7 @@ private: void *target_; int yOffset_; int currentYOffset_; + int x_ = -1; int width_ = 360; int height_ = -1; bool fullscreen_ = false;