1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#![doc(html_logo_url = "https://msandova.pages.gitlab.gnome.org/trinket/libtrinket.svg")]
//! # Trinket Widget Library
//!
//! Trinket needs to be initialized before use by calling [init()], which should be
//! called after [gtk::init()].
//!
//! To use widget methods import `use trinket::prelude::*;`. For subclassing
//! widgets add `use trinket::subclass::prelude::*;`.
//!
//! See also: [C API Reference](https://msandova.pages.gitlab.gnome.org/trinket/).

use gtk::gdk;
use gtk::prelude::*;
use std::sync::Once;

#[cfg(feature = "bindings")]
pub mod ffi;
pub mod prelude;
pub mod subclass;

mod notification;
mod notification_bin;
mod notification_widget;
mod progress_icon;
mod qr_code;

pub use notification::{Notification, NONE_NOTIFICATION};
pub use notification_bin::{NotificationBin, NONE_NOTIFICATION_BIN};
pub(crate) use notification_widget::NotificationWidget;
pub use progress_icon::{ProgressIcon, NONE_PROGRESS_ICON};
pub use qr_code::{QRCode, NONE_QR_CODE};

/// Initializes Trinket.
///
/// Call this function just after initializing GTK, if you are using
/// [`gtk::Application`] it means it must be called when the
/// [`gio::subclass::prelude::ApplicationImpl::startup()`](gtk::gio::subclass::prelude::ApplicationImpl::startup()) signal is emitted.
///
/// If Trinket has already been initialized, the function will simply return.
///
/// This makes sure translations, and types for the Trinket
/// library are set up properly.
#[doc(alias = "tri_init")]
pub fn init() {
    static INIT: Once = Once::new();

    INIT.call_once(|| {
        ProgressIcon::static_type();
        NotificationBin::static_type();
        QRCode::static_type();

        gtk::init().unwrap();
        let provider = gtk::CssProvider::new();
        provider.load_from_data(include_bytes!("style.css"));
        if let Some(display) = gdk::Display::default() {
            gtk::StyleContext::add_provider_for_display(
                &display,
                &provider,
                gtk::STYLE_PROVIDER_PRIORITY_THEME,
            );
        }
    });
}