From c76d4bf20d95d8465a08585dd9e3af18cb6978d0 Mon Sep 17 00:00:00 2001 From: plombo Date: Tue, 22 Mar 2011 23:36:16 +0000 Subject: [PATCH] gtk: fix some minor issues Only allow the emulator to handle key events when the main window has the input focus Don't write anything to stdout when configuring a button using the GTK+ control config dialog. --- src/drivers/sdl/gui.cpp | 20 ++++++++++++-------- src/drivers/sdl/input.cpp | 12 ++++++++---- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/drivers/sdl/gui.cpp b/src/drivers/sdl/gui.cpp index 729684c9..35ea2972 100644 --- a/src/drivers/sdl/gui.cpp +++ b/src/drivers/sdl/gui.cpp @@ -58,7 +58,7 @@ int configGamepadButton(GtkButton* button, gpointer p) snprintf(buf, sizeof(buf), "SDL.Input.GamePad.%d", padNo); prefix = buf; - DWaitButton((const uint8*)"Press a button", &GamePadConfig[padNo][x], configNo); + DWaitButton(NULL, &GamePadConfig[padNo][x], configNo); g_config->setOption(prefix + GamePadNames[x], GamePadConfig[padNo][x].ButtonNum[configNo]); @@ -1091,7 +1091,6 @@ const char* Authors[]= { void openAbout () { - GtkWidget* aboutDialog; GdkPixbuf* logo = gdk_pixbuf_new_from_xpm_data(icon_xpm); gtk_show_about_dialog(GTK_WINDOW(MainWindow), @@ -1102,7 +1101,7 @@ void openAbout () //"license-type", GTK_LICENSE_GPL_2_0, "website", "http://fceux.com", "authors", Authors, - "logo", logo); + "logo", logo, NULL); } void toggleSound(GtkWidget* check, gpointer data) @@ -1837,11 +1836,16 @@ gint convertKeypress(GtkWidget *grab, GdkEventKey *event, gpointer user_data) if (sdlkey != 0) { SDL_PushEvent(&sdlev); - #if SDL_VERSION_ATLEAST(1, 3, 0) - SDL_GetKeyboardState(NULL)[SDL_GetScancodeFromKey(sdlkey)] = keystate; - #else - SDL_GetKeyState(NULL)[sdlkey] = keystate; - #endif + + // Only let the emulator handle the key event if this window has the input focus. + if(keystate == 0 || gtk_window_is_active(GTK_WINDOW(MainWindow))) + { + #if SDL_VERSION_ATLEAST(1, 3, 0) + SDL_GetKeyboardState(NULL)[SDL_GetScancodeFromKey(sdlkey)] = keystate; + #else + SDL_GetKeyState(NULL)[sdlkey] = keystate; + #endif + } } // Allow GTK+ to process this key. diff --git a/src/drivers/sdl/input.cpp b/src/drivers/sdl/input.cpp index 783937d4..33c9300a 100644 --- a/src/drivers/sdl/input.cpp +++ b/src/drivers/sdl/input.cpp @@ -1346,10 +1346,14 @@ DWaitButton(const uint8 *text, SDL_Event event; static int32 LastAx[64][64]; int x,y; - std::string title = "Press a key for "; - title += (const char*)text; - SDL_WM_SetCaption(title.c_str(),0); - puts((const char *)text); + + if(text) { + std::string title = "Press a key for "; + title += (const char*)text; + SDL_WM_SetCaption(title.c_str(),0); + puts((const char *)text); + } + for(x = 0; x < 64; x++) { for(y = 0; y < 64; y++) { LastAx[x][y]=0x100000;