New Release
It is time again for a new gtk-rs release!
If you have been watching our crates on crates.io closely or if you have attended GUADEC you may already have noticed that we have released new versions of the gtk-rs crates.
The new versions contain less breaking changes than some of our previous releases, so updating will be easier. The release however does include some nice improvements that can simplify your application as well as support the latest API additions of the underlying libraries.
As anticipated in the previous release, this will likely be the last release of the gtk3-rs bindings and we recommend to everyone to upgrade to GTK4. If you require gtk3-rs to keep up with new versions of gtk-rs-core please consider volunteering to help with maintenance of the project.
Increase of the minimum supported Rust version (MSRV) §
With this release, Rust 1.70 is the minimum version required to compile and use the bindings.
Supported versions §
- glib/gio: from version 2.56 to 2.78
- cairo: 1.16
- pango/pangocairo: from version 1.40 to the to be released 1.52
- gdk-pixbuf: from version 2.36 to 2.42
- graphene: from version 1.10 to 1.12
- gtk4: from 4.0 to 4.12 with minimal support of the upcoming 4.14 release
- gtk3: from 3.22
Documentation improvements §
In this release, we also started a slow but steady path towards automatically generating subclassing traits. The first step is to parse the corresponding virtual methods data from the GIR file and embed the documentation for these functions to their corresponding Rust functions like we do for normal functions/methods/types.
We also now embed the documentation for Class methods. See https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/subclass/widget/trait.WidgetClassExt.html#method.install_property_action
Last but not least, libraries depending on gtk-rs libraries can now have their documentation published in docs.rs by adding the following to your Cargo.toml.
[package.metadata.docs.rs]
all-features = true
rustc-args = ["--cfg", "docsrs"]
rustdoc-args = ["--cfg", "docsrs"]
features = []
Switch to bitflags 2.0 §
With this release we switched to version 2 of the bitflags crate. While we regularly update our dependencies to the latest version, this is of particular note since flag types are often used in glib and GTK API.
We also re-export bitflags
and once_cell
from the glib
crate so you can use them without directly depending on them.
gtk-rs-core §
New glib::derived_properties
macro §
With the glib::Properties
derive macro added in the last release, you still had to write these blanket functions manually
impl ObjectImpl for T {
fn properties() -> &'static [glib::ParamSpec] {
Self::derived_properties()
}
fn set_property(&self, id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
self.derived_set_property(id, value, pspec)
}
fn property(&self, id: usize, pspec: &glib::ParamSpec) -> glib::Value {
self.derived_property(id, pspec)
}
}
Now you can replace that code with
#[glib::derived_properties]
impl ObjectImpl for T {}
Replacement of glib::Continue
/ glib::Inhibit
§
These two types were a bit difficult to understand, as you had to pass a boolean glib::Continue(true)
/ glib::Inhibit(false)
. We replaced them with new enums
glib::Continue(true) -> glib::ControlFlow::Continue
glib::Continue(false) -> glib::ControlFlow::Break
glib::Inhibit(true) -> glib::Propagation::Stop
glib::Inhibit(false) -> glib::Propagation::Proceed
Making the meaning of each value clearer to the developer. This should be the most annoying change you need to do during the update to this release.
Typed constructors §
In the past we had a bunch of constructors taking glib::Type
as a parameter instead of T: impl StaticType
/ T: impl IsA<O>
. For this release, we cleaned up several of those constructors.
let model = gio::ListStore::new(SomeObject::static_type()); // before
let model = gio::ListStore::new::<SomeObject>(); // after
let model = gio::ListStore::with_type(SomeObject::static_type()); // is available for specific use cases
Changed constructors:
glib::SignalGroup
glib::FlagsClass
glib::EnumClass
New glib::ValueDelegate
macro §
Let’s say you want to create a wrapper around some type, but you want to retain ToValue
, FromValue
, and HasParamSpec
implementations, which are especially necessary when you want to use a type as a property. This is where the glib::ValueDelegate
macro comes in. Instead of having to manually implement the following:
pub struct Uid(String);
impl glib::types::StaticType for Uid {
fn static_type() -> glib::types::Type {
<String as glib::types::StaticType>::static_type()
}
}
impl glib::value::ToValue for Uid {
fn to_value(&self) -> glib::value::Value {
glib::value::ToValue::to_value(&self.0)
}
fn value_type(&self) -> glib::types::Type {
glib::value::ToValue::value_type(&self.0)
}
}
impl From<Uid> for glib::value::Value {
fn from(uid: Uid) -> Self {
glib::value::Value::from(uid.0)
}
}
unsafe impl<'a> glib::value::FromValue<'a> for Uid {
type Checker = <String as glib::value::FromValue<'a>>::Checker;
unsafe fn from_value(value: &'a glib::value::Value) -> Self {
Uid(<String as glib::value::FromValue<'a>>::from_value(value))
}
}
impl glib::HasParamSpec for Uid {
type ParamSpec = <String as glib::HasParamSpec>::ParamSpec;
type SetValue = Self;
type BuilderFn = <String as glib::HasParamSpec>::BuilderFn;
fn param_spec_builder() -> Self::BuilderFn {
<String as glib::HasParamSpec>::param_spec_builder()
}
}
you can simply use the macro as follows:
#[derive(glib::ValueDelegate)]
pub struct Uid(String);
For more complex cases, see the documentation.
You could also achieve the same by using glib::Boxed
, but glib::ValueDelegate
provides a thinner wrapper as it only calls to the inner implementation instead of using GBoxed
. Additionally, glib::ValueDelegate
propagates the GType
to the wrapper instead of creating a new GType
.
gtk4-rs §
The bindings now support GTK 4.12 with v4_12
feature flag. Other than that they didn’t see many user facing changes. The development mainly focused on various cleanups and bug fixes.
Blueprint support in gtk::CompositeTemplate
§
You can now use blueprint with both string
and file
attributes of the gtk::CompositeTemplate
macro. This requires having the blueprint-compiler
binary installed.
use gtk::{glib, prelude::*, subclass::prelude::*};
mod imp {
use super::*;
#[derive(Debug, Default, gtk::CompositeTemplate)]
#[template(string = "
template MyWidget : Widget {
Label label {
label: 'foobar';
}
Label my_label2 {
label: 'foobaz';
}
}
")]
pub struct MyWidget {
#[template_child]
pub label: TemplateChild<gtk::Label>,
#[template_child(id = "my_label2")]
pub label2: gtk::TemplateChild<gtk::Label>,
}
#[glib::object_subclass]
impl ObjectSubclass for MyWidget {
const NAME: &'static str = "MyWidget";
type Type = super::MyWidget;
type ParentType = gtk::Widget;
fn class_init(klass: &mut Self::Class) {
klass.bind_template();
}
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
obj.init_template();
}
}
impl ObjectImpl for MyWidget {
fn dispose(&self) {
while let Some(child) = self.obj().first_child() {
child.unparent();
}
}
}
impl WidgetImpl for MyWidget {}
}
glib::wrapper! {
pub struct MyWidget(ObjectSubclass<imp::MyWidget>) @extends gtk::Widget;
}
Stop using deprecated StyleContext APIs §
The gtk::StyleContext::add_provider_for_display
/ gtk::StyleContext::remove_provider_for_display
functions were never supposed to be part of the gtk::StyleContext
type. Since that type was deprecated upstream in GTK 4.10, the developers now annoyingly had to use #[allow(deprecated)]
, even though those two functions were not deprecated at all.
We have added gtk::style_context_add_provider_for_display
/ gtk::style_context_remove_provider_for_display
as a replacement for them.
Detailed Changes §
Here is the full list of the merged pull requests:
- glib-macros: Improve properties macro docs
- glib: Implement
ValueArray
Value
traits manually because of the c… - glib: add
strv::join()
method - glib-macros: Derive HasParamSpec for SharedBoxed
- glib-macros: allow properties macro generated functions to be unused
- properties: impl HasParamSpec for Vec<String> and StrV
- glib-macros: slightly improve Properties macro docs
- glib-macros: Improve conversion errors for setters
- graphene: Implement Default trait for vectors
- glib: Add various
IntoStrV
impls - glib: add
ParamSpecEnumBuilder::default_value()
- glib: object: improve downcasting docs
- glib: More strv fixes
- glib: implement WatchedObject for BorrowedObject
- gio: Don’t pass
NULL
tog\_list\_store\_find\_with\_equal\_func\_full()
- glib: add missing ObjectImpl vfuncs overrides
- glib: Implement PartialEq for WeakRef
- glib: Make
WeakRef
andSendWeakRef
useable with theProperties
derive macro - glib: strv: when calling
g_strv
ffi method, use ouras_ptr
implementation - glib: strv: when calling
g_strv
ffi method, use ouras_ptr
implementation - glib: Add
connect_notify*
methods toSignalGroup
- gio: add
FileEnumerator::into_stream
- cairo:
Surface::create_similar_image
should return an ImageSurface - glib: Don’t include the NULL terminator in the
IntoStrV
slice - gio: Make ListStore::new() take a type parameter
- gio: Added subclassing support for gio::SocketControlMessage
- Fixed unit tests under macOS and possibly other *nix flavors
- glib: Only optimize
IntoGStr
forString
when capacity allows - pangocairo-sys: fix package.description in Cargo.toml
- glib-macros: Add nullable attribute on properties macro
- glib-macros: impl HasParamSpec on glib::Variant
- glib: Optimize
IntoGStr
impl forString
by simply appending a NUL-byte - glib-macros: Add ValueDelegate macro
- glib: impl StaticType, FromValue, ToValue, HasParamSpec for Box<str>
- glib: implement From<GStringPtr> for GString
- glib: Switch Priority to associated constants
- glib-macros: Value delegate improvements
- glib: Implement bindings for g_win32 functions
- glib-macros: generate “From<Ident> for Value” on ValueDelegate
- glib: Fix building for architectures without 64-bit atomics
- glib-macros: Don’t assume edition=2021
- glib-macros: enable default features of syn
- glib-macros: Specify quoted types explicitly
- glib-macros: add docs on supported #[property] attributes
- glib: Allow using
Path
/PathBuf
inglib::Value
s - glib-macros: Import ParamSpecBuilderExt inside the scope of DerivedObjectProperties::derived_properties
- glib: Fix inverted boolean conditions when deciding whether to reserve new space
- glib-macros: Disambiguate TryFrom<usize>::Error for DerivedPropertiesEnum
- glib-macros: Strip raw identifier prefix from struct members for the Properties macro
- Split new/with_type in a few more places
- Fix required features not shown in docs
- Update syn: v2.0
- glib: Enable various smallvec features
- glib-macros: Strip out r# prefix from property names inside the GObject
- glib: Do not use ptr::offset/offset_from for private/impl offset
- glib: Fix heap buffer overflow due to operator precedence
- glib: strv: Implement From for constant GStr slices
- glib-macros: properties: Allow to omit set for construct_only properties
- pango: Lower pkg-config version requirement for v1_52
- glib: Add a std_once_cell feature
- Update to bitflags2
- glib: Replace Continue with ControlFlow
- glib: Remove Inhibit and replace it with ControlFlow
- pango: Mark manual impls as such
- glib: control flow: Fix logic in From implementation
- glib-macros: Implement
FromGlibPtrBorrow
on boxed and shared-boxed types - Use
--generate-link-to-definition
option when generating documentation - gio: Add retain method to
ListStore
- glib: Add support for NonZeroT types
- glib-macros: Remove unused dependency
- glib-macros: Add
use_derived_properties
macro - Don’t generate unit tuple in clone macro as default-return value
- glib-macros: Fix docs of
glib::derived_properties
- glib: Re-introduce an event propagation specific type
- gio: Set missing annotations for new FileInfo apis
- Add typos workflow
- glib: Fixed missing 512 flag, renamed 256 to
USER_0
- gio: Fix panic in
InputStream
- Disentangle docsrs and features
- gio: Fix panics if
PollableInputStream
/PollableOutputStream
ret…
- gdk: Implement Copy for
Key
- examples: Fix menu bar example
- examples: Update per Priority changes
- Prepare for gir collections
- Update to bitflags 2.0
- gtk3-macros: enable default features of syn
- Shorten and seal subclass traits, ExtManual traits
- Adapt to inhibit removal
- Upgrade syn to 2.0
- Add
--generate-link-to-definition
option when building on docs.rs - Remove
anyhow
dependency - Adapt to addition of glib::Propagation
- More fixes for docsrs attribute
- gtk4: Use correct length for the
StrV
when passing to C - gtk4: Add Accessible subclassing support
- gtk4: Add SectionModel subclassing support
- gtk4: Update for
IntoStrV
not including the NULL terminator in the … - gtk4: Implement convenience traits for StringObject
- gtk4: Move provider related functions outside of StyleContext
- gtk4: Remove manual overrides for GestureClick
- gtk4: Impl Write on text buffers
- gtk4: Add a GNOME 45 feature
- gtk4: allow subclassing WindowGroup
- gtk4-macros: Bump quick-xml to 0.30
- gtk4-macros: enable default features of syn
- gtk4-macros: Support blueprint files in CompositeTemplate
- gdk4: rgba: Add TRANSPARENT const
- gdk4: bind GLTextureBuilder::build
- gdk4: More GLTextureBuilder tweaks
- gdk4: Add ‘gl’ feature
- gdk4: Add missing Clipboard::set
- README: Document gnome_44 feature
- Prepare for gir collections
- Generate trait signature once for manual code
- Fix required features not shown in docs
- Update to bitflags2
- Adapt to glib::Inhibit removal
- Add new Path APIs
- docs: Untangle docsrs attribute from features
- docs: Add
--generate-link-to-definition
option when building on docs.rs - examples: Update ListStore::new
- examples: update for 4.10 deprecations
- examples: Use
gtk::Application::builder
- book: Use
gio::spawn_blocking
instead ofthread::spawn
- book: Use
derived_properties
macro - book: Update for 0.7.1
- book: Update instructions to
v4\_12
- book: Move to
std::cell::OnceCell
- book: Extend memory management chapter
- book: Add missing snippet for
new\_task
- book: Add a note to the book
- book: Fix typos and deprecations in the book for CSS chapter (14th).
- book: Change xml code block to diff in “Adapt Todo App”
- book: Remove mention of “clear_button”
- book: Add a note about finishing touches to “Set CSS Name and Use Exported Colors” section of 14th (CSS) chapter
- book: Replace usage of deprecated gtk::Dialog with adw::MessageDialog
- book: Add lock file for listings and update dirs
- book: Move to property macro
- book: Use generated wrapper method
- book: Bind Settings to
active
instead ofstate
- book: Use property docs of of gtk-rs
- book: Use glib Priority enum
- book: Use bind helper functions
- book: Update librsvg in installation_windows.md
- book: Fix button sensitivity action
- book: Use
iter
ongio::ListModel
All this was possible thanks to the gtk-rs/gir project as well:
- Reworked the book/tutorial
- Fixes an overflow bug that may occasionally panic if gir is built in debug
- codegen: Avoid useless borrows for properties setters
- Update to bitflags 2.0
- Add external docs url config option
- Replace dox feature with docsrs attribute
- Make features independent from docsrs attribute
- Remove docsrs attr for conditional compilation
- codegen: Drop useless any on a single feature
- parser: ignore
boxed
elements - codegen: only generate trait signatures once
- codegen: generate attributes on trait fns
- Implement basic virtual methods support
- analysis: Don’t fill imports from virtual methods
- Fix docs for docsrs attribute
- parser: ignore source-position in virtual methods
- analysis: Avoid overflow when determining whether to emit a parameter
- codegen: seal Ext traits
- generate cfg conditions for aliases, enums, interfaces and disguised
- codegen: Only use any if scope constraints > 1
- codegen: build tests on all unix platforms
- analysis: Prefer prelude/exported crates
- Update to bitflags 2.2
- codegen: Switch from Inhibit to ControlFlow
- codegen: Replace ControlFlow with Propagation
- Add trait_name to API docs
- Fix inserting all-features in Cargo.toml for docs.rs
Thanks to all of our contributors for their (awesome!) work on this release:
- @A6GibKm
- @AaronErhardt
- @andy128k
- @arcnmx
- @Benjins-automation
- @bilelmoussaoui
- @BrainBlasted
- @decathorpe
- @dependabot[bot]
- @elmarco
- @epilys
- @fbrouille
- @felinira
- @FineFindus
- @gdesmott
- @gianzellweger
- @GuillaumeGomez
- @happylinks
- @heftig
- @Hofer-Julian
- @jf2048
- @johan-bjareholt
- @jplatte
- @kawadakk
- @Kijewski
- @lupinx2
- @mashomee
- @MathieuDuponchelle
- @mbiggio
- @melix99
- @nicopap
- @pbor
- @pentamassiv
- @ranfdev
- @RealKC
- @rmnscnce
- @saethlin
- @Schmiddiii
- @sdroege
- @SeaDve
- @tintou
- @valpackett
- @wroyca
- @xanathar
- @yuraiz
- @zekefast