From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48060) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a5Bzx-0006P6-QN for qemu-devel@nongnu.org; Sat, 05 Dec 2015 07:31:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a5Bzu-0006ND-JQ for qemu-devel@nongnu.org; Sat, 05 Dec 2015 07:31:33 -0500 Received: from mail-wm0-x22d.google.com ([2a00:1450:400c:c09::22d]:37210) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a5Bzu-0006N3-9I for qemu-devel@nongnu.org; Sat, 05 Dec 2015 07:31:30 -0500 Received: by wmww144 with SMTP id w144so96576990wmw.0 for ; Sat, 05 Dec 2015 04:31:29 -0800 (PST) Date: Sat, 5 Dec 2015 13:31:23 +0100 From: =?UTF-8?B?SmluZMWZaWNoIE1ha292acSNa2E=?= Message-ID: <20151205133123.4f9f5035@holly> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/u+fd80y_Il7yHVZurmtcIN2" Subject: [Qemu-devel] [PATCH] sdl: shorten the GUI refresh interval when mouse or keyboard is active List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?B?SmluZMWZaWNoIE1ha292acSNa2E=?= --MP_/u+fd80y_Il7yHVZurmtcIN2 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi, some years ago, I submitted a patch improving the mouse response in SDL ui, but it got lost under the sands of time. Here is an updated version for both SDL and SDL2 frontends. With the change applied, when the gui receives a keyboard or mouse event, it shortens the gui refresh interval to 10ms instead of 30ms for next ~60ms. This results in a much better experience when using a mouse - similar to the "real" desktop. Please Cc:, I am not a subscriber. Regards, -- Jindrich Makovicka --MP_/u+fd80y_Il7yHVZurmtcIN2 Content-Type: text/x-patch Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename=0001-sdl-shorten-the-GUI-refresh-interval-when-mouse-or-k.patch =46rom c747a56164a9d4289eae71c653431d8f6fd688e0 Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?Jind=3DC5=3D99ich=3D20Makovi=3DC4=3D8Dka?=3D Date: Sat, 5 Dec 2015 13:28:22 +0100 Subject: [PATCH] sdl: shorten the GUI refresh interval when mouse or keyboa= rd is active MIME-Version: 1.0 Content-Type: text/plain; charset=3DUTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jind=C5=99ich Makovi=C4=8Dka --- ui/sdl.c | 22 ++++++++++++++++++++++ ui/sdl2.c | 24 ++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/ui/sdl.c b/ui/sdl.c index 570cb99..aef237a 100644 --- a/ui/sdl.c +++ b/ui/sdl.c @@ -60,6 +60,11 @@ static SDL_Cursor *guest_sprite =3D NULL; static SDL_PixelFormat host_format; static int scaling_active =3D 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) =20 #if 0 #define DEBUG_SDL @@ -802,6 +807,7 @@ static void handle_activation(SDL_Event *ev) static void sdl_refresh(DisplayChangeListener *dcl) { SDL_Event ev1, *ev =3D &ev1; + int idle =3D 1; =20 if (last_vm_running !=3D runstate_is_running()) { last_vm_running =3D runstate_is_running(); @@ -817,9 +823,11 @@ static void sdl_refresh(DisplayChangeListener *dcl) sdl_update(dcl, 0, 0, real_screen->w, real_screen->h); break; case SDL_KEYDOWN: + idle =3D 0; handle_keydown(ev); break; case SDL_KEYUP: + idle =3D 0; handle_keyup(ev); break; case SDL_QUIT: @@ -829,10 +837,12 @@ static void sdl_refresh(DisplayChangeListener *dcl) } break; case SDL_MOUSEMOTION: + idle =3D 0; handle_mousemotion(ev); break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: + idle =3D 0; handle_mousebutton(ev); break; case SDL_ACTIVEEVENT: @@ -847,6 +857,18 @@ static void sdl_refresh(DisplayChangeListener *dcl) break; } } + + if (idle) { + if (idle_counter < SDL_MAX_IDLE_COUNT) { + idle_counter++; + if (idle_counter >=3D SDL_MAX_IDLE_COUNT) { + dcl->update_interval =3D GUI_REFRESH_INTERVAL_DEFAULT; + } + } + } else { + idle_counter =3D 0; + dcl->update_interval =3D SDL_REFRESH_INTERVAL_BUSY; + } } =20 static void sdl_mouse_warp(DisplayChangeListener *dcl, diff --git a/ui/sdl2.c b/ui/sdl2.c index 5cb75aa..8f0fceb 100644 --- a/ui/sdl2.c +++ b/ui/sdl2.c @@ -48,6 +48,11 @@ static int guest_cursor; static int guest_x, guest_y; static SDL_Cursor *guest_sprite; static Notifier mouse_mode_notifier; +static int idle_counter; + +#define SDL2_REFRESH_INTERVAL_BUSY 10 +#define SDL2_MAX_IDLE_COUNT (2 * GUI_REFRESH_INTERVAL_DEFAULT \ + / SDL2_REFRESH_INTERVAL_BUSY + 1) =20 static void sdl_update_caption(struct sdl2_console *scon); =20 @@ -578,6 +583,7 @@ static void handle_windowevent(SDL_Event *ev) void sdl2_poll_events(struct sdl2_console *scon) { SDL_Event ev1, *ev =3D &ev1; + int idle =3D 1; =20 if (scon->last_vm_running !=3D runstate_is_running()) { scon->last_vm_running =3D runstate_is_running(); @@ -587,12 +593,15 @@ void sdl2_poll_events(struct sdl2_console *scon) while (SDL_PollEvent(ev)) { switch (ev->type) { case SDL_KEYDOWN: + idle =3D 0; handle_keydown(ev); break; case SDL_KEYUP: + idle =3D 0; handle_keyup(ev); break; case SDL_TEXTINPUT: + idle =3D 0; handle_textinput(ev); break; case SDL_QUIT: @@ -602,13 +611,16 @@ void sdl2_poll_events(struct sdl2_console *scon) } break; case SDL_MOUSEMOTION: + idle =3D 0; handle_mousemotion(ev); break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: + idle =3D 0; handle_mousebutton(ev); break; case SDL_MOUSEWHEEL: + idle =3D 0; handle_mousewheel(ev); break; case SDL_WINDOWEVENT: @@ -618,6 +630,18 @@ void sdl2_poll_events(struct sdl2_console *scon) break; } } + + if (idle) { + if (idle_counter < SDL2_MAX_IDLE_COUNT) { + idle_counter++; + if (idle_counter >=3D SDL2_MAX_IDLE_COUNT) { + scon->dcl.update_interval =3D GUI_REFRESH_INTERVAL_DEFAULT; + } + } + } else { + idle_counter =3D 0; + scon->dcl.update_interval =3D SDL2_REFRESH_INTERVAL_BUSY; + } } =20 static void sdl_mouse_warp(DisplayChangeListener *dcl, --=20 2.6.2 --MP_/u+fd80y_Il7yHVZurmtcIN2--