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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// Copyright (c) 2026 John Law
// SPDX-License-Identifier: MIT
//! Native Windows UI with a glass look: a tray icon and menu, a frosted-glass popup, themed
//! dialogs, and helpers for tray apps.
//!
//! - [`tray`]: an icon in the notification area with a menu, and [`Tray::wait`], the main
//! loop of the app. It sleeps until a menu command, a deadline, or an unlock of the session.
//! - [`popup`]: a frosted-glass popup with a question and choice buttons. It fades in without
//! taking the keyboard focus, can show whether a choice was correct, and can dismiss itself.
//! - [`dialog`]: a small modal window made of standard controls, in the same colors.
//! - [`placement`]: where a window shows, as fractions of the free space of the screen.
//! - [`autostart`], [`presence`], [`process`], [`single_instance`], and [`show_error`]: small
//! helpers that tray apps often need.
//!
//! All windows follow the Windows light or dark app mode and the display scale.
//!
//! # Threads
//!
//! Make one [`Ui`] on the thread that shows the windows, and make all windows on that thread.
//! [`Ui`] is not `Send`, so the compiler stops a window from going to another thread. The
//! thread must run the loops of [`Tray::wait`], [`ChoicePopup::ask`], and [`Dialog::run`]:
//! each of them handles the window messages of the thread while it waits.
//!
//! # Example
//!
//! A tray app that asks a question each minute and on "Ask now". The same program is in
//! `examples/quiz.rs`.
//!
//! ```no_run
//! use std::time::{Duration, SystemTime};
//!
//! use glasskit::Ui;
//! use glasskit::placement::Placement;
//! use glasskit::popup::{ChoicePopup, Prompt, Response};
//! use glasskit::tray::{Icon, MenuItem, Tray, Wake};
//!
//! #[derive(Debug, Clone, PartialEq, Eq)]
//! enum Command {
//! AskNow,
//! }
//!
//! fn main() -> glasskit::Result<()> {
//! let ui = Ui::new()?;
//! let size = Icon::tray_size();
//! let icon = Icon::from_argb(size, vec![0xFF2E_86DE; (size * size) as usize])?;
//! let mut tray = Tray::new(&ui, "Quiz", &icon)?;
//! tray.set_menu(&[
//! MenuItem::command(Command::AskNow, "Ask now"),
//! MenuItem::Separator,
//! MenuItem::Quit("Quit".into()),
//! ]);
//! let mut popup = ChoicePopup::new(&ui, Placement::default())?;
//! loop {
//! let next = SystemTime::now() + Duration::from_secs(60);
//! match tray.wait(Some(next))? {
//! Wake::Quit => return Ok(()),
//! Wake::SessionUnlocked => {}
//! Wake::Deadline | Wake::Command(Command::AskNow) => {
//! let prompt = Prompt::new("What is 2 + 2?", ["3", "4", "5"])
//! .correct(1)
//! .auto_dismiss(Some(Duration::from_secs(30)));
//! if popup.ask(&prompt)?.response == Response::Quit {
//! return Ok(());
//! }
//! }
//! }
//! }
//! }
//! ```
//!
//! [`Tray::wait`]: tray::Tray::wait
//! [`ChoicePopup::ask`]: popup::ChoicePopup::ask
//! [`Dialog::run`]: dialog::Dialog::run
compile_error!;
/// Compiles the example of the README as a doc test.
;
pub use ;
pub use Ui;
use crateCall;
use ;
use ;
use CreateMutexW;
use UI;
use UI;
use HSTRING;
/// Register a window class. A class stays registered until the process ends, so a second
/// registration of the same class is not an error.
pub
/// The system DPI stays at its sign-in value. Read the DPI of the monitor each time a window
/// opens, so a change of the display scale applies to the next window.
pub
/// Show an error in a message box, and wait until the user closes it.
/// It needs no [`Ui`], so it also works before the setup or after a failed setup.
/// Proof that this process is the only one with a name in the user session.
/// The name is free again when the guard is dropped or the process ends.
;
/// Take `name` for this process in the user session. It gives `None` if another process
/// has the name, for example a second start of the same app.