New crates, better APIs
Hi everyone, time for a new release!
Today, it’s all about improving APIs and providing the GdkX11 bindings. Let’s see it more in details!
Change of minimum supported Rust version §
The minimum supported Rust version is now 1.40. All the enums provided by the
gtk-rs crates now make use of the #[non_exhaustive]
attribute to indicate
that there might be more values being added in the future.
Updated library versions §
All the crates were updated to the latest library versions, that is, APIs that are newly available since GNOME 3.36 are provided by the bindings.
No more new_from_...()
and new_with_...()
§
In GLib-based APIs, a common pattern for constructors is to call them
new_from_...()
or new_with_...()
. In Rust the new_
prefix is usually
omitted, so all bindings were changed according to that too.
There might still be a few new_...()
functions in the bindings. If you find
one and think a different name would be better, please create an
issue.
glib-macros
§
There’s a new crate glib-macros
now, which is re-exported by the glib
crate and provides a couple of proc-macros
#[derive(GBoxed)
for easily deriving a boxed type for any Rust type the implements theClone
trait. This can be used to store values of that type in e.g. inglib::Value
.#[derive(GEnum)]
for integer representation Rust enums, which registers GLib type for them and allows to use them e.g. in aglib::Value
.#[gflags]
, which registers a GLib type for bitflags and wraps around thebitflags
crate. Same as above this can then be used e.g. in aglib::Value
.
Check the documentation for details about the above.
GdkX11 §
GTK and its companion library GDK provide various API for interoperability with platform interfaces, like X11 or Wayland or the equivalent APIs on Windows and macOS.
With this release a crate for the X11 integration API for GDK is included.
glib::ThreadPool
§
GLib provides a thread-pool API, which is now included in the bindings. There
are many crates that provide similar functionality but nothing that is part of
std
yet, as such the addition seemed useful unlike adding bindings for the
threading primitives in GLib.
The ThreadPool
bindings allow to create shared or exclusive thread pools,
where the shared thread pools are sharing their threads with other shared
ones. The maximum number of threads and various other parameters can be
configured on each thread pool, see
the docs.
After creation, new tasks can be pushed on the thread pool as a closure.
Optionally a Future
can be returned to get notified about the completion of
the task.
let pool = ThreadPool::new_exclusive(1)?;
// Runs `do_something()` on the thread pool and doesn't wait
pool.push(|| {
do_something();
});
// Runs `do_something_else()` on the thread pool and returns its
// return value via a `Future`
let fut = pool.push_future(|| {
let res = do_something_else();
res
});
// Asynchronously await the result of `do_something_else()`
let res = fut.await;
Storage of arbitrary data in glib::Object
s §
In C, GObject provides the ability to store arbitrary data on any object. Until this release this was not provided by the bindings as it generally is used as a workaround for a suboptimal architecture, and most importantly because all type information for the stored data is lost.
In this release unsafe
API for making use of this is provided but it’s the
caller’s responsibility to ensure that the types are matching.
let button = gtk::Button::with_label("test");
unsafe {
button.set_data("my-data", String::new("my-data-value"));
let my_data = button.get_data("my-data");
}
Before using this please make sure there is no better solution for what you’re trying to achieve.
cairo::Error
instead of cairo::Status
§
Previously all cairo
functions that could fail were returning a Status
enum in one way or another. This lead to unidiomatic error handling in Rust
applications.
In this release the Status
enum was replaced by an Error
enum that only
includes errors cases and is returned as part of the error case of Result
s.
This allows doing normal Rust error handling via the ?
operator, for
example.
cairo features §
The FreeType
and script
features of the cairo
bindings are now optional with
this release. It was already possible to compile the cairo C library without
them but the bindings assumed these features to always exist.
If you make use of these features you now need to enable them when depending
on the cairo
crate.
GDBus §
GLib comes with its own DBus IPC implementation. Starting with this release big parts of the API are included in the bindings and it is for example possible to create DBus services or use existing DBus services.
The API is very close to the C API and as such not very convenient to use yet, but more convenient APIs can be built on top of this in external crates or maybe in future versions of the bindings. More to see later!
No more Widget::destroy()
§
The gtk::Widget::destroy()
function is marked as unsafe
starting from this
release. Calling it on arbitrary widgets can cause all kinds of negative
side-effects and should be prevented.
Most usages of destroy()
were related to dialogs or other windows. Instead
of destroy()
the safer close()
can be used now, which also allows the
window to handle the event.
More subclassing support in gtk
§
This new release features subclassing support for many additional types: IconView, CellRenderers (Pixbuf, Text, Spinner, Progress, Toggle, Accel, Combo, Spin), DrawingArea, Plug, Socket and Fixed.
Together with all the ones that existed in previous releases, the most commonly used types in GTK where subclassing is useful should be covered. If some are missing, please open issues so we can add them.
Conclusion §
This release took us a lot of time but as you can see, it was definitely worth it. We expect to provide even more tools to make gtk-rs development as fun as possible and to continue to improve the bindings. More to come soon!
Changes §
For the interested ones, here is the list of the merged pull requests:
sys:
- Fix fixed size arrays
- Add gdkx11 lib
- Put back missing information
- Changes from new eoans gir-files
- Remove special case for gdkx11-sys
- Use options.split_build_rs
- Fix build_version.rs
- Restore missing library versions in build.rs
- gdk/gdk: build: Compute and export GDK backends
- GIR files focal update
- Add correct versions for get_type functions
- Depend on cairo-sys when selecting v3_24_2 feature
- Use eprintln
glib:
- types: fix crashes on Type::Invalid API
- add genum-derive crate
- Add PtrArray and related trait implementations
- 0.9.1 bugfix release
- Add more checks for clone macro
- Allow to specify type for closure arguments
- Derive fmt::Debug for a few more types
- Add glib::ThreadPool bindings
- Implements FromGlibPtrFull<*const T> for boxed types.
- Bind API to convert from/to bytes to/from Variant
- Don’t pass an owned string to g_quark_from_static_string()
- Replace unwrap calls with expect in tests
- Don’t store subclass impl/private data in an Option<T>
- translate: Clarify the purpose and the effect of translation traits
- Add manual traits check
- Various container translation cleanups/fixes
- Don’t require too strict bounds for ObjectSubclass::from_instance()
- Remove some unneeded mem::forget() calls and Option wrappers
- More clone fixes
- Add clone test case for “async”
- glib-macros: add GBoxed derive
- Return a bool instead of a Result from Object::has_property()
- Add logs API
- Clean up log functions
- Improve clone! error messages
- Improve log macros
- Add print in case an upgrade failed
- glib-macros: add gflags attribute macro
- Add @weak-allow-none for clone macro
- Add translate::Borrowed wrapper struct for from_glib_borrow()
- glib-macros: Update itertools to 0.9
- Use mem::ManuallyDrop instead of mem::forget() everywhere
- Remove unnecessary transmute calls
- Fix variant PartialOrd
- Remove deprecated Error::description impl
- Fix transmute mess
- Add test for callbacks validity
- Return a string of any lifetime from Quark::to_string()
- VariantDict support
- Clippy cleanliness and CI enforcement
- Only derive SetValueOptional for nullable GBoxed types
- Unset return nullable for uuid_string_random()
- Disable GTK4 from the Travis CI
- Add unsafe generic qdata API to ObjectExt
- Various improvements to property handling
- Update glib-macros to proc-macro-error 1.0
- Don’t require users of the glib proc macros to have gobject_sys in scope
- Ignore g_variant_get_gtype()
- Update to new gir and various related fixes
- Use g_type_register_static_simple() instead of g_type_register_static…
- Remove deprecated Error::description
- Clean up travis script
- Add missing Surface::get_device method
- Replace bad code
- Update for new from_glib_borrow signature
- Add missing fn
- Don’t include LGPL docs in the docs if both embed-lgpl-docs and purge-lgpl-docs features are selected
- errors: create an Error type and use that instead of Status
- Work around crash when trying to access data of an image surface
- add a freetype feature
- mark all the enums as non exhaustive
- add a script feature
- Add an ImageSurface::with_data method.
- Use system-deps crate instead of pkg-config directly
- SearchContext::replace_all returns the number of replaced matches
- Fix transmute mess
- Remove the unused dependency on fragile
- Add async I/O to FileLoader and FileSaver
- README: it’s actually sourceview
atk:
- Update for new from_glib_borrow signature
- Fix transmute mess
- Don’t include LGPL docs in the docs if both embed-lgpl-docs and purge…
gio:
- Fix/extend DataInputStream code
- Add manual trait doc check
- Credentials::get_unix_user returns user id
- Update for new from_glib_borrow signature
- Use mem::ManuallyDrop instead of mem::forget() everywhere
- Remove unneeded transmute calls
- Fix transmute mess
- Add callback check
- Support various things which needed glib::VariantDict
- Clippy-clean plus CI
- SubProcess::communicate_utf8_async() is nullable for the returned std…
- Don’t include LGPL docs in the docs if both embed-lgpl-docs and purge…
- input_stream: add AsyncBufRead adapter
- Increase reference count of the stored streams in the IOStream when s…
- Mark the source_object argument to the ThreadedSocketService::run as …
- Improve ThreadedSocketService::new
- Generate D-Bus classes
- Update for new from_glib_borrow signature
- remove clippy lint about transmute cast
- Don’t include LGPL docs in the docs if both embed-lgpl-docs and purge…
- Fix memory unsafety in
FontDescription::set\_family\_static
- Update for new from_glib_borrow signature
- Fix transmute mess
- Fix arithmetic overflow in Pixbuf::put_pixel
- Don’t include LGPL docs in the docs if both embed-lgpl-docs and purge…
gdk:
- Ignore thread_add and threads_add_timeout in favor of glibs analog
- Delete check_init_asserts
- Update for new from_glib_borrow signature
- window: store event_mask using EventMask
- Fix transmute mess
- Don’t include LGPL docs in the docs if both embed-lgpl-docs and purge…
- Nicer bindings for Key(val) related functions
gtk:
- Delete LGPL docs
- Fix osx CI build
- Switch from lazy_static to once_cell
- Add subclass for IconView
- Add subclass for CellRenderer and CellRendererPixbuf (Closes #936)
- Added vfunc to IconView
- Added more CellRenderer subclasses: Text, Spinner, Progress, Toggle, Accel, Combo, Spin
- Fix an ownership issue
- Implement size vfunc for Widget
- Added subclassing for DrawingArea
- Macos no Plug and Socket
- Update Copyright Year
- InfoBar::get_content_area return Box
- Add StyleContext::get_font, deignore Value getters
- Add subclass support for Fixed
- Mark Widget::destroy as unsafe
- Simplify travis file
- Fix doc link
- Add vfuncs to WidgetImpl
- Add ImplExt traits to subclass prelude
- add basic subclassing functionality for treeview
- Add size_allocate vfunc to gtk::Widget
- CellRenderer: fix null dereference for activate
- Add scroll_event vfunc to WidgetImpl
- Update for new from_glib_borrow signature
- The TreeSortable functions are called on the underlying model
- Fix transmute mess
- Workaround for GtkWindow::set-focus parameter nullability
- Add gtk::Socket and gtk::Plug subclassing support
- Clippy fixes
- Application initialization
- gdk_backend config flags
- Change some get_ functions to return non-nullable
- Fix more non-nullable returns
- Don’t include LGPL docs in the docs if both embed-lgpl-docs and purge…
- Let Widget::hide_on_delete return Inhibit
- bind
Image.surface
andCellRendererPixbuf.surface
properties - Fix TextBuffer signals that can invalidate/modify TextIters
- generate missing builders
- generate missing Gtk.EventController*
- generate missing Shortcut* objects
- Generate GtkGestureStylus
- Ignore some builders
- Clean up travis
- Update for new from_glib_borrow signature
- remove clippy lint about transmute cast
- Don’t include LGPL docs in the docs if both embed-lgpl-docs and purge…
All this was possible thanks to the gtk-rs/gir project as well:
- Fix signal doc
- Remove unused variable
- Fix fields with fixed size array type
- Add new nullable_return_is_error configuration for return types
- Use once_cell::sync::Lazy instead of lazy_static
- Fix returning array from async trampolines
- Add support for PtrArray
- Run rustfmt on generated code
- Allow to override use-return-for-result in function configuration.
- Check gir file
- git: check return value from ‘git’ command
- Generate code for new from_glib_borrow signature
- use #[non_exhaustive] for generated enums
- Simplify chunk::Assert* and fix missing init check for async_future methods
- Add a check to avoid unforeseen failures
- Show more not generated types
- Builder postprocess
- Generate duplicated enum values in the -sys crate
- Consider nullability for async function return values
- Initial conversion to github actions
- Add options.split_build_rs
- Add static lifetime to generated build_version.rs
- tests: use split_build_rs in gdk gir test
- Add options.extra_versions and lib_version_overrides configurations
- Allow overriding safety assertions for functions
- Fix some code generation issues
- Fix wrongly written
object.function.return
- Fix and ignore clippy warnings
- Add ImportsWithDefaults
- Correctly get function configuration and make use of it for get_type(…
- functions: rename constructors
- Handle version configuration on get_type functions in non-sys mode
- Generate version conditions for functions in sys mode no lower than t…
- Give preference to configured function versions over versions automat…
- Allow to ignore builders
- Update builder documentation
- cargo_toml: set feature-versions for all versions
- cargo_toml: use lib_version_overrides when defining feature versions
- Remove deleting pkg_config
- Use system-deps
- Use
eprintln
for writing to stderr - Generate docs for bitfields too
- Correctly generate doc elements for bitfields
- Fix variant doc generation
- Update dependencies
Thanks to all of our contributors for their (awesome!) work on this release:
- @andy128k
- @ArekPiekarz
- @bilelmoussaoui
- @brackleian
- @cuviper
- @danigm
- @dcz-purism
- @de-vri-es
- @dhonx
- @EPashkin
- @federicomenaquintero
- @fengalin
- @gdesmott
- @GuillaumeGomez
- @hfiguiere
- @jneem
- @jplatte
- @kinnison
- @luukvanderduim
- @majorz
- @misson20000
- @myfreeweb
- @nt8r
- @sdroege
- @sophie-h
- @tsahyt
- @vhdirk
- @yvt
- @zeenix