Skip to content

Commit 1360868

Browse files
gtk: Move provider related functions outside of StyleContext
To avoid them being marked as deprecated in v4_10and is also more sementically correct Fixes #1317
1 parent dab8dc0 commit 1360868

File tree

8 files changed

+83
-34
lines changed

8 files changed

+83
-34
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
=======
77
Bilal Elmoussaoui:
88
- gtk: Implement convenience traits for StringObject
9+
- gtk: Move `gtk::StyleContext::add_provider_for_display` & `gtk::StyleContext::remove_provider_for_display` functions
10+
outside of `gtk::StyleContext` type as it was deprecated in GTK 4.10 causing a wrong deprecation warning.
11+
Switch to `gtk::style_context_add_provider_for_display` & `gtk::style_context_remove_provider_for_display` instead.
912

1013
>>>>>>> 0b4dd7717 (gtk: Implement convenience traits for StringObject)
1114
## [0.6.5]

examples/css/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use gtk::prelude::*;
44
use gtk::gdk::Display;
55
use gtk::{
66
Application, ApplicationWindow, Box as Box_, Button, ComboBoxText, CssProvider, Entry,
7-
Orientation, StyleContext, STYLE_PROVIDER_PRIORITY_APPLICATION,
7+
Orientation, STYLE_PROVIDER_PRIORITY_APPLICATION,
88
};
99

