Improve media viewer hiding workaround on macOS.

This commit is contained in:
John Preston 2020-11-19 17:59:43 +03:00
parent 51f960442e
commit e29ee439cf
2 changed files with 25 additions and 19 deletions

View file

@ -4295,8 +4295,31 @@ bool OverlayWidget::eventFilter(QObject *obj, QEvent *e) {
return OverlayParent::eventFilter(obj, e); return OverlayParent::eventFilter(obj, e);
} }
void OverlayWidget::applyHideWindowWorkaround() {
#ifdef USE_OPENGL_OVERLAY_WIDGET
// QOpenGLWidget can't properly destroy a child widget if
// it is hidden exactly after that, so it must be repainted
// before it is hidden without the child widget.
if (!isHidden()) {
_dropdown->hideFast();
hideChildren();
_wasRepainted = false;
repaint();
if (!_wasRepainted) {
// Qt has some optimization to prevent too frequent repaints.
// If the previous repaint was less than 1/60 second it silently
// converts repaint() call to an update() call. But we have to
// repaint right now, before hide(), with _streamingControls destroyed.
auto event = QEvent(QEvent::UpdateRequest);
QApplication::sendEvent(this, &event);
}
}
#endif // USE_OPENGL_OVERLAY_WIDGET
}
void OverlayWidget::setVisibleHook(bool visible) { void OverlayWidget::setVisibleHook(bool visible) {
if (!visible) { if (!visible) {
applyHideWindowWorkaround();
_sharedMedia = nullptr; _sharedMedia = nullptr;
_sharedMediaData = std::nullopt; _sharedMediaData = std::nullopt;
_sharedMediaDataKey = std::nullopt; _sharedMediaDataKey = std::nullopt;
@ -4313,25 +4336,6 @@ void OverlayWidget::setVisibleHook(bool visible) {
_controlsOpacity = anim::value(1, 1); _controlsOpacity = anim::value(1, 1);
_groupThumbs = nullptr; _groupThumbs = nullptr;
_groupThumbsRect = QRect(); _groupThumbsRect = QRect();
#ifdef USE_OPENGL_OVERLAY_WIDGET
// QOpenGLWidget can't properly destroy a child widget if
// it is hidden exactly after that, so it must be repainted
// before it is hidden without the child widget.
if (!isHidden()) {
_dropdown->hideFast();
hideChildren();
_wasRepainted = false;
repaint();
if (!_wasRepainted) {
// Qt has some optimization to prevent too frequent repaints.
// If the previous repaint was less than 1/60 second it silently
// converts repaint() call to an update() call. But we have to
// repaint right now, before hide(), with _streamingControls destroyed.
auto event = QEvent(QEvent::UpdateRequest);
QApplication::sendEvent(this, &event);
}
}
#endif // USE_OPENGL_OVERLAY_WIDGET
} }
OverlayParent::setVisibleHook(visible); OverlayParent::setVisibleHook(visible);
if (visible) { if (visible) {

View file

@ -372,6 +372,8 @@ private:
void clearStreaming(bool savePosition = true); void clearStreaming(bool savePosition = true);
bool canInitStreaming() const; bool canInitStreaming() const;
void applyHideWindowWorkaround();
QBrush _transparentBrush; QBrush _transparentBrush;
Main::Session *_session = nullptr; Main::Session *_session = nullptr;