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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Take a look at the license at the top of the repository in the LICENSE file.

use crate::{EventType, Surface};
use glib::translate::*;
use std::fmt;

glib::wrapper! {
    /// An event related to a broken windowing system grab.
    #[doc(alias = "GdkGrabBrokenEvent")]
    pub struct GrabBrokenEvent(Shared<ffi::GdkGrabBrokenEvent>);

    match fn {
        ref => |ptr| ffi::gdk_event_ref(ptr as *mut ffi::GdkEvent),
        unref => |ptr| ffi::gdk_event_unref(ptr as *mut ffi::GdkEvent),
    }
}

define_event! {
    GrabBrokenEvent,
    ffi::GdkGrabBrokenEvent,
    ffi::gdk_grab_broken_event_get_type,
    &[EventType::GrabBroken]
}

impl GrabBrokenEvent {
    /// Extracts the grab surface from a grab broken event.
    ///
    /// # Returns
    ///
    /// the grab surface of `self`
    #[doc(alias = "gdk_grab_broken_event_get_grab_surface")]
    #[doc(alias = "get_grab_surface")]
    pub fn grab_surface(&self) -> Option<Surface> {
        unsafe {
            from_glib_none(ffi::gdk_grab_broken_event_get_grab_surface(
                self.to_glib_none().0,
            ))
        }
    }

    /// Checks whether the grab broken event is for an implicit grab.
    ///
    /// # Returns
    ///
    /// [`true`] if the an implicit grab was broken
    #[doc(alias = "gdk_grab_broken_event_get_implicit")]
    #[doc(alias = "get_implicit")]
    pub fn is_implicit(&self) -> bool {
        unsafe {
            from_glib(ffi::gdk_grab_broken_event_get_implicit(
                self.to_glib_none().0,
            ))
        }
    }
}

impl fmt::Display for GrabBrokenEvent {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.debug_struct("GrabBrokenEvent")
            .field("grab_surface", &self.grab_surface())
            .field("implicit", &self.is_implicit())
            .finish()
    }
}