1010
fn main() -> glib::ExitCode {
@@ -15,7 +15,7 @@ fn main() -> glib::ExitCode {
1515
provider.load_from_data(include_str!("style.css"));
1616
// We give the CssProvided to the default screen so the CSS rules we added
1717
// can be applied to our window.
18-
StyleContext::add_provider_for_display(
18+
gtk::style_context_add_provider_for_display(
1919
&Display::default().expect("Could not connect to a display."),
2020
&provider,
2121
STYLE_PROVIDER_PRIORITY_APPLICATION,

examples/custom_editable/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn main() -> glib::ExitCode {
1717
application.connect_startup(|_| {
1818
let provider = gtk::CssProvider::new();
1919
provider.load_from_data(include_str!("style.css"));
20-
gtk::StyleContext::add_provider_for_display(
20+
gtk::style_context_add_provider_for_display(
2121
&gdk::Display::default().unwrap(),
2222
&provider,
2323
800,

gtk4/Gir.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2064,6 +2064,11 @@ generate_builder = false
20642064
name = "Gtk.StyleContext"
20652065
status = "generate"
20662066
generate_builder = false
2067+
[[object.function]]
2068+
pattern = "(add|remove)_provider_for_display"
2069+
# To avoid them being marked as deprecated along with StyleContext
2070+
# see https://github.com/gtk-rs/gtk4-rs/issues/1317
2071+
manual = true
20672072

20682073
[[object]]
20692074
name = "Gtk.Switch"

gtk4/src/auto/style_context.rs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,36 +22,6 @@ glib::wrapper! {
2222

2323
impl StyleContext {
2424
pub const NONE: Option<&'static StyleContext> = None;
25-
26-
#[doc(alias = "gtk_style_context_add_provider_for_display")]
27-
pub fn add_provider_for_display(
28-
display: &impl IsA<gdk::Display>,
29-
provider: &impl IsA<StyleProvider>,
30-
priority: u32,
31-
) {
32-
skip_assert_initialized!();
33-
unsafe {
34-
ffi::gtk_style_context_add_provider_for_display(
35-
display.as_ref().to_glib_none().0,
36-
provider.as_ref().to_glib_none().0,
37-
priority,
38-
);
39-
}
40-
}
41-
42-
#[doc(alias = "gtk_style_context_remove_provider_for_display")]
43-
pub fn remove_provider_for_display(
44-
display: &impl IsA<gdk::Display>,
45-
provider: &impl IsA<StyleProvider>,
46-
) {
47-
skip_assert_initialized!();
48-
unsafe {
49-
ffi::gtk_style_context_remove_provider_for_display(
50-
display.as_ref().to_glib_none().0,
51-
provider.as_ref().to_glib_none().0,
52-
);
53-
}
54-
}
5525
}
5626

5727
pub trait StyleContextExt: 'static {

gtk4/src/functions.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Take a look at the license at the top of the repository in the LICENSE file.
22

3-
use crate::{prelude::*, AboutDialog, Window};
3+
use crate::{prelude::*, AboutDialog, StyleProvider, Window};
44
use glib::{translate::*, IntoGStr, Quark, Slice, ToValue};
55
use once_cell::sync::Lazy;
66
use std::{boxed::Box as Box_, mem, pin::Pin, ptr};
@@ -254,3 +254,35 @@ pub fn test_list_all_types() -> Slice<glib::Type> {
254254
Slice::from_glib_container_num(types as *mut _, n_types.assume_init() as usize)
255255
}
256256
}
257+
258+
#[doc(alias = "gtk_style_context_add_provider_for_display")]
259+
#[doc(alias = "add_provider_for_display")]
260+
pub fn style_context_add_provider_for_display(
261+
display: &impl IsA<gdk::Display>,
262+
provider: &impl IsA<StyleProvider>,
263+
priority: u32,
264+
) {
265+
skip_assert_initialized!();
266+
unsafe {
267+
ffi::gtk_style_context_add_provider_for_display(
268+
display.as_ref().to_glib_none().0,
269+
provider.as_ref().to_glib_none().0,
270+
priority,
271+
);
272+
}
273+
}
274+
275+
#[doc(alias = "gtk_style_context_remove_provider_for_display")]
276+
#[doc(alias = "remove_provider_for_display")]
277+
pub fn style_context_remove_provider_for_display(
278+
display: &impl IsA<gdk::Display>,
279+
provider: &impl IsA<StyleProvider>,
280+
) {
281+
skip_assert_initialized!();
282+
unsafe {
283+
ffi::gtk_style_context_remove_provider_for_display(
284+
display.as_ref().to_glib_none().0,
285+
provider.as_ref().to_glib_none().0,
286+
);
287+
}
288+
}

gtk4/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ mod snapshot;
184184
mod spin_button;
185185
mod string_list;
186186
mod string_object;
187+
mod style_context;
187188
mod text;
188189
mod text_buffer;
189190
mod tree_model;

gtk4/src/style_context.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Take a look at the license at the top of the repository in the LICENSE file.
2+
3+
pub use crate::{prelude::*, StyleContext, StyleProvider};
4+
use glib::translate::*;
5+
6+
impl StyleContext {
7+
#[deprecated(note = "Use gtk::style_context_add_provider_for_display instead.")]
8+
#[doc(alias = "gtk_style_context_add_provider_for_display")]
9+
pub fn add_provider_for_display(
10+
display: &impl IsA<gdk::Display>,
11+
provider: &impl IsA<StyleProvider>,
12+
priority: u32,
13+
) {
14+
skip_assert_initialized!();
15+
unsafe {
16+
ffi::gtk_style_context_add_provider_for_display(
17+
display.as_ref().to_glib_none().0,
18+
provider.as_ref().to_glib_none().0,
19+
priority,
20+
);
21+
}
22+
}
23+
24+
#[deprecated(note = "Use gtk::style_context_remove_provider_for_display instead.")]
25+
#[doc(alias = "gtk_style_context_remove_provider_for_display")]
26+
pub fn remove_provider_for_display(
27+
display: &impl IsA<gdk::Display>,
28+
provider: &impl IsA<StyleProvider>,
29+
) {
30+
skip_assert_initialized!();
31+
unsafe {
32+
ffi::gtk_style_context_remove_provider_for_display(
33+
display.as_ref().to_glib_none().0,
34+
provider.as_ref().to_glib_none().0,
35+
);
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)