|
1 |
| -use cosmic::iced::wayland::SurfaceIdWrapper; |
2 | 1 | use cosmic::iced::widget;
|
3 | 2 | use cosmic::iced_native::alignment::Horizontal;
|
4 | 3 | use cosmic::iced_native::layout::Limits;
|
@@ -97,7 +96,7 @@ impl Application for Audio {
|
97 | 96 | self.theme
|
98 | 97 | }
|
99 | 98 |
|
100 |
| - fn close_requested(&self, _id: SurfaceIdWrapper) -> Self::Message { |
| 99 | + fn close_requested(&self, _id: window::Id) -> Self::Message { |
101 | 100 | Message::Ignore
|
102 | 101 | }
|
103 | 102 |
|
@@ -268,134 +267,131 @@ impl Application for Audio {
|
268 | 267 | pulse::connect().map(Message::Pulse)
|
269 | 268 | }
|
270 | 269 |
|
271 |
| - fn view(&self, id: SurfaceIdWrapper) -> Element<Message> { |
272 |
| - match id { |
273 |
| - SurfaceIdWrapper::LayerSurface(_) => unimplemented!(), |
274 |
| - SurfaceIdWrapper::Window(_) => self |
275 |
| - .applet_helper |
| 270 | + fn view(&self, id: window::Id) -> Element<Message> { |
| 271 | + if id == window::Id::new(0) { |
| 272 | + self.applet_helper |
276 | 273 | .icon_button(&self.icon_name)
|
277 | 274 | .on_press(Message::TogglePopup)
|
278 |
| - .into(), |
279 |
| - SurfaceIdWrapper::Popup(_) => { |
280 |
| - let audio_disabled = matches!(self.pulse_state, PulseState::Disconnected(_)); |
281 |
| - let out_f64 = VolumeLinear::from( |
282 |
| - self.current_output |
283 |
| - .as_ref() |
284 |
| - .map(|o| o.volume.avg()) |
285 |
| - .unwrap_or_default(), |
286 |
| - ) |
287 |
| - .0 * 100.0; |
288 |
| - let in_f64 = VolumeLinear::from( |
289 |
| - self.current_input |
290 |
| - .as_ref() |
291 |
| - .map(|o| o.volume.avg()) |
292 |
| - .unwrap_or_default(), |
293 |
| - ) |
294 |
| - .0 * 100.0; |
295 |
| - |
296 |
| - let audio_content = if audio_disabled { |
297 |
| - column![text("PulseAudio Disconnected") |
298 |
| - .width(Length::Fill) |
299 |
| - .horizontal_alignment(Horizontal::Center) |
300 |
| - .size(24),] |
301 |
| - } else { |
302 |
| - column![ |
303 |
| - row![ |
304 |
| - icon("audio-volume-high-symbolic", 32) |
305 |
| - .width(Length::Units(24)) |
306 |
| - .height(Length::Units(24)) |
307 |
| - .style(Svg::Symbolic), |
308 |
| - slider(0.0..=100.0, out_f64, Message::SetOutputVolume) |
309 |
| - .width(Length::FillPortion(5)), |
310 |
| - text(format!("{}%", out_f64.round())) |
311 |
| - .width(Length::FillPortion(1)) |
312 |
| - .horizontal_alignment(Horizontal::Right) |
313 |
| - ] |
314 |
| - .spacing(12) |
315 |
| - .align_items(Alignment::Center) |
316 |
| - .padding([8, 24]), |
317 |
| - row![ |
318 |
| - icon("audio-input-microphone-symbolic", 32) |
319 |
| - .width(Length::Units(24)) |
320 |
| - .height(Length::Units(24)) |
321 |
| - .style(Svg::Symbolic), |
322 |
| - slider(0.0..=100.0, in_f64, Message::SetInputVolume) |
323 |
| - .width(Length::FillPortion(5)), |
324 |
| - text(format!("{}%", in_f64.round())) |
325 |
| - .width(Length::FillPortion(1)) |
326 |
| - .horizontal_alignment(Horizontal::Right) |
327 |
| - ] |
328 |
| - .spacing(12) |
329 |
| - .align_items(Alignment::Center) |
330 |
| - .padding([8, 24]), |
331 |
| - container(divider::horizontal::light()) |
332 |
| - .padding([12, 24]) |
333 |
| - .width(Length::Fill), |
334 |
| - revealer( |
335 |
| - self.is_open == IsOpen::Output, |
336 |
| - "Output", |
337 |
| - match &self.current_output { |
338 |
| - Some(output) => pretty_name(output.description.clone()), |
339 |
| - None => String::from("No device selected"), |
340 |
| - }, |
341 |
| - self.outputs |
342 |
| - .clone() |
343 |
| - .into_iter() |
344 |
| - .map(|output| ( |
345 |
| - output.name.clone().unwrap_or_default(), |
346 |
| - pretty_name(output.description) |
347 |
| - )) |
348 |
| - .collect(), |
349 |
| - Message::OutputToggle, |
350 |
| - Message::OutputChanged, |
351 |
| - ), |
352 |
| - revealer( |
353 |
| - self.is_open == IsOpen::Input, |
354 |
| - "Input", |
355 |
| - match &self.current_input { |
356 |
| - Some(input) => pretty_name(input.description.clone()), |
357 |
| - None => String::from("No device selected"), |
358 |
| - }, |
359 |
| - self.inputs |
360 |
| - .clone() |
361 |
| - .into_iter() |
362 |
| - .map(|input| ( |
363 |
| - input.name.clone().unwrap_or_default(), |
364 |
| - pretty_name(input.description) |
365 |
| - )) |
366 |
| - .collect(), |
367 |
| - Message::InputToggle, |
368 |
| - Message::InputChanged, |
369 |
| - ) |
| 275 | + .into() |
| 276 | + } else { |
| 277 | + let audio_disabled = matches!(self.pulse_state, PulseState::Disconnected(_)); |
| 278 | + let out_f64 = VolumeLinear::from( |
| 279 | + self.current_output |
| 280 | + .as_ref() |
| 281 | + .map(|o| o.volume.avg()) |
| 282 | + .unwrap_or_default(), |
| 283 | + ) |
| 284 | + .0 * 100.0; |
| 285 | + let in_f64 = VolumeLinear::from( |
| 286 | + self.current_input |
| 287 | + .as_ref() |
| 288 | + .map(|o| o.volume.avg()) |
| 289 | + .unwrap_or_default(), |
| 290 | + ) |
| 291 | + .0 * 100.0; |
| 292 | + |
| 293 | + let audio_content = if audio_disabled { |
| 294 | + column![text("PulseAudio Disconnected") |
| 295 | + .width(Length::Fill) |
| 296 | + .horizontal_alignment(Horizontal::Center) |
| 297 | + .size(24),] |
| 298 | + } else { |
| 299 | + column![ |
| 300 | + row![ |
| 301 | + icon("audio-volume-high-symbolic", 32) |
| 302 | + .width(Length::Units(24)) |
| 303 | + .height(Length::Units(24)) |
| 304 | + .style(Svg::Symbolic), |
| 305 | + slider(0.0..=100.0, out_f64, Message::SetOutputVolume) |
| 306 | + .width(Length::FillPortion(5)), |
| 307 | + text(format!("{}%", out_f64.round())) |
| 308 | + .width(Length::FillPortion(1)) |
| 309 | + .horizontal_alignment(Horizontal::Right) |
370 | 310 | ]
|
371 |
| - .align_items(Alignment::Start) |
372 |
| - }; |
373 |
| - let content = column![ |
374 |
| - audio_content, |
375 |
| - container(divider::horizontal::light()) |
376 |
| - .padding([12, 24]) |
377 |
| - .width(Length::Fill), |
378 |
| - container(toggler( |
379 |
| - Some("Show Media Controls on Top Panel".into()), |
380 |
| - self.show_media_controls_in_top_panel, |
381 |
| - Message::ToggleMediaControlsInTopPanel, |
382 |
| - )) |
383 |
| - .padding([0, 24]), |
| 311 | + .spacing(12) |
| 312 | + .align_items(Alignment::Center) |
| 313 | + .padding([8, 24]), |
| 314 | + row![ |
| 315 | + icon("audio-input-microphone-symbolic", 32) |
| 316 | + .width(Length::Units(24)) |
| 317 | + .height(Length::Units(24)) |
| 318 | + .style(Svg::Symbolic), |
| 319 | + slider(0.0..=100.0, in_f64, Message::SetInputVolume) |
| 320 | + .width(Length::FillPortion(5)), |
| 321 | + text(format!("{}%", in_f64.round())) |
| 322 | + .width(Length::FillPortion(1)) |
| 323 | + .horizontal_alignment(Horizontal::Right) |
| 324 | + ] |
| 325 | + .spacing(12) |
| 326 | + .align_items(Alignment::Center) |
| 327 | + .padding([8, 24]), |
384 | 328 | container(divider::horizontal::light())
|
385 | 329 | .padding([12, 24])
|
386 | 330 | .width(Length::Fill),
|
387 |
| - button(APPLET_BUTTON_THEME) |
388 |
| - .text("Sound Settings...") |
389 |
| - .padding([8, 24]) |
390 |
| - .width(Length::Fill) |
| 331 | + revealer( |
| 332 | + self.is_open == IsOpen::Output, |
| 333 | + "Output", |
| 334 | + match &self.current_output { |
| 335 | + Some(output) => pretty_name(output.description.clone()), |
| 336 | + None => String::from("No device selected"), |
| 337 | + }, |
| 338 | + self.outputs |
| 339 | + .clone() |
| 340 | + .into_iter() |
| 341 | + .map(|output| ( |
| 342 | + output.name.clone().unwrap_or_default(), |
| 343 | + pretty_name(output.description) |
| 344 | + )) |
| 345 | + .collect(), |
| 346 | + Message::OutputToggle, |
| 347 | + Message::OutputChanged, |
| 348 | + ), |
| 349 | + revealer( |
| 350 | + self.is_open == IsOpen::Input, |
| 351 | + "Input", |
| 352 | + match &self.current_input { |
| 353 | + Some(input) => pretty_name(input.description.clone()), |
| 354 | + None => String::from("No device selected"), |
| 355 | + }, |
| 356 | + self.inputs |
| 357 | + .clone() |
| 358 | + .into_iter() |
| 359 | + .map(|input| ( |
| 360 | + input.name.clone().unwrap_or_default(), |
| 361 | + pretty_name(input.description) |
| 362 | + )) |
| 363 | + .collect(), |
| 364 | + Message::InputToggle, |
| 365 | + Message::InputChanged, |
| 366 | + ) |
391 | 367 | ]
|
392 | 368 | .align_items(Alignment::Start)
|
393 |
| - .padding([8, 0]); |
394 |
| - |
395 |
| - self.applet_helper |
396 |
| - .popup_container(container(content)) |
397 |
| - .into() |
398 |
| - } |
| 369 | + }; |
| 370 | + let content = column![ |
| 371 | + audio_content, |
| 372 | + container(divider::horizontal::light()) |
| 373 | + .padding([12, 24]) |
| 374 | + .width(Length::Fill), |
| 375 | + container(toggler( |
| 376 | + Some("Show Media Controls on Top Panel".into()), |
| 377 | + self.show_media_controls_in_top_panel, |
| 378 | + Message::ToggleMediaControlsInTopPanel, |
| 379 | + )) |
| 380 | + .padding([0, 24]), |
| 381 | + container(divider::horizontal::light()) |
| 382 | + .padding([12, 24]) |
| 383 | + .width(Length::Fill), |
| 384 | + button(APPLET_BUTTON_THEME) |
| 385 | + .text("Sound Settings...") |
| 386 | + .padding([8, 24]) |
| 387 | + .width(Length::Fill) |
| 388 | + ] |
| 389 | + .align_items(Alignment::Start) |
| 390 | + .padding([8, 0]); |
| 391 | + |
| 392 | + self.applet_helper |
| 393 | + .popup_container(container(content)) |
| 394 | + .into() |
399 | 395 | }
|
400 | 396 | }
|
401 | 397 | }
|
|
0 commit comments