Ticket #3194: alternative.patch

File alternative.patch, 2.6 KB (added by elexis, 7 years ago)

Alternative code calling HotkeyInputHandler from HotkeyInputHandler when creating SDL_HOTKEYDOWN from SDL_KEYDOWN instead.

  • source/gui/CGUI.cpp

    InReaction CGUI::HandleEvent(const SDL_E  
    7373
    7474        std::map<CStr, std::vector<IGUIObject*> >::iterator it = m_HotkeyObjects.find(hotkey);
    7575        if (it != m_HotkeyObjects.end())
    7676            for (IGUIObject* const& obj : it->second)
    7777            {
    78                 // Update hotkey status before sending the event,
    79                 // else the status will be outdated when processing the GUI event.
    80                 HotkeyInputHandler(ev);
    81                 ret = IN_HANDLED;
    82 
    83                 if (ev->ev.type == SDL_HOTKEYDOWN)
    84                     obj->SendEvent(GUIM_PRESSED, "press");
    85                 else
    86                     obj->SendEvent(GUIM_RELEASED, "release");
     78                if ((ev->ev.type == SDL_HOTKEYDOWN && obj->SendEvent(GUIM_PRESSED, "press") == IN_HANDLED) ||
     79                    (ev->ev.type == SDL_HOTKEYUP && obj->SendEvent(GUIM_RELEASED, "release") == IN_HANDLED))
     80                {
     81                    ret = IN_HANDLED;
     82                }
    8783            }
    8884    }
    8985
    9086    else if (ev->ev.type == SDL_MOUSEMOTION)
    9187    {
  • source/ps/Hotkey.cpp

     
    1 /* Copyright (C) 2015 Wildfire Games.
     1/* Copyright (C) 2016 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
    55 * it under the terms of the GNU General Public License as published by
    66 * the Free Software Foundation, either version 2 of the License, or
    InReaction HotkeyInputHandler(const SDL_  
    304304    for (size_t i = 0; i < closestMapNames.size(); ++i)
    305305    {
    306306        SDL_Event_ hotkeyNotification;
    307307        hotkeyNotification.ev.type = SDL_HOTKEYDOWN;
    308308        hotkeyNotification.ev.user.data1 = const_cast<char*>(closestMapNames[i]);
     309
     310        // Update g_HotkeyMap since this event will be processed by the GUI handler before
     311        // updating g_HotkeyMap, while the GUI handler requires that init prior
     312        HotkeyInputHandler(&hotkeyNotification);
     313
    309314        in_push_priority_event(&hotkeyNotification);
    310315    }
    311316
    312317    // -- KEYUP SECTION --
    313318
    InReaction HotkeyInputHandler(const SDL_  
    332337        if (accept)
    333338        {
    334339            SDL_Event_ hotkeyNotification;
    335340            hotkeyNotification.ev.type = SDL_HOTKEYUP;
    336341            hotkeyNotification.ev.user.data1 = const_cast<char*>(hotkey.name.c_str());
     342
     343            // Update g_HotkeyMap since this event will be processed by the GUI handler before
     344            // updating g_HotkeyMap, while the GUI handler requires that init prior
     345            HotkeyInputHandler(&hotkeyNotification);
     346
    337347            in_push_priority_event(&hotkeyNotification);
    338348        }
    339349    }
    340350
    341351    return IN_PASS;