Handle key{bindings,shortcuts} correctly on frame.

Some keybindings were not handled by the frame. That includes some
wxAcceleratorEntry keys. On Linux, if you set a key shortcut using a key
with no modifier ("U" for "Input > Configure"), pressing the key would
not lead to anything.

This is very likely related to wxGTK, although it is not possible to
confirm this at the moment.
This commit is contained in:
Edênis Freindorfer Azevedo 2019-06-11 16:39:26 -03:00 committed by Rafael Kitover
parent cec1dbfd36
commit 69b581f7e5
2 changed files with 34 additions and 22 deletions

View File

@ -816,6 +816,26 @@ void MainFrame::OnSize(wxSizeEvent& event)
update_opts();
}
int MainFrame::FilterEvent(wxEvent& event)
{
if (!IsPaused() && event.GetEventType() == wxEVT_KEY_DOWN)
{
wxKeyEvent& ke = (wxKeyEvent&)event;
int keyCode = ke.GetKeyCode();
int keyMod = ke.GetModifiers();
wxAcceleratorEntry_v accels = wxGetApp().GetAccels();
for (size_t i = 0; i < accels.size(); ++i)
if (keyCode == accels[i].GetKeyCode() && keyMod == accels[i].GetFlags())
{
wxCommandEvent evh(wxEVT_COMMAND_MENU_SELECTED, accels[i].GetCommand());
evh.SetEventObject(this);
GetEventHandler()->ProcessEvent(evh);
return true;
}
}
return -1;
}
wxString MainFrame::GetGamePath(wxString path)
{
wxString game_path = path;
@ -1217,24 +1237,9 @@ void MainFrame::IdentifyRom()
// a few keys (e.g. only ctrl-x works for exit, but not esc & ctrl-q;
// ctrl-w does not work for close). It's possible another entity is
// grabbing those keys, but I can't track it down.
// FIXME: move this to MainFrame
//int wxvbamApp::FilterEvent(wxEvent& event)
//{
// //if(frame && frame->IsPaused(true))
// return -1;
//
// if (event.GetEventType() == wxEVT_KEY_DOWN) {
// wxKeyEvent& ke = (wxKeyEvent&)event;
//
// for (int i = 0; i < accels.size(); i++) {
// if (accels[i].GetKeyCode() == ke.GetKeyCode() && accels[i].GetFlags() == ke.GetModifiers()) {
// wxCommandEvent ev(wxEVT_COMMAND_MENU_SELECTED, accels[i].GetCommand());
// ev.SetEventObject(this);
// frame->GetEventHandler()->ProcessEvent(ev);
// return 1;
// }
// }
// }
//
// return -1;
//}
int wxvbamApp::FilterEvent(wxEvent& event)
{
if (frame)
return frame->FilterEvent(event);
return wxApp::FilterEvent(event);
}

View File

@ -108,9 +108,14 @@ public:
};
#endif
// without this, global accels don't always work
//int FilterEvent(wxEvent& event);
int FilterEvent(wxEvent&);
wxAcceleratorEntry_v accels;
wxAcceleratorEntry_v GetAccels()
{
return accels;
}
// the main configuration
wxFileConfig* cfg;
// vba-over.ini
@ -230,6 +235,8 @@ public:
void SetJoystick();
int FilterEvent(wxEvent& event);
GameArea* GetPanel()
{
return panel;