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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use crate::globals::GlobalData;
use std::sync::atomic::Ordering;
use wayland_client::{Connection, Dispatch, QueueHandle};
use wayland_protocols::ext::session_lock::v1::client::{
    ext_session_lock_manager_v1, ext_session_lock_surface_v1, ext_session_lock_v1,
};

use super::{
    SessionLock, SessionLockData, SessionLockHandler, SessionLockState, SessionLockSurface,
    SessionLockSurfaceConfigure, SessionLockSurfaceData,
};

impl<D> Dispatch<ext_session_lock_manager_v1::ExtSessionLockManagerV1, GlobalData, D>
    for SessionLockState
where
    D: Dispatch<ext_session_lock_manager_v1::ExtSessionLockManagerV1, GlobalData>,
{
    fn event(
        _state: &mut D,
        _proxy: &ext_session_lock_manager_v1::ExtSessionLockManagerV1,
        _event: ext_session_lock_manager_v1::Event,
        _: &GlobalData,
        _: &Connection,
        _: &QueueHandle<D>,
    ) {
        unreachable!()
    }
}

impl<D> Dispatch<ext_session_lock_v1::ExtSessionLockV1, SessionLockData, D> for SessionLockState
where
    D: Dispatch<ext_session_lock_v1::ExtSessionLockV1, SessionLockData> + SessionLockHandler,
{
    fn event(
        state: &mut D,
        proxy: &ext_session_lock_v1::ExtSessionLockV1,
        event: ext_session_lock_v1::Event,
        _: &SessionLockData,
        conn: &Connection,
        qh: &QueueHandle<D>,
    ) {
        if let Some(session_lock) = SessionLock::from_ext_session_lock(proxy) {
            match event {
                ext_session_lock_v1::Event::Locked => {
                    session_lock.0.locked.store(true, Ordering::SeqCst);
                    state.locked(conn, qh, session_lock);
                }
                ext_session_lock_v1::Event::Finished => {
                    state.finished(conn, qh, session_lock);
                }
                _ => unreachable!(),
            }
        }
    }
}

impl<D> Dispatch<ext_session_lock_surface_v1::ExtSessionLockSurfaceV1, SessionLockSurfaceData, D>
    for SessionLockState
where
    D: Dispatch<ext_session_lock_surface_v1::ExtSessionLockSurfaceV1, SessionLockSurfaceData>
        + SessionLockHandler,
{
    fn event(
        state: &mut D,
        proxy: &ext_session_lock_surface_v1::ExtSessionLockSurfaceV1,
        event: ext_session_lock_surface_v1::Event,
        _: &SessionLockSurfaceData,
        conn: &Connection,
        qh: &QueueHandle<D>,
    ) {
        if let Some(session_lock_surface) = SessionLockSurface::from_ext_session_lock_surface(proxy)
        {
            match event {
                ext_session_lock_surface_v1::Event::Configure { serial, width, height } => {
                    proxy.ack_configure(serial);
                    state.configure(
                        conn,
                        qh,
                        session_lock_surface,
                        SessionLockSurfaceConfigure { new_size: (width, height) },
                        serial,
                    );
                }
                _ => unreachable!(),
            }
        }
    }
}