From b79ada6aa584f16b3f9f2c3d542570505100bae4 Mon Sep 17 00:00:00 2001 From: Semphris Date: Thu, 16 Jan 2025 21:51:38 -0500 Subject: [PATCH] Windows trays: Fix ParentEntry & Enabling The test/testtray program would crash on Windows when adding any item and then removing it, because a submenu's parent_entry field was not set. Additionally, I noticed that some extraneous code copied from the {G,S}etTrayEntryChecked made {G,S}etTrayEntryEnabled work only for checkboxes, which is not the desired behavior. Both issues were fixed in this commit. --- src/tray/windows/SDL_tray.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/tray/windows/SDL_tray.c b/src/tray/windows/SDL_tray.c index f5eb6da261..88a35a7ec4 100644 --- a/src/tray/windows/SDL_tray.c +++ b/src/tray/windows/SDL_tray.c @@ -420,6 +420,7 @@ SDL_TrayEntry *SDL_InsertTrayEntryAt(SDL_TrayMenu *menu, int pos, const char *la entry->submenu->hMenu = CreatePopupMenu(); entry->submenu->nEntries = 0; entry->submenu->entries = NULL; + entry->submenu->parent_entry = entry; entry->id = (UINT_PTR) entry->submenu->hMenu; } else { @@ -528,21 +529,11 @@ bool SDL_GetTrayEntryChecked(SDL_TrayEntry *entry) void SDL_SetTrayEntryEnabled(SDL_TrayEntry *entry, bool enabled) { - if (!(entry->flags & SDL_TRAYENTRY_CHECKBOX)) { - SDL_SetError("Cannot update check for entry not created with SDL_TRAYENTRY_CHECKBOX"); - return; - } - EnableMenuItem(entry->parent->hMenu, (UINT) entry->id, MF_BYCOMMAND | (enabled ? MF_ENABLED : (MF_DISABLED | MF_GRAYED))); } bool SDL_GetTrayEntryEnabled(SDL_TrayEntry *entry) { - if (!(entry->flags & SDL_TRAYENTRY_CHECKBOX)) { - SDL_SetError("Cannot fetch check for entry not created with SDL_TRAYENTRY_CHECKBOX"); - return false; - } - MENUITEMINFOW mii; mii.cbSize = sizeof(MENUITEMINFOW); mii.fMask = MIIM_STATE;