New Release
gtk4-rs 0.9
and gtk-rs-core 0.20
were just freshly released, just in time
for also being included in the GNOME 47 release.
This release is again relatively small, mostly providing bindings to new APIs
and improvements to the glib::clone!
and glib::closure!
macros to work
better with cargo fmt
and rust-analyzer.
As usual, at the same time gstreamer-rs 0.23
and gst-plugins-rs 0.13
,
libadwaita 0.7
and other related crates got a new release compatible with
the new gtk4-rs and gtk-rs-core releases and their own set of changes.
gtk-rs-core §
New syntax for glib::clone!
and glib::closure!
§
The syntax for the clone!
and closure!
macros was updated to look more
like valid Rust code, and as a side effect it is also handled correctly by
cargo fmt
, rust-analyzer and other tooling now.
The old syntax is still supported but will give a deprecation warning.
To get an idea of the change, what previously looked like:
clone!(@strong self as obj, @weak v => @default-return false, move |x| {
println!("obj: {}, v: {}, x: {}", obj, v, x);
true
})
would now look like this:
clone!(
#[strong(rename_to = obj)]
self,
#[weak]
v,
#[upgrade_or]
false,
move |x| {
println!("obj: {}, v: {}, x: {}", obj, v, x);
true
},
);
Check the documentation for more details about the new syntax.
GLib 2.82 APIs §
New GLib and GIO 2.82 APIs are supported with this release. GLib 2.56 is still the minimum version supported by the bindings.
Trait re-organization for defining new GObject interfaces §
The traits for defining new GObject interfaces were slightly re-organized to make them more similar with the ones for defining new GObjects.
Previously one would write:
#[derive(Clone, Copy)]
#[repr(C)]
pub struct MyStaticInterface {
parent: glib::gobject_ffi::GTypeInterface,
}
#[glib::object_interface]
unsafe impl ObjectInterface for MyStaticInterface {
const NAME: &'static str = "MyStaticInterface";
}
This would now become:
#[derive(Clone, Copy)]
#[repr(C)]
pub struct MyStaticInterfaceClass {
parent: glib::gobject_ffi::GTypeInterface,
}
unsafe impl InterfaceStruct for MyStaticInterfaceClass {
type Type = MyStaticInterface;
}
pub enum MyStaticInterface {}
#[glib::object_interface]
impl ObjectInterface for MyStaticInterface {
const NAME: &'static str = "MyStaticInterface";
type Interface = MyStaticInterfaceClass;
}
While it is a bit more code, this is almost the same as for GObjects now.
Safer borrowing of GObjects and other types from FFI code §
It is possible to directly borrow GObjects and other types in FFI code without additional refcounting or copying. In previous releases the API for that was completely based on pointers, which allowed to accidentally create dangling pointers without the compiler being able to help.
let obj = {
let mut ptr: *mut glib::ffi::GObject = ...;
let obj: &glib::Object = glib::Object::from_glib_ptr_borrow(&mut ptr);
obj
};
// At this point `obj` is pointing at a stack frame that does not exist anymore
Starting with this release, a reference to a pointer is used instead to avoid this from happening. The above code would not compile anymore. Previously the lifetime of the returned object would be arbitrary, now it is bound strictly to the lifetime of the pointer.
Code using this API likely does not need any changes unless the code was previously wrong.
gtk4-rs §
GTK 4.16 APIs §
New GTK 4.16 APIs are supported with this release. GTK 4.0 is still the minimum version supported by the bindings.
Changes §
For the interested ones, here is the list of the merged pull requests:
- Update to new clone! macro syntax
- book: Fix typo
- Remove unnecessary upcast from examples/squeezer_bin/main.rs
- typos: Ignore versions.txt file
- examples/squeezer_bin: Mark properties as writable
- Fix
SqueezerBin::size\_allocate()
in example - Stop renaming ffi crates
- custom_orientable: Fix interface property override
- gtk: Implement Downgrade for TemplateChild<T>
- Update list_widgets.md
- examples: Support GL >= 3.1 and GLES >= 3.0 in the glium example
- Update link for Cogitri/Health to World/Health
- Simplify reading file contents to a String
- macros: Drop anyhow dependency
- Fix typo in todo_1.md
- gtk4: Manually implement
GraphicsOffload
constructor for now - gtk4: Require GDK 4.14 when enabling the
v4\_14
feature - macros: Drop macro-proc-error and upgrade syn to 2.0
- dockerfile: Update libadwaita to 1.5
- docs: fix
Path
setting on windows - Correctly handle
NULL
GError\*\*
out parameters - Replace simple
impl Debug
with derivedDebug
in tokio example - Simplify library configuration step for Windows
- docs: Run on our container image
- gio: Add a method to get a stream of incoming connections to SocketListener
- glib: Add support for registering GTypes with name conflicts
- glib: Make
TypeData
struct fields private - glib-macros: Don’t produce unnecessary braces in
clone!(async move { x })
- Update to system-deps 7
- glib-macros: Fix unit return in
closure!()
macro - strv: add From implementation from a String array
- Derive TransparentPtrType trait for Boxed
- gio: Properly export Win32InputStream / Win32OutputStream traits
- Update
clone!
andclosure!
macro to new syntax - Stop renaming ffi crates
- gio: remove Send + Sync requirements from DBusConnection::register_ob…
- spell fix
- gio: make DBusConnection::register_object take optional clousures
- glib: Add unsafe
Value::into\_send\_value()
- glib: Improve
ValueArray
API, add tests and assertions for invalid … - glib: Fix
MatchInfo::next()
handling of returningFALSE
- glib/functions: add compute_checksum_for_string
- glib: Add bindings for
g\_value\_set\_static\_string()
- docs: Fix broken links / cleanup README
- glib: Implement Sync for ThreadGuard
- glib: Only implement Send on JoinHandle if the result is Send
- glib: Decouple ObjectInterface impl from interface class struct
- glib: Add missing Send bound to the output type of the
spawn\_from\_within()
future - glib-macros: Refactor parsing code of object_subclass/object_interface
- examples: Add example for custom class structs and virtual methods
- ObjectBuilder: add property_if(), property_if_some(), property_from_iter() \& property_if_not_empty()
- glib: Don’t use
g\_object\_list\_properties()
for setting properties - glib: Use a reference to a pointer of correct mutability for from_glib_ptr_borrow()
- glib: Re-add and rename manual Win32 API additions
- glib-macros/properties: Allow structs with no properties
- glib::wrapper: Add docs for impls generated by the wrapper macro
- glib-sys: Add missing includes in
manual.h
- glib-sys: fix struct size mismatches
- glib: Freeze property notifications while setting multiple properties
- glib-macros: Improve error message when
Properties
struct doesn’t have at least one#\[property(…)\]
- docs:
construct
attribute forglib::Properties
- glib: fix UB in VariantStrIter::impl_get
- glib: Don’t misuse
slice::get\_unchecked()
- gio: correctly free argument list items
- glib: Optimize string collation bindings a bit
- glib: Drop the main context future return value sender on finalize
- pango: add some missing AttrInt constructors.
- glib: Embed docs for ParamSpec types
- glib: Requires Upgrade on Downgrade::Weak type
- macros: allow to specify #[default] for glib::flags
- glib: Add
Quark::from\_static\_str()
- docs: Move metadata back to packages
- cairo: Fix version of the v1_18 feature
- Document values of Continue and Break
All this was possible thanks to the gtk-rs/gir project as well:
- Minor cleanup to use
is\_some\_and(...)
instead ofmap\_or(false, ...)
- Update to system-deps 7
- More docs improvements
- codegen: Handle mangled types names
- members: drop useless alias config
- Various properties fixes
- codegen: Avoid double alias on badly annotated fn
- Use getter and setter annotations
- Support finish-func annotation
- codegen: Stop renaming ffi crate
- Use final annotation
- Add support for
libc::time\_t
and related types - Revert Automatically assume that win32_ and unix_ should use the related cfg
- Correctly generate cfg condition for ABI tests
- Generate cfgs with
update\_cfgs
on enums as well
Thanks to all of our contributors for their (awesome!) work on this release: