aboutsummaryrefslogtreecommitdiff
path: root/ui/sdl2.c
diff options
context:
space:
mode:
authorJindřich Makovička <makovick@gmail.com>2016-01-12 20:18:24 +0100
committerGerd Hoffmann <kraxel@redhat.com>2016-02-02 14:05:07 +0100
commit56bdd4b69aa10bec274b1e812685bcf44dcb0c72 (patch)
treefe0f5c5d53d3e1c126a9f830bf68a60396614e8c /ui/sdl2.c
parent919e11f3735c524e23d049512d3306ea1cc63fba (diff)
sdl: shorten the GUI refresh interval when mouse or keyboard is active
Signed-off-by: Jindřich Makovička <makovick@gmail.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'ui/sdl2.c')
-rw-r--r--ui/sdl2.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/ui/sdl2.c b/ui/sdl2.c
index 46270f4172..c0a76d7744 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -49,6 +49,10 @@ static int guest_x, guest_y;
static SDL_Cursor *guest_sprite;
static Notifier mouse_mode_notifier;
+#define SDL2_REFRESH_INTERVAL_BUSY 10
+#define SDL2_MAX_IDLE_COUNT (2 * GUI_REFRESH_INTERVAL_DEFAULT \
+ / SDL2_REFRESH_INTERVAL_BUSY + 1)
+
static void sdl_update_caption(struct sdl2_console *scon);
static struct sdl2_console *get_scon_from_window(uint32_t window_id)
@@ -578,6 +582,7 @@ static void handle_windowevent(SDL_Event *ev)
void sdl2_poll_events(struct sdl2_console *scon)
{
SDL_Event ev1, *ev = &ev1;
+ int idle = 1;
if (scon->last_vm_running != runstate_is_running()) {
scon->last_vm_running = runstate_is_running();
@@ -587,12 +592,15 @@ void sdl2_poll_events(struct sdl2_console *scon)
while (SDL_PollEvent(ev)) {
switch (ev->type) {
case SDL_KEYDOWN:
+ idle = 0;
handle_keydown(ev);
break;
case SDL_KEYUP:
+ idle = 0;
handle_keyup(ev);
break;
case SDL_TEXTINPUT:
+ idle = 0;
handle_textinput(ev);
break;
case SDL_QUIT:
@@ -602,13 +610,16 @@ void sdl2_poll_events(struct sdl2_console *scon)
}
break;
case SDL_MOUSEMOTION:
+ idle = 0;
handle_mousemotion(ev);
break;
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
+ idle = 0;
handle_mousebutton(ev);
break;
case SDL_MOUSEWHEEL:
+ idle = 0;
handle_mousewheel(ev);
break;
case SDL_WINDOWEVENT:
@@ -618,6 +629,18 @@ void sdl2_poll_events(struct sdl2_console *scon)
break;
}
}
+
+ if (idle) {
+ if (scon->idle_counter < SDL2_MAX_IDLE_COUNT) {
+ scon->idle_counter++;
+ if (scon->idle_counter >= SDL2_MAX_IDLE_COUNT) {
+ scon->dcl.update_interval = GUI_REFRESH_INTERVAL_DEFAULT;
+ }
+ }
+ } else {
+ scon->idle_counter = 0;
+ scon->dcl.update_interval = SDL2_REFRESH_INTERVAL_BUSY;
+ }
}
static void sdl_mouse_warp(DisplayChangeListener *dcl,