don't capture the mouse if you're not the active window or if a menu is popped up

This commit is contained in:
Brad Hefta-Gaub 2016-02-18 17:11:40 -08:00
parent adcadedc65
commit 0de5c1cf71
4 changed files with 20 additions and 2 deletions

View file

@ -968,6 +968,7 @@ int Menu::positionBeforeSeparatorIfNeeded(MenuWrapper* menu, int requestedPositi
return requestedPosition;
}
bool Menu::_isSomeSubmenuShown = false;
MenuWrapper* Menu::addMenu(const QString& menuName, const QString& grouping) {
QStringList menuTree = menuName.split(">");
@ -994,6 +995,12 @@ MenuWrapper* Menu::addMenu(const QString& menuName, const QString& grouping) {
}
QMenuBar::repaint();
// hook our show/hide for popup menus, so we can keep track of whether or not one
// of our submenus is currently showing.
connect(menu->_realMenu, &QMenu::aboutToShow, []() { _isSomeSubmenuShown = true; });
connect(menu->_realMenu, &QMenu::aboutToHide, []() { _isSomeSubmenuShown = false; });
return menu;
}

View file

@ -42,6 +42,7 @@ public:
QAction* newAction() {
return new QAction(_realMenu);
}
private:
MenuWrapper(QMenu* menu);
@ -117,6 +118,8 @@ public slots:
void toggleDeveloperMenus();
void toggleAdvancedMenus();
static bool isSomeSubmenuShown() { return _isSomeSubmenuShown; }
private:
typedef void(*settingsAction)(Settings&, QAction&);
static void loadAction(Settings& settings, QAction& action);
@ -142,6 +145,8 @@ private:
bool isValidGrouping(const QString& grouping) const { return grouping == "Advanced" || grouping == "Developer"; }
QHash<QString, bool> _groupingVisible;
QHash<QString, QSet<QAction*>> _groupingActions;
static bool _isSomeSubmenuShown;
};
namespace MenuOption {

View file

@ -308,9 +308,13 @@ QPointF ApplicationCompositor::getMouseEventPosition(QMouseEvent* event) {
return event->localPos();
}
bool ApplicationCompositor::shouldCaptureMouse() const {
// if we're in HMD mode, and some window of ours is active, but we're not currently showing a popup menu
return qApp->isHMDMode() && QApplication::activeWindow() && !Menu::isSomeSubmenuShown();
}
void ApplicationCompositor::handleLeaveEvent() {
if (qApp->isHMDMode()) {
if (shouldCaptureMouse()) {
auto applicationGeometry = qApp->getApplicationGeometry();
_ignoreMouseMove = true;
auto sendToPos = applicationGeometry.center();
@ -328,7 +332,7 @@ bool ApplicationCompositor::handleRealMouseMoveEvent(bool sendFakeEvent) {
}
// If we're in HMD mode
if (qApp->isHMDMode()) {
if (shouldCaptureMouse()) {
auto newPosition = QCursor::pos();
auto changeInRealMouse = newPosition - _lastKnownRealMouse;
auto newReticlePosition = _reticlePositionInHMD + toGlm(changeInRealMouse);

View file

@ -105,6 +105,8 @@ public:
private:
bool shouldCaptureMouse() const;
void displayOverlayTextureStereo(RenderArgs* renderArgs, float aspectRatio, float fov);
void bindCursorTexture(gpu::Batch& batch, uint8_t cursorId = 0);
void buildHemiVertices(const float fov, const float aspectRatio, const int slices, const int stacks);