Skip to content

Commit

Permalink
Only cancel mouse drags if window deactivates
Browse files Browse the repository at this point in the history
Some windows managers deactivate views when the mouse cursor leaves them
regardless of whether a drag is in progress. This would lead to mouse
drags being cancelled inadvertedly because we cancel mouse drags when
a map view or the UV view lose focus.

In this commit, we change it so that we cancel mouse drags when the
window is deactivated.
  • Loading branch information
kduske committed Feb 27, 2023
1 parent 80d3498 commit fa28809
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
11 changes: 10 additions & 1 deletion common/src/View/MapViewBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,16 @@ void MapViewBase::hideAllEntityLinks()
setPref(Preferences::FaceRenderMode, Preferences::entityLinkModeNone());
}

bool MapViewBase::event(QEvent* event)
{
if (event->type() == QEvent::WindowDeactivate)
{
cancelMouseDrag();
}

return RenderView::event(event);
}

void MapViewBase::focusInEvent(QFocusEvent* event)
{
updateActionStates(); // enable/disable QShortcut's to reflect whether we have focus
Expand All @@ -914,7 +924,6 @@ void MapViewBase::focusInEvent(QFocusEvent* event)

void MapViewBase::focusOutEvent(QFocusEvent* event)
{
cancelMouseDrag();
clearModifierKeys();
update();
RenderView::focusOutEvent(event);
Expand Down
2 changes: 1 addition & 1 deletion common/src/View/MapViewBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ class MapViewBase : public RenderView,
void showDirectlySelectedEntityLinks();
void hideAllEntityLinks();

protected:
bool event(QEvent* event) override;
void focusInEvent(QFocusEvent* event) override;
void focusOutEvent(QFocusEvent* event) override;

Expand Down
10 changes: 7 additions & 3 deletions common/src/View/UVView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,14 @@ void UVView::setSubDivisions(const vm::vec2i& subDivisions)
update();
}

void UVView::focusOutEvent(QFocusEvent* event)
bool UVView::event(QEvent* event)
{
ToolBoxConnector::cancelDrag();
RenderView::focusOutEvent(event);
if (event->type() == QEvent::WindowDeactivate)
{
cancelDrag();
}

return RenderView::event(event);
}

void UVView::createTools()
Expand Down
3 changes: 1 addition & 2 deletions common/src/View/UVView.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ class UVView : public RenderView, public ToolBoxConnector

void setSubDivisions(const vm::vec2i& subDivisions);

protected:
void focusOutEvent(QFocusEvent* event) override;
bool event(QEvent* event) override;

private:
void createTools();
Expand Down

0 comments on commit fa28809

Please sign in to comment.