From e2bc0cbd8407e06ad92c0ba1e8bc92fa58b3a5e2 Mon Sep 17 00:00:00 2001 From: miruka Date: Fri, 10 Jul 2020 03:36:16 -0400 Subject: [PATCH] Improve context menu cursor workaround - Close menu instead of clicking item, to match behavior of other programs - Now work on all edges of the menu, not just top --- src/gui/Base/HMenu.qml | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/gui/Base/HMenu.qml b/src/gui/Base/HMenu.qml index 8ea6fc54..ec77691d 100644 --- a/src/gui/Base/HMenu.qml +++ b/src/gui/Base/HMenu.qml @@ -27,17 +27,19 @@ Menu { border.color: theme.controls.menu.border border.width: theme.controls.menu.borderWidth - Item { - // Workaround for this: when opening the menu at cursor position, - // cursor will be in the menu's border instead of first menu item, - // forcing the user to move the mouse for the click to do anything. - width: parent.width - height: parent.border.width + // Workaround for this: when opening menu at mouse position, + // cursor will be in menu's border which doesn't handle clicks + TapHandler { + gesturePolicy: TapHandler.ReleaseWithinBounds + onTapped: eventPoint => { + const pos = eventPoint.position + const border = parent.border.width - TapHandler { - gesturePolicy: TapHandler.ReleaseWithinBounds - onTapped: if (menu.itemAt(0) && menu.itemAt(0).clicked) - menu.itemAt(0).clicked() + if (pos.x <= border || pos.x >= parent.width - border) + menu.close() + + if (pos.y <= border || pos.y >= parent.height - border) + menu.close() } } }