From: Jan Kiszka <jan.kiszka@web.de>
To: Anthony Liguori <aliguori@us.ibm.com>,
qemu-devel <qemu-devel@nongnu.org>
Subject: [Qemu-devel] [PATCH 12/15] sdl: Dynamically grab input in absolute mouse mode
Date: Sat, 30 Jul 2011 11:39:15 +0200 [thread overview]
Message-ID: <ceaadf7e4172bc980735abb6bcf51673fc97d002.1312018756.git.jan.kiszka@web.de> (raw)
In-Reply-To: <cover.1312018756.git.jan.kiszka@web.de>
In-Reply-To: <cover.1312018756.git.jan.kiszka@web.de>
From: Jan Kiszka <jan.kiszka@siemens.com>
Not grabbing the input means that special keys like ALT+TAB are still
handled by the host. Improve the usability by grabbing input once the
mouse is inside the guest screen, provided the SDL window has the input
focus. Release it again when the mouse is moved to any border. Also grab
the input when we gain the input focus and the mouse is within the
screen limits.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
ui/sdl.c | 43 +++++++++++++++++++++++++++++++++++++------
1 files changed, 37 insertions(+), 6 deletions(-)
diff --git a/ui/sdl.c b/ui/sdl.c
index 5ad38d5..e8ac3bb 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -490,15 +490,12 @@ static void sdl_mouse_mode_change(Notifier *notify, void *data)
{
if (kbd_mouse_is_absolute()) {
if (!absolute_enabled) {
- sdl_hide_cursor();
- if (gui_grab) {
- sdl_grab_end();
- }
+ sdl_grab_start();
absolute_enabled = 1;
}
} else if (absolute_enabled) {
- sdl_show_cursor();
- absolute_enabled = 0;
+ sdl_grab_end();
+ absolute_enabled = 0;
}
}
@@ -572,6 +569,19 @@ static void toggle_full_screen(DisplayState *ds)
vga_hw_update();
}
+static void absolute_mouse_grab(void)
+{
+ int mouse_x, mouse_y;
+
+ if (SDL_GetAppState() & SDL_APPINPUTFOCUS) {
+ SDL_GetMouseState(&mouse_x, &mouse_y);
+ if (mouse_x > 0 && mouse_x < real_screen->w - 1 &&
+ mouse_y > 0 && mouse_y < real_screen->h - 1) {
+ sdl_grab_start();
+ }
+ }
+}
+
static void sdl_refresh(DisplayState *ds)
{
SDL_Event ev1, *ev = &ev1;
@@ -638,6 +648,7 @@ static void sdl_refresh(DisplayState *ds)
}
} else if (absolute_enabled) {
sdl_hide_cursor();
+ absolute_mouse_grab();
}
break;
default:
@@ -724,6 +735,22 @@ static void sdl_refresh(DisplayState *ds)
}
break;
case SDL_MOUSEMOTION:
+ if (is_graphic_console() &&
+ (kbd_mouse_is_absolute() || absolute_enabled)) {
+ int max_x = real_screen->w - 1;
+ int max_y = real_screen->h - 1;
+
+ if (gui_grab &&
+ (ev->motion.x == 0 || ev->motion.y == 0 ||
+ ev->motion.x == max_x || ev->motion.y == max_y)) {
+ sdl_grab_end();
+ }
+ if (!gui_grab && SDL_GetAppState() & SDL_APPINPUTFOCUS &&
+ (ev->motion.x > 0 && ev->motion.x < max_x &&
+ ev->motion.y > 0 && ev->motion.y < max_y)) {
+ sdl_grab_start();
+ }
+ }
if (gui_grab || kbd_mouse_is_absolute() ||
absolute_enabled) {
sdl_send_mouse_event(ev->motion.xrel, ev->motion.yrel, 0,
@@ -764,6 +791,10 @@ static void sdl_refresh(DisplayState *ds)
!ev->active.gain && !gui_fullscreen) {
sdl_grab_end();
}
+ if (!gui_grab && ev->active.gain && is_graphic_console() &&
+ (kbd_mouse_is_absolute() || absolute_enabled)) {
+ absolute_mouse_grab();
+ }
if (ev->active.state & SDL_APPACTIVE) {
if (ev->active.gain) {
/* Back to default interval */
--
1.7.3.4
next prev parent reply other threads:[~2011-07-30 9:39 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-30 9:39 [Qemu-devel] [PATCH 00/15] sdl: Usability improvements Jan Kiszka
2011-07-30 9:39 ` [Qemu-devel] [PATCH 01/15] sdl: Fix termination in -no-shutdown mode Jan Kiszka
2011-07-30 12:57 ` Anthony Liguori
2011-07-30 9:39 ` [Qemu-devel] [PATCH 02/15] sdl: Do not make full screen mode resizable Jan Kiszka
2011-07-30 9:39 ` [Qemu-devel] [PATCH 03/15] sdl: Avoid redundant scaling deactivation Jan Kiszka
2011-07-30 9:39 ` [Qemu-devel] [PATCH 04/15] sdl: Properly mark modifier+u as hotkey Jan Kiszka
2011-07-30 9:39 ` [Qemu-devel] [PATCH 05/15] sdl: Fix full screen toggling from scaled mode Jan Kiszka
2011-07-30 9:39 ` [Qemu-devel] [PATCH 06/15] sdl: Restore scaling mode on return from full screen Jan Kiszka
2011-07-30 9:39 ` [Qemu-devel] [PATCH 07/15] sdl: Drop bogus gui_fullscreen_initial_grab Jan Kiszka
2011-07-30 9:39 ` [Qemu-devel] [PATCH 08/15] sdl: Initialize gui_fullscreen earlier during setup Jan Kiszka
2011-07-30 9:39 ` [Qemu-devel] [PATCH 09/15] sdl: Consistently avoid grabbing input for text consoles Jan Kiszka
2011-07-30 9:39 ` [Qemu-devel] [PATCH 10/15] sdl: Never release input while in full screen mode Jan Kiszka
2011-07-30 9:39 ` [Qemu-devel] [PATCH 11/15] sdl: Fix cursor handling when switching consoles in absolute mouse mode Jan Kiszka
2011-07-30 9:39 ` Jan Kiszka [this message]
2011-07-30 9:39 ` [Qemu-devel] [PATCH 13/15] sdl: Add zoom hot keys Jan Kiszka
2011-07-30 9:39 ` [Qemu-devel] [PATCH 14/15] sdl: Factor out event handlers from sdl_refresh Jan Kiszka
2011-07-30 9:39 ` [Qemu-devel] [PATCH 15/15] sdl: Refactor sdl_send_mouse_event Jan Kiszka
2011-08-01 0:28 ` [Qemu-devel] [PATCH 00/15] sdl: Usability improvements Anthony Liguori
2011-08-05 16:47 ` Anthony Liguori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ceaadf7e4172bc980735abb6bcf51673fc97d002.1312018756.git.jan.kiszka@web.de \
--to=jan.kiszka@web.de \
--cc=aliguori@us.ibm.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).