@@ -13,11 +13,15 @@ use iced_layershell::reexport::{
1313} ;
1414use iced_layershell:: settings:: { LayerShellSettings , Settings , StartMode } ;
1515use iced_layershell:: to_layer_message;
16+ use iced_wayland_subscriber:: { OutputInfo , WaylandEvents } ;
17+ use wayland_client:: Connection ;
1618
1719pub fn main ( ) -> Result < ( ) , iced_layershell:: Error > {
1820 tracing_subscriber:: fmt ( ) . init ( ) ;
21+ let connection = Connection :: connect_to_env ( ) . unwrap ( ) ;
22+ let connection2 = connection. clone ( ) ;
1923 daemon (
20- || Counter :: new ( "hello" ) ,
24+ move || Counter :: new ( "hello" , connection . clone ( ) ) ,
2125 Counter :: namespace,
2226 Counter :: update,
2327 Counter :: view,
@@ -32,23 +36,26 @@ pub fn main() -> Result<(), iced_layershell::Error> {
3236 start_mode : StartMode :: AllScreens ,
3337 ..Default :: default ( )
3438 } ,
39+ with_connection : Some ( connection2) ,
3540 ..Default :: default ( )
3641 } )
3742 . run ( )
3843}
3944
40- #[ derive( Debug , Default ) ]
45+ #[ derive( Debug ) ]
4146struct Counter {
4247 value : i32 ,
4348 text : String ,
4449 ids : HashMap < iced:: window:: Id , WindowInfo > ,
50+ connection : Connection ,
4551}
4652
4753#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
4854enum WindowInfo {
4955 Left ,
5056 NormalWindow ,
5157 PopUp ,
58+ TopBar ,
5259}
5360
5461#[ derive( Debug , Clone , Copy ) ]
@@ -71,6 +78,7 @@ enum Message {
7178 TextInput ( String ) ,
7279 Direction ( WindowDirection ) ,
7380 IcedEvent ( Event ) ,
81+ Wayland ( WaylandEvents ) ,
7482}
7583
7684impl Counter {
@@ -85,11 +93,12 @@ impl Counter {
8593}
8694
8795impl Counter {
88- fn new ( text : & str ) -> Self {
96+ fn new ( text : & str , connection : Connection ) -> Self {
8997 Self {
9098 value : 0 ,
9199 text : text. to_string ( ) ,
92100 ids : HashMap :: new ( ) ,
101+ connection,
93102 }
94103 }
95104
@@ -116,6 +125,7 @@ impl Counter {
116125 iced:: Subscription :: batch ( vec ! [
117126 event:: listen( ) . map( Message :: IcedEvent ) ,
118127 iced:: window:: close_events( ) . map( Message :: WindowClosed ) ,
128+ iced_wayland_subscriber:: listen( self . connection. clone( ) . into( ) ) . map( Message :: Wayland ) ,
119129 ] )
120130 }
121131
@@ -155,6 +165,21 @@ impl Counter {
155165 }
156166 Command :: none ( )
157167 }
168+ Message :: Wayland ( WaylandEvents :: OutputInsert ( OutputInfo { wl_output, .. } ) ) => {
169+ let id = iced:: window:: Id :: unique ( ) ;
170+ self . ids . insert ( id, WindowInfo :: TopBar ) ;
171+ Command :: done ( Message :: NewLayerShell {
172+ settings : NewLayerShellSettings {
173+ anchor : Anchor :: Left | Anchor :: Right | Anchor :: Top ,
174+ layer : Layer :: Top ,
175+ exclusive_zone : Some ( 30 ) ,
176+ size : Some ( ( 0 , 30 ) ) ,
177+ output_option : OutputOption :: Output ( wl_output) ,
178+ ..Default :: default ( )
179+ } ,
180+ id,
181+ } )
182+ }
158183 Message :: IncrementPressed => {
159184 self . value += 1 ;
160185 Command :: none ( )
@@ -236,6 +261,9 @@ impl Counter {
236261 . height ( Length :: Fill )
237262 . into ( ) ;
238263 }
264+ if let Some ( WindowInfo :: TopBar ) = self . id_info ( id) {
265+ return text ( "hello here is topbar" ) . into ( ) ;
266+ }
239267 if let Some ( WindowInfo :: PopUp ) = self . id_info ( id) {
240268 return container ( button ( "close PopUp" ) . on_press ( Message :: Close ( id) ) )
241269 . center_x ( Length :: Fill )
0 commit comments