feat(editor): lock the cursor on platforms other than wayland

This commit is contained in:
maelstrom 2025-08-12 03:33:32 +02:00
parent 52cfa69a6e
commit 7bd3e70c3a

View file

@ -4,6 +4,7 @@
#include <memory> #include <memory>
#include <miniaudio.h> #include <miniaudio.h>
#include <qnamespace.h> #include <qnamespace.h>
#include <qguiapplication.h>
#include <string> #include <string>
#include "./ui_mainwindow.h" #include "./ui_mainwindow.h"
#include "mainglwidget.h" #include "mainglwidget.h"
@ -78,9 +79,12 @@ void MainGLWidget::handleCameraRotate(QMouseEvent* evt) {
if (!isMouseRightDragging) return; if (!isMouseRightDragging) return;
camera.processRotation(evt->pos().x() - lastMousePos.x(), evt->pos().y() - lastMousePos.y()); camera.processRotation(evt->pos().x() - lastMousePos.x(), evt->pos().y() - lastMousePos.y());
lastMousePos = evt->pos();
// QCursor::setPos(lastMousePos); // Does not work on Wayland. Find an alternative
if (QGuiApplication::platformName() != "wayland")
QCursor::setPos(mapToGlobal(lastMousePos));
else
lastMousePos = evt->pos();
} }
@ -328,6 +332,7 @@ std::optional<HandleFace> MainGLWidget::raycastHandle(glm::vec3 pointDir) {
} }
void MainGLWidget::handleCursorChange(QMouseEvent* evt) { void MainGLWidget::handleCursorChange(QMouseEvent* evt) {
if (isMouseRightDragging) return; // Don't change the cursor while it is intentionally blank
QPoint position = evt->pos(); QPoint position = evt->pos();
glm::vec3 pointDir = camera.getScreenDirection(glm::vec2(position.x(), position.y()), glm::vec2(width(), height())); glm::vec3 pointDir = camera.getScreenDirection(glm::vec2(position.x(), position.y()), glm::vec2(width(), height()));
@ -380,6 +385,7 @@ void MainGLWidget::mousePressEvent(QMouseEvent* evt) {
case Qt::RightButton: { case Qt::RightButton: {
lastMousePos = evt->pos(); lastMousePos = evt->pos();
isMouseRightDragging = true; isMouseRightDragging = true;
setCursor(Qt::BlankCursor);
return; return;
// Clicking on objects // Clicking on objects
} case Qt::LeftButton: { } case Qt::LeftButton: {
@ -469,6 +475,7 @@ void MainGLWidget::mouseReleaseEvent(QMouseEvent* evt) {
isMouseDragging = false; isMouseDragging = false;
draggingObject = {}; draggingObject = {};
draggingHandle = std::nullopt; draggingHandle = std::nullopt;
setCursor(Qt::ArrowCursor);
if (!initialTransforms.empty()) { if (!initialTransforms.empty()) {
UndoState historyState; UndoState historyState;