diff --git a/src/gtk/joypadconfig.cpp b/src/gtk/joypadconfig.cpp index e6d36bff..d7183133 100644 --- a/src/gtk/joypadconfig.cpp +++ b/src/gtk/joypadconfig.cpp @@ -21,27 +21,42 @@ #include #include "intl.h" -#include "../sdl/inputSDL.h" namespace VBA { +const EKey JoypadConfigDialog::m_aeKeys[] = + { + KEY_UP, + KEY_DOWN, + KEY_LEFT, + KEY_RIGHT, + KEY_BUTTON_A, + KEY_BUTTON_B, + KEY_BUTTON_L, + KEY_BUTTON_R, + KEY_BUTTON_SELECT, + KEY_BUTTON_START, + KEY_BUTTON_SPEED, + KEY_BUTTON_CAPTURE + }; + JoypadConfigDialog::JoypadConfigDialog(GtkDialog * _pstDialog, const Glib::RefPtr & _poXml) : Gtk::Dialog(_pstDialog) { m_poOkButton = dynamic_cast(_poXml->get_widget("JoypadOkButton")); - m_oEntries.push_back(dynamic_cast(_poXml->get_widget("JoypadLeftEntry"))); - m_oEntries.push_back(dynamic_cast(_poXml->get_widget("JoypadRightEntry"))); m_oEntries.push_back(dynamic_cast(_poXml->get_widget("JoypadUpEntry"))); m_oEntries.push_back(dynamic_cast(_poXml->get_widget("JoypadDownEntry"))); + m_oEntries.push_back(dynamic_cast(_poXml->get_widget("JoypadLeftEntry"))); + m_oEntries.push_back(dynamic_cast(_poXml->get_widget("JoypadRightEntry"))); m_oEntries.push_back(dynamic_cast(_poXml->get_widget("JoypadAEntry"))); m_oEntries.push_back(dynamic_cast(_poXml->get_widget("JoypadBEntry"))); - m_oEntries.push_back(dynamic_cast(_poXml->get_widget("JoypadSelectEntry"))); - m_oEntries.push_back(dynamic_cast(_poXml->get_widget("JoypadStartEntry"))); m_oEntries.push_back(dynamic_cast(_poXml->get_widget("JoypadLEntry"))); m_oEntries.push_back(dynamic_cast(_poXml->get_widget("JoypadREntry"))); + m_oEntries.push_back(dynamic_cast(_poXml->get_widget("JoypadSelectEntry"))); + m_oEntries.push_back(dynamic_cast(_poXml->get_widget("JoypadStartEntry"))); m_oEntries.push_back(dynamic_cast(_poXml->get_widget("JoypadSpeedEntry"))); m_oEntries.push_back(dynamic_cast(_poXml->get_widget("JoypadCaptureEntry"))); @@ -68,7 +83,7 @@ void JoypadConfigDialog::vUpdateEntries() { const char * csName = 0; - guint uiKeyval = inputGetKeymap(PAD_MAIN, (EKey)i); + guint uiKeyval = inputGetKeymap(PAD_MAIN, m_aeKeys[i]); int dev = uiKeyval >> 16; if (dev == 0) { @@ -130,6 +145,11 @@ bool JoypadConfigDialog::bOnEntryFocusOut(GdkEventFocus * _pstEvent) bool JoypadConfigDialog::on_key_press_event(GdkEventKey * _pstEvent) { + // Forward the keyboard event to the input module by faking a SDL event + SDL_Event event; + event.type = SDL_KEYDOWN; + event.key.keysym.sym = (SDLKey)_pstEvent->keyval; + vOnInputEvent(event); /* if (m_puiCurrentKeyCode == NULL) { return Gtk::Dialog::on_key_press_event(_pstEvent); @@ -177,4 +197,20 @@ bool JoypadConfigDialog::on_key_press_event(GdkEventKey * _pstEvent) return true; } +void JoypadConfigDialog::vOnInputEvent(const SDL_Event &event) +{ + int code = inputGetEventCode(event); + inputSetKeymap(PAD_MAIN, m_aeKeys[m_uiCurrentEntry], code); + vUpdateEntries(); + + if (m_uiCurrentEntry + 1 < m_oEntries.size()) + { + m_oEntries[m_uiCurrentEntry + 1]->grab_focus(); + } + else + { + m_poOkButton->grab_focus(); + } +} + } // namespace VBA diff --git a/src/gtk/joypadconfig.h b/src/gtk/joypadconfig.h index 075288eb..84f6bb44 100644 --- a/src/gtk/joypadconfig.h +++ b/src/gtk/joypadconfig.h @@ -25,6 +25,8 @@ #include #include +#include "../sdl/inputSDL.h" + namespace VBA { @@ -39,12 +41,14 @@ protected: bool bOnEntryFocusIn(GdkEventFocus * _pstEvent, guint _uiEntry); bool bOnEntryFocusOut(GdkEventFocus * _pstEvent); + void vOnInputEvent(const SDL_Event &event); bool on_key_press_event(GdkEventKey * _pstEvent); private: Gtk::Button * m_poOkButton; std::vector m_oEntries; guint m_uiCurrentEntry; + static const EKey m_aeKeys[]; void vUpdateEntries(); }; diff --git a/src/gtk/vba.glade b/src/gtk/vba.glade index 990da66f..e265f427 100644 --- a/src/gtk/vba.glade +++ b/src/gtk/vba.glade @@ -2086,22 +2086,12 @@ True GTK_BUTTONBOX_END - - - True - True - True - gtk-cancel - True - -6 - - True True True - gtk-ok + gtk-close True -5