1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
4// DO NOT EDIT
5
6use crate::{ffi, GLContext, GLDisplay};
7use glib::{
8 object::ObjectType as _,
9 prelude::*,
10 signal::{connect_raw, SignalHandlerId},
11 translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16 #[doc(alias = "GstGLWindow")]
17 pub struct GLWindow(Object<ffi::GstGLWindow, ffi::GstGLWindowClass>) @extends gst::Object;
18
19 match fn {
20 type_ => || ffi::gst_gl_window_get_type(),
21 }
22}
23
24impl GLWindow {
25 pub const NONE: Option<&'static GLWindow> = None;
26
27 #[doc(alias = "gst_gl_window_new")]
28 pub fn new(display: &impl IsA<GLDisplay>) -> GLWindow {
29 skip_assert_initialized!();
30 unsafe { from_glib_full(ptr:ffi::gst_gl_window_new(display.as_ref().to_glib_none().0)) }
31 }
32}
33
34unsafe impl Send for GLWindow {}
35unsafe impl Sync for GLWindow {}
36
37mod sealed {
38 pub trait Sealed {}
39 impl<T: super::IsA<super::GLWindow>> Sealed for T {}
40}
41
42pub trait GLWindowExt: IsA<GLWindow> + sealed::Sealed + 'static {
43 #[cfg(feature = "v1_16")]
44 #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
45 #[doc(alias = "gst_gl_window_controls_viewport")]
46 fn controls_viewport(&self) -> bool {
47 unsafe {
48 from_glib(ffi::gst_gl_window_controls_viewport(
49 self.as_ref().to_glib_none().0,
50 ))
51 }
52 }
53
54 #[doc(alias = "gst_gl_window_draw")]
55 fn draw(&self) {
56 unsafe {
57 ffi::gst_gl_window_draw(self.as_ref().to_glib_none().0);
58 }
59 }
60
61 #[doc(alias = "gst_gl_window_get_context")]
62 #[doc(alias = "get_context")]
63 fn context(&self) -> GLContext {
64 unsafe {
65 from_glib_full(ffi::gst_gl_window_get_context(
66 self.as_ref().to_glib_none().0,
67 ))
68 }
69 }
70
71 #[doc(alias = "gst_gl_window_get_surface_dimensions")]
72 #[doc(alias = "get_surface_dimensions")]
73 fn surface_dimensions(&self) -> (u32, u32) {
74 unsafe {
75 let mut width = std::mem::MaybeUninit::uninit();
76 let mut height = std::mem::MaybeUninit::uninit();
77 ffi::gst_gl_window_get_surface_dimensions(
78 self.as_ref().to_glib_none().0,
79 width.as_mut_ptr(),
80 height.as_mut_ptr(),
81 );
82 (width.assume_init(), height.assume_init())
83 }
84 }
85
86 #[doc(alias = "gst_gl_window_handle_events")]
87 fn handle_events(&self, handle_events: bool) {
88 unsafe {
89 ffi::gst_gl_window_handle_events(
90 self.as_ref().to_glib_none().0,
91 handle_events.into_glib(),
92 );
93 }
94 }
95
96 #[cfg(feature = "v1_18")]
97 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
98 #[doc(alias = "gst_gl_window_has_output_surface")]
99 fn has_output_surface(&self) -> bool {
100 unsafe {
101 from_glib(ffi::gst_gl_window_has_output_surface(
102 self.as_ref().to_glib_none().0,
103 ))
104 }
105 }
106
107 #[doc(alias = "gst_gl_window_queue_resize")]
108 fn queue_resize(&self) {
109 unsafe {
110 ffi::gst_gl_window_queue_resize(self.as_ref().to_glib_none().0);
111 }
112 }
113
114 #[doc(alias = "gst_gl_window_quit")]
115 fn quit(&self) {
116 unsafe {
117 ffi::gst_gl_window_quit(self.as_ref().to_glib_none().0);
118 }
119 }
120
121 #[doc(alias = "gst_gl_window_resize")]
122 fn resize(&self, width: u32, height: u32) {
123 unsafe {
124 ffi::gst_gl_window_resize(self.as_ref().to_glib_none().0, width, height);
125 }
126 }
127
128 #[doc(alias = "gst_gl_window_run")]
129 fn run(&self) {
130 unsafe {
131 ffi::gst_gl_window_run(self.as_ref().to_glib_none().0);
132 }
133 }
134
135 #[doc(alias = "gst_gl_window_send_key_event")]
136 fn send_key_event(&self, event_type: &str, key_str: &str) {
137 unsafe {
138 ffi::gst_gl_window_send_key_event(
139 self.as_ref().to_glib_none().0,
140 event_type.to_glib_none().0,
141 key_str.to_glib_none().0,
142 );
143 }
144 }
145
146 #[doc(alias = "gst_gl_window_send_mouse_event")]
147 fn send_mouse_event(&self, event_type: &str, button: i32, posx: f64, posy: f64) {
148 unsafe {
149 ffi::gst_gl_window_send_mouse_event(
150 self.as_ref().to_glib_none().0,
151 event_type.to_glib_none().0,
152 button,
153 posx,
154 posy,
155 );
156 }
157 }
158
159 #[cfg(feature = "v1_18")]
160 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
161 #[doc(alias = "gst_gl_window_send_scroll_event")]
162 fn send_scroll_event(&self, posx: f64, posy: f64, delta_x: f64, delta_y: f64) {
163 unsafe {
164 ffi::gst_gl_window_send_scroll_event(
165 self.as_ref().to_glib_none().0,
166 posx,
167 posy,
168 delta_x,
169 delta_y,
170 );
171 }
172 }
173
174 #[doc(alias = "gst_gl_window_set_preferred_size")]
175 fn set_preferred_size(&self, width: i32, height: i32) {
176 unsafe {
177 ffi::gst_gl_window_set_preferred_size(self.as_ref().to_glib_none().0, width, height);
178 }
179 }
180
181 #[doc(alias = "gst_gl_window_set_render_rectangle")]
182 fn set_render_rectangle(
183 &self,
184 x: i32,
185 y: i32,
186 width: i32,
187 height: i32,
188 ) -> Result<(), glib::error::BoolError> {
189 unsafe {
190 glib::result_from_gboolean!(
191 ffi::gst_gl_window_set_render_rectangle(
192 self.as_ref().to_glib_none().0,
193 x,
194 y,
195 width,
196 height
197 ),
198 "Failed to set the specified region"
199 )
200 }
201 }
202
203 #[doc(alias = "gst_gl_window_show")]
204 fn show(&self) {
205 unsafe {
206 ffi::gst_gl_window_show(self.as_ref().to_glib_none().0);
207 }
208 }
209
210 #[doc(alias = "key-event")]
211 fn connect_key_event<F: Fn(&Self, &str, &str) + Send + Sync + 'static>(
212 &self,
213 f: F,
214 ) -> SignalHandlerId {
215 unsafe extern "C" fn key_event_trampoline<
216 P: IsA<GLWindow>,
217 F: Fn(&P, &str, &str) + Send + Sync + 'static,
218 >(
219 this: *mut ffi::GstGLWindow,
220 id: *mut std::ffi::c_char,
221 key: *mut std::ffi::c_char,
222 f: glib::ffi::gpointer,
223 ) {
224 let f: &F = &*(f as *const F);
225 f(
226 GLWindow::from_glib_borrow(this).unsafe_cast_ref(),
227 &glib::GString::from_glib_borrow(id),
228 &glib::GString::from_glib_borrow(key),
229 )
230 }
231 unsafe {
232 let f: Box_<F> = Box_::new(f);
233 connect_raw(
234 self.as_ptr() as *mut _,
235 b"key-event\0".as_ptr() as *const _,
236 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
237 key_event_trampoline::<Self, F> as *const (),
238 )),
239 Box_::into_raw(f),
240 )
241 }
242 }
243
244 #[doc(alias = "mouse-event")]
245 fn connect_mouse_event<F: Fn(&Self, &str, i32, f64, f64) + Send + Sync + 'static>(
246 &self,
247 f: F,
248 ) -> SignalHandlerId {
249 unsafe extern "C" fn mouse_event_trampoline<
250 P: IsA<GLWindow>,
251 F: Fn(&P, &str, i32, f64, f64) + Send + Sync + 'static,
252 >(
253 this: *mut ffi::GstGLWindow,
254 id: *mut std::ffi::c_char,
255 button: std::ffi::c_int,
256 x: std::ffi::c_double,
257 y: std::ffi::c_double,
258 f: glib::ffi::gpointer,
259 ) {
260 let f: &F = &*(f as *const F);
261 f(
262 GLWindow::from_glib_borrow(this).unsafe_cast_ref(),
263 &glib::GString::from_glib_borrow(id),
264 button,
265 x,
266 y,
267 )
268 }
269 unsafe {
270 let f: Box_<F> = Box_::new(f);
271 connect_raw(
272 self.as_ptr() as *mut _,
273 b"mouse-event\0".as_ptr() as *const _,
274 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
275 mouse_event_trampoline::<Self, F> as *const (),
276 )),
277 Box_::into_raw(f),
278 )
279 }
280 }
281
282 #[cfg(feature = "v1_18")]
283 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
284 #[doc(alias = "scroll-event")]
285 fn connect_scroll_event<F: Fn(&Self, f64, f64, f64, f64) + Send + Sync + 'static>(
286 &self,
287 f: F,
288 ) -> SignalHandlerId {
289 unsafe extern "C" fn scroll_event_trampoline<
290 P: IsA<GLWindow>,
291 F: Fn(&P, f64, f64, f64, f64) + Send + Sync + 'static,
292 >(
293 this: *mut ffi::GstGLWindow,
294 x: std::ffi::c_double,
295 y: std::ffi::c_double,
296 delta_x: std::ffi::c_double,
297 delta_y: std::ffi::c_double,
298 f: glib::ffi::gpointer,
299 ) {
300 let f: &F = &*(f as *const F);
301 f(
302 GLWindow::from_glib_borrow(this).unsafe_cast_ref(),
303 x,
304 y,
305 delta_x,
306 delta_y,
307 )
308 }
309 unsafe {
310 let f: Box_<F> = Box_::new(f);
311 connect_raw(
312 self.as_ptr() as *mut _,
313 b"scroll-event\0".as_ptr() as *const _,
314 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
315 scroll_event_trampoline::<Self, F> as *const (),
316 )),
317 Box_::into_raw(f),
318 )
319 }
320 }
321
322 #[cfg(feature = "v1_20")]
323 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
324 #[doc(alias = "window-handle-changed")]
325 fn connect_window_handle_changed<F: Fn(&Self) + Send + Sync + 'static>(
326 &self,
327 f: F,
328 ) -> SignalHandlerId {
329 unsafe extern "C" fn window_handle_changed_trampoline<
330 P: IsA<GLWindow>,
331 F: Fn(&P) + Send + Sync + 'static,
332 >(
333 this: *mut ffi::GstGLWindow,
334 f: glib::ffi::gpointer,
335 ) {
336 let f: &F = &*(f as *const F);
337 f(GLWindow::from_glib_borrow(this).unsafe_cast_ref())
338 }
339 unsafe {
340 let f: Box_<F> = Box_::new(f);
341 connect_raw(
342 self.as_ptr() as *mut _,
343 b"window-handle-changed\0".as_ptr() as *const _,
344 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
345 window_handle_changed_trampoline::<Self, F> as *const (),
346 )),
347 Box_::into_raw(f),
348 )
349 }
350 }
351}
352
353impl<O: IsA<GLWindow>> GLWindowExt for O {}
354