diff options
author | Anthony Liguori <aliguori@us.ibm.com> | 2010-03-10 09:42:58 -0600 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2010-03-19 15:27:38 -0500 |
commit | 3af12c86d9db42c826dc9a7577b657543baf7fab (patch) | |
tree | 6c2856fe803e158f4e6083737757624a9388fb49 /sdl.c | |
parent | 37c34d9d5d87ea9d51760310c8863b82cb8c055a (diff) |
sdl: use mouse mode notifier
Today we poll the mouse mode whenever there is a mouse movement. There is a
subtle usability problem with this though.
If we're in relative mode and grab is enabled, when we change to absolute mode,
we break grab. This gives a user a seamless transition when the new pointer
is enabled.
But because we poll for mouse change, this grab break won't occur until the user
attempts to move the mouse. By using notifiers, the grab break happens as soon
as possible.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'sdl.c')
-rw-r--r-- | sdl.c | 31 |
1 files changed, 20 insertions, 11 deletions
@@ -57,6 +57,7 @@ static SDL_Cursor *guest_sprite = NULL; static uint8_t allocator; static SDL_PixelFormat host_format; static int scaling_active = 0; +static Notifier mouse_mode_notifier; static void sdl_update(DisplayState *ds, int x, int y, int w, int h) { @@ -486,6 +487,22 @@ static void sdl_grab_end(void) sdl_update_caption(); } +static void sdl_mouse_mode_change(Notifier *notify) +{ + if (kbd_mouse_is_absolute()) { + if (!absolute_enabled) { + sdl_hide_cursor(); + if (gui_grab) { + sdl_grab_end(); + } + absolute_enabled = 1; + } + } else if (absolute_enabled) { + sdl_show_cursor(); + absolute_enabled = 0; + } +} + static void sdl_send_mouse_event(int dx, int dy, int dz, int x, int y, int state) { int buttons; @@ -498,19 +515,8 @@ static void sdl_send_mouse_event(int dx, int dy, int dz, int x, int y, int state buttons |= MOUSE_EVENT_MBUTTON; if (kbd_mouse_is_absolute()) { - if (!absolute_enabled) { - sdl_hide_cursor(); - if (gui_grab) { - sdl_grab_end(); - } - absolute_enabled = 1; - } - dx = x * 0x7FFF / (width - 1); dy = y * 0x7FFF / (height - 1); - } else if (absolute_enabled) { - sdl_show_cursor(); - absolute_enabled = 0; } else if (guest_cursor) { x -= guest_x; y -= guest_y; @@ -876,6 +882,9 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame) dpy_resize(ds); } + mouse_mode_notifier.notify = sdl_mouse_mode_change; + qemu_add_mouse_mode_change_notifier(&mouse_mode_notifier); + sdl_update_caption(); SDL_EnableKeyRepeat(250, 50); gui_grab = 0; |