diff --git a/CMakeLists.txt b/CMakeLists.txt index 89ef1c7b..93077bb8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -206,6 +206,7 @@ SET(SRC_GTK src/gtk/screenarea-opengl.cpp src/gtk/tools.cpp src/gtk/window.cpp + src/sdl/inputSDL.cpp src/sdl/sndSDL.cpp ) diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 67da40e0..10cd58d9 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -31,6 +31,7 @@ #include "../dmg/gbPrinter.h" #include "../Sound.h" #include "../Util.h" +#include "../sdl/inputSDL.h" #include "tools.h" #include "intl.h" @@ -517,7 +518,7 @@ Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr & _poXml) : poCMI->signal_toggled().connect(sigc::bind( sigc::mem_fun(*this, &Window::vOnSoundMuteToggled), poCMI)); - + struct { const char * m_csName; @@ -808,7 +809,7 @@ void Window::vInitScreenArea(EVideoOutput _eVideoOutput) poC = dynamic_cast(m_poXml->get_widget("ScreenContainer")); poC->remove(); poC->set(Gtk::ALIGN_CENTER, Gtk::ALIGN_CENTER, 1.0, 1.0); - + try { switch (_eVideoOutput) @@ -882,7 +883,7 @@ void Window::vInitSystem() } Init_2xSaI(32); - + soundInit(); } @@ -898,7 +899,7 @@ void Window::vInitSDL() if (bDone) return; - int iFlags = (SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE); + int iFlags = (SDL_INIT_EVERYTHING | SDL_INIT_NOPARACHUTE); if (SDL_Init(iFlags) < 0) { @@ -906,6 +907,13 @@ void Window::vInitSDL() abort(); } + // TODO : remove + int sdlNumDevices = SDL_NumJoysticks(); + for (int i = 0; i < sdlNumDevices; i++) + SDL_JoystickOpen(i); + + inputInitJoysticks(); + bDone = true; } @@ -1788,4 +1796,23 @@ void Window::vToggleFullscreen() } } +void Window::vSDLPollEvents() +{ + SDL_Event event; + while(SDL_PollEvent(&event)) + { + switch(event.type) + { + case SDL_JOYHATMOTION: + case SDL_JOYBUTTONDOWN: + case SDL_JOYBUTTONUP: + case SDL_JOYAXISMOTION: + case SDL_KEYDOWN: + case SDL_KEYUP: + inputProcessSDLEvent(event); + break; + } + } +} + } // VBA namespace diff --git a/src/gtk/window.h b/src/gtk/window.h index a5cb4b57..ca2cfddb 100644 --- a/src/gtk/window.h +++ b/src/gtk/window.h @@ -295,6 +295,7 @@ private: void vSelectBestThrottleItem(); void vUpdateGameSlots(); void vToggleFullscreen(); + void vSDLPollEvents(); }; } // namespace VBA diff --git a/src/gtk/windowcallbacks.cpp b/src/gtk/windowcallbacks.cpp index 7823c16d..3a9d7d31 100644 --- a/src/gtk/windowcallbacks.cpp +++ b/src/gtk/windowcallbacks.cpp @@ -23,12 +23,15 @@ #include #include +#include + #include "../agb/GBA.h" #include "../dmg/gb.h" #include "../dmg/gbGlobals.h" #include "../dmg/gbPrinter.h" #include "../Sound.h" #include "../Util.h" +#include "../sdl/inputSDL.h" #include "tools.h" #include "intl.h" @@ -933,7 +936,7 @@ void Window::vOnGDBWait() poDialog->set_transient_for(*this); int iPort = 55555; - poSpin->set_value(iPort); + poSpin->set_value(iPort); bool bOk = false; if (poDialog->run() == Gtk::RESPONSE_OK) @@ -1027,7 +1030,7 @@ void Window::vOnGDBLoadAndWait() poDialog->set_transient_for(*this); int iPort = 55555; - poSpin->set_value(iPort); + poSpin->set_value(iPort); bool bOk = false; if (poDialog->run() == Gtk::RESPONSE_OK) @@ -1078,7 +1081,7 @@ void Window::vOnGDBDisconnect() void Window::vOnHelpAbout() { Gtk::AboutDialog oAboutDialog; - + oAboutDialog.set_transient_for(*this); oAboutDialog.set_name("VBA-M"); @@ -1099,13 +1102,13 @@ void Window::vOnHelpAbout() list_authors.push_back("jbo_85"); list_authors.push_back("bgK"); oAboutDialog.set_authors(list_authors); - + std::list list_artists; list_artists.push_back("Matteo Drera"); list_artists.push_back("Jakub Steiner"); list_artists.push_back("Jones Lee"); oAboutDialog.set_artists(list_artists); - + oAboutDialog.run(); } @@ -1121,7 +1124,7 @@ bool Window::bOnEmuIdle() { Glib::TimeVal uiTime; uiTime.assign_current_time(); - + if (uiTime - m_uiThrottleLastTime >= m_uiThrottleDelay) { m_uiThrottleDelay = Glib::TimeVal(0, 0); @@ -1133,6 +1136,8 @@ bool Window::bOnEmuIdle() } } + vSDLPollEvents(); + m_stEmulator.emuMain(m_stEmulator.emuCount); return true; } @@ -1172,6 +1177,12 @@ bool Window::on_key_press_event(GdkEventKey * _pstEvent) return true; } + // 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; + inputProcessSDLEvent(event); + if ((_pstEvent->state & Gtk::AccelGroup::get_default_mod_mask()) || (eKey = m_oKeymap[_pstEvent->hardware_keycode]) == KeyNone) { @@ -1228,6 +1239,12 @@ bool Window::on_key_press_event(GdkEventKey * _pstEvent) bool Window::on_key_release_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; + inputProcessSDLEvent(event); + EKey eKey; if ((_pstEvent->state & Gtk::AccelGroup::get_default_mod_mask()) @@ -1286,7 +1303,7 @@ bool Window::on_window_state_event(GdkEventWindowState* _pstEvent) { m_bFullscreen = _pstEvent->new_window_state & GDK_WINDOW_STATE_FULLSCREEN; } - + return true; }