animate/legacy/
backend.rs1use glib::{
2 object::ObjectType as ObjectType_,
3 signal::{connect_raw, SignalHandlerId},
4 translate::*,
5};
6use std::boxed::Box as Box_;
7use std::{fmt, mem::transmute};
8
9glib_wrapper! {
10 pub struct Backend(Object<ffi::ClutterBackend, ffi::ClutterBackendClass, BackendClass>);
11
12 match fn {
13 get_type => || ffi::clutter_backend_get_type(),
14 }
15}
16
17impl Backend {
18 pub fn get_font_options(&self) -> Option<cairo::FontOptions> {
26 unsafe { from_glib_none(ffi::clutter_backend_get_font_options(self.to_glib_none().0)) }
27 }
28
29 pub fn get_resolution(&self) -> f64 {
45 unsafe { ffi::clutter_backend_get_resolution(self.to_glib_none().0) }
46 }
47
48 pub fn set_font_options(&self, options: &cairo::FontOptions) {
60 unsafe {
61 ffi::clutter_backend_set_font_options(self.to_glib_none().0, options.to_glib_none().0);
62 }
63 }
64
65 pub fn connect_font_changed<F: Fn(&Backend) + 'static>(&self, f: F) -> SignalHandlerId {
68 unsafe extern "C" fn font_changed_trampoline<F: Fn(&Backend) + 'static>(
69 this: *mut ffi::ClutterBackend,
70 f: glib_sys::gpointer,
71 ) {
72 let f: &F = &*(f as *const F);
73 f(&from_glib_borrow(this))
74 }
75 unsafe {
76 let f: Box_<F> = Box_::new(f);
77 connect_raw(
78 self.as_ptr() as *mut _,
79 b"font-changed\0".as_ptr() as *const _,
80 Some(transmute::<_, unsafe extern "C" fn()>(
81 font_changed_trampoline::<F> as *const (),
82 )),
83 Box_::into_raw(f),
84 )
85 }
86 }
87
88 pub fn connect_resolution_changed<F: Fn(&Backend) + 'static>(&self, f: F) -> SignalHandlerId {
91 unsafe extern "C" fn resolution_changed_trampoline<F: Fn(&Backend) + 'static>(
92 this: *mut ffi::ClutterBackend,
93 f: glib_sys::gpointer,
94 ) {
95 let f: &F = &*(f as *const F);
96 f(&from_glib_borrow(this))
97 }
98 unsafe {
99 let f: Box_<F> = Box_::new(f);
100 connect_raw(
101 self.as_ptr() as *mut _,
102 b"resolution-changed\0".as_ptr() as *const _,
103 Some(transmute::<_, unsafe extern "C" fn()>(
104 resolution_changed_trampoline::<F> as *const (),
105 )),
106 Box_::into_raw(f),
107 )
108 }
109 }
110
111 pub fn connect_settings_changed<F: Fn(&Backend) + 'static>(&self, f: F) -> SignalHandlerId {
114 unsafe extern "C" fn settings_changed_trampoline<F: Fn(&Backend) + 'static>(
115 this: *mut ffi::ClutterBackend,
116 f: glib_sys::gpointer,
117 ) {
118 let f: &F = &*(f as *const F);
119 f(&from_glib_borrow(this))
120 }
121 unsafe {
122 let f: Box_<F> = Box_::new(f);
123 connect_raw(
124 self.as_ptr() as *mut _,
125 b"settings-changed\0".as_ptr() as *const _,
126 Some(transmute::<_, unsafe extern "C" fn()>(
127 settings_changed_trampoline::<F> as *const (),
128 )),
129 Box_::into_raw(f),
130 )
131 }
132 }
133}
134
135impl fmt::Display for Backend {
136 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
137 write!(f, "Backend")
138 }
139}