summaryrefslogtreecommitdiff
path: root/src/ui/util.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-01-17 18:43:20 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-01-17 18:43:20 +0200
commit7e393a4fda482d01252bd1a6e84ca8149bcc278e (patch)
tree3f4d5be987f7c2fd5fd3fcd8a2d97d7fb3cae8db /src/ui/util.c
parentdb264802503606fd2d8a02fd761ad0914c28818a (diff)
Improved menu button behavior
Clicking a menu button while the menu is open should just close the menu. Menus should not close if the mouse pointer leaves the window.
Diffstat (limited to 'src/ui/util.c')
-rw-r--r--src/ui/util.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/ui/util.c b/src/ui/util.c
index 222d5716..7fc27130 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -380,9 +380,21 @@ static iBool isCommandIgnoredByMenus_(const char *cmd) {
380 equal_Command(cmd, "bookmarks.request.finished") || 380 equal_Command(cmd, "bookmarks.request.finished") ||
381 equal_Command(cmd, "window.resized") || 381 equal_Command(cmd, "window.resized") ||
382 equal_Command(cmd, "window.reload.update") || 382 equal_Command(cmd, "window.reload.update") ||
383 equal_Command(cmd, "window.mouse.exited") ||
384 equal_Command(cmd, "window.mouse.entered") ||
383 (equal_Command(cmd, "mouse.clicked") && !arg_Command(cmd)); /* button released */ 385 (equal_Command(cmd, "mouse.clicked") && !arg_Command(cmd)); /* button released */
384} 386}
385 387
388static iLabelWidget *parentMenuButton_(const iWidget *menu) {
389 if (isInstance_Object(menu->parent, &Class_LabelWidget)) {
390 iLabelWidget *button = (iLabelWidget *) menu->parent;
391 if (!cmp_String(command_LabelWidget(button), "menu.open")) {
392 return button;
393 }
394 }
395 return NULL;
396}
397
386static iBool menuHandler_(iWidget *menu, const char *cmd) { 398static iBool menuHandler_(iWidget *menu, const char *cmd) {
387 if (isVisible_Widget(menu)) { 399 if (isVisible_Widget(menu)) {
388 if (equalWidget_Command(cmd, menu, "menu.opened")) { 400 if (equalWidget_Command(cmd, menu, "menu.opened")) {
@@ -394,6 +406,9 @@ static iBool menuHandler_(iWidget *menu, const char *cmd) {
394 } 406 }
395 if ((equal_Command(cmd, "mouse.clicked") || equal_Command(cmd, "mouse.missed")) && 407 if ((equal_Command(cmd, "mouse.clicked") || equal_Command(cmd, "mouse.missed")) &&
396 arg_Command(cmd)) { 408 arg_Command(cmd)) {
409 if (hitChild_Widget(get_Window()->root, coord_Command(cmd)) == parentMenuButton_(menu)) {
410 return iFalse;
411 }
397 /* Dismiss open menus when clicking outside them. */ 412 /* Dismiss open menus when clicking outside them. */
398 closeMenu_Widget(menu); 413 closeMenu_Widget(menu);
399 return iTrue; 414 return iTrue;