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#[doc(alias = "GTK_STYLE_PROVIDER_PRIORITY_FALLBACK")]
34pub const STYLE_PROVIDER_PRIORITY_FALLBACK: u32 = ffi::GTK_STYLE_PROVIDER_PRIORITY_FALLBACK as _;
35#[doc(alias = "GTK_STYLE_PROVIDER_PRIORITY_THEME")]
36pub const STYLE_PROVIDER_PRIORITY_THEME: u32 = ffi::GTK_STYLE_PROVIDER_PRIORITY_THEME as _;
37#[doc(alias = "GTK_STYLE_PROVIDER_PRIORITY_SETTINGS")]
38pub const STYLE_PROVIDER_PRIORITY_SETTINGS: u32 = ffi::GTK_STYLE_PROVIDER_PRIORITY_SETTINGS as _;
39#[doc(alias = "GTK_STYLE_PROVIDER_PRIORITY_APPLICATION")]
40pub const STYLE_PROVIDER_PRIORITY_APPLICATION: u32 =
41    ffi::GTK_STYLE_PROVIDER_PRIORITY_APPLICATION as _;
42#[doc(alias = "GTK_STYLE_PROVIDER_PRIORITY_USER")]
43pub const STYLE_PROVIDER_PRIORITY_USER: u32 = ffi::GTK_STYLE_PROVIDER_PRIORITY_USER as _;
44
45#[doc(alias = "GTK_ACCESSIBLE_VALUE_UNDEFINED")]
46pub const ACCESSIBLE_VALUE_UNDEFINED: i32 = ffi::GTK_ACCESSIBLE_VALUE_UNDEFINED as _;
47
48#[doc(alias = "GTK_INVALID_LIST_POSITION")]
49pub const INVALID_LIST_POSITION: u32 = ffi::GTK_INVALID_LIST_POSITION as _;
50
51#[doc(alias = "GTK_PRIORITY_RESIZE")]
52pub const PRIORITY_RESIZE: u32 = ffi::GTK_PRIORITY_RESIZE as _;
53#[doc(alias = "GTK_TEXT_VIEW_PRIORITY_VALIDATE")]
54pub const TEXT_VIEW_PRIORITY_VALIDATE: u32 = ffi::GTK_TEXT_VIEW_PRIORITY_VALIDATE as _;
55
56#[macro_use]
57mod rt;
58
59#[doc(hidden)]
60pub fn test_synced<F, R>(function: F) -> R
61where
62    F: FnOnce() -> R + Send + std::panic::UnwindSafe + 'static,
63    R: Send + 'static,
64{
65    skip_assert_initialized!();
66    static TEST_THREAD_WORKER: std::sync::OnceLock<glib::ThreadPool> = std::sync::OnceLock::new();
67    let pool = TEST_THREAD_WORKER.get_or_init(|| {
68        let pool = glib::ThreadPool::exclusive(1).unwrap();
69        pool.push(move || {
70            crate::init().expect("Tests failed to initialize gtk");
71        })
72        .expect("Failed to schedule a test call");
73        pool
74    });
75
76    use std::{panic, sync::mpsc};
77
78    let (tx, rx) = mpsc::sync_channel(1);
79    pool.push(move || {
80        tx.send(panic::catch_unwind(function))
81            .unwrap_or_else(|_| panic!("Failed to return result from thread pool"));
82    })
83    .expect("Failed to schedule a test call");
84    rx.recv()
85        .expect("Failed to receive result from thread pool")
86        .unwrap_or_else(|e| std::panic::resume_unwind(e))
87}
88
89#[allow(clippy::derived_hash_with_manual_eq)]
90#[allow(clippy::too_many_arguments)]
91#[allow(clippy::type_complexity)]
92#[allow(unused_imports)]
93mod auto;
94
95#[macro_use]
96pub mod subclass;
97#[macro_use]
98mod expression;
99
100pub mod builders;
101pub mod prelude;
102
103pub use auto::*;
104pub use rt::*;
105
106pub mod accessible;
107#[cfg(feature = "v4_14")]
108#[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
109mod accessible_text_range;
110mod actionable;
111mod application;
112mod assistant;
113mod bitset_iter;
114mod bookmark_list;
115mod border;
116mod builder;
117mod builder_cscope;
118mod builder_rust_scope;
119mod calendar;
120mod callback_action;
121mod cell_area;
122mod cell_layout;
123mod closure_expression;
124mod color_chooser;
125mod combo_box;
126mod constant_expression;
127mod constraint_guide;
128mod constraint_layout;
129mod css_location;
130mod custom_filter;
131mod custom_sorter;
132mod dialog;
133mod directory_list;
134mod drawing_area;
135mod drop_target;
136mod editable;
137mod editable_label;
138mod entry;
139mod entry_buffer;
140mod entry_completion;
141mod enums;
142mod event_controller;
143mod event_controller_key;
144mod expression_watch;
145mod file_chooser;
146mod file_chooser_dialog;
147mod flow_box;
148mod font_chooser;
149#[cfg(feature = "v4_10")]
150#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
151mod font_dialog;
152mod functions;
153mod gesture_stylus;
154mod icon_theme;
155mod im_context_simple;
156mod info_bar;
157mod keyval_trigger;
158mod label;
159mod list_box;
160mod list_store;
161mod map_list_model;
162mod media_stream;
163mod menu_button;
164mod message_dialog;
165mod mnemonic_trigger;
166mod native_dialog;
167mod notebook;
168mod object_expression;
169mod overlay;
170mod pad_action_entry;
171mod page_range;
172mod param_spec_expression;
173#[cfg(target_os = "linux")]
174#[cfg_attr(docsrs, doc(cfg(target_os = "linux")))]
175mod print_job;
176mod print_operation;
177mod print_settings;
178mod property_expression;
179mod recent_data;
180mod requisition;
181mod response_type;
182mod scale;
183mod shortcut;
184mod shortcut_trigger;
185mod shortcuts_section;
186mod signal_list_item_factory;
187mod snapshot;
188mod spin_button;
189mod string_list;
190mod string_object;
191mod style_context;
192mod text;
193mod text_buffer;
194mod tree_model;
195mod tree_model_filter;
196mod tree_path;
197mod tree_row_reference;
198mod tree_selection;
199mod tree_sortable;
200mod tree_store;
201mod tree_view;
202mod tree_view_column;
203mod widget;
204
205#[cfg(feature = "v4_14")]
206#[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
207pub use accessible_text_range::AccessibleTextRange;
208pub use bitset_iter::BitsetIter;
209pub use border::Border;
210pub use builder_cscope::BuilderCScope;
211pub use builder_rust_scope::BuilderRustScope;
212pub use css_location::CssLocation;
213pub use enums::Align;
214pub use expression_watch::ExpressionWatch;
215pub use functions::*;
216pub use keyval_trigger::KeyvalTrigger;
217pub use mnemonic_trigger::MnemonicTrigger;
218pub use pad_action_entry::PadActionEntry;
219pub use page_range::PageRange;
220pub use recent_data::RecentData;
221pub use response_type::ResponseType;
222pub use subclass::widget::TemplateChild;
223pub use tree_sortable::SortColumn;
224pub use widget::TickCallbackId;