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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
use crate::ColorRGBColor;
use glib::object::Cast;
use glib::object::IsA;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use glib::StaticType;
use glib::ToValue;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem::transmute;
glib::wrapper! {
#[doc(alias = "HeApplication")]
pub struct Application(Object<ffi::HeApplication, ffi::HeApplicationClass>) @extends gtk::Application, gio::Application, @implements gio::ActionGroup, gio::ActionMap;
match fn {
type_ => || ffi::he_application_get_type(),
}
}
impl Application {
pub const NONE: Option<&'static Application> = None;
pub fn builder() -> ApplicationBuilder {
ApplicationBuilder::default()
}
}
#[derive(Clone, Default)]
#[must_use = "The builder must be built to be used"]
pub struct ApplicationBuilder {
default_accent_color: Option<ColorRGBColor>,
accent_color: Option<ColorRGBColor>,
foreground: Option<ColorRGBColor>,
accent_foreground: Option<ColorRGBColor>,
menubar: Option<gio::MenuModel>,
register_session: Option<bool>,
action_group: Option<gio::ActionGroup>,
application_id: Option<String>,
flags: Option<gio::ApplicationFlags>,
inactivity_timeout: Option<u32>,
resource_base_path: Option<String>,
}
impl ApplicationBuilder {
pub fn new() -> Self {
Self::default()
}
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
pub fn build(self) -> Application {
let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
if let Some(ref default_accent_color) = self.default_accent_color {
properties.push(("default-accent-color", default_accent_color));
}
if let Some(ref accent_color) = self.accent_color {
properties.push(("accent-color", accent_color));
}
if let Some(ref foreground) = self.foreground {
properties.push(("foreground", foreground));
}
if let Some(ref accent_foreground) = self.accent_foreground {
properties.push(("accent-foreground", accent_foreground));
}
if let Some(ref menubar) = self.menubar {
properties.push(("menubar", menubar));
}
if let Some(ref register_session) = self.register_session {
properties.push(("register-session", register_session));
}
if let Some(ref action_group) = self.action_group {
properties.push(("action-group", action_group));
}
if let Some(ref application_id) = self.application_id {
properties.push(("application-id", application_id));
}
if let Some(ref flags) = self.flags {
properties.push(("flags", flags));
}
if let Some(ref inactivity_timeout) = self.inactivity_timeout {
properties.push(("inactivity-timeout", inactivity_timeout));
}
if let Some(ref resource_base_path) = self.resource_base_path {
properties.push(("resource-base-path", resource_base_path));
}
let ret = glib::Object::new::<Application>(&properties)
.expect("Failed to create an instance of Application");
{
Application::register_startup_hook(&ret);
}
ret
}
pub fn default_accent_color(mut self, default_accent_color: &ColorRGBColor) -> Self {
self.default_accent_color = Some(default_accent_color.clone());
self
}
pub fn accent_color(mut self, accent_color: &ColorRGBColor) -> Self {
self.accent_color = Some(accent_color.clone());
self
}
pub fn foreground(mut self, foreground: &ColorRGBColor) -> Self {
self.foreground = Some(foreground.clone());
self
}
pub fn accent_foreground(mut self, accent_foreground: &ColorRGBColor) -> Self {
self.accent_foreground = Some(accent_foreground.clone());
self
}
pub fn menubar(mut self, menubar: &impl IsA<gio::MenuModel>) -> Self {
self.menubar = Some(menubar.clone().upcast());
self
}
pub fn register_session(mut self, register_session: bool) -> Self {
self.register_session = Some(register_session);
self
}
pub fn action_group(mut self, action_group: &impl IsA<gio::ActionGroup>) -> Self {
self.action_group = Some(action_group.clone().upcast());
self
}
pub fn application_id(mut self, application_id: &str) -> Self {
self.application_id = Some(application_id.to_string());
self
}
pub fn flags(mut self, flags: gio::ApplicationFlags) -> Self {
self.flags = Some(flags);
self
}
pub fn inactivity_timeout(mut self, inactivity_timeout: u32) -> Self {
self.inactivity_timeout = Some(inactivity_timeout);
self
}
pub fn resource_base_path(mut self, resource_base_path: &str) -> Self {
self.resource_base_path = Some(resource_base_path.to_string());
self
}
}
pub trait HeApplicationExt: 'static {
#[doc(alias = "he_application_get_default_accent_color")]
#[doc(alias = "get_default_accent_color")]
fn default_accent_color(&self) -> Option<ColorRGBColor>;
#[doc(alias = "accent-color")]
fn set_accent_color(&self, accent_color: Option<&ColorRGBColor>);
fn set_foreground(&self, foreground: Option<&ColorRGBColor>);
#[doc(alias = "accent-foreground")]
fn set_accent_foreground(&self, accent_foreground: Option<&ColorRGBColor>);
#[doc(alias = "default-accent-color")]
fn connect_default_accent_color_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
#[doc(alias = "accent-color")]
fn connect_accent_color_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
#[doc(alias = "foreground")]
fn connect_foreground_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
#[doc(alias = "accent-foreground")]
fn connect_accent_foreground_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}
impl<O: IsA<Application>> HeApplicationExt for O {
fn default_accent_color(&self) -> Option<ColorRGBColor> {
unsafe {
from_glib_none(ffi::he_application_get_default_accent_color(
self.as_ref().to_glib_none().0,
))
}
}
fn set_accent_color(&self, accent_color: Option<&ColorRGBColor>) {
glib::ObjectExt::set_property(self.as_ref(), "accent-color", &accent_color)
}
fn set_foreground(&self, foreground: Option<&ColorRGBColor>) {
glib::ObjectExt::set_property(self.as_ref(), "foreground", &foreground)
}
fn set_accent_foreground(&self, accent_foreground: Option<&ColorRGBColor>) {
glib::ObjectExt::set_property(self.as_ref(), "accent-foreground", &accent_foreground)
}
fn connect_default_accent_color_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_default_accent_color_trampoline<
P: IsA<Application>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::HeApplication,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(Application::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::default-accent-color\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_default_accent_color_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_accent_color_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_accent_color_trampoline<
P: IsA<Application>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::HeApplication,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(Application::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::accent-color\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_accent_color_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_foreground_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_foreground_trampoline<
P: IsA<Application>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::HeApplication,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(Application::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::foreground\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_foreground_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_accent_foreground_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_accent_foreground_trampoline<
P: IsA<Application>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::HeApplication,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(Application::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::accent-foreground\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_accent_foreground_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl fmt::Display for Application {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("Application")
}
}