custom_shell_and_lockscreen/
custom-shell-and-lockscreen.rs1use gtk;
2use libphosh as phosh;
3use libphosh::prelude::*;
4
5fn main() {
6 gtk::init().unwrap();
7
8 let clock = phosh::WallClock::new();
9 clock.set_default();
10
11 let shell = custom_shell::CustomShell::new();
12 shell.set_default();
13 shell.set_locked(true);
14
15 shell.connect_ready(|_| {
16 glib::g_message!("example", "Custom Rusty shell ready");
17 });
18
19 gtk::main();
20}
21
22mod custom_shell {
23 use glib::Object;
24 use gtk::glib;
25
26 glib::wrapper! {
27 pub struct CustomShell(ObjectSubclass<imp::CustomShell>)
28 @extends libphosh::Shell;
29 }
30
31 impl CustomShell {
32 pub fn new() -> Self {
33 Object::builder().build()
34 }
35 }
36
37 impl Default for CustomShell {
38 fn default() -> Self {
39 Self::new()
40 }
41 }
42
43 mod imp {
44 use gtk::glib;
45 use gtk::glib::Type;
46 use gtk::prelude::StaticType;
47 use gtk::subclass::prelude::{ObjectImpl, ObjectSubclass};
48 use libphosh::subclass::shell::ShellImpl;
49 use crate::custom_lockscreen::CustomLockscreen;
50
51 #[derive(Default)]
52 pub struct CustomShell;
53
54 #[glib::object_subclass]
55 impl ObjectSubclass for CustomShell {
56 const NAME: &'static str = "CustomShell";
57 type Type = super::CustomShell;
58 type ParentType = libphosh::Shell;
59 }
60
61 impl ObjectImpl for CustomShell {}
62
63 impl ShellImpl for CustomShell {
64 fn get_lockscreen_type(&self) -> Type {
65 CustomLockscreen::static_type()
66 }
67 }
68 }
69}
70
71mod custom_lockscreen {
72 use glib::Object;
73
74 glib::wrapper! {
75 pub struct CustomLockscreen(ObjectSubclass<imp::CustomLockscreen>)
76 @extends libphosh::Lockscreen;
77 }
78
79 impl CustomLockscreen {
80 pub fn new() -> Self {
81 Object::builder().build()
82 }
83 }
84
85 impl Default for CustomLockscreen {
86 fn default() -> Self {
87 Self::new()
88 }
89 }
90
91 mod imp {
92 use gtk::subclass::prelude::*;
93 use gtk::{glib, Image};
94 use gtk::prelude::WidgetExt;
95 use libphosh::Lockscreen;
96 use libphosh::prelude::LockscreenExt;
97 use libphosh::subclass::lockscreen::LockscreenImpl;
98
99 #[derive(Default)]
100 pub struct CustomLockscreen {}
101
102 #[glib::object_subclass]
103 impl ObjectSubclass for CustomLockscreen {
104 const NAME: &'static str = "CustomLockscreen";
105 type Type = super::CustomLockscreen;
106 type ParentType = Lockscreen;
107 }
108
109 impl ObjectImpl for CustomLockscreen {
110 fn constructed(&self) {
111 self.parent_constructed();
112 glib::g_message!("example", "Constructed custom Lockscreen");
113
114 let hi = Image::builder()
115 .icon_name("face-kiss")
116 .pixel_size(100)
117 .build();
118 self.obj().add_extra_page(&hi);
119 hi.set_visible(true);
120
121 self.obj().connect_lockscreen_unlock(|_| {
122 glib::g_message!("example", "Custom Lockscreen was unlocked.");
123 });
124
125 self.obj().connect_page_notify(|me| {
126 glib::g_message!("example", "Lockscreen page changed to {:?}", me.page());
127 });
128 }
129 }
130
131 impl WidgetImpl for CustomLockscreen {}
132 impl ContainerImpl for CustomLockscreen {}
133 impl BinImpl for CustomLockscreen {}
134 impl WindowImpl for CustomLockscreen {}
135 impl LockscreenImpl for CustomLockscreen {}
136 }
137}