From 2d18fc8052eefbbee04b61d6308b5400118209f1 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 5 Dec 2019 17:59:06 +0100 Subject: [PATCH] LibGUI: Move tooltip window rects if they don't end up on screen This makes the quick launch button tooltips actually readable. :^) --- Libraries/LibGUI/GApplication.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Libraries/LibGUI/GApplication.cpp b/Libraries/LibGUI/GApplication.cpp index d6f070b4b5..ffa89e79f3 100644 --- a/Libraries/LibGUI/GApplication.cpp +++ b/Libraries/LibGUI/GApplication.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -106,7 +107,19 @@ void GApplication::show_tooltip(const StringView& tooltip, const Point& screen_l m_tooltip_window->set_double_buffering_enabled(false); } m_tooltip_window->set_tooltip(tooltip); - m_tooltip_window->move_to(screen_location); + + Rect desktop_rect = GDesktop::the().rect(); + + const int margin = 30; + Point adjusted_pos = screen_location; + if (adjusted_pos.x() + m_tooltip_window->width() >= desktop_rect.width() - margin) { + adjusted_pos = adjusted_pos.translated(-m_tooltip_window->width(), 0); + } + if (adjusted_pos.y() + m_tooltip_window->height() >= desktop_rect.height() - margin) { + adjusted_pos = adjusted_pos.translated(0, -(m_tooltip_window->height() * 2)); + } + + m_tooltip_window->move_to(adjusted_pos); m_tooltip_window->show(); }