Skip to content

Commit fb43fe9

Browse files
authored
Merge pull request #311 from sdroege/2024-07-17-new-release
Add new gtk-rs-core 0.20 / gtk4-rs 0.9 release
2 parents f1fa9a4 + fdf526f commit fb43fe9

File tree

1 file changed

+270
-0
lines changed

1 file changed

+270
-0
lines changed

Diff for: _posts/2024-07-17-new-release.md

+270
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,270 @@
1+
---
2+
layout: post
3+
author: gtk-rs developers
4+
title: New Release
5+
categories: [front, crates]
6+
date: 2024-07-17 09:00:00 +0000
7+
---
8+
9+
gtk4-rs `0.9` and gtk-rs-core `0.20` were just freshly released, just in time
10+
for also being included in the GNOME 47 release.
11+
12+
This release is again relatively small, mostly providing bindings to new APIs
13+
and improvements to the `glib::clone!` and `glib::closure!` macros to work
14+
better with `cargo fmt` and rust-analyzer.
15+
16+
As usual, at the same time gstreamer-rs `0.23` and gst-plugins-rs `0.13`,
17+
libadwaita `0.7` and other related crates got a new release compatible with
18+
the new gtk4-rs and gtk-rs-core releases and their own set of changes.
19+
20+
### gtk-rs-core
21+
22+
#### New syntax for `glib::clone!` and `glib::closure!`
23+
24+
The syntax for the `clone!` and `closure!` macros was updated to look more
25+
like valid Rust code, and as a side effect it is also handled correctly by
26+
`cargo fmt`, rust-analyzer and other tooling now.
27+
28+
The old syntax is still supported but will give a deprecation warning.
29+
30+
To get an idea of the change, what previously looked like:
31+
32+
```rust
33+
clone!(@strong self as obj, @weak v => @default-return false, move |x| {
34+
println!("obj: {}, v: {}, x: {}", obj, v, x);
35+
true
36+
})
37+
```
38+
39+
would now look like this:
40+
41+
```rust
42+
clone!(
43+
#[strong(rename_to = obj)]
44+
self,
45+
#[weak]
46+
v,
47+
#[upgrade_or]
48+
false,
49+
move |x| {
50+
println!("obj: {}, v: {}, x: {}", obj, v, x);
51+
true
52+
},
53+
);
54+
```
55+
56+
Check the [documentation](https://gtk-rs.org/gtk-rs-core/stable/0.20/docs/glib/macro.clone.html) for more details about the new syntax.
57+
58+
#### GLib 2.82 APIs
59+
60+
New GLib and GIO 2.82 APIs are supported with this release. GLib 2.56 is still
61+
the minimum version supported by the bindings.
62+
63+
#### Trait re-organization for defining new GObject interfaces
64+
65+
The traits for defining new GObject interfaces were slightly re-organized to
66+
make them more similar with the ones for defining new GObjects.
67+
68+
Previously one would write:
69+
70+
```rust
71+
#[derive(Clone, Copy)]
72+
#[repr(C)]
73+
pub struct MyStaticInterface {
74+
parent: glib::gobject_ffi::GTypeInterface,
75+
}
76+
77+
#[glib::object_interface]
78+
unsafe impl ObjectInterface for MyStaticInterface {
79+
const NAME: &'static str = "MyStaticInterface";
80+
}
81+
```
82+
83+
This would now become:
84+
85+
```rust
86+
#[derive(Clone, Copy)]
87+
#[repr(C)]
88+
pub struct MyStaticInterfaceClass {
89+
parent: glib::gobject_ffi::GTypeInterface,
90+
}
91+
92+
unsafe impl InterfaceStruct for MyStaticInterfaceClass {
93+
type Type = MyStaticInterface;
94+
}
95+
96+
pub enum MyStaticInterface {}
97+
98+
#[glib::object_interface]
99+
impl ObjectInterface for MyStaticInterface {
100+
const NAME: &'static str = "MyStaticInterface";
101+
102+
type Interface = MyStaticInterfaceClass;
103+
}
104+
```
105+
106+
While it is a bit more code, this is almost the same as for GObjects now.
107+
108+
#### Safer borrowing of GObjects and other types from FFI code
109+
110+
It is possible to directly borrow GObjects and other types in FFI code without
111+
additional refcounting or copying. In previous releases the API for that was
112+
completely based on pointers, which allowed to accidentally create dangling
113+
pointers without the compiler being able to help.
114+
115+
```rust
116+
let obj = {
117+
let mut ptr: *mut glib::ffi::GObject = ...;
118+
let obj: &glib::Object = glib::Object::from_glib_ptr_borrow(&mut ptr);
119+
obj
120+
};
121+
// At this point `obj` is pointing at a stack frame that does not exist anymore
122+
```
123+
124+
Starting with this release, a reference to a pointer is used instead to avoid
125+
this from happening. The above code would not compile anymore. Previously the
126+
lifetime of the returned object would be arbitrary, now it is bound strictly
127+
to the lifetime of the pointer.
128+
129+
Code using this API likely does not need any changes unless the code was
130+
previously wrong.
131+
132+
### gtk4-rs
133+
134+
#### GTK 4.16 APIs
135+
136+
New GTK 4.16 APIs are supported with this release. GTK 4.0 is still the
137+
minimum version supported by the bindings.
138+
139+
### Changes
140+
141+
For the interested ones, here is the list of the merged pull requests:
142+
143+
[gtk4-rs](https://github.com/gtk-rs/gtk4-rs):
144+
145+
* [Update to new clone! macro syntax](https://github.com/gtk-rs/gtk4-rs/pull/1773)
146+
* [book: Fix typo](https://github.com/gtk-rs/gtk4-rs/pull/1769)
147+
* [Remove unnecessary upcast from examples/squeezer\_bin/main.rs](https://github.com/gtk-rs/gtk4-rs/pull/1763)
148+
* [typos: Ignore versions.txt file](https://github.com/gtk-rs/gtk4-rs/pull/1762)
149+
* [examples/squeezer\_bin: Mark properties as writable](https://github.com/gtk-rs/gtk4-rs/pull/1761)
150+
* [Fix `SqueezerBin::size\_allocate()` in example](https://github.com/gtk-rs/gtk4-rs/pull/1760)
151+
* [Stop renaming ffi crates](https://github.com/gtk-rs/gtk4-rs/pull/1758)
152+
* [custom\_orientable: Fix interface property override](https://github.com/gtk-rs/gtk4-rs/pull/1755)
153+
* [gtk: Implement Downgrade for TemplateChild<T>](https://github.com/gtk-rs/gtk4-rs/pull/1750)
154+
* [Update list\_widgets.md](https://github.com/gtk-rs/gtk4-rs/pull/1742)
155+
* [examples: Support GL >= 3.1 and GLES >= 3.0 in the glium example](https://github.com/gtk-rs/gtk4-rs/pull/1733)
156+
* [Update link for Cogitri/Health to World/Health](https://github.com/gtk-rs/gtk4-rs/pull/1725)
157+
* [Simplify reading file contents to a String](https://github.com/gtk-rs/gtk4-rs/pull/1719)
158+
* [macros: Drop anyhow dependency](https://github.com/gtk-rs/gtk4-rs/pull/1708)
159+
* [Fix typo in todo\_1.md](https://github.com/gtk-rs/gtk4-rs/pull/1707)
160+
* [gtk4: Manually implement `GraphicsOffload` constructor for now](https://github.com/gtk-rs/gtk4-rs/pull/1705)
161+
* [gtk4: Require GDK 4.14 when enabling the `v4\_14` feature](https://github.com/gtk-rs/gtk4-rs/pull/1704)
162+
* [macros: Drop macro-proc-error and upgrade syn to 2.0](https://github.com/gtk-rs/gtk4-rs/pull/1688)
163+
* [dockerfile: Update libadwaita to 1.5](https://github.com/gtk-rs/gtk4-rs/pull/1687)
164+
* [docs: fix `Path` setting on windows](https://github.com/gtk-rs/gtk4-rs/pull/1675)
165+
* [Correctly handle `NULL` `GError\*\*` out parameters](https://github.com/gtk-rs/gtk4-rs/pull/1672)
166+
* [Replace simple `impl Debug` with derived `Debug` in tokio example](https://github.com/gtk-rs/gtk4-rs/pull/1663)
167+
* [Simplify library configuration step for Windows](https://github.com/gtk-rs/gtk4-rs/pull/1644)
168+
169+
[gtk-rs-core](https://github.com/gtk-rs/gtk-rs-core):
170+
171+
* [docs: Run on our container image](https://github.com/gtk-rs/gtk-rs-core/pull/1455)
172+
* [gio: Add a method to get a stream of incoming connections to SocketListener](https://github.com/gtk-rs/gtk-rs-core/pull/1454)
173+
* [glib: Add support for registering GTypes with name conflicts](https://github.com/gtk-rs/gtk-rs-core/pull/1451)
174+
* [glib: Make `TypeData` struct fields private](https://github.com/gtk-rs/gtk-rs-core/pull/1449)
175+
* [glib-macros: Don't produce unnecessary braces in `clone!(async move { x })`](https://github.com/gtk-rs/gtk-rs-core/pull/1443)
176+
* [Update to system-deps 7](https://github.com/gtk-rs/gtk-rs-core/pull/1440)
177+
* [glib-macros: Fix unit return in `closure!()` macro](https://github.com/gtk-rs/gtk-rs-core/pull/1438)
178+
* [strv: add From implementation from a String array](https://github.com/gtk-rs/gtk-rs-core/pull/1432)
179+
* [Derive TransparentPtrType trait for Boxed](https://github.com/gtk-rs/gtk-rs-core/pull/1431)
180+
* [gio: Properly export Win32InputStream / Win32OutputStream traits](https://github.com/gtk-rs/gtk-rs-core/pull/1429)
181+
* [Update `clone!` and `closure!` macro to new syntax](https://github.com/gtk-rs/gtk-rs-core/pull/1424)
182+
* [Stop renaming ffi crates](https://github.com/gtk-rs/gtk-rs-core/pull/1423)
183+
* [gio: remove Send + Sync requirements from DBusConnection::register\_ob…](https://github.com/gtk-rs/gtk-rs-core/pull/1422)
184+
* [spell fix](https://github.com/gtk-rs/gtk-rs-core/pull/1419)
185+
* [gio: make DBusConnection::register\_object take optional clousures](https://github.com/gtk-rs/gtk-rs-core/pull/1417)
186+
* [glib: Add unsafe `Value::into\_send\_value()`](https://github.com/gtk-rs/gtk-rs-core/pull/1413)
187+
* [glib: Improve `ValueArray` API, add tests and assertions for invalid …](https://github.com/gtk-rs/gtk-rs-core/pull/1411)
188+
* [glib: Fix `MatchInfo::next()` handling of returning `FALSE`](https://github.com/gtk-rs/gtk-rs-core/pull/1410)
189+
* [glib/functions: add compute\_checksum\_for\_string](https://github.com/gtk-rs/gtk-rs-core/pull/1406)
190+
* [glib: Add bindings for `g\_value\_set\_static\_string()`](https://github.com/gtk-rs/gtk-rs-core/pull/1400)
191+
* [docs: Fix broken links / cleanup README](https://github.com/gtk-rs/gtk-rs-core/pull/1395)
192+
* [glib: Implement Sync for ThreadGuard](https://github.com/gtk-rs/gtk-rs-core/pull/1388)
193+
* [glib: Only implement Send on JoinHandle if the result is Send](https://github.com/gtk-rs/gtk-rs-core/pull/1387)
194+
* [glib: Decouple ObjectInterface impl from interface class struct](https://github.com/gtk-rs/gtk-rs-core/pull/1384)
195+
* [glib: Add missing Send bound to the output type of the `spawn\_from\_within()` future](https://github.com/gtk-rs/gtk-rs-core/pull/1383)
196+
* [glib-macros: Refactor parsing code of object\_subclass/object\_interface](https://github.com/gtk-rs/gtk-rs-core/pull/1379)
197+
* [examples: Add example for custom class structs and virtual methods](https://github.com/gtk-rs/gtk-rs-core/pull/1378)
198+
* [ObjectBuilder: add property\_if(), property\_if\_some(), property\_from\_iter() \& property\_if\_not\_empty()](https://github.com/gtk-rs/gtk-rs-core/pull/1377)
199+
* [glib: Don't use `g\_object\_list\_properties()` for setting properties](https://github.com/gtk-rs/gtk-rs-core/pull/1376)
200+
* [glib: Use a reference to a pointer of correct mutability for from\_glib\_ptr\_borrow()](https://github.com/gtk-rs/gtk-rs-core/pull/1375)
201+
* [glib: Re-add and rename manual Win32 API additions](https://github.com/gtk-rs/gtk-rs-core/pull/1372)
202+
* [glib-macros/properties: Allow structs with no properties](https://github.com/gtk-rs/gtk-rs-core/pull/1370)
203+
* [glib::wrapper: Add docs for impls generated by the wrapper macro](https://github.com/gtk-rs/gtk-rs-core/pull/1369)
204+
* [glib-sys: Add missing includes in `manual.h`](https://github.com/gtk-rs/gtk-rs-core/pull/1361)
205+
* [glib-sys: fix struct size mismatches](https://github.com/gtk-rs/gtk-rs-core/pull/1360)
206+
* [glib: Freeze property notifications while setting multiple properties](https://github.com/gtk-rs/gtk-rs-core/pull/1355)
207+
* [glib-macros: Improve error message when `Properties` struct doesn't have at least one `#\[property(…)\]`](https://github.com/gtk-rs/gtk-rs-core/pull/1352)
208+
* [docs: `construct` attribute for `glib::Properties`](https://github.com/gtk-rs/gtk-rs-core/pull/1344)
209+
* [glib: fix UB in VariantStrIter::impl\_get](https://github.com/gtk-rs/gtk-rs-core/pull/1343)
210+
* [glib: Don't misuse `slice::get\_unchecked()`](https://github.com/gtk-rs/gtk-rs-core/pull/1337)
211+
* [gio: correctly free argument list items](https://github.com/gtk-rs/gtk-rs-core/pull/1331)
212+
* [glib: Optimize string collation bindings a bit](https://github.com/gtk-rs/gtk-rs-core/pull/1329)
213+
* [glib: Drop the main context future return value sender on finalize](https://github.com/gtk-rs/gtk-rs-core/pull/1328)
214+
* [pango: add some missing AttrInt constructors.](https://github.com/gtk-rs/gtk-rs-core/pull/1325)
215+
* [glib: Embed docs for ParamSpec types](https://github.com/gtk-rs/gtk-rs-core/pull/1323)
216+
* [glib: Requires Upgrade on Downgrade::Weak type](https://github.com/gtk-rs/gtk-rs-core/pull/1321)
217+
* [macros: allow to specify #\[default\] for glib::flags](https://github.com/gtk-rs/gtk-rs-core/pull/1316)
218+
* [glib: Add `Quark::from\_static\_str()`](https://github.com/gtk-rs/gtk-rs-core/pull/1312)
219+
* [docs: Move metadata back to packages](https://github.com/gtk-rs/gtk-rs-core/pull/1311)
220+
* [cairo: Fix version of the v1\_18 feature](https://github.com/gtk-rs/gtk-rs-core/pull/1310)
221+
* [Document values of Continue and Break](https://github.com/gtk-rs/gtk-rs-core/pull/1304)
222+
223+
All this was possible thanks to the [gtk-rs/gir](https://github.com/gtk-rs/gir) project as well:
224+
225+
* [Minor cleanup to use `is\_some\_and(...)` instead of `map\_or(false, ...)`](https://github.com/gtk-rs/gir/pull/1584)
226+
* [Update to system-deps 7](https://github.com/gtk-rs/gir/pull/1583)
227+
* [More docs improvements](https://github.com/gtk-rs/gir/pull/1576)
228+
* [codegen: Handle mangled types names](https://github.com/gtk-rs/gir/pull/1575)
229+
* [members: drop useless alias config](https://github.com/gtk-rs/gir/pull/1574)
230+
* [Various properties fixes](https://github.com/gtk-rs/gir/pull/1573)
231+
* [codegen: Avoid double alias on badly annotated fn](https://github.com/gtk-rs/gir/pull/1572)
232+
* [Use getter and setter annotations](https://github.com/gtk-rs/gir/pull/1571)
233+
* [Support finish-func annotation](https://github.com/gtk-rs/gir/pull/1570)
234+
* [codegen: Stop renaming ffi crate](https://github.com/gtk-rs/gir/pull/1569)
235+
* [Use final annotation](https://github.com/gtk-rs/gir/pull/1568)
236+
* [Add support for `libc::time\_t` and related types](https://github.com/gtk-rs/gir/pull/1562)
237+
* [Revert Automatically assume that win32\_ and unix\_ should use the related cfg](https://github.com/gtk-rs/gir/pull/1547)
238+
* [Correctly generate cfg condition for ABI tests](https://github.com/gtk-rs/gir/pull/1546)
239+
* [Generate cfgs with `update\_cfgs` on enums as well](https://github.com/gtk-rs/gir/pull/1545)
240+
241+
Thanks to all of our contributors for their (awesome!) work on this release:
242+
243+
* [@A6GibKm](https://github.com/A6GibKm)
244+
* [@alatiera](https://github.com/alatiera)
245+
* [@amyspark](https://github.com/amyspark)
246+
* [@bilelmoussaoui](https://github.com/bilelmoussaoui)
247+
* [@carlosmn](https://github.com/carlosmn)
248+
* [@DaKnig](https://github.com/DaKnig)
249+
* [@decathorpe](https://github.com/decathorpe)
250+
* [@ellnix](https://github.com/ellnix)
251+
* [@enaut](https://github.com/enaut)
252+
* [@exi](https://github.com/exi)
253+
* [@felinira](https://github.com/felinira)
254+
* [@fengalin](https://github.com/fengalin)
255+
* [@GuillaumeGomez](https://github.com/GuillaumeGomez)
256+
* [@Hofer-Julian](https://github.com/Hofer-Julian)
257+
* [@liushuyu](https://github.com/liushuyu)
258+
* [@marcinjahn](https://github.com/marcinjahn)
259+
* [@misson20000](https://github.com/misson20000)
260+
* [@mjgarton](https://github.com/mjgarton)
261+
* [@mokurin000](https://github.com/mokurin000)
262+
* [@mtilda](https://github.com/mtilda)
263+
* [@nazar-pc](https://github.com/nazar-pc)
264+
* [@pbor](https://github.com/pbor)
265+
* [@pranjalkole](https://github.com/pranjalkole)
266+
* [@sdroege](https://github.com/sdroege)
267+
* [@vhakulinen](https://github.com/vhakulinen)
268+
* [@woelfman](https://github.com/woelfman)
269+
* [@ystreet](https://github.com/ystreet)
270+
* [@zecakeh](https://github.com/zecakeh)

0 commit comments

Comments
 (0)