1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use crate::bind;

use super::Window;

/// An extension for [`Window`] to grab/ungrab the mouse.
pub trait MouseGrabExt {
    /// Grabs the mouse.
    fn grab(&self);
    /// Ungrabs the mouse.
    fn ungrab(&self);
    /// Returns whether the window is grabbing the mouse.
    fn is_grabbed(&self) -> bool;
}

impl MouseGrabExt for Window<'_> {
    fn grab(&self) {
        unsafe { bind::SDL_SetWindowGrab(self.as_ptr(), 1) }
    }

    fn ungrab(&self) {
        unsafe { bind::SDL_SetWindowGrab(self.as_ptr(), 0) }
    }

    fn is_grabbed(&self) -> bool {
        unsafe { bind::SDL_GetWindowGrab(self.as_ptr()) != 0 }
    }
}