Skip to main content

gtk4/
lib.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3#![cfg_attr(docsrs, feature(doc_cfg))]
4#![allow(deprecated)]
5#![allow(clippy::manual_c_str_literals)]
6#![doc = include_str!("../README.md")]
7
8// Re-export gtk dependencies
9pub use cairo;
10pub use gdk;
11pub use gdk_pixbuf;
12pub use gio;
13pub use glib;
14pub use graphene;
15pub use gsk;
16pub use gtk4_sys as ffi;
17pub use pango;
18
19#[macro_use]
20#[doc(hidden)]
21#[allow(unused_imports)]
22pub extern crate field_offset;
23#[macro_use]
24#[doc(hidden)]
25#[allow(unused_imports)]
26pub extern crate gtk4_macros;
27
28#[doc(hidden)]
29pub use field_offset::*;
30#[doc(hidden)]
31pub use gtk4_macros::*;
32
33/// The priority used for default style information
34/// that is used in the absence of themes.
35///
36/// Note that this is not very useful for providing default
37/// styling for custom style classes - themes are likely to
38/// override styling provided at this priority with
39/// catch-all `* {...}` rules.
40#[doc(alias = "GTK_STYLE_PROVIDER_PRIORITY_FALLBACK")]
41pub const STYLE_PROVIDER_PRIORITY_FALLBACK: u32 = ffi::GTK_STYLE_PROVIDER_PRIORITY_FALLBACK as _;
42/// The priority used for style information provided
43/// by themes.
44#[doc(alias = "GTK_STYLE_PROVIDER_PRIORITY_THEME")]
45pub const STYLE_PROVIDER_PRIORITY_THEME: u32 = ffi::GTK_STYLE_PROVIDER_PRIORITY_THEME as _;
46/// The priority used for style information provided
47/// via [`Settings`][crate::Settings].
48///
49/// This priority is higher than `GTK_STYLE_PROVIDER_PRIORITY_THEME`
50/// to let settings override themes.
51#[doc(alias = "GTK_STYLE_PROVIDER_PRIORITY_SETTINGS")]
52pub const STYLE_PROVIDER_PRIORITY_SETTINGS: u32 = ffi::GTK_STYLE_PROVIDER_PRIORITY_SETTINGS as _;
53/// A priority that can be used when adding a [`StyleProvider`][crate::StyleProvider]
54/// for application-specific style information.
55#[doc(alias = "GTK_STYLE_PROVIDER_PRIORITY_APPLICATION")]
56pub const STYLE_PROVIDER_PRIORITY_APPLICATION: u32 =
57    ffi::GTK_STYLE_PROVIDER_PRIORITY_APPLICATION as _;
58/// The priority used for the style information from
59/// `$XDG_CONFIG_HOME/gtk-4.0/gtk.css`.
60///
61/// You should not use priorities higher than this, to
62/// give the user the last word.
63#[doc(alias = "GTK_STYLE_PROVIDER_PRIORITY_USER")]
64pub const STYLE_PROVIDER_PRIORITY_USER: u32 = ffi::GTK_STYLE_PROVIDER_PRIORITY_USER as _;
65
66/// An undefined value. The accessible attribute is either unset, or its
67/// value is undefined.
68#[doc(alias = "GTK_ACCESSIBLE_VALUE_UNDEFINED")]
69pub const ACCESSIBLE_VALUE_UNDEFINED: i32 = ffi::GTK_ACCESSIBLE_VALUE_UNDEFINED as _;
70
71/// The value used to refer to a guaranteed invalid position
72/// in a `GListModel`.
73///
74/// This value may be returned from some functions, others may
75/// accept it as input. Its interpretation may differ for different
76/// functions.
77///
78/// Refer to each function's documentation for if this value is
79/// allowed and what it does.
80#[doc(alias = "GTK_INVALID_LIST_POSITION")]
81pub const INVALID_LIST_POSITION: u32 = ffi::GTK_INVALID_LIST_POSITION as _;
82
83/// Use this priority for functionality related to size allocation.
84///
85/// It is used internally by GTK+ to compute the sizes of widgets.
86/// This priority is higher than `GDK_PRIORITY_REDRAW` to avoid
87/// resizing a widget which was just redrawn.
88#[doc(alias = "GTK_PRIORITY_RESIZE")]
89pub const PRIORITY_RESIZE: u32 = ffi::GTK_PRIORITY_RESIZE as _;
90/// The priority at which the text view validates onscreen lines
91/// in an idle job in the background.
92#[doc(alias = "GTK_TEXT_VIEW_PRIORITY_VALIDATE")]
93pub const TEXT_VIEW_PRIORITY_VALIDATE: u32 = ffi::GTK_TEXT_VIEW_PRIORITY_VALIDATE as _;
94
95#[macro_use]
96mod rt;
97
98#[doc(hidden)]
99pub fn test_synced<F, R>(function: F) -> R
100where
101    F: FnOnce() -> R + Send + std::panic::UnwindSafe + 'static,
102    R: Send + 'static,
103{
104    skip_assert_initialized!();
105    static TEST_THREAD_WORKER: std::sync::OnceLock<glib::ThreadPool> = std::sync::OnceLock::new();
106    let pool = TEST_THREAD_WORKER.get_or_init(|| {
107        let pool = glib::ThreadPool::exclusive(1).unwrap();
108        pool.push(move || {
109            crate::init().expect("Tests failed to initialize gtk");
110        })
111        .expect("Failed to schedule a test call");
112        pool
113    });
114
115    use std::{panic, sync::mpsc};
116
117    let (tx, rx) = mpsc::sync_channel(1);
118    pool.push(move || {
119        tx.send(panic::catch_unwind(function))
120            .unwrap_or_else(|_| panic!("Failed to return result from thread pool"));
121    })
122    .expect("Failed to schedule a test call");
123    rx.recv()
124        .expect("Failed to receive result from thread pool")
125        .unwrap_or_else(|e| std::panic::resume_unwind(e))
126}
127
128#[allow(clippy::derived_hash_with_manual_eq)]
129#[allow(clippy::too_many_arguments)]
130#[allow(clippy::type_complexity)]
131#[allow(clippy::let_and_return)]
132#[allow(unused_imports)]
133mod auto;
134
135#[macro_use]
136pub mod subclass;
137#[macro_use]
138mod expression;
139
140pub mod builders;
141pub mod prelude;
142
143pub use auto::*;
144pub use rt::*;
145
146pub mod accessible;
147#[cfg(feature = "v4_14")]
148#[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
149mod accessible_text_range;
150mod actionable;
151mod application;
152mod assistant;
153mod bitset_iter;
154mod bookmark_list;
155mod border;
156mod builder;
157mod builder_cscope;
158mod builder_rust_scope;
159mod calendar;
160mod callback_action;
161mod cell_area;
162mod cell_layout;
163mod closure_expression;
164mod color_chooser;
165mod combo_box;
166mod constant_expression;
167mod constraint_guide;
168mod constraint_layout;
169mod css_location;
170mod custom_filter;
171mod custom_sorter;
172mod dialog;
173mod directory_list;
174mod drawing_area;
175mod drop_target;
176mod editable;
177mod editable_label;
178mod entry;
179mod entry_buffer;
180mod entry_completion;
181mod enums;
182mod event_controller;
183mod event_controller_key;
184mod expression_watch;
185mod file_chooser;
186mod file_chooser_dialog;
187mod flow_box;
188mod font_chooser;
189#[cfg(feature = "v4_10")]
190#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
191mod font_dialog;
192mod functions;
193mod gesture_stylus;
194mod icon_theme;
195mod im_context_simple;
196mod info_bar;
197mod keyval_trigger;
198mod label;
199mod list_box;
200mod list_store;
201mod map_list_model;
202mod media_stream;
203mod menu_button;
204mod message_dialog;
205mod mnemonic_trigger;
206mod native_dialog;
207mod notebook;
208mod object_expression;
209mod overlay;
210mod pad_action_entry;
211mod page_range;
212mod param_spec_expression;
213#[cfg(target_os = "linux")]
214#[cfg_attr(docsrs, doc(cfg(target_os = "linux")))]
215mod print_job;
216mod print_operation;
217mod print_settings;
218mod property_expression;
219mod recent_data;
220mod requisition;
221mod response_type;
222mod scale;
223mod shortcut;
224mod shortcut_trigger;
225mod shortcuts_section;
226mod signal_list_item_factory;
227mod snapshot;
228mod spin_button;
229mod string_list;
230mod string_object;
231mod style_context;
232mod text;
233mod text_buffer;
234mod tree_model;
235mod tree_model_filter;
236mod tree_path;
237mod tree_row_reference;
238mod tree_selection;
239mod tree_sortable;
240mod tree_store;
241mod tree_view;
242mod tree_view_column;
243mod widget;
244
245#[cfg(feature = "v4_14")]
246#[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
247pub use accessible_text_range::AccessibleTextRange;
248pub use bitset_iter::BitsetIter;
249pub use border::Border;
250pub use builder_cscope::BuilderCScope;
251pub use builder_rust_scope::BuilderRustScope;
252pub use css_location::CssLocation;
253pub use enums::Align;
254pub use expression_watch::ExpressionWatch;
255pub use functions::*;
256pub use keyval_trigger::KeyvalTrigger;
257pub use mnemonic_trigger::MnemonicTrigger;
258pub use pad_action_entry::PadActionEntry;
259pub use page_range::PageRange;
260pub use recent_data::RecentData;
261pub use response_type::ResponseType;
262pub use subclass::widget::TemplateChild;
263pub use tree_sortable::SortColumn;
264pub use widget::TickCallbackId;