update iced
This commit is contained in:
parent
11faa567f3
commit
5b5cd77e7c
45 changed files with 2360 additions and 1537 deletions
|
|
@ -8,7 +8,7 @@ pub(crate) mod window_image;
|
|||
|
||||
use crate::localize::localize;
|
||||
use cosmic::{
|
||||
app::Command,
|
||||
app,
|
||||
applet::cosmic_panel_config::PanelAnchor,
|
||||
cctk::{
|
||||
cosmic_protocols::toplevel_info::v1::client::zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1,
|
||||
|
|
@ -17,27 +17,29 @@ use cosmic::{
|
|||
desktop::DesktopEntryData,
|
||||
iced::{
|
||||
self,
|
||||
wayland::popup::{destroy_popup, get_popup},
|
||||
id::Id as WidgetId,
|
||||
platform_specific::shell::wayland::commands::popup::{destroy_popup, get_popup},
|
||||
widget::text,
|
||||
window::{self},
|
||||
Length, Subscription,
|
||||
Length, Limits, Subscription,
|
||||
},
|
||||
widget::mouse_area,
|
||||
widget::{autosize::autosize, mouse_area},
|
||||
Task,
|
||||
};
|
||||
|
||||
use cosmic::{
|
||||
iced_style::application,
|
||||
iced_widget::{Column, Row},
|
||||
};
|
||||
use cosmic::iced_widget::{Column, Row};
|
||||
|
||||
use cosmic::{widget::tooltip, Element, Theme};
|
||||
use cosmic::{widget::tooltip, Element};
|
||||
use once_cell::sync::Lazy;
|
||||
use wayland_subscription::{
|
||||
ToplevelRequest, ToplevelUpdate, WaylandImage, WaylandRequest, WaylandUpdate,
|
||||
};
|
||||
|
||||
static AUTOSIZE_MAIN_ID: Lazy<WidgetId> = Lazy::new(|| WidgetId::new("autosize-main"));
|
||||
|
||||
pub fn run() -> cosmic::iced::Result {
|
||||
localize();
|
||||
cosmic::applet::run::<Minimize>(true, ())
|
||||
cosmic::applet::run::<Minimize>(())
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
|
@ -56,11 +58,11 @@ struct Minimize {
|
|||
impl Minimize {
|
||||
fn max_icon_count(&self) -> Option<usize> {
|
||||
let mut index = None;
|
||||
let Some(max_major_axis_len) = self.core.applet.configure.as_ref().and_then(|c| {
|
||||
let Some(max_major_axis_len) = self.core.applet.suggested_bounds.as_ref().map(|c| {
|
||||
// if we have a configure for width and height, we're in a overflow popup
|
||||
match self.core.applet.anchor {
|
||||
PanelAnchor::Top | PanelAnchor::Bottom => c.new_size.0,
|
||||
PanelAnchor::Left | PanelAnchor::Right => c.new_size.1,
|
||||
PanelAnchor::Top | PanelAnchor::Bottom => c.width as u32,
|
||||
PanelAnchor::Left | PanelAnchor::Right => c.height as u32,
|
||||
}
|
||||
}) else {
|
||||
return index;
|
||||
|
|
@ -68,7 +70,7 @@ impl Minimize {
|
|||
let button_total_size = self.core.applet.suggested_size(true).0
|
||||
+ self.core.applet.suggested_padding(true) * 2
|
||||
+ 4;
|
||||
let btn_count = max_major_axis_len.get() / button_total_size as u32;
|
||||
let btn_count = max_major_axis_len / button_total_size as u32;
|
||||
if btn_count >= self.apps.len() as u32 {
|
||||
index = None;
|
||||
} else {
|
||||
|
|
@ -93,13 +95,13 @@ impl cosmic::Application for Minimize {
|
|||
type Flags = ();
|
||||
const APP_ID: &'static str = "com.system76.CosmicAppletMinimize";
|
||||
|
||||
fn init(core: cosmic::app::Core, _flags: ()) -> (Self, Command<Message>) {
|
||||
fn init(core: cosmic::app::Core, _flags: ()) -> (Self, app::Task<Message>) {
|
||||
(
|
||||
Self {
|
||||
core,
|
||||
..Default::default()
|
||||
},
|
||||
Command::none(),
|
||||
Task::none(),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -111,11 +113,11 @@ impl cosmic::Application for Minimize {
|
|||
&mut self.core
|
||||
}
|
||||
|
||||
fn style(&self) -> Option<<Theme as application::StyleSheet>::Style> {
|
||||
fn style(&self) -> Option<cosmic::iced_runtime::Appearance> {
|
||||
Some(cosmic::applet::style())
|
||||
}
|
||||
|
||||
fn update(&mut self, message: Message) -> Command<Message> {
|
||||
fn update(&mut self, message: Message) -> app::Task<Message> {
|
||||
match message {
|
||||
Message::Wayland(update) => match update {
|
||||
WaylandUpdate::Init(tx) => {
|
||||
|
|
@ -190,7 +192,7 @@ impl cosmic::Application for Minimize {
|
|||
},
|
||||
};
|
||||
let mut popup_settings = self.core.applet.get_popup_settings(
|
||||
window::Id::MAIN,
|
||||
self.core.main_window_id().unwrap(),
|
||||
new_id,
|
||||
None,
|
||||
None,
|
||||
|
|
@ -203,7 +205,7 @@ impl cosmic::Application for Minimize {
|
|||
}
|
||||
Message::CloseOverflowPopup => todo!(),
|
||||
};
|
||||
Command::none()
|
||||
Task::none()
|
||||
}
|
||||
|
||||
fn subscription(&self) -> Subscription<Message> {
|
||||
|
|
@ -236,7 +238,7 @@ impl cosmic::Application for Minimize {
|
|||
Message::Activate(handle.clone()),
|
||||
padding,
|
||||
)),
|
||||
data.name.clone(),
|
||||
text(data.name.clone()).shaping(text::Shaping::Advanced),
|
||||
// tooltip::Position::FollowCursor,
|
||||
// FIXME tooltip fails to appear when created as indicated in design
|
||||
// maybe it should be a subsurface
|
||||
|
|
@ -248,7 +250,6 @@ impl cosmic::Application for Minimize {
|
|||
},
|
||||
)
|
||||
.snap_within_viewport(false)
|
||||
.text_shaping(text::Shaping::Advanced)
|
||||
.into()
|
||||
});
|
||||
let overflow_btn = if max_icon_count < self.apps.len() {
|
||||
|
|
@ -272,31 +273,48 @@ impl cosmic::Application for Minimize {
|
|||
// TODO optional dividers on ends if detects app list neighbor
|
||||
// not sure the best way to tell if there is an adjacent app-list
|
||||
let icon_buttons = icon_buttons.chain(overflow_btn.into_iter());
|
||||
let content = if matches!(
|
||||
let content: Element<_> = if matches!(
|
||||
self.core.applet.anchor,
|
||||
PanelAnchor::Top | PanelAnchor::Bottom
|
||||
) {
|
||||
Row::with_children(icon_buttons)
|
||||
.align_items(cosmic::iced_core::Alignment::Center)
|
||||
.align_y(cosmic::iced_core::Alignment::Center)
|
||||
.height(Length::Shrink)
|
||||
.width(Length::Shrink)
|
||||
.spacing(space_xxs)
|
||||
.into()
|
||||
} else {
|
||||
Column::with_children(icon_buttons)
|
||||
.align_items(cosmic::iced_core::Alignment::Center)
|
||||
.align_x(cosmic::iced_core::Alignment::Center)
|
||||
.height(Length::Shrink)
|
||||
.width(Length::Shrink)
|
||||
.spacing(space_xxs)
|
||||
.into()
|
||||
};
|
||||
if self.overflow_popup.is_some() {
|
||||
mouse_area(content)
|
||||
.on_press(Message::CloseOverflowPopup)
|
||||
.into()
|
||||
} else {
|
||||
content
|
||||
|
||||
let mut limits = Limits::NONE.min_width(1.).min_height(1.);
|
||||
|
||||
if let Some(b) = self.core.applet.suggested_bounds {
|
||||
if b.width as i32 > 0 {
|
||||
limits = limits.max_width(b.width);
|
||||
}
|
||||
if b.height as i32 > 0 {
|
||||
limits = limits.max_height(b.height);
|
||||
}
|
||||
}
|
||||
|
||||
autosize(
|
||||
if self.overflow_popup.is_some() {
|
||||
mouse_area(content)
|
||||
.on_press(Message::CloseOverflowPopup)
|
||||
.into()
|
||||
} else {
|
||||
content
|
||||
},
|
||||
AUTOSIZE_MAIN_ID.clone(),
|
||||
)
|
||||
.limits(limits)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn view_window(&self, _id: window::Id) -> Element<Self::Message> {
|
||||
|
|
@ -325,7 +343,7 @@ impl cosmic::Application for Minimize {
|
|||
Message::Activate(handle.clone()),
|
||||
padding,
|
||||
)),
|
||||
data.name.clone(),
|
||||
text(data.name.clone()).shaping(text::Shaping::Advanced),
|
||||
// tooltip::Position::FollowCursor,
|
||||
// FIXME tooltip fails to appear when created as indicated in design
|
||||
// maybe it should be a subsurface
|
||||
|
|
@ -337,7 +355,6 @@ impl cosmic::Application for Minimize {
|
|||
},
|
||||
)
|
||||
.snap_within_viewport(false)
|
||||
.text_shaping(text::Shaping::Advanced)
|
||||
.into()
|
||||
});
|
||||
|
||||
|
|
@ -353,14 +370,14 @@ impl cosmic::Application for Minimize {
|
|||
) {
|
||||
Element::from(
|
||||
Row::with_children(icon_buttons)
|
||||
.align_items(cosmic::iced_core::Alignment::Center)
|
||||
.align_y(cosmic::iced_core::Alignment::Center)
|
||||
.height(Length::Shrink)
|
||||
.width(Length::Shrink)
|
||||
.spacing(space_xxs),
|
||||
)
|
||||
} else {
|
||||
Column::with_children(icon_buttons)
|
||||
.align_items(cosmic::iced_core::Alignment::Center)
|
||||
.align_x(cosmic::iced_core::Alignment::Center)
|
||||
.height(Length::Shrink)
|
||||
.width(Length::Shrink)
|
||||
.spacing(space_xxs)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,12 @@
|
|||
//! This code was generated by `zbus-xmlgen` `2.0.1` from DBus introspection data.
|
||||
//! Source: `Interface '/org/freedesktop/UPower/KbdBacklight' from service 'org.freedesktop.UPower' on system bus`.
|
||||
use cctk::{sctk::reexports::calloop, toplevel_info::ToplevelInfo};
|
||||
use cosmic::{cctk, cctk::cosmic_protocols, iced, iced::subscription, iced_futures::futures};
|
||||
use cosmic::{
|
||||
cctk::{self, cosmic_protocols},
|
||||
iced::{self, Subscription},
|
||||
iced_core::image::Bytes,
|
||||
iced_futures::{futures, stream},
|
||||
};
|
||||
use cosmic_protocols::toplevel_info::v1::client::zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1;
|
||||
use futures::{
|
||||
channel::mpsc::{unbounded, UnboundedReceiver},
|
||||
|
|
@ -23,16 +28,15 @@ pub static WAYLAND_RX: Lazy<Mutex<Option<UnboundedReceiver<WaylandUpdate>>>> =
|
|||
Lazy::new(|| Mutex::new(None));
|
||||
|
||||
pub fn wayland_subscription() -> iced::Subscription<WaylandUpdate> {
|
||||
subscription::channel(
|
||||
Subscription::run_with_id(
|
||||
std::any::TypeId::of::<WaylandUpdate>(),
|
||||
50,
|
||||
move |mut output| async move {
|
||||
stream::channel(50, move |mut output| async move {
|
||||
let mut state = State::Waiting;
|
||||
|
||||
loop {
|
||||
state = start_listening(state, &mut output).await;
|
||||
}
|
||||
},
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -86,12 +90,18 @@ pub enum WaylandUpdate {
|
|||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct WaylandImage {
|
||||
pub img: Arc<image::RgbaImage>,
|
||||
pub img: Bytes,
|
||||
pub width: u32,
|
||||
pub height: u32,
|
||||
}
|
||||
|
||||
impl WaylandImage {
|
||||
pub fn new(img: image::RgbaImage) -> Self {
|
||||
Self { img: Arc::new(img) }
|
||||
Self {
|
||||
img: Bytes::copy_from_slice(img.as_bytes()),
|
||||
width: img.width(),
|
||||
height: img.height(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,20 +33,16 @@ where
|
|||
image_button: button::custom(
|
||||
container(
|
||||
container(if let Some(img) = img {
|
||||
let max_dim = img.img.width().max(img.img.height()).max(1);
|
||||
let max_dim = img.width.max(img.height).max(1);
|
||||
let ratio = max_dim as f32 / (size - border * 2.0).max(1.0);
|
||||
let adjusted_width = img.img.width() as f32 / ratio;
|
||||
let adjusted_height = img.img.height() as f32 / ratio;
|
||||
let adjusted_width = img.width as f32 / ratio;
|
||||
let adjusted_height = img.height as f32 / ratio;
|
||||
|
||||
Element::from(
|
||||
Image::new(Handle::from_pixels(
|
||||
img.img.width(),
|
||||
img.img.height(),
|
||||
img.clone(),
|
||||
))
|
||||
.width(Length::Fixed(adjusted_width))
|
||||
.height(Length::Fixed(adjusted_height))
|
||||
.content_fit(cosmic::iced_core::ContentFit::Contain),
|
||||
Image::new(Handle::from_rgba(img.width, img.height, img.img))
|
||||
.width(Length::Fixed(adjusted_width))
|
||||
.height(Length::Fixed(adjusted_height))
|
||||
.content_fit(cosmic::iced_core::ContentFit::Contain),
|
||||
)
|
||||
} else {
|
||||
Element::from(
|
||||
|
|
@ -55,15 +51,13 @@ where
|
|||
.height(Length::Fixed((size - border * 2.0).max(0.))),
|
||||
)
|
||||
})
|
||||
.style(Container::Custom(Box::new(move |theme| {
|
||||
container::Appearance {
|
||||
border: Border {
|
||||
color: theme.cosmic().bg_divider().into(),
|
||||
width: border,
|
||||
radius: 0.0.into(),
|
||||
},
|
||||
..Default::default()
|
||||
}
|
||||
.class(Container::Custom(Box::new(move |theme| container::Style {
|
||||
border: Border {
|
||||
color: theme.cosmic().bg_divider().into(),
|
||||
width: border,
|
||||
radius: 0.0.into(),
|
||||
},
|
||||
..Default::default()
|
||||
})))
|
||||
.padding(border as u16)
|
||||
.height(Length::Shrink)
|
||||
|
|
@ -78,7 +72,7 @@ where
|
|||
.on_press(on_press)
|
||||
.width(Length::Shrink)
|
||||
.height(Length::Shrink)
|
||||
.style(Button::AppletIcon)
|
||||
.class(Button::AppletIcon)
|
||||
.padding(0)
|
||||
.into(),
|
||||
icon: icon
|
||||
|
|
@ -104,13 +98,16 @@ impl<'a, Msg> Widget<Msg, cosmic::Theme, cosmic::Renderer> for WindowImage<'a, M
|
|||
state: &'b mut Tree,
|
||||
layout: Layout<'_>,
|
||||
renderer: &cosmic::Renderer,
|
||||
translation: Vector,
|
||||
) -> Option<cosmic::iced_core::overlay::Element<'b, Msg, cosmic::Theme, cosmic::Renderer>> {
|
||||
let children = [&mut self.image_button, &mut self.icon]
|
||||
.into_iter()
|
||||
.zip(&mut state.children)
|
||||
.zip(layout.children())
|
||||
.filter_map(|((child, state), layout)| {
|
||||
child.as_widget_mut().overlay(state, layout, renderer)
|
||||
child
|
||||
.as_widget_mut()
|
||||
.overlay(state, layout, renderer, translation)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
|
|
@ -195,9 +192,7 @@ impl<'a, Msg> Widget<Msg, cosmic::Theme, cosmic::Renderer> for WindowImage<'a, M
|
|||
tree: &mut cosmic::iced_core::widget::Tree,
|
||||
layout: cosmic::iced_core::Layout<'_>,
|
||||
renderer: &cosmic::Renderer,
|
||||
operation: &mut dyn cosmic::widget::Operation<
|
||||
cosmic::iced_core::widget::OperationOutputWrapper<Msg>,
|
||||
>,
|
||||
operation: &mut dyn cosmic::widget::Operation<()>,
|
||||
) {
|
||||
let layout = layout.children().collect::<Vec<_>>();
|
||||
let children = [&self.image_button, &self.icon];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue