From 5aa37f6f5c9026346e8dbc7db26cf73516a7a876 Mon Sep 17 00:00:00 2001 From: Oliver Kraitschy Date: Thu, 30 Jan 2020 23:06:01 +0100 Subject: [PATCH] WindowServer: make menus wrap vertically This commit adds vertical wrap to menus. The first item is focused if Key_Down is pressed on the last item and the last item is focused if Key_up is pressed on the first item. --- Servers/WindowServer/WSMenu.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Servers/WindowServer/WSMenu.cpp b/Servers/WindowServer/WSMenu.cpp index fa622f8c893..f59d30bceeb 100644 --- a/Servers/WindowServer/WSMenu.cpp +++ b/Servers/WindowServer/WSMenu.cpp @@ -393,9 +393,12 @@ void WSMenu::event(CEvent& event) return; do { - if (m_hovered_item_index <= 0) + if (m_hovered_item_index == 0) + m_hovered_item_index = m_items.size() - 1; + else if (m_hovered_item_index < 0) return; - --m_hovered_item_index; + else + --m_hovered_item_index; } while (hovered_item()->type() == WSMenuItem::Separator); if (is_scrollable() && m_hovered_item_index < m_scroll_offset) @@ -412,9 +415,12 @@ void WSMenu::event(CEvent& event) return; do { - if (m_hovered_item_index >= m_items.size() - 1) + if (m_hovered_item_index == m_items.size() - 1) + m_hovered_item_index = 0; + else if (m_hovered_item_index > m_items.size() - 1) return; - ++m_hovered_item_index; + else + ++m_hovered_item_index; } while (hovered_item()->type() == WSMenuItem::Separator); if (is_scrollable() && m_hovered_item_index >= (m_scroll_offset + visible_item_count()))