Skip to content

Commit

Permalink
Merge pull request #506 from gtk-rs/bilelmoussaoui/gdk-drop-fixes
Browse files Browse the repository at this point in the history
Drop api fixes
  • Loading branch information
sdroege authored Jul 12, 2021
2 parents 2cb43db + 67894aa commit e79791a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 60 deletions.
5 changes: 4 additions & 1 deletion gdk4/Gir.toml
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,10 @@ name = "Gdk.Drop"
status = "generate"
[[object.function]]
name = "read_async"
manual = true # const ptr
manual = true # don't require Send
[[object.function]]
name = "read_value_async"
manual = true # don't require Send

[[object]]
name = "Gdk.Event"
Expand Down
58 changes: 0 additions & 58 deletions gdk4/src/auto/drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ use crate::Display;
use crate::Drag;
use crate::DragAction;
use crate::Surface;
use glib::object::IsA;
use glib::object::ObjectType as ObjectType_;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem::transmute;
use std::pin::Pin;
use std::ptr;

glib::wrapper! {
#[doc(alias = "GdkDrop")]
Expand Down Expand Up @@ -72,61 +69,6 @@ impl Drop {
unsafe { from_glib_none(ffi::gdk_drop_get_surface(self.to_glib_none().0)) }
}

#[doc(alias = "gdk_drop_read_value_async")]
pub fn read_value_async<
P: IsA<gio::Cancellable>,
Q: FnOnce(Result<glib::Value, glib::Error>) + Send + 'static,
>(
&self,
type_: glib::types::Type,
io_priority: glib::Priority,
cancellable: Option<&P>,
callback: Q,
) {
let user_data: Box_<Q> = Box_::new(callback);
unsafe extern "C" fn read_value_async_trampoline<
Q: FnOnce(Result<glib::Value, glib::Error>) + Send + 'static,
>(
_source_object: *mut glib::gobject_ffi::GObject,
res: *mut gio::ffi::GAsyncResult,
user_data: glib::ffi::gpointer,
) {
let mut error = ptr::null_mut();
let ret = ffi::gdk_drop_read_value_finish(_source_object as *mut _, res, &mut error);
let result = if error.is_null() {
Ok(from_glib_none(ret))
} else {
Err(from_glib_full(error))
};
let callback: Box_<Q> = Box_::from_raw(user_data as *mut _);
callback(result);
}
let callback = read_value_async_trampoline::<Q>;
unsafe {
ffi::gdk_drop_read_value_async(
self.to_glib_none().0,
type_.into_glib(),
io_priority.into_glib(),
cancellable.map(|p| p.as_ref()).to_glib_none().0,
Some(callback),
Box_::into_raw(user_data) as *mut _,
);
}
}

pub fn read_value_async_future(
&self,
type_: glib::types::Type,
io_priority: glib::Priority,
) -> Pin<Box_<dyn std::future::Future<Output = Result<glib::Value, glib::Error>> + 'static>>
{
Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
obj.read_value_async(type_, io_priority, Some(cancellable), move |res| {
send.resolve(res);
});
}))
}

#[doc(alias = "gdk_drop_status")]
pub fn status(&self, actions: DragAction, preferred: DragAction) {
unsafe {
Expand Down
57 changes: 56 additions & 1 deletion gdk4/src/drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Drop {
&mut error,
);
let result = if error.is_null() {
Ok((from_glib_full(ret), from_glib_full(out_mime_type)))
Ok((from_glib_full(ret), from_glib_none(out_mime_type)))
} else {
Err(from_glib_full(error))
};
Expand Down Expand Up @@ -79,4 +79,59 @@ impl Drop {
});
}))
}

#[doc(alias = "gdk_drop_read_value_async")]
pub fn read_value_async<
P: IsA<gio::Cancellable>,
Q: FnOnce(Result<glib::Value, glib::Error>) + 'static,
>(
&self,
type_: glib::types::Type,
io_priority: glib::Priority,
cancellable: Option<&P>,
callback: Q,
) {
let user_data: Box<Q> = Box::new(callback);
unsafe extern "C" fn read_value_async_trampoline<
Q: FnOnce(Result<glib::Value, glib::Error>) + 'static,
>(
_source_object: *mut glib::gobject_ffi::GObject,
res: *mut gio::ffi::GAsyncResult,
user_data: glib::ffi::gpointer,
) {
let mut error = ptr::null_mut();
let ret = ffi::gdk_drop_read_value_finish(_source_object as *mut _, res, &mut error);
let result = if error.is_null() {
Ok(from_glib_none(ret))
} else {
Err(from_glib_full(error))
};
let callback: Box<Q> = Box::from_raw(user_data as *mut _);
callback(result);
}
let callback = read_value_async_trampoline::<Q>;
unsafe {
ffi::gdk_drop_read_value_async(
self.to_glib_none().0,
type_.into_glib(),
io_priority.into_glib(),
cancellable.map(|p| p.as_ref()).to_glib_none().0,
Some(callback),
Box::into_raw(user_data) as *mut _,
);
}
}

pub fn read_value_async_future(
&self,
type_: glib::types::Type,
io_priority: glib::Priority,
) -> Pin<Box<dyn std::future::Future<Output = Result<glib::Value, glib::Error>> + 'static>>
{
Box::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
obj.read_value_async(type_, io_priority, Some(cancellable), move |res| {
send.resolve(res);
});
}))
}
}

0 comments on commit e79791a

Please sign in to comment.