@@ -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 , WaylandEvent } ;
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 ) ]
@@ -59,6 +66,22 @@ enum WindowDirection {
5966 Bottom ( Id ) ,
6067}
6168
69+ #[ derive( Debug , Clone ) ]
70+ enum WayEvent {
71+ OutputInsert ( OutputInfo ) ,
72+ #[ allow( unused) ]
73+ Stop ( String ) ,
74+ }
75+
76+ impl From < WaylandEvent > for WayEvent {
77+ fn from ( value : WaylandEvent ) -> Self {
78+ match value {
79+ WaylandEvent :: Stop ( e) => WayEvent :: Stop ( e. to_string ( ) ) ,
80+ WaylandEvent :: OutputInsert ( output) => WayEvent :: OutputInsert ( output) ,
81+ }
82+ }
83+ }
84+
6285#[ to_layer_message( multi) ]
6386#[ derive( Debug , Clone ) ]
6487enum Message {
@@ -71,6 +94,7 @@ enum Message {
7194 TextInput ( String ) ,
7295 Direction ( WindowDirection ) ,
7396 IcedEvent ( Event ) ,
97+ Wayland ( WayEvent ) ,
7498}
7599
76100impl Counter {
@@ -85,11 +109,12 @@ impl Counter {
85109}
86110
87111impl Counter {
88- fn new ( text : & str ) -> Self {
112+ fn new ( text : & str , connection : Connection ) -> Self {
89113 Self {
90114 value : 0 ,
91115 text : text. to_string ( ) ,
92116 ids : HashMap :: new ( ) ,
117+ connection,
93118 }
94119 }
95120
@@ -116,6 +141,8 @@ impl Counter {
116141 iced:: Subscription :: batch ( vec ! [
117142 event:: listen( ) . map( Message :: IcedEvent ) ,
118143 iced:: window:: close_events( ) . map( Message :: WindowClosed ) ,
144+ iced_wayland_subscriber:: listen( self . connection. clone( ) )
145+ . map( |message| Message :: Wayland ( message. into( ) ) ) ,
119146 ] )
120147 }
121148
@@ -155,6 +182,21 @@ impl Counter {
155182 }
156183 Command :: none ( )
157184 }
185+ Message :: Wayland ( WayEvent :: OutputInsert ( OutputInfo { wl_output, .. } ) ) => {
186+ let id = iced:: window:: Id :: unique ( ) ;
187+ self . ids . insert ( id, WindowInfo :: TopBar ) ;
188+ Command :: done ( Message :: NewLayerShell {
189+ settings : NewLayerShellSettings {
190+ anchor : Anchor :: Left | Anchor :: Right | Anchor :: Top ,
191+ layer : Layer :: Top ,
192+ exclusive_zone : Some ( 30 ) ,
193+ size : Some ( ( 0 , 30 ) ) ,
194+ output_option : OutputOption :: Output ( wl_output) ,
195+ ..Default :: default ( )
196+ } ,
197+ id,
198+ } )
199+ }
158200 Message :: IncrementPressed => {
159201 self . value += 1 ;
160202 Command :: none ( )
@@ -236,6 +278,9 @@ impl Counter {
236278 . height ( Length :: Fill )
237279 . into ( ) ;
238280 }
281+ if let Some ( WindowInfo :: TopBar ) = self . id_info ( id) {
282+ return text ( "hello here is topbar" ) . into ( ) ;
283+ }
239284 if let Some ( WindowInfo :: PopUp ) = self . id_info ( id) {
240285 return container ( button ( "close PopUp" ) . on_press ( Message :: Close ( id) ) )
241286 . center_x ( Length :: Fill )
0 commit comments