@@ -82,6 +82,12 @@ enum RenderSurface {
8282 LayerShell ( wlr_layer:: LayerSurface ) ,
8383}
8484
85+ impl RenderSurface {
86+ fn is_overlay ( & self ) -> bool {
87+ matches ! ( self , RenderSurface :: LayerShell ( _) )
88+ }
89+ }
90+
8591impl std:: ops:: Deref for RenderSurface {
8692 type Target = WlSurface ;
8793
@@ -132,11 +138,18 @@ impl Window {
132138 None ,
133139 ) ;
134140
135- if let Some ( ( top_offset, left_offset) ) = params. window_offsets {
136- layer. set_anchor ( wlr_layer:: Anchor :: LEFT | wlr_layer:: Anchor :: TOP ) ;
137- layer. set_margin ( top_offset, 0 , 0 , left_offset) ;
138- }
139- layer. set_size ( width, height) ;
141+ layer. set_anchor (
142+ wlr_layer:: Anchor :: TOP
143+ | wlr_layer:: Anchor :: BOTTOM
144+ | wlr_layer:: Anchor :: LEFT
145+ | wlr_layer:: Anchor :: RIGHT ,
146+ ) ;
147+ // If you pass 0 for either value, the compositor will assign it and inform you
148+ // of the assignment in the configure event. You must set your anchor to opposite
149+ // edges in the dimensions you omit; not doing so is a protocol error.
150+ // src: https://wayland.app/protocols/wlr-layer-shell-unstable-v1
151+ layer. set_size ( 0 , 0 ) ;
152+ layer. set_exclusive_zone ( -1 ) ;
140153 layer. set_keyboard_interactivity ( wlr_layer:: KeyboardInteractivity :: Exclusive ) ;
141154
142155 layer. commit ( ) ;
@@ -189,6 +202,28 @@ impl Window {
189202 self . height * u32:: from ( self . scale )
190203 }
191204
205+ fn content_size ( & self ) -> ( u32 , u32 ) {
206+ let params: Params = self . config . param ( ) ;
207+ ( params. width , params. height )
208+ }
209+
210+ /// Returns the (x, y) pixel offset to position the content area within the
211+ /// surface, in logical (unscaled) coordinates.
212+ fn content_offset ( & self ) -> ( f32 , f32 ) {
213+ if !self . surface . is_overlay ( ) {
214+ return ( 0.0 , 0.0 ) ;
215+ }
216+ let params: Params = self . config . param ( ) ;
217+ if let Some ( ( top, left) ) = params. window_offsets {
218+ ( left as f32 , top as f32 )
219+ } else {
220+ let ( cw, ch) = self . content_size ( ) ;
221+ let x = ( self . width as f32 - cw as f32 ) / 2.0 ;
222+ let y = ( self . height as f32 - ch as f32 ) / 2.0 ;
223+ ( x, y)
224+ }
225+ }
226+
192227 pub fn draw ( & mut self , qh : & QueueHandle < Self > ) {
193228 let width = self . width ( ) . try_into ( ) . expect ( "width overflow" ) ;
194229 let height = self . height ( ) . try_into ( ) . expect ( "height overflow" ) ;
@@ -212,6 +247,18 @@ impl Window {
212247 . 0
213248 } ) ;
214249
250+ let overlay = self . surface . is_overlay ( ) ;
251+ let ( content_w, content_h) = if overlay {
252+ let ( cw, ch) = self . content_size ( ) ;
253+ let s = i32:: from ( self . scale ) ;
254+ ( cw as i32 * s, ch as i32 * s)
255+ } else {
256+ ( width, height)
257+ } ;
258+ let ( offset_x, offset_y) = self . content_offset ( ) ;
259+ let scaled_offset_x = offset_x * self . scale as f32 ;
260+ let scaled_offset_y = offset_y * self . scale as f32 ;
261+
215262 let canvas = match self . pool . canvas ( & buffer) {
216263 Some ( canvas) => canvas,
217264 None => {
@@ -247,10 +294,10 @@ impl Window {
247294 } ;
248295
249296 let mut space_left = Space {
250- width : width as f32 ,
251- height : height as f32 ,
297+ width : content_w as f32 ,
298+ height : content_h as f32 ,
252299 } ;
253- let mut point = Point :: new ( 0. , 0. ) ;
300+ let mut point = Point :: new ( scaled_offset_x , scaled_offset_y ) ;
254301
255302 let ( mut drawables, dyn_space) =
256303 crate :: draw:: make_drawables ( & self . config , & mut self . state , self . scale ) ;
0 commit comments