From 0a5b029a391f972e9c0fb1c5078f5b362a3d7401 Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Tue, 13 Aug 2019 08:37:25 +0200 Subject: [PATCH] Reduce duplicate code calculating popup position Summary: The popup/exec if was duplicated three times, only to calculate the y position. Reviewers: #kwin, romangg, zzag Reviewed By: #kwin, romangg, zzag Subscribers: zzag, romangg, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D23102 --- useractions.cpp | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/useractions.cpp b/useractions.cpp index eb52d7c19e..1cca3893a0 100644 --- a/useractions.cpp +++ b/useractions.cpp @@ -148,36 +148,23 @@ void UserActionsMenu::show(const QRect &pos, AbstractClient *client) } m_client = cl; init(); - Workspace *ws = Workspace::self(); int x = pos.left(); int y = pos.bottom(); - const bool needsPopup = kwinApp()->shouldUseWaylandForCompositing(); m_client->blockActivityUpdates(true); - - if (y == pos.top()) { - if (needsPopup) { - m_menu->popup(QPoint(x, y)); - } else { - m_menu->exec(QPoint(x, y)); - } - } else { - QRect area = ws->clientArea(ScreenArea, QPoint(x, y), VirtualDesktopManager::self()->current()); + if (y != pos.top()) { + const QRect area = Workspace::self()->clientArea(ScreenArea, QPoint(x, y), + VirtualDesktopManager::self()->current()); menuAboutToShow(); // needed for sizeHint() to be correct :-/ int popupHeight = m_menu->sizeHint().height(); - if (y + popupHeight < area.height()) { - if (needsPopup) { - m_menu->popup(QPoint(x, y)); - } else { - m_menu->exec(QPoint(x, y)); - } - } else { - if (needsPopup) { - m_menu->popup(QPoint(x, pos.top() - popupHeight)); - } else { - m_menu->exec(QPoint(x, pos.top() - popupHeight)); - } + if (y + popupHeight >= area.height()) { + y = pos.top() - popupHeight; } } + if (kwinApp()->shouldUseWaylandForCompositing()) { + m_menu->popup(QPoint(x, y)); + } else { + m_menu->exec(QPoint(x, y)); + } if (m_client) { m_client->blockActivityUpdates(false); }