From 1fcddb3b100d2d9d4e907f982988b4a15385d652 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Mon, 16 Feb 2009 12:46:00 +0000 Subject: [PATCH] [win32] Track mouse leave messages Bug 1178 - No enter / leave events on actors when pointer leaves the stage window This patch causes the Win32 backend to emit CLUTTER_LEAVE events when a WM_MOUSELEAVE event is received in the same way that f505536 does for the X11 backend. Windows will only send WM_MOUSELEAVE events if they are previously requested using TrackMouseEvent so this needs to be called whenever the mouse enters the window. There is no WM_MOUSELEAVE event but we can detect when the mouse enters because we get a WM_MOUSEMOVE event. --- clutter/win32/clutter-event-win32.c | 25 +++++++++++++++++++++++++ clutter/win32/clutter-stage-win32.h | 1 + 2 files changed, 26 insertions(+) diff --git a/clutter/win32/clutter-event-win32.c b/clutter/win32/clutter-event-win32.c index d72c81ba6..9c4a3c943 100644 --- a/clutter/win32/clutter-event-win32.c +++ b/clutter/win32/clutter-event-win32.c @@ -502,6 +502,31 @@ message_translate (ClutterBackend *backend, event->motion.x = GET_X_LPARAM (msg->lParam); event->motion.y = GET_Y_LPARAM (msg->lParam); event->motion.modifier_state = get_modifier_state (msg->wParam); + /* We need to start tracking when the mouse leaves the stage if + we're not already */ + if (!stage_win32->tracking_mouse) + { + TRACKMOUSEEVENT tmevent; + + tmevent.cbSize = sizeof (tmevent); + tmevent.dwFlags = TME_LEAVE; + tmevent.hwndTrack = stage_win32->hwnd; + TrackMouseEvent (&tmevent); + + stage_win32->tracking_mouse = TRUE; + } + break; + + case WM_MOUSELEAVE: + event->crossing.type = CLUTTER_LEAVE; + event->crossing.time = msg->time; + event->crossing.x = msg->pt.x; + event->crossing.y = msg->pt.y; + + /* When we get a leave message the mouse tracking is + automatically cancelled so we'll need to start it again when + the mouse next enters the window */ + stage_win32->tracking_mouse = FALSE; break; case WM_KEYDOWN: diff --git a/clutter/win32/clutter-stage-win32.h b/clutter/win32/clutter-stage-win32.h index e4bebce12..d91b87d48 100644 --- a/clutter/win32/clutter-stage-win32.h +++ b/clutter/win32/clutter-stage-win32.h @@ -51,6 +51,7 @@ struct _ClutterStageWin32 gint scroll_pos; RECT fullscreen_rect; gboolean is_foreign_win; + gboolean tracking_mouse; ClutterBackendWin32 *backend; ClutterStageState state;