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
//! Screen saving that allows the screen to be blanked by a screen saver.

use static_assertions::assert_not_impl_all;
use std::marker::PhantomData;

use crate::{bind, Video};

/// A screen saver that be enabled until dropped it.
pub struct ScreenSaver<'video> {
    _phantom: PhantomData<&'video Video<'video>>,
}

impl std::fmt::Debug for ScreenSaver<'_> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("ScreenSaver").finish()
    }
}

assert_not_impl_all!(ScreenSaver: Send, Sync);

impl<'video> ScreenSaver<'video> {
    /// Constructs and starts a screen saver.
    #[must_use]
    pub fn new(_: &'video Video) -> Self {
        unsafe { bind::SDL_EnableScreenSaver() }
        Self {
            _phantom: PhantomData,
        }
    }
}

impl<'video> Drop for ScreenSaver<'video> {
    fn drop(&mut self) {
        unsafe { bind::SDL_DisableScreenSaver() }
    }
}