GithubHelp home page GithubHelp logo

Add bindings to save* functions about gtk3-rs HOT 10 CLOSED

Sh4rK avatar Sh4rK commented on August 25, 2024 1
Add bindings to save* functions

from gtk3-rs.

Comments (10)

EPashkin avatar EPashkin commented on August 25, 2024 1

I mean that gdk_pixbuf_save have at minimum 5 parameters.
gdk_pixbuf_save(pb, save_path.as_ptr(), format.as_ptr(), err_[or]_, ptr::null_mut());

from gtk3-rs.

gkoz avatar gkoz commented on August 25, 2024 1

The difficulty with varargs is why they provide the _savev and other ...v functions. I believe there are translation implementations for &[&str] to char** so this should be doable.

from gtk3-rs.

occamz avatar occamz commented on August 25, 2024

Second that! I've been trying to capture a screenshot using the functions through gdk_pixbuf_sys:

let save_path = CString::new("--full-path-to-file--").unwrap();
let format = CString::new("png").unwrap();

gdk::init();

let desktop = gdk::Window::get_default_root_window();

//Init "empty" GError object
let msg = ptr::null_mut::<i8>();
let b = Box::new(GError { domain: 0, code: 0, message: msg });
let error: *mut *mut GError = &mut Box::into_raw(b);
//Result: (gdk_testing:5953): GdkPixbuf-CRITICAL **: gdk_pixbuf_save: assertion 'error == NULL || *error == NULL' failed

//GError *err = NULL;
let err = &mut ptr::null_mut::<GError>();
//Result: Process didn't exit successfully: target/debug/gdk_testing (signal: 11, SIGSEGV: invalid memory reference)

unsafe {
    let pb = gdk_pixbuf_get_from_window(gdk_get_default_root_window(), 0, 0, desktop.get_width(), desktop.get_height());
    println!("Channels: {}", gdk_pixbuf_get_n_channels(pb));
    gdk_pixbuf_save(pb, save_path.as_ptr(), format.as_ptr(), err_[or]_);

    println!("{}x{}", desktop.get_width(), desktop.get_height());
}

When I use the error variable as input to the save function I get

Result: (gdk_testing:5953): GdkPixbuf-CRITICAL **: gdk_pixbuf_save: assertion 'error == NULL || *error == NULL' failed

and for the err variable

Result: Process didn't exit successfully: target/debug/gdk_testing (signal: 11, SIGSEGV: invalid memory reference)

Probably my usage of GError, got any tips?

from gtk3-rs.

EPashkin avatar EPashkin commented on August 25, 2024

You need error argument be null or pointer to null. We have rust class Error as wrapper.

    pub fn load_from_path(&self, path: &str) -> Result<(), Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let _ = ffi::gtk_css_provider_load_from_path(self.to_glib_none().0, path.to_glib_none().0, &mut error);
            if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) }
        }
    }

from gtk3-rs.

EPashkin avatar EPashkin commented on August 25, 2024

Missed that you tried both cases :(
May be problem with last parameter, you tried pass ptr::null_mut() after error?

from gtk3-rs.

occamz avatar occamz commented on August 25, 2024

I saw the Error struct when I searched through all sources for any reference or abstraction of GError, but I wasn't able to use it with the lower level _sys functions. Is there some way I could create an Error and convert it to GError and pass it to the _sys functions?

I tried using ptr::null_mut() instead of &mut ptr::null_mut::<GError>()which compiled but resulted in the same segfault.

Thanks for a response :)

from gtk3-rs.

occamz avatar occamz commented on August 25, 2024

Thank you! I can't believe I didn't understand that the "..." ment options until NULL. I went with let null: *const i32 = ptr::null(); and it worked!

Awesome :D

from gtk3-rs.

EPashkin avatar EPashkin commented on August 25, 2024

"..." is main problem why no save_* currently, almost only gdk_pixbuf_savev can be added 😢

from gtk3-rs.

occamz avatar occamz commented on August 25, 2024

Yeah, it's a really weird way to specify parameters :/ so it isn't technically possible to do that through Rust in a reliable way? I'm really new to it...

from gtk3-rs.

sdroege avatar sdroege commented on August 25, 2024

There are various save functions now.

from gtk3-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.