chore: updates after iced-rebase
This commit is contained in:
parent
bd0d180482
commit
71d9d6d5bb
41 changed files with 1786 additions and 2396 deletions
|
|
@ -24,20 +24,16 @@ use cosmic::{
|
|||
window,
|
||||
},
|
||||
surface, theme,
|
||||
widget::{Row, button, container, divider, horizontal_space, icon, text},
|
||||
widget::{Row, button, container, divider, icon, space, text, toggler},
|
||||
};
|
||||
use cosmic_settings_sound_subscription as css;
|
||||
use cosmic_time::{Instant, Timeline, anim, chain, id};
|
||||
use iced::platform_specific::shell::wayland::commands::popup::{destroy_popup, get_popup};
|
||||
use mpris_subscription::{MprisRequest, MprisUpdate};
|
||||
use mpris2_zbus::player::PlaybackStatus;
|
||||
use std::sync::LazyLock;
|
||||
|
||||
mod config;
|
||||
mod mpris_subscription;
|
||||
|
||||
static SHOW_MEDIA_CONTROLS: LazyLock<id::Toggler> = LazyLock::new(id::Toggler::unique);
|
||||
|
||||
const GO_BACK: &str = "media-skip-backward-symbolic";
|
||||
const GO_NEXT: &str = "media-skip-forward-symbolic";
|
||||
const PAUSE: &str = "media-playback-pause-symbolic";
|
||||
|
|
@ -66,8 +62,6 @@ pub struct Audio {
|
|||
sink_breakpoints: &'static [u32],
|
||||
/// Breakpoitns for the source volume slider.
|
||||
source_breakpoints: &'static [u32],
|
||||
/// Track animations used by the revealers.
|
||||
timeline: Timeline,
|
||||
/// Config file specific to this applet.
|
||||
config: AudioAppletConfig,
|
||||
/// mpris player status
|
||||
|
|
@ -129,8 +123,7 @@ pub enum Message {
|
|||
InputToggle,
|
||||
TogglePopup,
|
||||
CloseRequested(window::Id),
|
||||
ToggleMediaControlsInTopPanel(chain::Toggler, bool),
|
||||
Frame(Instant),
|
||||
ToggleMediaControlsInTopPanel(bool),
|
||||
ConfigChanged(AudioAppletConfig),
|
||||
Mpris(mpris_subscription::MprisUpdate),
|
||||
MprisRequest(MprisRequest),
|
||||
|
|
@ -272,13 +265,12 @@ impl cosmic::Application for Audio {
|
|||
&mut self.core
|
||||
}
|
||||
|
||||
fn style(&self) -> Option<cosmic::iced_runtime::Appearance> {
|
||||
fn style(&self) -> Option<iced::theme::Style> {
|
||||
Some(cosmic::applet::style())
|
||||
}
|
||||
|
||||
fn update(&mut self, message: Message) -> app::Task<Message> {
|
||||
match message {
|
||||
Message::Frame(now) => self.timeline.now(now),
|
||||
Message::Ignore => {}
|
||||
Message::TogglePopup => {
|
||||
if let Some(p) = self.popup.take() {
|
||||
|
|
@ -286,7 +278,6 @@ impl cosmic::Application for Audio {
|
|||
} else {
|
||||
let new_id = window::Id::unique();
|
||||
self.popup.replace(new_id);
|
||||
self.timeline = Timeline::new();
|
||||
|
||||
(self.max_sink_volume, self.sink_breakpoints) = if amplification_sink() {
|
||||
(150, &[100][..])
|
||||
|
|
@ -365,8 +356,7 @@ impl cosmic::Application for Audio {
|
|||
.map(|message| Message::Subscription(message).into());
|
||||
}
|
||||
|
||||
Message::ToggleMediaControlsInTopPanel(chain, enabled) => {
|
||||
self.timeline.set_chain(chain).start();
|
||||
Message::ToggleMediaControlsInTopPanel(enabled) => {
|
||||
self.config.show_media_controls_in_top_panel = enabled;
|
||||
if let Ok(helper) =
|
||||
cosmic::cosmic_config::Config::new(Self::APP_ID, AudioAppletConfig::VERSION)
|
||||
|
|
@ -478,9 +468,6 @@ impl cosmic::Application for Audio {
|
|||
|
||||
fn subscription(&self) -> Subscription<Message> {
|
||||
Subscription::batch([
|
||||
self.timeline
|
||||
.as_subscription()
|
||||
.map(|(_, now)| Message::Frame(now)),
|
||||
self.core.watch_config(Self::APP_ID).map(|u| {
|
||||
for err in u.errors {
|
||||
tracing::error!(?err, "Error watching config");
|
||||
|
|
@ -532,6 +519,7 @@ impl cosmic::Application for Audio {
|
|||
applet_column::Column::with_children(playback_buttons)
|
||||
.push(btn)
|
||||
.align_x(Alignment::Center)
|
||||
.height(Length::Shrink)
|
||||
// TODO configurable variable from the panel?
|
||||
.spacing(
|
||||
-(self.core.applet.suggested_padding(true).0 as f32)
|
||||
|
|
@ -542,6 +530,7 @@ impl cosmic::Application for Audio {
|
|||
applet_row::Row::with_children(playback_buttons)
|
||||
.push(btn)
|
||||
.align_y(Alignment::Center)
|
||||
.width(Length::Shrink)
|
||||
// TODO configurable variable from the panel?
|
||||
.spacing(
|
||||
-(self.core.applet.suggested_padding(true).0 as f32)
|
||||
|
|
@ -696,7 +685,7 @@ impl cosmic::Application for Audio {
|
|||
);
|
||||
|
||||
let mut control_elements = Vec::with_capacity(4);
|
||||
control_elements.push(horizontal_space().width(Length::Fill).into());
|
||||
control_elements.push(space::horizontal().width(Length::Fill).into());
|
||||
if let Some(go_prev) = self.go_previous(32) {
|
||||
control_elements.push(go_prev);
|
||||
}
|
||||
|
|
@ -745,16 +734,11 @@ impl cosmic::Application for Audio {
|
|||
audio_content,
|
||||
padded_control(divider::horizontal::default()).padding([space_xxs, space_s]),
|
||||
padded_control(
|
||||
anim!(
|
||||
// toggler
|
||||
SHOW_MEDIA_CONTROLS,
|
||||
&self.timeline,
|
||||
Some(fl!("show-media-controls")),
|
||||
self.config.show_media_controls_in_top_panel,
|
||||
Message::ToggleMediaControlsInTopPanel,
|
||||
)
|
||||
.text_size(14)
|
||||
.width(Length::Fill)
|
||||
toggler(self.config.show_media_controls_in_top_panel)
|
||||
.on_toggle(Message::ToggleMediaControlsInTopPanel)
|
||||
.label(fl!("show-media-controls"))
|
||||
.text_size(14)
|
||||
.width(Length::Fill)
|
||||
),
|
||||
padded_control(divider::horizontal::default()).padding([space_xxs, space_s]),
|
||||
menu_button(text::body(fl!("sound-settings"))).on_press(Message::OpenSettings)
|
||||
|
|
|
|||
|
|
@ -156,50 +156,51 @@ where
|
|||
}
|
||||
|
||||
fn layout(
|
||||
&self,
|
||||
&mut self,
|
||||
tree: &mut Tree,
|
||||
renderer: &Renderer,
|
||||
limits: &layout::Limits,
|
||||
) -> layout::Node {
|
||||
self.content
|
||||
.as_widget()
|
||||
.as_widget_mut()
|
||||
.layout(&mut tree.children[0], renderer, limits)
|
||||
}
|
||||
|
||||
fn operate(
|
||||
&self,
|
||||
&mut self,
|
||||
tree: &mut Tree,
|
||||
layout: Layout<'_>,
|
||||
renderer: &Renderer,
|
||||
operation: &mut dyn Operation<()>,
|
||||
) {
|
||||
self.content
|
||||
.as_widget()
|
||||
.as_widget_mut()
|
||||
.operate(&mut tree.children[0], layout, renderer, operation);
|
||||
}
|
||||
|
||||
fn on_event(
|
||||
fn update(
|
||||
&mut self,
|
||||
tree: &mut Tree,
|
||||
event: Event,
|
||||
event: &Event,
|
||||
layout: Layout<'_>,
|
||||
cursor: mouse::Cursor,
|
||||
renderer: &Renderer,
|
||||
clipboard: &mut dyn Clipboard,
|
||||
shell: &mut Shell<'_, Message>,
|
||||
viewport: &Rectangle,
|
||||
) -> event::Status {
|
||||
if let event::Status::Captured = self.content.as_widget_mut().on_event(
|
||||
) {
|
||||
self.content.as_widget_mut().update(
|
||||
&mut tree.children[0],
|
||||
event.clone(),
|
||||
&event,
|
||||
layout,
|
||||
cursor,
|
||||
renderer,
|
||||
clipboard,
|
||||
shell,
|
||||
viewport,
|
||||
) {
|
||||
return event::Status::Captured;
|
||||
);
|
||||
if shell.is_event_captured() {
|
||||
return;
|
||||
}
|
||||
|
||||
update(
|
||||
|
|
@ -209,7 +210,7 @@ where
|
|||
cursor,
|
||||
shell,
|
||||
tree.state.downcast_mut::<State>(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
fn mouse_interaction(
|
||||
|
|
@ -249,17 +250,24 @@ where
|
|||
viewport,
|
||||
);
|
||||
}
|
||||
|
||||
fn overlay<'b>(
|
||||
&'b mut self,
|
||||
tree: &'b mut Tree,
|
||||
layout: Layout<'_>,
|
||||
layout: Layout<'b>,
|
||||
renderer: &Renderer,
|
||||
viewport: &Rectangle,
|
||||
translation: Vector,
|
||||
) -> Option<overlay::Element<'b, Message, Theme, Renderer>> {
|
||||
self.content
|
||||
.as_widget_mut()
|
||||
.overlay(&mut tree.children[0], layout, renderer, translation)
|
||||
self.content.as_widget_mut().overlay(
|
||||
&mut tree.children[0],
|
||||
layout,
|
||||
renderer,
|
||||
viewport,
|
||||
translation,
|
||||
)
|
||||
}
|
||||
|
||||
fn drag_destinations(
|
||||
&self,
|
||||
state: &Tree,
|
||||
|
|
@ -298,7 +306,7 @@ fn update<Message: Clone, Theme, Renderer>(
|
|||
cursor: mouse::Cursor,
|
||||
shell: &mut Shell<'_, Message>,
|
||||
state: &mut State,
|
||||
) -> event::Status {
|
||||
) {
|
||||
if !cursor.is_over(layout.bounds()) {
|
||||
if !state.is_out_of_bounds {
|
||||
if widget
|
||||
|
|
@ -312,12 +320,13 @@ fn update<Message: Clone, Theme, Renderer>(
|
|||
if let Some(message) = widget.on_mouse_exit.as_ref() {
|
||||
shell.publish(message.clone());
|
||||
}
|
||||
return event::Status::Captured;
|
||||
shell.capture_event();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return event::Status::Ignored;
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(message) = widget.on_press.as_ref() {
|
||||
|
|
@ -326,8 +335,8 @@ fn update<Message: Clone, Theme, Renderer>(
|
|||
{
|
||||
state.drag_initiated = cursor.position();
|
||||
shell.publish(message.clone());
|
||||
|
||||
return event::Status::Captured;
|
||||
shell.capture_event();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -337,32 +346,32 @@ fn update<Message: Clone, Theme, Renderer>(
|
|||
{
|
||||
state.drag_initiated = None;
|
||||
shell.publish(message.clone());
|
||||
|
||||
return event::Status::Captured;
|
||||
shell.capture_event();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(message) = widget.on_right_press.as_ref() {
|
||||
if let Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Right)) = event {
|
||||
shell.publish(message.clone());
|
||||
|
||||
return event::Status::Captured;
|
||||
shell.capture_event();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(message) = widget.on_right_release.as_ref() {
|
||||
if let Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Right)) = event {
|
||||
shell.publish(message.clone());
|
||||
|
||||
return event::Status::Captured;
|
||||
shell.capture_event();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(message) = widget.on_middle_press.as_ref() {
|
||||
if let Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Middle)) = event {
|
||||
shell.publish(message.clone());
|
||||
|
||||
return event::Status::Captured;
|
||||
shell.capture_event();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -370,7 +379,8 @@ fn update<Message: Clone, Theme, Renderer>(
|
|||
if let Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Middle)) = event {
|
||||
shell.publish(message.clone());
|
||||
|
||||
return event::Status::Captured;
|
||||
shell.capture_event();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if let Some(message) = widget
|
||||
|
|
@ -384,7 +394,8 @@ fn update<Message: Clone, Theme, Renderer>(
|
|||
if widget.on_mouse_enter.is_some() {
|
||||
shell.publish(message.clone());
|
||||
}
|
||||
return event::Status::Captured;
|
||||
shell.capture_event();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -400,8 +411,8 @@ fn update<Message: Clone, Theme, Renderer>(
|
|||
if position.distance(drag_source) > 1.0 {
|
||||
state.drag_initiated = None;
|
||||
shell.publish(message.clone());
|
||||
|
||||
return event::Status::Captured;
|
||||
shell.capture_event();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -409,9 +420,8 @@ fn update<Message: Clone, Theme, Renderer>(
|
|||
if let Some(message) = widget.on_mouse_wheel.as_ref() {
|
||||
if let Event::Mouse(mouse::Event::WheelScrolled { delta }) = event {
|
||||
shell.publish((message)(*delta));
|
||||
return event::Status::Captured;
|
||||
shell.capture_event();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
event::Status::Ignored
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,14 +83,13 @@ impl PlayerStatus {
|
|||
pub fn mpris_subscription<I: 'static + Hash + Copy + Send + Sync + Debug>(
|
||||
id: I,
|
||||
) -> iced::Subscription<MprisUpdate> {
|
||||
Subscription::run_with_id(
|
||||
id,
|
||||
Subscription::run_with(id, |_| {
|
||||
stream::channel(50, move |mut output| async move {
|
||||
run(&mut output).await;
|
||||
let _ = output.send(MprisUpdate::Finished).await;
|
||||
futures::future::pending().await
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue