@@ -6,12 +6,11 @@ use crate::{
6
6
} ;
7
7
use glib:: { clone, closure_local, ControlFlow , SignalHandlerId } ;
8
8
use gtk:: { prelude:: * , subclass:: prelude:: * } ;
9
- use std:: cell:: { Cell , RefCell , OnceCell } ;
9
+ use std:: cell:: { Cell , RefCell } ;
10
10
use wireplumber as wp;
11
+ use crate :: pwvucontrol_warning;
11
12
12
13
mod imp {
13
- use crate :: pwvucontrol_warning;
14
-
15
14
use super :: * ;
16
15
17
16
#[ derive( Default , gtk:: CompositeTemplate , glib:: Properties ) ]
@@ -22,8 +21,8 @@ mod imp {
22
21
pub ( super ) node_object : RefCell < Option < PwNodeObject > > ,
23
22
24
23
metadata_changed_event : Cell < Option < SignalHandlerId > > ,
25
- levelbarprovider : OnceCell < LevelbarProvider > ,
26
- timeoutid : Cell < Option < glib :: SourceId > > ,
24
+ levelbarprovider : Cell < Option < LevelbarProvider > > ,
25
+ timeoutid : Cell < Option < gtk :: TickCallbackId > > ,
27
26
pub ( super ) level : Cell < f32 > ,
28
27
pub ( super ) default_node : Cell < u32 > ,
29
28
pub ( super ) default_node_changed_handler : RefCell < Option < Box < dyn Fn ( ) > > > ,
@@ -166,12 +165,6 @@ mod imp {
166
165
self . level_bar . add_offset_value ( gtk:: LEVEL_BAR_OFFSET_HIGH , 0.0 ) ;
167
166
self . level_bar . add_offset_value ( gtk:: LEVEL_BAR_OFFSET_FULL , 1.0 ) ;
168
167
169
- // Monitoring ourselves cause an infinite loop.
170
- if item. name ( ) != "pwvucontrol-peak-detect" {
171
- self . setuplevelbar ( ) ;
172
- } else {
173
- self . level_bar . set_visible ( false ) ;
174
- }
175
168
}
176
169
177
170
fn dispose ( & self ) {
@@ -181,12 +174,31 @@ mod imp {
181
174
metadata. disconnect ( sid) ;
182
175
} ;
183
176
} ;
177
+ }
178
+ }
179
+
180
+ impl WidgetImpl for PwVolumeBox {
181
+ fn unmap ( & self ) {
184
182
if let Some ( t) = self . timeoutid . take ( ) {
185
183
t. remove ( ) ;
186
184
}
185
+ self . levelbarprovider . take ( ) ;
186
+ self . parent_unmap ( ) ;
187
+ }
188
+
189
+ fn map ( & self ) {
190
+ self . parent_map ( ) ;
191
+
192
+ // Monitoring ourselves cause an infinite loop.
193
+ let item = self . node_object . borrow ( ) ;
194
+ let item = item. as_ref ( ) . unwrap ( ) ;
195
+ if item. name ( ) != "pwvucontrol-peak-detect" {
196
+ self . setuplevelbar ( ) ;
197
+ } else {
198
+ self . level_bar . set_visible ( false ) ;
199
+ }
187
200
}
188
201
}
189
- impl WidgetImpl for PwVolumeBox { }
190
202
impl ListBoxRowImpl for PwVolumeBox { }
191
203
192
204
impl BuildableImpl for PwVolumeBox {
@@ -217,13 +229,14 @@ mod imp {
217
229
let item = item. as_ref ( ) . cloned ( ) . unwrap ( ) ;
218
230
219
231
if let Ok ( provider) = LevelbarProvider :: new ( & self . obj ( ) , item. boundid ( ) ) {
220
- self . levelbarprovider . set ( provider) . expect ( "Provider not set already" ) ;
232
+ self . levelbarprovider . set ( Some ( provider) ) ;
221
233
222
234
let obj = self . obj ( ) ;
223
- self . level_bar . add_tick_callback ( clone ! ( @strong obj => @default -panic, move |_, _| {
235
+ let callbackid = self . level_bar . add_tick_callback ( clone ! ( @strong obj => @default -panic, move |_, _| {
224
236
obj. imp( ) . level_bar. set_value( obj. imp( ) . level. get( ) as f64 ) ;
225
237
ControlFlow :: Continue
226
238
} ) ) ;
239
+ self . timeoutid . set ( Some ( callbackid) ) ;
227
240
}
228
241
}
229
242
}
0 commit comments