spice-client-glib 0.8.0

Rust bindings for the Spice client library
Documentation
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// DO NOT EDIT
#![allow(deprecated)]

use crate::{ffi, Channel, DisplayPrimary, GlScanout};
use glib::{
    object::ObjectType as _,
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    #[doc(alias = "SpiceDisplayChannel")]
    pub struct DisplayChannel(Object<ffi::SpiceDisplayChannel, ffi::SpiceDisplayChannelClass>) @extends Channel;

    match fn {
        type_ => || ffi::spice_display_channel_get_type(),
    }
}

impl DisplayChannel {
    #[doc(alias = "spice_display_channel_change_preferred_compression")]
    #[doc(alias = "display_channel_change_preferred_compression")]
    pub fn change_preferred_compression(&self, compression: i32) {
        unsafe {
            ffi::spice_display_channel_change_preferred_compression(
                self.to_glib_none().0,
                compression,
            );
        }
    }

    #[doc(alias = "spice_display_channel_change_preferred_video_codec_types")]
    #[doc(alias = "display_channel_change_preferred_video_codec_types")]
    pub fn change_preferred_video_codec_types(&self, codecs: &[i32]) -> Result<(), glib::Error> {
        let ncodecs = codecs.len() as _;
        unsafe {
            let mut error = std::ptr::null_mut();
            let is_ok = ffi::spice_display_channel_change_preferred_video_codec_types(
                self.to_glib_none().0,
                codecs.to_glib_none().0,
                ncodecs,
                &mut error,
            );
            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    #[doc(alias = "spice_display_channel_get_primary")]
    #[doc(alias = "display_channel_get_primary")]
    pub fn get_primary(
        &self,
        surface_id: u32,
        primary: &mut DisplayPrimary,
    ) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib::result_from_gboolean!(
                ffi::spice_display_channel_get_primary(
                    self.to_glib_none().0,
                    surface_id,
                    primary.to_glib_none_mut().0
                ),
                "No primary surface"
            )
        }
    }

    #[cfg_attr(feature = "v0_43", deprecated = "Since 0.43")]
    #[allow(deprecated)]
    #[doc(alias = "spice_display_channel_get_gl_scanout")]
    #[doc(alias = "get_gl_scanout")]
    #[doc(alias = "gl-scanout")]
    pub fn gl_scanout(&self) -> Option<GlScanout> {
        unsafe {
            from_glib_none(ffi::spice_display_channel_get_gl_scanout(
                self.to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "spice_display_channel_gl_draw_done")]
    pub fn gl_draw_done(&self) {
        unsafe {
            ffi::spice_display_channel_gl_draw_done(self.to_glib_none().0);
        }
    }

    pub fn height(&self) -> u32 {
        ObjectExt::property(self, "height")
    }

    #[doc(alias = "monitors-max")]
    pub fn monitors_max(&self) -> u32 {
        ObjectExt::property(self, "monitors-max")
    }

    pub fn width(&self) -> u32 {
        ObjectExt::property(self, "width")
    }

    #[doc(alias = "display-invalidate")]
    pub fn connect_display_invalidate<F: Fn(&Self, i32, i32, i32, i32) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn display_invalidate_trampoline<
            F: Fn(&DisplayChannel, i32, i32, i32, i32) + 'static,
        >(
            this: *mut ffi::SpiceDisplayChannel,
            x: std::ffi::c_int,
            y: std::ffi::c_int,
            width: std::ffi::c_int,
            height: std::ffi::c_int,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(&from_glib_borrow(this), x, y, width, height)
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"display-invalidate".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    display_invalidate_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "display-mark")]
    pub fn connect_display_mark<F: Fn(&Self, i32) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn display_mark_trampoline<F: Fn(&DisplayChannel, i32) + 'static>(
            this: *mut ffi::SpiceDisplayChannel,
            mark: std::ffi::c_int,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(&from_glib_borrow(this), mark)
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"display-mark".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    display_mark_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "display-primary-destroy")]
    pub fn connect_display_primary_destroy<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn display_primary_destroy_trampoline<
            F: Fn(&DisplayChannel) + 'static,
        >(
            this: *mut ffi::SpiceDisplayChannel,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(&from_glib_borrow(this))
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"display-primary-destroy".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    display_primary_destroy_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "gl-draw")]
    pub fn connect_gl_draw<F: Fn(&Self, u32, u32, u32, u32) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn gl_draw_trampoline<
            F: Fn(&DisplayChannel, u32, u32, u32, u32) + 'static,
        >(
            this: *mut ffi::SpiceDisplayChannel,
            x: std::ffi::c_uint,
            y: std::ffi::c_uint,
            width: std::ffi::c_uint,
            height: std::ffi::c_uint,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(&from_glib_borrow(this), x, y, width, height)
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"gl-draw".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    gl_draw_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    //#[doc(alias = "gst-video-overlay")]
    //pub fn connect_gst_video_overlay<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId {
    //    Ignored pipeline: Gst.Pipeline
    //}

    #[doc(alias = "gl-scanout")]
    pub fn connect_gl_scanout_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_gl_scanout_trampoline<F: Fn(&DisplayChannel) + 'static>(
            this: *mut ffi::SpiceDisplayChannel,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(&from_glib_borrow(this))
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::gl-scanout".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_gl_scanout_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "height")]
    pub fn connect_height_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_height_trampoline<F: Fn(&DisplayChannel) + 'static>(
            this: *mut ffi::SpiceDisplayChannel,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(&from_glib_borrow(this))
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::height".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_height_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "monitors")]
    pub fn connect_monitors_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_monitors_trampoline<F: Fn(&DisplayChannel) + 'static>(
            this: *mut ffi::SpiceDisplayChannel,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(&from_glib_borrow(this))
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::monitors".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_monitors_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "monitors-max")]
    pub fn connect_monitors_max_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_monitors_max_trampoline<F: Fn(&DisplayChannel) + 'static>(
            this: *mut ffi::SpiceDisplayChannel,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(&from_glib_borrow(this))
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::monitors-max".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_monitors_max_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "width")]
    pub fn connect_width_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_width_trampoline<F: Fn(&DisplayChannel) + 'static>(
            this: *mut ffi::SpiceDisplayChannel,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(&from_glib_borrow(this))
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::width".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_width_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}