Skip to main content

gdk4/auto/
surface.rs

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// DO NOT EDIT
4#![allow(deprecated)]
5
6use crate::{
7    CairoContext, Cursor, Device, Display, Event, FrameClock, GLContext, ModifierType, Monitor,
8    VulkanContext, ffi,
9};
10use glib::{
11    object::ObjectType as _,
12    prelude::*,
13    signal::{SignalHandlerId, connect_raw},
14    translate::*,
15};
16use std::boxed::Box as Box_;
17
18glib::wrapper! {
19    #[doc(alias = "GdkSurface")]
20    pub struct Surface(Object<ffi::GdkSurface, ffi::GdkSurfaceClass>);
21
22    match fn {
23        type_ => || ffi::gdk_surface_get_type(),
24    }
25}
26
27impl Surface {
28    pub const NONE: Option<&'static Surface> = None;
29
30    #[doc(alias = "gdk_surface_new_popup")]
31    pub fn new_popup(parent: &impl IsA<Surface>, autohide: bool) -> Surface {
32        skip_assert_initialized!();
33        unsafe {
34            from_glib_full(ffi::gdk_surface_new_popup(
35                parent.as_ref().to_glib_none().0,
36                autohide.into_glib(),
37            ))
38        }
39    }
40
41    #[doc(alias = "gdk_surface_new_toplevel")]
42    pub fn new_toplevel(display: &impl IsA<Display>) -> Surface {
43        skip_assert_initialized!();
44        unsafe {
45            from_glib_full(ffi::gdk_surface_new_toplevel(
46                display.as_ref().to_glib_none().0,
47            ))
48        }
49    }
50}
51
52pub trait SurfaceExt: IsA<Surface> + 'static {
53    #[doc(alias = "gdk_surface_beep")]
54    fn beep(&self) {
55        unsafe {
56            ffi::gdk_surface_beep(self.as_ref().to_glib_none().0);
57        }
58    }
59
60    #[cfg_attr(feature = "v4_18", deprecated = "Since 4.18")]
61    #[allow(deprecated)]
62    #[doc(alias = "gdk_surface_create_cairo_context")]
63    fn create_cairo_context(&self) -> CairoContext {
64        unsafe {
65            from_glib_full(ffi::gdk_surface_create_cairo_context(
66                self.as_ref().to_glib_none().0,
67            ))
68        }
69    }
70
71    #[doc(alias = "gdk_surface_create_gl_context")]
72    fn create_gl_context(&self) -> Result<GLContext, glib::Error> {
73        unsafe {
74            let mut error = std::ptr::null_mut();
75            let ret =
76                ffi::gdk_surface_create_gl_context(self.as_ref().to_glib_none().0, &mut error);
77            if error.is_null() {
78                Ok(from_glib_full(ret))
79            } else {
80                Err(from_glib_full(error))
81            }
82        }
83    }
84
85    #[cfg_attr(feature = "v4_14", deprecated = "Since 4.14")]
86    #[allow(deprecated)]
87    #[doc(alias = "gdk_surface_create_vulkan_context")]
88    fn create_vulkan_context(&self) -> Result<VulkanContext, glib::Error> {
89        unsafe {
90            let mut error = std::ptr::null_mut();
91            let ret =
92                ffi::gdk_surface_create_vulkan_context(self.as_ref().to_glib_none().0, &mut error);
93            if error.is_null() {
94                Ok(from_glib_full(ret))
95            } else {
96                Err(from_glib_full(error))
97            }
98        }
99    }
100
101    #[doc(alias = "gdk_surface_destroy")]
102    fn destroy(&self) {
103        unsafe {
104            ffi::gdk_surface_destroy(self.as_ref().to_glib_none().0);
105        }
106    }
107
108    #[doc(alias = "gdk_surface_get_cursor")]
109    #[doc(alias = "get_cursor")]
110    fn cursor(&self) -> Option<Cursor> {
111        unsafe { from_glib_none(ffi::gdk_surface_get_cursor(self.as_ref().to_glib_none().0)) }
112    }
113
114    #[doc(alias = "gdk_surface_get_device_cursor")]
115    #[doc(alias = "get_device_cursor")]
116    fn device_cursor(&self, device: &impl IsA<Device>) -> Option<Cursor> {
117        unsafe {
118            from_glib_none(ffi::gdk_surface_get_device_cursor(
119                self.as_ref().to_glib_none().0,
120                device.as_ref().to_glib_none().0,
121            ))
122        }
123    }
124
125    #[doc(alias = "gdk_surface_get_device_position")]
126    #[doc(alias = "get_device_position")]
127    fn device_position(&self, device: &impl IsA<Device>) -> Option<(f64, f64, ModifierType)> {
128        unsafe {
129            let mut x = std::mem::MaybeUninit::uninit();
130            let mut y = std::mem::MaybeUninit::uninit();
131            let mut mask = std::mem::MaybeUninit::uninit();
132            let ret = from_glib(ffi::gdk_surface_get_device_position(
133                self.as_ref().to_glib_none().0,
134                device.as_ref().to_glib_none().0,
135                x.as_mut_ptr(),
136                y.as_mut_ptr(),
137                mask.as_mut_ptr(),
138            ));
139            if ret {
140                Some((
141                    x.assume_init(),
142                    y.assume_init(),
143                    from_glib(mask.assume_init()),
144                ))
145            } else {
146                None
147            }
148        }
149    }
150
151    #[doc(alias = "gdk_surface_get_display")]
152    #[doc(alias = "get_display")]
153    fn display(&self) -> Display {
154        unsafe { from_glib_none(ffi::gdk_surface_get_display(self.as_ref().to_glib_none().0)) }
155    }
156
157    #[doc(alias = "gdk_surface_get_frame_clock")]
158    #[doc(alias = "get_frame_clock")]
159    #[doc(alias = "frame-clock")]
160    fn frame_clock(&self) -> FrameClock {
161        unsafe {
162            from_glib_none(ffi::gdk_surface_get_frame_clock(
163                self.as_ref().to_glib_none().0,
164            ))
165        }
166    }
167
168    #[doc(alias = "gdk_surface_get_height")]
169    #[doc(alias = "get_height")]
170    fn height(&self) -> i32 {
171        unsafe { ffi::gdk_surface_get_height(self.as_ref().to_glib_none().0) }
172    }
173
174    #[doc(alias = "gdk_surface_get_mapped")]
175    #[doc(alias = "get_mapped")]
176    #[doc(alias = "mapped")]
177    fn is_mapped(&self) -> bool {
178        unsafe { from_glib(ffi::gdk_surface_get_mapped(self.as_ref().to_glib_none().0)) }
179    }
180
181    #[cfg(feature = "v4_12")]
182    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
183    #[doc(alias = "gdk_surface_get_scale")]
184    #[doc(alias = "get_scale")]
185    fn scale(&self) -> f64 {
186        unsafe { ffi::gdk_surface_get_scale(self.as_ref().to_glib_none().0) }
187    }
188
189    #[doc(alias = "gdk_surface_get_scale_factor")]
190    #[doc(alias = "get_scale_factor")]
191    #[doc(alias = "scale-factor")]
192    fn scale_factor(&self) -> i32 {
193        unsafe { ffi::gdk_surface_get_scale_factor(self.as_ref().to_glib_none().0) }
194    }
195
196    #[doc(alias = "gdk_surface_get_width")]
197    #[doc(alias = "get_width")]
198    fn width(&self) -> i32 {
199        unsafe { ffi::gdk_surface_get_width(self.as_ref().to_glib_none().0) }
200    }
201
202    #[doc(alias = "gdk_surface_hide")]
203    fn hide(&self) {
204        unsafe {
205            ffi::gdk_surface_hide(self.as_ref().to_glib_none().0);
206        }
207    }
208
209    #[doc(alias = "gdk_surface_is_destroyed")]
210    fn is_destroyed(&self) -> bool {
211        unsafe {
212            from_glib(ffi::gdk_surface_is_destroyed(
213                self.as_ref().to_glib_none().0,
214            ))
215        }
216    }
217
218    #[doc(alias = "gdk_surface_queue_render")]
219    fn queue_render(&self) {
220        unsafe {
221            ffi::gdk_surface_queue_render(self.as_ref().to_glib_none().0);
222        }
223    }
224
225    #[doc(alias = "gdk_surface_request_layout")]
226    fn request_layout(&self) {
227        unsafe {
228            ffi::gdk_surface_request_layout(self.as_ref().to_glib_none().0);
229        }
230    }
231
232    #[doc(alias = "gdk_surface_set_cursor")]
233    #[doc(alias = "cursor")]
234    fn set_cursor(&self, cursor: Option<&Cursor>) {
235        unsafe {
236            ffi::gdk_surface_set_cursor(self.as_ref().to_glib_none().0, cursor.to_glib_none().0);
237        }
238    }
239
240    #[doc(alias = "gdk_surface_set_device_cursor")]
241    fn set_device_cursor(&self, device: &impl IsA<Device>, cursor: &Cursor) {
242        unsafe {
243            ffi::gdk_surface_set_device_cursor(
244                self.as_ref().to_glib_none().0,
245                device.as_ref().to_glib_none().0,
246                cursor.to_glib_none().0,
247            );
248        }
249    }
250
251    #[doc(alias = "gdk_surface_set_input_region")]
252    fn set_input_region(&self, region: Option<&cairo::Region>) {
253        unsafe {
254            ffi::gdk_surface_set_input_region(
255                self.as_ref().to_glib_none().0,
256                mut_override(region.to_glib_none().0),
257            );
258        }
259    }
260
261    #[cfg_attr(feature = "v4_16", deprecated = "Since 4.16")]
262    #[allow(deprecated)]
263    #[doc(alias = "gdk_surface_set_opaque_region")]
264    fn set_opaque_region(&self, region: Option<&cairo::Region>) {
265        unsafe {
266            ffi::gdk_surface_set_opaque_region(
267                self.as_ref().to_glib_none().0,
268                mut_override(region.to_glib_none().0),
269            );
270        }
271    }
272
273    #[doc(alias = "enter-monitor")]
274    fn connect_enter_monitor<F: Fn(&Self, &Monitor) + 'static>(&self, f: F) -> SignalHandlerId {
275        unsafe extern "C" fn enter_monitor_trampoline<
276            P: IsA<Surface>,
277            F: Fn(&P, &Monitor) + 'static,
278        >(
279            this: *mut ffi::GdkSurface,
280            monitor: *mut ffi::GdkMonitor,
281            f: glib::ffi::gpointer,
282        ) {
283            unsafe {
284                let f: &F = &*(f as *const F);
285                f(
286                    Surface::from_glib_borrow(this).unsafe_cast_ref(),
287                    &from_glib_borrow(monitor),
288                )
289            }
290        }
291        unsafe {
292            let f: Box_<F> = Box_::new(f);
293            connect_raw(
294                self.as_ptr() as *mut _,
295                c"enter-monitor".as_ptr(),
296                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
297                    enter_monitor_trampoline::<Self, F> as *const (),
298                )),
299                Box_::into_raw(f),
300            )
301        }
302    }
303
304    #[doc(alias = "event")]
305    fn connect_event<F: Fn(&Self, &Event) -> bool + 'static>(&self, f: F) -> SignalHandlerId {
306        unsafe extern "C" fn event_trampoline<
307            P: IsA<Surface>,
308            F: Fn(&P, &Event) -> bool + 'static,
309        >(
310            this: *mut ffi::GdkSurface,
311            event: *mut ffi::GdkEvent,
312            f: glib::ffi::gpointer,
313        ) -> glib::ffi::gboolean {
314            unsafe {
315                let f: &F = &*(f as *const F);
316                f(
317                    Surface::from_glib_borrow(this).unsafe_cast_ref(),
318                    &from_glib_borrow(event),
319                )
320                .into_glib()
321            }
322        }
323        unsafe {
324            let f: Box_<F> = Box_::new(f);
325            connect_raw(
326                self.as_ptr() as *mut _,
327                c"event".as_ptr(),
328                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
329                    event_trampoline::<Self, F> as *const (),
330                )),
331                Box_::into_raw(f),
332            )
333        }
334    }
335
336    #[doc(alias = "layout")]
337    fn connect_layout<F: Fn(&Self, i32, i32) + 'static>(&self, f: F) -> SignalHandlerId {
338        unsafe extern "C" fn layout_trampoline<P: IsA<Surface>, F: Fn(&P, i32, i32) + 'static>(
339            this: *mut ffi::GdkSurface,
340            width: std::ffi::c_int,
341            height: std::ffi::c_int,
342            f: glib::ffi::gpointer,
343        ) {
344            unsafe {
345                let f: &F = &*(f as *const F);
346                f(
347                    Surface::from_glib_borrow(this).unsafe_cast_ref(),
348                    width,
349                    height,
350                )
351            }
352        }
353        unsafe {
354            let f: Box_<F> = Box_::new(f);
355            connect_raw(
356                self.as_ptr() as *mut _,
357                c"layout".as_ptr(),
358                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
359                    layout_trampoline::<Self, F> as *const (),
360                )),
361                Box_::into_raw(f),
362            )
363        }
364    }
365
366    #[doc(alias = "leave-monitor")]
367    fn connect_leave_monitor<F: Fn(&Self, &Monitor) + 'static>(&self, f: F) -> SignalHandlerId {
368        unsafe extern "C" fn leave_monitor_trampoline<
369            P: IsA<Surface>,
370            F: Fn(&P, &Monitor) + 'static,
371        >(
372            this: *mut ffi::GdkSurface,
373            monitor: *mut ffi::GdkMonitor,
374            f: glib::ffi::gpointer,
375        ) {
376            unsafe {
377                let f: &F = &*(f as *const F);
378                f(
379                    Surface::from_glib_borrow(this).unsafe_cast_ref(),
380                    &from_glib_borrow(monitor),
381                )
382            }
383        }
384        unsafe {
385            let f: Box_<F> = Box_::new(f);
386            connect_raw(
387                self.as_ptr() as *mut _,
388                c"leave-monitor".as_ptr(),
389                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
390                    leave_monitor_trampoline::<Self, F> as *const (),
391                )),
392                Box_::into_raw(f),
393            )
394        }
395    }
396
397    #[doc(alias = "render")]
398    fn connect_render<F: Fn(&Self, &cairo::Region) -> bool + 'static>(
399        &self,
400        f: F,
401    ) -> SignalHandlerId {
402        unsafe extern "C" fn render_trampoline<
403            P: IsA<Surface>,
404            F: Fn(&P, &cairo::Region) -> bool + 'static,
405        >(
406            this: *mut ffi::GdkSurface,
407            region: *mut cairo::ffi::cairo_region_t,
408            f: glib::ffi::gpointer,
409        ) -> glib::ffi::gboolean {
410            unsafe {
411                let f: &F = &*(f as *const F);
412                f(
413                    Surface::from_glib_borrow(this).unsafe_cast_ref(),
414                    &from_glib_borrow(region),
415                )
416                .into_glib()
417            }
418        }
419        unsafe {
420            let f: Box_<F> = Box_::new(f);
421            connect_raw(
422                self.as_ptr() as *mut _,
423                c"render".as_ptr(),
424                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
425                    render_trampoline::<Self, F> as *const (),
426                )),
427                Box_::into_raw(f),
428            )
429        }
430    }
431
432    #[doc(alias = "cursor")]
433    fn connect_cursor_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
434        unsafe extern "C" fn notify_cursor_trampoline<P: IsA<Surface>, F: Fn(&P) + 'static>(
435            this: *mut ffi::GdkSurface,
436            _param_spec: glib::ffi::gpointer,
437            f: glib::ffi::gpointer,
438        ) {
439            unsafe {
440                let f: &F = &*(f as *const F);
441                f(Surface::from_glib_borrow(this).unsafe_cast_ref())
442            }
443        }
444        unsafe {
445            let f: Box_<F> = Box_::new(f);
446            connect_raw(
447                self.as_ptr() as *mut _,
448                c"notify::cursor".as_ptr(),
449                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
450                    notify_cursor_trampoline::<Self, F> as *const (),
451                )),
452                Box_::into_raw(f),
453            )
454        }
455    }
456
457    #[doc(alias = "height")]
458    fn connect_height_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
459        unsafe extern "C" fn notify_height_trampoline<P: IsA<Surface>, F: Fn(&P) + 'static>(
460            this: *mut ffi::GdkSurface,
461            _param_spec: glib::ffi::gpointer,
462            f: glib::ffi::gpointer,
463        ) {
464            unsafe {
465                let f: &F = &*(f as *const F);
466                f(Surface::from_glib_borrow(this).unsafe_cast_ref())
467            }
468        }
469        unsafe {
470            let f: Box_<F> = Box_::new(f);
471            connect_raw(
472                self.as_ptr() as *mut _,
473                c"notify::height".as_ptr(),
474                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
475                    notify_height_trampoline::<Self, F> as *const (),
476                )),
477                Box_::into_raw(f),
478            )
479        }
480    }
481
482    #[doc(alias = "mapped")]
483    fn connect_mapped_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
484        unsafe extern "C" fn notify_mapped_trampoline<P: IsA<Surface>, F: Fn(&P) + 'static>(
485            this: *mut ffi::GdkSurface,
486            _param_spec: glib::ffi::gpointer,
487            f: glib::ffi::gpointer,
488        ) {
489            unsafe {
490                let f: &F = &*(f as *const F);
491                f(Surface::from_glib_borrow(this).unsafe_cast_ref())
492            }
493        }
494        unsafe {
495            let f: Box_<F> = Box_::new(f);
496            connect_raw(
497                self.as_ptr() as *mut _,
498                c"notify::mapped".as_ptr(),
499                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
500                    notify_mapped_trampoline::<Self, F> as *const (),
501                )),
502                Box_::into_raw(f),
503            )
504        }
505    }
506
507    #[cfg(feature = "v4_12")]
508    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
509    #[doc(alias = "scale")]
510    fn connect_scale_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
511        unsafe extern "C" fn notify_scale_trampoline<P: IsA<Surface>, F: Fn(&P) + 'static>(
512            this: *mut ffi::GdkSurface,
513            _param_spec: glib::ffi::gpointer,
514            f: glib::ffi::gpointer,
515        ) {
516            unsafe {
517                let f: &F = &*(f as *const F);
518                f(Surface::from_glib_borrow(this).unsafe_cast_ref())
519            }
520        }
521        unsafe {
522            let f: Box_<F> = Box_::new(f);
523            connect_raw(
524                self.as_ptr() as *mut _,
525                c"notify::scale".as_ptr(),
526                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
527                    notify_scale_trampoline::<Self, F> as *const (),
528                )),
529                Box_::into_raw(f),
530            )
531        }
532    }
533
534    #[doc(alias = "scale-factor")]
535    fn connect_scale_factor_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
536        unsafe extern "C" fn notify_scale_factor_trampoline<
537            P: IsA<Surface>,
538            F: Fn(&P) + 'static,
539        >(
540            this: *mut ffi::GdkSurface,
541            _param_spec: glib::ffi::gpointer,
542            f: glib::ffi::gpointer,
543        ) {
544            unsafe {
545                let f: &F = &*(f as *const F);
546                f(Surface::from_glib_borrow(this).unsafe_cast_ref())
547            }
548        }
549        unsafe {
550            let f: Box_<F> = Box_::new(f);
551            connect_raw(
552                self.as_ptr() as *mut _,
553                c"notify::scale-factor".as_ptr(),
554                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
555                    notify_scale_factor_trampoline::<Self, F> as *const (),
556                )),
557                Box_::into_raw(f),
558            )
559        }
560    }
561
562    #[doc(alias = "width")]
563    fn connect_width_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
564        unsafe extern "C" fn notify_width_trampoline<P: IsA<Surface>, F: Fn(&P) + 'static>(
565            this: *mut ffi::GdkSurface,
566            _param_spec: glib::ffi::gpointer,
567            f: glib::ffi::gpointer,
568        ) {
569            unsafe {
570                let f: &F = &*(f as *const F);
571                f(Surface::from_glib_borrow(this).unsafe_cast_ref())
572            }
573        }
574        unsafe {
575            let f: Box_<F> = Box_::new(f);
576            connect_raw(
577                self.as_ptr() as *mut _,
578                c"notify::width".as_ptr(),
579                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
580                    notify_width_trampoline::<Self, F> as *const (),
581                )),
582                Box_::into_raw(f),
583            )
584        }
585    }
586}
587
588impl<O: IsA<Surface>> SurfaceExt for O {}