From 88a15ca1069f079d3d584a34a4d03c1d0b22c79a Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Sun, 16 Jan 2022 08:36:36 +0200 Subject: Event processing issue that causes menus to be dismissed immediately This seems like a regression in SDL. SDL_PollEvent() doesn't behave like before. As a workaround, wait for events with a very short timeout. IssueID #436 --- src/app.c | 7 +++++++ src/ui/util.c | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/app.c b/src/app.c index 229fde75..d4e09d6f 100644 --- a/src/app.c +++ b/src/app.c @@ -1260,7 +1260,14 @@ static iBool nextEvent_App_(iApp *d, enum iAppEventMode eventMode, SDL_Event *ev return SDL_WaitEvent(event); } } + /* SDL regression circa 2.0.18? SDL_PollEvent() doesn't always return + events posted immediately beforehand. Waiting with a very short timeout + seems to work better. */ +#if defined (iPlatformLinux) + return SDL_WaitEventTimeout(event, 1); +#else return SDL_PollEvent(event); +#endif } static iPtrArray *listWindows_App_(const iApp *d, iPtrArray *windows) { diff --git a/src/ui/util.c b/src/ui/util.c index bdbbb98e..0adaebb6 100644 --- a/src/ui/util.c +++ b/src/ui/util.c @@ -705,6 +705,9 @@ static iBool menuHandler_(iWidget *menu, const char *cmd) { closeMenu_Widget(menu); return iTrue; } + if (equal_Command(cmd, "cancel") && pointerLabel_Command(cmd, "menu") == menu) { + return iFalse; + } if (equal_Command(cmd, "contextclick") && pointer_Command(cmd) == menu) { return iFalse; } @@ -1074,7 +1077,7 @@ void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, int menuOpenFlags) { const iBool isPortraitPhone = (isPhone && isPortrait_App()); const iBool isSlidePanel = (flags_Widget(d) & horizontalOffset_WidgetFlag) != 0; if (postCommands) { - postCommand_App("cancel"); /* dismiss any other menus */ + postCommandf_App("cancel menu:%p", d); /* dismiss any other menus */ } /* Menu closes when commands are emitted, so handle any pending ones beforehand. */ processEvents_App(postedEventsOnly_AppEventMode); -- cgit v1.2.3