Fix preview not opening on Wayland

Deferring the opening of the preview slightly gives the preview select
dialog time to close and for focus to shift back to the main window.

PR #22608.
Closes #22607.

---------

Co-authored-by: Vladimir Golovnev <glassez@yandex.ru>
This commit is contained in:
Isak05 2025-04-27 09:02:52 +02:00 committed by GitHub
parent 70822e8942
commit 45babc336d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 8 deletions

View file

@ -312,10 +312,7 @@ void TransferListWidget::torrentDoubleClicked()
case PREVIEW_FILE:
if (torrentContainsPreviewableFiles(torrent))
{
auto *dialog = new PreviewSelectDialog(this, torrent);
dialog->setAttribute(Qt::WA_DeleteOnClose);
connect(dialog, &PreviewSelectDialog::readyToPreviewFile, this, &TransferListWidget::previewFile);
dialog->show();
openPreviewSelectDialog(torrent);
}
else
{
@ -617,10 +614,7 @@ void TransferListWidget::previewSelectedTorrents()
{
if (torrentContainsPreviewableFiles(torrent))
{
auto *dialog = new PreviewSelectDialog(this, torrent);
dialog->setAttribute(Qt::WA_DeleteOnClose);
connect(dialog, &PreviewSelectDialog::readyToPreviewFile, this, &TransferListWidget::previewFile);
dialog->show();
openPreviewSelectDialog(torrent);
}
else
{
@ -1449,3 +1443,13 @@ void TransferListWidget::wheelEvent(QWheelEvent *event)
QTreeView::wheelEvent(event); // event delegated to base class
}
void TransferListWidget::openPreviewSelectDialog(const BitTorrent::Torrent *torrent)
{
auto *dialog = new PreviewSelectDialog(this, torrent);
dialog->setAttribute(Qt::WA_DeleteOnClose);
// Qt::QueuedConnection is required to prevent a bug on wayland compositors where the preview won't open.
// It occurs when the window focus shifts immediately after TransferListWidget::previewFile has been called.
connect(dialog, &PreviewSelectDialog::readyToPreviewFile, this, &TransferListWidget::previewFile, Qt::QueuedConnection);
dialog->show();
}

View file

@ -123,6 +123,7 @@ private:
void dragMoveEvent(QDragMoveEvent *event) override;
void dropEvent(QDropEvent *event) override;
void wheelEvent(QWheelEvent *event) override;
void openPreviewSelectDialog(const BitTorrent::Torrent *torrent);
QModelIndex mapToSource(const QModelIndex &index) const;
QModelIndexList mapToSource(const QModelIndexList &indexes) const;
QModelIndex mapFromSource(const QModelIndex &index) const;