From 63603ff97c7b528d8e529867f67ccd65c963fff9 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Tue, 3 Apr 2018 14:21:15 +1200 Subject: [PATCH 1/4] Fix window height reported by Window.geometryChanged() signal --- interface/src/scripting/WindowScriptingInterface.cpp | 11 ++++++++++- interface/src/scripting/WindowScriptingInterface.h | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/interface/src/scripting/WindowScriptingInterface.cpp b/interface/src/scripting/WindowScriptingInterface.cpp index 58ec744f4e..7ca4e495b1 100644 --- a/interface/src/scripting/WindowScriptingInterface.cpp +++ b/interface/src/scripting/WindowScriptingInterface.cpp @@ -51,7 +51,7 @@ WindowScriptingInterface::WindowScriptingInterface() { } }); - connect(qApp->getWindow(), &MainWindow::windowGeometryChanged, this, &WindowScriptingInterface::geometryChanged); + connect(qApp->getWindow(), &MainWindow::windowGeometryChanged, this, &WindowScriptingInterface::onWindowGeometryChanged); } WindowScriptingInterface::~WindowScriptingInterface() { @@ -397,6 +397,15 @@ int WindowScriptingInterface::getY() { return qApp->getWindow()->y(); } +void WindowScriptingInterface::onWindowGeometryChanged(const QRect& windowGeometry) { + auto geometry = windowGeometry; + auto menu = qApp->getPrimaryMenu(); + if (menu) { + geometry.setHeight(geometry.height() - menu->geometry().height()); + } + emit geometryChanged(geometry); +} + void WindowScriptingInterface::copyToClipboard(const QString& text) { if (QThread::currentThread() != qApp->thread()) { QMetaObject::invokeMethod(this, "copyToClipboard", Q_ARG(QString, text)); diff --git a/interface/src/scripting/WindowScriptingInterface.h b/interface/src/scripting/WindowScriptingInterface.h index e3b092d011..b41051cc6b 100644 --- a/interface/src/scripting/WindowScriptingInterface.h +++ b/interface/src/scripting/WindowScriptingInterface.h @@ -522,6 +522,7 @@ public slots: void closeMessageBox(int id); private slots: + void onWindowGeometryChanged(const QRect& geometry); void onMessageBoxSelected(int button); void disconnectedFromDomain(); From a3c8b2792d2df9faf23a87e17c5450f2c8f734e4 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 4 Apr 2018 09:42:05 +1200 Subject: [PATCH 2/4] Fix Window.geometryChanged() values for moving and resizing window --- interface/src/scripting/WindowScriptingInterface.cpp | 2 +- libraries/ui/src/MainWindow.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/interface/src/scripting/WindowScriptingInterface.cpp b/interface/src/scripting/WindowScriptingInterface.cpp index 7ca4e495b1..f65142f875 100644 --- a/interface/src/scripting/WindowScriptingInterface.cpp +++ b/interface/src/scripting/WindowScriptingInterface.cpp @@ -401,7 +401,7 @@ void WindowScriptingInterface::onWindowGeometryChanged(const QRect& windowGeomet auto geometry = windowGeometry; auto menu = qApp->getPrimaryMenu(); if (menu) { - geometry.setHeight(geometry.height() - menu->geometry().height()); + geometry.setY(geometry.y() + menu->geometry().height()); } emit geometryChanged(geometry); } diff --git a/libraries/ui/src/MainWindow.cpp b/libraries/ui/src/MainWindow.cpp index 091fd850af..f9fc71e417 100644 --- a/libraries/ui/src/MainWindow.cpp +++ b/libraries/ui/src/MainWindow.cpp @@ -79,12 +79,12 @@ void MainWindow::closeEvent(QCloseEvent* event) { } void MainWindow::moveEvent(QMoveEvent* event) { - emit windowGeometryChanged(QRect(event->pos(), size())); + emit windowGeometryChanged(QRect(QPoint(geometry().x(), geometry().y()), size())); // Geometry excluding the window frame. QMainWindow::moveEvent(event); } void MainWindow::resizeEvent(QResizeEvent* event) { - emit windowGeometryChanged(QRect(QPoint(x(), y()), event->size())); + emit windowGeometryChanged(QRect(QPoint(geometry().x(), geometry().y()), size())); // Geometry excluding the window frame. QMainWindow::resizeEvent(event); } From 6868ca971f35ba18838369b9c4a6f4a21a821d46 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 4 Apr 2018 09:43:39 +1200 Subject: [PATCH 3/4] Make Window.x and Window.y report top left of drawable area of window --- interface/src/scripting/WindowScriptingInterface.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/interface/src/scripting/WindowScriptingInterface.cpp b/interface/src/scripting/WindowScriptingInterface.cpp index f65142f875..9c46f9e98a 100644 --- a/interface/src/scripting/WindowScriptingInterface.cpp +++ b/interface/src/scripting/WindowScriptingInterface.cpp @@ -390,11 +390,13 @@ glm::vec2 WindowScriptingInterface::getDeviceSize() const { } int WindowScriptingInterface::getX() { - return qApp->getWindow()->x(); + return qApp->getWindow()->geometry().x(); } int WindowScriptingInterface::getY() { - return qApp->getWindow()->y(); + auto menu = qApp->getPrimaryMenu(); + int menuHeight = menu ? menu->geometry().height() : 0; + return qApp->getWindow()->geometry().y() + menuHeight; } void WindowScriptingInterface::onWindowGeometryChanged(const QRect& windowGeometry) { From 095c1b837c43ba9bb387cff37b34d8fde8081f14 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 4 Apr 2018 09:48:33 +1200 Subject: [PATCH 4/4] Update JSDoc --- interface/src/scripting/WindowScriptingInterface.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/interface/src/scripting/WindowScriptingInterface.h b/interface/src/scripting/WindowScriptingInterface.h index b41051cc6b..dd74358064 100644 --- a/interface/src/scripting/WindowScriptingInterface.h +++ b/interface/src/scripting/WindowScriptingInterface.h @@ -33,8 +33,10 @@ * @property {number} innerHeight - The height of the drawable area of the Interface window (i.e., without borders or other * chrome), in pixels. Read-only. * @property {object} location - Provides facilities for working with your current metaverse location. See {@link location}. - * @property {number} x - The x coordinate of the top left corner of the Interface window on the display. Read-only. - * @property {number} y - The y coordinate of the top left corner of the Interface window on the display. Read-only. + * @property {number} x - The x display coordinate of the top left corner of the drawable area of the Interface window. + * Read-only. + * @property {number} y - The y display coordinate of the top left corner of the drawable area of the Interface window. + * Read-only. */ class WindowScriptingInterface : public QObject, public Dependency {