@@ -16,6 +16,7 @@ use crate::{pointer::Location, wl_typed::WlTyped};
16
16
#[ derive( Debug ) ]
17
17
pub struct DecorationParts {
18
18
parts : [ Part ; 5 ] ,
19
+ hide_titlebar : bool ,
19
20
}
20
21
21
22
impl DecorationParts {
@@ -32,10 +33,13 @@ impl DecorationParts {
32
33
base_surface : & WlTyped < WlSurface , SurfaceData > ,
33
34
subcompositor : & SubcompositorState ,
34
35
queue_handle : & QueueHandle < State > ,
36
+ hide_titlebar : bool ,
35
37
) -> Self
36
38
where
37
39
State : Dispatch < WlSurface , SurfaceData > + Dispatch < WlSubsurface , SubsurfaceData > + ' static ,
38
40
{
41
+ let header_offset = if hide_titlebar { 0 } else { HEADER_SIZE } ;
42
+
39
43
// XXX the order must be in sync with associated constants.
40
44
let parts = [
41
45
// Top.
@@ -45,7 +49,7 @@ impl DecorationParts {
45
49
queue_handle,
46
50
Rect {
47
51
x : -( BORDER_SIZE as i32 ) ,
48
- y : -( HEADER_SIZE as i32 + BORDER_SIZE as i32 ) ,
52
+ y : -( header_offset as i32 + BORDER_SIZE as i32 ) ,
49
53
width : 0 , // Defined by `Self::resize`.
50
54
height : BORDER_SIZE ,
51
55
} ,
@@ -63,7 +67,7 @@ impl DecorationParts {
63
67
queue_handle,
64
68
Rect {
65
69
x : -( BORDER_SIZE as i32 ) ,
66
- y : -( HEADER_SIZE as i32 ) ,
70
+ y : -( header_offset as i32 ) ,
67
71
width : BORDER_SIZE ,
68
72
height : 0 , // Defined by `Self::resize`.
69
73
} ,
@@ -81,7 +85,7 @@ impl DecorationParts {
81
85
queue_handle,
82
86
Rect {
83
87
x : 0 , // Defined by `Self::resize`.
84
- y : -( HEADER_SIZE as i32 ) ,
88
+ y : -( header_offset as i32 ) ,
85
89
width : BORDER_SIZE ,
86
90
height : 0 , // Defined by `Self::resize`.
87
91
} ,
@@ -125,32 +129,72 @@ impl DecorationParts {
125
129
) ,
126
130
] ;
127
131
128
- Self { parts }
132
+ Self {
133
+ parts,
134
+ hide_titlebar,
135
+ }
129
136
}
130
137
131
138
pub fn parts ( & self ) -> std:: iter:: Enumerate < std:: slice:: Iter < Part > > {
132
139
self . parts . iter ( ) . enumerate ( )
133
140
}
134
141
135
- pub fn hide ( & self ) {
136
- for part in self . parts . iter ( ) {
142
+ pub fn parts_mut ( & mut self ) -> std:: iter:: Enumerate < std:: slice:: IterMut < Part > > {
143
+ self . parts . iter_mut ( ) . enumerate ( )
144
+ }
145
+
146
+ pub fn borders_mut ( & mut self ) -> impl Iterator < Item = & mut Part > {
147
+ self . parts_mut ( )
148
+ . filter ( |( idx, _) | * idx != Self :: HEADER )
149
+ . map ( |( _, p) | p)
150
+ }
151
+
152
+ pub fn header ( & self ) -> & Part {
153
+ & self . parts [ Self :: HEADER ]
154
+ }
155
+
156
+ pub fn header_mut ( & mut self ) -> & mut Part {
157
+ & mut self . parts [ Self :: HEADER ]
158
+ }
159
+
160
+ pub fn hide ( & mut self ) {
161
+ for part in self . parts . iter_mut ( ) {
162
+ part. hide = true ;
137
163
part. subsurface . set_sync ( ) ;
138
164
part. surface . attach ( None , 0 , 0 ) ;
139
165
part. surface . commit ( ) ;
140
166
}
141
167
}
142
168
143
- pub fn hide_borders ( & self ) {
144
- for ( _, part) in self . parts ( ) . filter ( |( idx, _) | * idx != Self :: HEADER ) {
169
+ pub fn show ( & mut self ) {
170
+ for part in self . parts . iter_mut ( ) {
171
+ part. hide = false ;
172
+ }
173
+ }
174
+
175
+ pub fn hide_borders ( & mut self ) {
176
+ for part in self . borders_mut ( ) {
177
+ part. hide = true ;
145
178
part. surface . attach ( None , 0 , 0 ) ;
146
179
part. surface . commit ( ) ;
147
180
}
148
181
}
149
182
183
+ pub fn hide_titlebar ( & mut self ) {
184
+ let part = self . header_mut ( ) ;
185
+ part. hide = true ;
186
+ part. surface . attach ( None , 0 , 0 ) ;
187
+ part. surface . commit ( ) ;
188
+ }
189
+
150
190
// These unwraps are guaranteed to succeed because the affected options are filled above
151
191
// and then never emptied afterwards.
152
192
#[ allow( clippy:: unwrap_used) ]
153
193
pub fn resize ( & mut self , width : u32 , height : u32 ) {
194
+ let header_size = if self . hide_titlebar { 0 } else { HEADER_SIZE } ;
195
+
196
+ let height_with_header = height + header_size;
197
+
154
198
self . parts [ Self :: HEADER ] . surface_rect . width = width;
155
199
156
200
self . parts [ Self :: BOTTOM ] . surface_rect . width = width + 2 * BORDER_SIZE ;
@@ -163,18 +207,12 @@ impl DecorationParts {
163
207
self . parts [ Self :: TOP ] . input_rect . as_mut ( ) . unwrap ( ) . width =
164
208
self . parts [ Self :: TOP ] . surface_rect . width - ( BORDER_SIZE * 2 ) + ( RESIZE_HANDLE_SIZE * 2 ) ;
165
209
166
- self . parts [ Self :: LEFT ] . surface_rect . height = height + HEADER_SIZE ;
167
- self . parts [ Self :: LEFT ] . input_rect . as_mut ( ) . unwrap ( ) . height =
168
- self . parts [ Self :: LEFT ] . surface_rect . height ;
210
+ self . parts [ Self :: LEFT ] . surface_rect . height = height_with_header;
211
+ self . parts [ Self :: LEFT ] . input_rect . as_mut ( ) . unwrap ( ) . height = height_with_header;
169
212
170
- self . parts [ Self :: RIGHT ] . surface_rect . height = self . parts [ Self :: LEFT ] . surface_rect . height ;
213
+ self . parts [ Self :: RIGHT ] . surface_rect . height = height_with_header ;
171
214
self . parts [ Self :: RIGHT ] . surface_rect . x = width as i32 ;
172
- self . parts [ Self :: RIGHT ] . input_rect . as_mut ( ) . unwrap ( ) . height =
173
- self . parts [ Self :: RIGHT ] . surface_rect . height ;
174
- }
175
-
176
- pub fn header ( & self ) -> & Part {
177
- & self . parts [ Self :: HEADER ]
215
+ self . parts [ Self :: RIGHT ] . input_rect . as_mut ( ) . unwrap ( ) . height = height_with_header;
178
216
}
179
217
180
218
pub fn side_height ( & self ) -> u32 {
@@ -221,6 +259,8 @@ pub struct Part {
221
259
///
222
260
/// `None` if it fully covers `surface_rect`.
223
261
pub input_rect : Option < Rect > ,
262
+
263
+ pub hide : bool ,
224
264
}
225
265
226
266
impl Part {
@@ -248,6 +288,7 @@ impl Part {
248
288
subsurface,
249
289
surface_rect,
250
290
input_rect,
291
+ hide : false ,
251
292
}
252
293
}
253
294
}
0 commit comments