Fix missing parent of tooltips for Wayland (#4998)

Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
smc 2023-12-09 12:28:33 +01:00 committed by GitHub
parent 3ad2e4b30a
commit fec8f8c49f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 39 additions and 46 deletions

View file

@ -48,6 +48,7 @@
- Bugfix: Fixed rare crash with Image Uploader when closing a split right after starting an upload. (#4971) - 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 support for Windows 11 Snap layouts. (#4994)
- Bugfix: Fixed some windows appearing between screens. (#4797) - 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: 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: Change clang-format from v14 to v16. (#4929)
- Dev: Fixed UTF16 encoding of `modes` file for the installer. (#4791) - Dev: Fixed UTF16 encoding of `modes` file for the installer. (#4791)

View file

@ -10,7 +10,6 @@
#include "widgets/helper/EffectLabel.hpp" #include "widgets/helper/EffectLabel.hpp"
#include "widgets/helper/TitlebarButtons.hpp" #include "widgets/helper/TitlebarButtons.hpp"
#include "widgets/Label.hpp" #include "widgets/Label.hpp"
#include "widgets/TooltipWidget.hpp"
#include "widgets/Window.hpp" #include "widgets/Window.hpp"
#include <QApplication> #include <QApplication>
@ -468,11 +467,6 @@ EffectLabel *BaseWindow::addTitleBarLabel(std::function<void()> onClicked)
void BaseWindow::changeEvent(QEvent *) void BaseWindow::changeEvent(QEvent *)
{ {
if (this->isVisible())
{
TooltipWidget::instance()->hide();
}
#ifdef USEWINSDK #ifdef USEWINSDK
if (this->ui_.titlebarButtons) if (this->ui_.titlebarButtons)
{ {
@ -497,7 +491,6 @@ void BaseWindow::changeEvent(QEvent *)
void BaseWindow::leaveEvent(QEvent *) void BaseWindow::leaveEvent(QEvent *)
{ {
TooltipWidget::instance()->hide();
} }
void BaseWindow::moveTo(QPoint point, widgets::BoundsChecking mode) void BaseWindow::moveTo(QPoint point, widgets::BoundsChecking mode)

View file

@ -12,12 +12,6 @@
namespace chatterino { namespace chatterino {
TooltipWidget *TooltipWidget::instance()
{
static TooltipWidget *tooltipWidget = new TooltipWidget();
return tooltipWidget;
}
TooltipWidget::TooltipWidget(BaseWidget *parent) TooltipWidget::TooltipWidget(BaseWidget *parent)
: BaseWindow({BaseWindow::TopMost, BaseWindow::DontFocus, : BaseWindow({BaseWindow::TopMost, BaseWindow::DontFocus,
BaseWindow::DisableLayoutSave}, BaseWindow::DisableLayoutSave},

View file

@ -29,9 +29,7 @@ class TooltipWidget : public BaseWindow
Q_OBJECT Q_OBJECT
public: public:
static TooltipWidget *instance(); TooltipWidget(BaseWidget *parent);
TooltipWidget(BaseWidget *parent = nullptr);
~TooltipWidget() override = default; ~TooltipWidget() override = default;
void setOne(const TooltipEntry &entry, void setOne(const TooltipEntry &entry,

View file

@ -285,6 +285,7 @@ ChannelView::ChannelView(BaseWidget *parent, Split *split, Context context,
, highlightAnimation_(this) , highlightAnimation_(this)
, context_(context) , context_(context)
, messages_(messagesLimit) , messages_(messagesLimit)
, tooltipWidget_(new TooltipWidget(this))
{ {
this->setMouseTracking(true); this->setMouseTracking(true);
@ -1632,7 +1633,7 @@ void ChannelView::enterEvent(QEvent * /*event*/)
void ChannelView::leaveEvent(QEvent * /*event*/) void ChannelView::leaveEvent(QEvent * /*event*/)
{ {
TooltipWidget::instance()->hide(); this->tooltipWidget_->hide();
this->unpause(PauseReason::Mouse); this->unpause(PauseReason::Mouse);
@ -1653,7 +1654,6 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
this->pause(PauseReason::Mouse); this->pause(PauseReason::Mouse);
} }
auto *tooltipWidget = TooltipWidget::instance();
std::shared_ptr<MessageLayout> layout; std::shared_ptr<MessageLayout> layout;
QPoint relativePos; QPoint relativePos;
int messageIndex; int messageIndex;
@ -1662,7 +1662,7 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
if (!tryGetMessageAt(event->pos(), layout, relativePos, messageIndex)) if (!tryGetMessageAt(event->pos(), layout, relativePos, messageIndex))
{ {
this->setCursor(Qt::ArrowCursor); this->setCursor(Qt::ArrowCursor);
tooltipWidget->hide(); this->tooltipWidget_->hide();
return; return;
} }
@ -1700,14 +1700,14 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
if (layout->flags.has(MessageLayoutFlag::Collapsed)) if (layout->flags.has(MessageLayoutFlag::Collapsed))
{ {
this->setCursor(Qt::PointingHandCursor); this->setCursor(Qt::PointingHandCursor);
tooltipWidget->hide(); this->tooltipWidget_->hide();
return; return;
} }
if (hoverLayoutElement == nullptr) if (hoverLayoutElement == nullptr)
{ {
this->setCursor(Qt::ArrowCursor); this->setCursor(Qt::ArrowCursor);
tooltipWidget->hide(); this->tooltipWidget_->hide();
return; return;
} }
@ -1721,7 +1721,7 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
if (element->getTooltip().isEmpty() || if (element->getTooltip().isEmpty() ||
(isLinkValid && isNotEmote && !getSettings()->linkInfoTooltip)) (isLinkValid && isNotEmote && !getSettings()->linkInfoTooltip))
{ {
tooltipWidget->hide(); this->tooltipWidget_->hide();
} }
else else
{ {
@ -1739,7 +1739,7 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
if (emoteElement) if (emoteElement)
{ {
tooltipWidget->setOne({ this->tooltipWidget_->setOne({
showThumbnail showThumbnail
? emoteElement->getEmote()->images.getImage(3.0) ? emoteElement->getEmote()->images.getImage(3.0)
: nullptr, : nullptr,
@ -1798,12 +1798,12 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
auto style = layeredEmotes.size() > 2 auto style = layeredEmotes.size() > 2
? TooltipStyle::Grid ? TooltipStyle::Grid
: TooltipStyle::Vertical; : TooltipStyle::Vertical;
tooltipWidget->set(entries, style); this->tooltipWidget_->set(entries, style);
} }
} }
else if (badgeElement) else if (badgeElement)
{ {
tooltipWidget->setOne({ this->tooltipWidget_->setOne({
showThumbnail showThumbnail
? badgeElement->getEmote()->images.getImage(3.0) ? badgeElement->getEmote()->images.getImage(3.0)
: nullptr, : nullptr,
@ -1834,7 +1834,7 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
if (thumbnailSize == 0) if (thumbnailSize == 0)
{ {
// "Show thumbnails" is set to "Off", show text only // "Show thumbnails" is set to "Off", show text only
tooltipWidget->setOne({nullptr, element->getTooltip()}); this->tooltipWidget_->setOne({nullptr, element->getTooltip()});
} }
else else
{ {
@ -1851,21 +1851,24 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
if (element->getThumbnailType() == if (element->getThumbnailType() ==
MessageElement::ThumbnailType::Link_Thumbnail) MessageElement::ThumbnailType::Link_Thumbnail)
{ {
tooltipWidget->setOne({std::move(thumb), this->tooltipWidget_->setOne({
element->getTooltip(), thumbnailSize, std::move(thumb),
thumbnailSize}); element->getTooltip(),
thumbnailSize,
thumbnailSize,
});
} }
else else
{ {
tooltipWidget->setOne({std::move(thumb), ""}); this->tooltipWidget_->setOne({std::move(thumb), ""});
} }
} }
} }
tooltipWidget->moveTo(event->globalPos() + QPoint(16, 16), this->tooltipWidget_->moveTo(event->globalPos() + QPoint(16, 16),
widgets::BoundsChecking::CursorPosition); widgets::BoundsChecking::CursorPosition);
tooltipWidget->setWordWrap(isLinkValid); this->tooltipWidget_->setWordWrap(isLinkValid);
tooltipWidget->show(); this->tooltipWidget_->show();
} }
// check if word has a link // check if word has a link

View file

@ -7,6 +7,7 @@
#include "messages/Selection.hpp" #include "messages/Selection.hpp"
#include "util/ThreadGuard.hpp" #include "util/ThreadGuard.hpp"
#include "widgets/BaseWidget.hpp" #include "widgets/BaseWidget.hpp"
#include "widgets/TooltipWidget.hpp"
#include <pajlada/signals/signal.hpp> #include <pajlada/signals/signal.hpp>
#include <QMenu> #include <QMenu>
@ -333,6 +334,8 @@ private:
MessagePreferences messagePreferences_; MessagePreferences messagePreferences_;
void scrollUpdateRequested(); void scrollUpdateRequested();
TooltipWidget *const tooltipWidget_{};
}; };
} // namespace chatterino } // namespace chatterino

View file

@ -39,7 +39,6 @@
#include "widgets/splits/SplitHeader.hpp" #include "widgets/splits/SplitHeader.hpp"
#include "widgets/splits/SplitInput.hpp" #include "widgets/splits/SplitInput.hpp"
#include "widgets/splits/SplitOverlay.hpp" #include "widgets/splits/SplitOverlay.hpp"
#include "widgets/TooltipWidget.hpp"
#include "widgets/Window.hpp" #include "widgets/Window.hpp"
#include <QApplication> #include <QApplication>
@ -993,8 +992,6 @@ void Split::leaveEvent(QEvent *event)
this->overlay_->hide(); this->overlay_->hide();
TooltipWidget::instance()->hide();
this->handleModifiers(QGuiApplication::queryKeyboardModifiers()); this->handleModifiers(QGuiApplication::queryKeyboardModifiers());
} }

View file

@ -223,6 +223,7 @@ namespace chatterino {
SplitHeader::SplitHeader(Split *split) SplitHeader::SplitHeader(Split *split)
: BaseWidget(split) : BaseWidget(split)
, split_(split) , split_(split)
, tooltipWidget_(new TooltipWidget(this))
{ {
this->initializeLayout(); this->initializeLayout();
@ -948,15 +949,16 @@ void SplitHeader::enterEvent(QEvent *event)
{ {
auto *channel = this->split_->getChannel().get(); auto *channel = this->split_->getChannel().get();
auto *tooltip = TooltipWidget::instance(); this->tooltipWidget_->setOne({nullptr, this->tooltipText_});
tooltip->setOne({nullptr, this->tooltipText_}); this->tooltipWidget_->setWordWrap(true);
tooltip->setWordWrap(true); this->tooltipWidget_->adjustSize();
tooltip->adjustSize(); auto pos =
auto pos = this->mapToGlobal(this->rect().bottomLeft()) + this->mapToGlobal(this->rect().bottomLeft()) +
QPoint((this->width() - tooltip->width()) / 2, 1); QPoint((this->width() - this->tooltipWidget_->width()) / 2, 1);
tooltip->moveTo(pos, widgets::BoundsChecking::CursorPosition); this->tooltipWidget_->moveTo(pos,
tooltip->show(); widgets::BoundsChecking::CursorPosition);
this->tooltipWidget_->show();
} }
BaseWidget::enterEvent(event); BaseWidget::enterEvent(event);
@ -964,7 +966,7 @@ void SplitHeader::enterEvent(QEvent *event)
void SplitHeader::leaveEvent(QEvent *event) void SplitHeader::leaveEvent(QEvent *event)
{ {
TooltipWidget::instance()->hide(); this->tooltipWidget_->hide();
BaseWidget::leaveEvent(event); BaseWidget::leaveEvent(event);
} }

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "widgets/BaseWidget.hpp" #include "widgets/BaseWidget.hpp"
#include "widgets/TooltipWidget.hpp"
#include <boost/signals2.hpp> #include <boost/signals2.hpp>
#include <pajlada/settings/setting.hpp> #include <pajlada/settings/setting.hpp>
@ -68,6 +69,7 @@ private:
Split *const split_{}; Split *const split_{};
QString tooltipText_{}; QString tooltipText_{};
TooltipWidget *const tooltipWidget_{};
bool isLive_{false}; bool isLive_{false};
QString thumbnail_; QString thumbnail_;
QElapsedTimer lastThumbnail_; QElapsedTimer lastThumbnail_;