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
use std::sync::Arc;
use std::sync::Mutex;
use core::{From, Registry, Surface};
use core::compositor::WSurface;
use core::subcompositor::SubSurface;
use ffi::interfaces::subcompositor::{wl_subcompositor, wl_subcompositor_destroy};
use ffi::{FFI, Bind, abi};
struct InternalSubCompositor {
_registry: Registry,
ptr: *mut wl_subcompositor
}
unsafe impl Send for InternalSubCompositor {}
#[derive(Clone)]
pub struct SubCompositor {
internal : Arc<Mutex<InternalSubCompositor>>
}
impl SubCompositor {
pub fn get_subsurface<S>(&self, surface: S, parent: &WSurface)
-> SubSurface<S>
where S: Surface
{
From::from((self.clone(), surface, parent))
}
}
impl Drop for InternalSubCompositor {
fn drop(&mut self) {
unsafe { wl_subcompositor_destroy(self.ptr) };
}
}
impl Bind<Registry> for SubCompositor {
fn interface() -> &'static abi::wl_interface {
#[cfg(feature = "dlopen")] use ffi::abi::WAYLAND_CLIENT_HANDLE;
#[cfg(not(feature = "dlopen"))] use ffi::abi::wl_subcompositor_interface;
ffi_dispatch_static!(WAYLAND_CLIENT_HANDLE, wl_subcompositor_interface)
}
unsafe fn wrap(ptr: *mut wl_subcompositor, registry: Registry) -> SubCompositor {
SubCompositor {
internal: Arc::new(Mutex::new(InternalSubCompositor {
_registry: registry,
ptr: ptr
}))
}
}
}
impl FFI for SubCompositor {
type Ptr = wl_subcompositor;
fn ptr(&self) -> *const wl_subcompositor {
let internal = self.internal.lock().unwrap();
internal.ptr as *const wl_subcompositor
}
unsafe fn ptr_mut(&self) -> *mut wl_subcompositor {
let internal = self.internal.lock().unwrap();
internal.ptr
}
}