1fn main() {
2 #[cfg(all(target_os = "linux", feature = "wayland"))]
3 example::main();
4
5 #[cfg(not(all(target_os = "linux", feature = "wayland")))]
6 panic!("This example requires the `wayland` feature and a linux system.");
7}
8
9#[cfg(all(target_os = "linux", feature = "wayland"))]
10mod example {
11 use std::time::{Duration, SystemTime, UNIX_EPOCH};
12
13 use gpui::{
14 App, Application, Bounds, Context, FontWeight, Size, Window, WindowBackgroundAppearance,
15 WindowBounds, WindowKind, WindowOptions, div, layer_shell::*, point, prelude::*, px, rems,
16 rgba, white,
17 };
18
19 struct LayerShellExample;
20
21 impl LayerShellExample {
22 fn new(cx: &mut Context<Self>) -> Self {
23 cx.spawn(async move |this, cx| {
24 loop {
25 let _ = this.update(cx, |_, cx| cx.notify());
26 cx.background_executor()
27 .timer(Duration::from_millis(500))
28 .await;
29 }
30 })
31 .detach();
32
33 LayerShellExample
34 }
35 }
36
37 impl Render for LayerShellExample {
38 fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
39 let now = SystemTime::now()
40 .duration_since(UNIX_EPOCH)
41 .unwrap()
42 .as_secs();
43
44 let hours = (now / 3600) % 24;
45 let minutes = (now / 60) % 60;
46 let seconds = now % 60;
47
48 div()
49 .size_full()
50 .flex()
51 .items_center()
52 .justify_center()
53 .text_size(rems(4.5))
54 .font_weight(FontWeight::EXTRA_BOLD)
55 .text_color(white())
56 .bg(rgba(0x0000044))
57 .rounded_xl()
58 .child(format!("{:02}:{:02}:{:02}", hours, minutes, seconds))
59 }
60 }
61
62 pub fn main() {
63 Application::new().run(|cx: &mut App| {
64 cx.open_window(
65 WindowOptions {
66 titlebar: None,
67 window_bounds: Some(WindowBounds::Windowed(Bounds {
68 origin: point(px(0.), px(0.)),
69 size: Size::new(px(500.), px(200.)),
70 })),
71 app_id: Some("gpui-layer-shell-example".to_string()),
72 window_background: WindowBackgroundAppearance::Transparent,
73 kind: WindowKind::LayerShell(LayerShellOptions {
74 namespace: "gpui".to_string(),
75 anchor: Anchor::LEFT | Anchor::RIGHT | Anchor::BOTTOM,
76 margin: Some((px(0.), px(0.), px(40.), px(0.))),
77 keyboard_interactivity: KeyboardInteractivity::None,
78 ..Default::default()
79 }),
80 ..Default::default()
81 },
82 |_, cx| cx.new(LayerShellExample::new),
83 )
84 .unwrap();
85 });
86 }
87}