Don't involve screen geometry for tooltip on Wayland

This commit is contained in:
Ilya Fedin 2022-03-16 12:49:01 +04:00 committed by John Preston
parent 87c95b8fa7
commit af680714ff

View file

@ -10,6 +10,7 @@
#include "ui/platform/ui_platform_utility.h" #include "ui/platform/ui_platform_utility.h"
#include "base/invoke_queued.h" #include "base/invoke_queued.h"
#include "styles/style_widgets.h" #include "styles/style_widgets.h"
#include "base/platform/base_platform_info.h"
#include <QtGui/QScreen> #include <QtGui/QScreen>
#include <QtWidgets/QApplication> #include <QtWidgets/QApplication>
@ -72,8 +73,9 @@ Tooltip::~Tooltip() {
} }
void Tooltip::popup(const QPoint &m, const QString &text, const style::Tooltip *st) { void Tooltip::popup(const QPoint &m, const QString &text, const style::Tooltip *st) {
const auto screen = QGuiApplication::screenAt(m); const auto usingScreenGeometry = !::Platform::IsWayland();
if (!screen) { const auto screen = usingScreenGeometry ? QGuiApplication::screenAt(m) : nullptr;
if (usingScreenGeometry && !screen) {
Hide(); Hide();
return; return;
} }
@ -114,18 +116,20 @@ void Tooltip::popup(const QPoint &m, const QString &text, const style::Tooltip *
} }
// adjust tooltip position // adjust tooltip position
const auto r = screen->availableGeometry(); if (screen) {
if (r.x() + r.width() - _st->skip < p.x() + s.width() && p.x() + s.width() > m.x()) { const auto r = screen->availableGeometry();
p.setX(qMax(r.x() + r.width() - int32(_st->skip) - s.width(), m.x() - s.width())); if (r.x() + r.width() - _st->skip < p.x() + s.width() && p.x() + s.width() > m.x()) {
} p.setX(qMax(r.x() + r.width() - int32(_st->skip) - s.width(), m.x() - s.width()));
if (r.x() + _st->skip > p.x() && p.x() < m.x()) { }
p.setX(qMin(m.x(), r.x() + int32(_st->skip))); if (r.x() + _st->skip > p.x() && p.x() < m.x()) {
} p.setX(qMin(m.x(), r.x() + int32(_st->skip)));
if (r.y() + r.height() - _st->skip < p.y() + s.height()) { }
p.setY(m.y() - s.height() - _st->skip); if (r.y() + r.height() - _st->skip < p.y() + s.height()) {
} p.setY(m.y() - s.height() - _st->skip);
if (r.y() > p.x()) { }
p.setY(qMin(m.y() + _st->shift.y(), r.y() + r.height() - s.height())); if (r.y() > p.x()) {
p.setY(qMin(m.y() + _st->shift.y(), r.y() + r.height() - s.height()));
}
} }
setGeometry(QRect(p, s)); setGeometry(QRect(p, s));