diff --git a/CHANGELOG.md b/CHANGELOG.md index c958e6292..88558b3c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ - Bugfix: Fixed rare crash with Image Uploader when closing a split right after starting an upload. (#4971) - Bugfix: Fixed support for Windows 11 Snap layouts. (#4994) - Bugfix: Fixed some windows appearing between screens. (#4797) +- Bugfix: Fixed a bug on Wayland where tooltips would spawn as separate windows instead of behaving like tooltips. (#4998) - Dev: Run miniaudio in a separate thread, and simplify it to not manage the device ourselves. There's a chance the simplification is a bad idea. (#4978) - Dev: Change clang-format from v14 to v16. (#4929) - Dev: Fixed UTF16 encoding of `modes` file for the installer. (#4791) diff --git a/src/widgets/BaseWindow.cpp b/src/widgets/BaseWindow.cpp index 59abe0a4f..6fdfe75c7 100644 --- a/src/widgets/BaseWindow.cpp +++ b/src/widgets/BaseWindow.cpp @@ -10,7 +10,6 @@ #include "widgets/helper/EffectLabel.hpp" #include "widgets/helper/TitlebarButtons.hpp" #include "widgets/Label.hpp" -#include "widgets/TooltipWidget.hpp" #include "widgets/Window.hpp" #include @@ -468,11 +467,6 @@ EffectLabel *BaseWindow::addTitleBarLabel(std::function onClicked) void BaseWindow::changeEvent(QEvent *) { - if (this->isVisible()) - { - TooltipWidget::instance()->hide(); - } - #ifdef USEWINSDK if (this->ui_.titlebarButtons) { @@ -497,7 +491,6 @@ void BaseWindow::changeEvent(QEvent *) void BaseWindow::leaveEvent(QEvent *) { - TooltipWidget::instance()->hide(); } void BaseWindow::moveTo(QPoint point, widgets::BoundsChecking mode) diff --git a/src/widgets/TooltipWidget.cpp b/src/widgets/TooltipWidget.cpp index dba8afc77..aa4894a8f 100644 --- a/src/widgets/TooltipWidget.cpp +++ b/src/widgets/TooltipWidget.cpp @@ -12,12 +12,6 @@ namespace chatterino { -TooltipWidget *TooltipWidget::instance() -{ - static TooltipWidget *tooltipWidget = new TooltipWidget(); - return tooltipWidget; -} - TooltipWidget::TooltipWidget(BaseWidget *parent) : BaseWindow({BaseWindow::TopMost, BaseWindow::DontFocus, BaseWindow::DisableLayoutSave}, diff --git a/src/widgets/TooltipWidget.hpp b/src/widgets/TooltipWidget.hpp index 526ec7a1c..df40e998a 100644 --- a/src/widgets/TooltipWidget.hpp +++ b/src/widgets/TooltipWidget.hpp @@ -29,9 +29,7 @@ class TooltipWidget : public BaseWindow Q_OBJECT public: - static TooltipWidget *instance(); - - TooltipWidget(BaseWidget *parent = nullptr); + TooltipWidget(BaseWidget *parent); ~TooltipWidget() override = default; void setOne(const TooltipEntry &entry, diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 2ac6848be..171f05e65 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -285,6 +285,7 @@ ChannelView::ChannelView(BaseWidget *parent, Split *split, Context context, , highlightAnimation_(this) , context_(context) , messages_(messagesLimit) + , tooltipWidget_(new TooltipWidget(this)) { this->setMouseTracking(true); @@ -1632,7 +1633,7 @@ void ChannelView::enterEvent(QEvent * /*event*/) void ChannelView::leaveEvent(QEvent * /*event*/) { - TooltipWidget::instance()->hide(); + this->tooltipWidget_->hide(); this->unpause(PauseReason::Mouse); @@ -1653,7 +1654,6 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) this->pause(PauseReason::Mouse); } - auto *tooltipWidget = TooltipWidget::instance(); std::shared_ptr layout; QPoint relativePos; int messageIndex; @@ -1662,7 +1662,7 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) if (!tryGetMessageAt(event->pos(), layout, relativePos, messageIndex)) { this->setCursor(Qt::ArrowCursor); - tooltipWidget->hide(); + this->tooltipWidget_->hide(); return; } @@ -1700,14 +1700,14 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) if (layout->flags.has(MessageLayoutFlag::Collapsed)) { this->setCursor(Qt::PointingHandCursor); - tooltipWidget->hide(); + this->tooltipWidget_->hide(); return; } if (hoverLayoutElement == nullptr) { this->setCursor(Qt::ArrowCursor); - tooltipWidget->hide(); + this->tooltipWidget_->hide(); return; } @@ -1721,7 +1721,7 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) if (element->getTooltip().isEmpty() || (isLinkValid && isNotEmote && !getSettings()->linkInfoTooltip)) { - tooltipWidget->hide(); + this->tooltipWidget_->hide(); } else { @@ -1739,7 +1739,7 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) if (emoteElement) { - tooltipWidget->setOne({ + this->tooltipWidget_->setOne({ showThumbnail ? emoteElement->getEmote()->images.getImage(3.0) : nullptr, @@ -1798,12 +1798,12 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) auto style = layeredEmotes.size() > 2 ? TooltipStyle::Grid : TooltipStyle::Vertical; - tooltipWidget->set(entries, style); + this->tooltipWidget_->set(entries, style); } } else if (badgeElement) { - tooltipWidget->setOne({ + this->tooltipWidget_->setOne({ showThumbnail ? badgeElement->getEmote()->images.getImage(3.0) : nullptr, @@ -1834,7 +1834,7 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) if (thumbnailSize == 0) { // "Show thumbnails" is set to "Off", show text only - tooltipWidget->setOne({nullptr, element->getTooltip()}); + this->tooltipWidget_->setOne({nullptr, element->getTooltip()}); } else { @@ -1851,21 +1851,24 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) if (element->getThumbnailType() == MessageElement::ThumbnailType::Link_Thumbnail) { - tooltipWidget->setOne({std::move(thumb), - element->getTooltip(), thumbnailSize, - thumbnailSize}); + this->tooltipWidget_->setOne({ + std::move(thumb), + element->getTooltip(), + thumbnailSize, + thumbnailSize, + }); } else { - tooltipWidget->setOne({std::move(thumb), ""}); + this->tooltipWidget_->setOne({std::move(thumb), ""}); } } } - tooltipWidget->moveTo(event->globalPos() + QPoint(16, 16), - widgets::BoundsChecking::CursorPosition); - tooltipWidget->setWordWrap(isLinkValid); - tooltipWidget->show(); + this->tooltipWidget_->moveTo(event->globalPos() + QPoint(16, 16), + widgets::BoundsChecking::CursorPosition); + this->tooltipWidget_->setWordWrap(isLinkValid); + this->tooltipWidget_->show(); } // check if word has a link diff --git a/src/widgets/helper/ChannelView.hpp b/src/widgets/helper/ChannelView.hpp index 005ba31d7..08da3ae06 100644 --- a/src/widgets/helper/ChannelView.hpp +++ b/src/widgets/helper/ChannelView.hpp @@ -7,6 +7,7 @@ #include "messages/Selection.hpp" #include "util/ThreadGuard.hpp" #include "widgets/BaseWidget.hpp" +#include "widgets/TooltipWidget.hpp" #include #include @@ -333,6 +334,8 @@ private: MessagePreferences messagePreferences_; void scrollUpdateRequested(); + + TooltipWidget *const tooltipWidget_{}; }; } // namespace chatterino diff --git a/src/widgets/splits/Split.cpp b/src/widgets/splits/Split.cpp index 50d231fe7..90ab8bd46 100644 --- a/src/widgets/splits/Split.cpp +++ b/src/widgets/splits/Split.cpp @@ -39,7 +39,6 @@ #include "widgets/splits/SplitHeader.hpp" #include "widgets/splits/SplitInput.hpp" #include "widgets/splits/SplitOverlay.hpp" -#include "widgets/TooltipWidget.hpp" #include "widgets/Window.hpp" #include @@ -993,8 +992,6 @@ void Split::leaveEvent(QEvent *event) this->overlay_->hide(); - TooltipWidget::instance()->hide(); - this->handleModifiers(QGuiApplication::queryKeyboardModifiers()); } diff --git a/src/widgets/splits/SplitHeader.cpp b/src/widgets/splits/SplitHeader.cpp index 19e34e8b3..58d75b44b 100644 --- a/src/widgets/splits/SplitHeader.cpp +++ b/src/widgets/splits/SplitHeader.cpp @@ -223,6 +223,7 @@ namespace chatterino { SplitHeader::SplitHeader(Split *split) : BaseWidget(split) , split_(split) + , tooltipWidget_(new TooltipWidget(this)) { this->initializeLayout(); @@ -948,15 +949,16 @@ void SplitHeader::enterEvent(QEvent *event) { auto *channel = this->split_->getChannel().get(); - auto *tooltip = TooltipWidget::instance(); - tooltip->setOne({nullptr, this->tooltipText_}); - tooltip->setWordWrap(true); - tooltip->adjustSize(); - auto pos = this->mapToGlobal(this->rect().bottomLeft()) + - QPoint((this->width() - tooltip->width()) / 2, 1); + this->tooltipWidget_->setOne({nullptr, this->tooltipText_}); + this->tooltipWidget_->setWordWrap(true); + this->tooltipWidget_->adjustSize(); + auto pos = + this->mapToGlobal(this->rect().bottomLeft()) + + QPoint((this->width() - this->tooltipWidget_->width()) / 2, 1); - tooltip->moveTo(pos, widgets::BoundsChecking::CursorPosition); - tooltip->show(); + this->tooltipWidget_->moveTo(pos, + widgets::BoundsChecking::CursorPosition); + this->tooltipWidget_->show(); } BaseWidget::enterEvent(event); @@ -964,7 +966,7 @@ void SplitHeader::enterEvent(QEvent *event) void SplitHeader::leaveEvent(QEvent *event) { - TooltipWidget::instance()->hide(); + this->tooltipWidget_->hide(); BaseWidget::leaveEvent(event); } diff --git a/src/widgets/splits/SplitHeader.hpp b/src/widgets/splits/SplitHeader.hpp index 321a4e947..872ba8a8b 100644 --- a/src/widgets/splits/SplitHeader.hpp +++ b/src/widgets/splits/SplitHeader.hpp @@ -1,6 +1,7 @@ #pragma once #include "widgets/BaseWidget.hpp" +#include "widgets/TooltipWidget.hpp" #include #include @@ -68,6 +69,7 @@ private: Split *const split_{}; QString tooltipText_{}; + TooltipWidget *const tooltipWidget_{}; bool isLive_{false}; QString thumbnail_; QElapsedTimer lastThumbnail_;