diff options
Diffstat (limited to 'qemu/ui/sdl.c')
-rw-r--r-- | qemu/ui/sdl.c | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/qemu/ui/sdl.c b/qemu/ui/sdl.c index 3be29101e..d8cf5bcf7 100644 --- a/qemu/ui/sdl.c +++ b/qemu/ui/sdl.c @@ -25,10 +25,12 @@ /* Avoid compiler warning because macro is redefined in SDL_syswm.h. */ #undef WIN32_LEAN_AND_MEAN +#include "qemu/osdep.h" #include <SDL.h> #include <SDL_syswm.h> #include "qemu-common.h" +#include "qemu/cutils.h" #include "ui/console.h" #include "ui/input.h" #include "sysemu/sysemu.h" @@ -60,6 +62,11 @@ static SDL_Cursor *guest_sprite = NULL; static SDL_PixelFormat host_format; static int scaling_active = 0; static Notifier mouse_mode_notifier; +static int idle_counter; + +#define SDL_REFRESH_INTERVAL_BUSY 10 +#define SDL_MAX_IDLE_COUNT (2 * GUI_REFRESH_INTERVAL_DEFAULT \ + / SDL_REFRESH_INTERVAL_BUSY + 1) #if 0 #define DEBUG_SDL @@ -465,7 +472,7 @@ static void sdl_mouse_mode_change(Notifier *notify, void *data) static void sdl_send_mouse_event(int dx, int dy, int x, int y, int state) { - static uint32_t bmap[INPUT_BUTTON_MAX] = { + static uint32_t bmap[INPUT_BUTTON__MAX] = { [INPUT_BUTTON_LEFT] = SDL_BUTTON(SDL_BUTTON_LEFT), [INPUT_BUTTON_MIDDLE] = SDL_BUTTON(SDL_BUTTON_MIDDLE), [INPUT_BUTTON_RIGHT] = SDL_BUTTON(SDL_BUTTON_RIGHT), @@ -802,6 +809,7 @@ static void handle_activation(SDL_Event *ev) static void sdl_refresh(DisplayChangeListener *dcl) { SDL_Event ev1, *ev = &ev1; + int idle = 1; if (last_vm_running != runstate_is_running()) { last_vm_running = runstate_is_running(); @@ -817,9 +825,11 @@ static void sdl_refresh(DisplayChangeListener *dcl) sdl_update(dcl, 0, 0, real_screen->w, real_screen->h); break; case SDL_KEYDOWN: + idle = 0; handle_keydown(ev); break; case SDL_KEYUP: + idle = 0; handle_keyup(ev); break; case SDL_QUIT: @@ -829,10 +839,12 @@ static void sdl_refresh(DisplayChangeListener *dcl) } break; case SDL_MOUSEMOTION: + idle = 0; handle_mousemotion(ev); break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: + idle = 0; handle_mousebutton(ev); break; case SDL_ACTIVEEVENT: @@ -847,6 +859,18 @@ static void sdl_refresh(DisplayChangeListener *dcl) break; } } + + if (idle) { + if (idle_counter < SDL_MAX_IDLE_COUNT) { + idle_counter++; + if (idle_counter >= SDL_MAX_IDLE_COUNT) { + dcl->update_interval = GUI_REFRESH_INTERVAL_DEFAULT; + } + } + } else { + idle_counter = 0; + dcl->update_interval = SDL_REFRESH_INTERVAL_BUSY; + } } static void sdl_mouse_warp(DisplayChangeListener *dcl, @@ -985,7 +1009,7 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame) sdl_grab_start(); } - dcl = g_malloc0(sizeof(DisplayChangeListener)); + dcl = g_new0(DisplayChangeListener, 1); dcl->ops = &dcl_ops; register_displaychangelistener(dcl); |