private void WindowUngrabbed (IntPtr hwnd) {
bool was_grabbed = Grab.Hwnd != IntPtr.Zero;
Grab.Hwnd = IntPtr.Zero;
Grab.Confined = false;
if (was_grabbed) {
// lparam should be the handle to the window gaining the mouse capture,
// but X doesn't seem to give us that information.
// Also only generate WM_CAPTURECHANGED if the window actually was grabbed.
// X will send a NotifyUngrab, but since it comes late sometimes we're
// calling WindowUngrabbed directly from UngrabWindow in order to send
// this WM right away.
SendMessage (hwnd, Msg.WM_CAPTURECHANGED, IntPtr.Zero, IntPtr.Zero);
}
}