perf: cache image handles
This commit is contained in:
parent
762b92e5d1
commit
9ba6a0481c
3 changed files with 34 additions and 33 deletions
|
|
@ -35,11 +35,11 @@ pub struct Common<M> {
|
|||
pub error_opt: Option<String>,
|
||||
pub fallback_background: widget::image::Handle,
|
||||
pub layouts_opt: Option<Arc<xkb_data::KeyboardLayouts>>,
|
||||
pub network_icon_opt: Option<&'static str>,
|
||||
pub network_icon_opt: Option<widget::Icon>,
|
||||
pub on_output_event: Option<Box<dyn Fn(OutputEvent, WlOutput) -> M>>,
|
||||
pub on_session_lock_event: Option<Box<dyn Fn(SessionLockEvent) -> M>>,
|
||||
pub output_names: HashMap<WlOutput, String>,
|
||||
pub power_info_opt: Option<(String, f64)>,
|
||||
pub power_info_opt: Option<(widget::Icon, f64)>,
|
||||
pub prompt_opt: Option<(String, bool, Option<String>)>,
|
||||
pub subsurface_rects: HashMap<WlOutput, Rectangle>,
|
||||
pub surface_ids: HashMap<WlOutput, SurfaceId>,
|
||||
|
|
@ -283,7 +283,8 @@ impl<M: From<Message> + Send + 'static> Common<M> {
|
|||
}
|
||||
}
|
||||
Message::NetworkIcon(network_icon_opt) => {
|
||||
self.network_icon_opt = network_icon_opt;
|
||||
self.network_icon_opt =
|
||||
network_icon_opt.map(|name| widget::icon::from_name(name).into());
|
||||
}
|
||||
Message::OutputEvent(output_event, output) => {
|
||||
if let Some(on_output_event) = &self.on_output_event {
|
||||
|
|
@ -291,7 +292,8 @@ impl<M: From<Message> + Send + 'static> Common<M> {
|
|||
}
|
||||
}
|
||||
Message::PowerInfo(power_info_opt) => {
|
||||
self.power_info_opt = power_info_opt;
|
||||
self.power_info_opt = power_info_opt
|
||||
.map(|(name, level)| (widget::icon::from_name(name).into(), level));
|
||||
}
|
||||
Message::Prompt(prompt, secret, value_opt) => {
|
||||
let prompt_was_none = self.prompt_opt.is_none();
|
||||
|
|
|
|||
|
|
@ -303,6 +303,10 @@ pub fn main() -> Result<(), Box<dyn Error>> {
|
|||
};
|
||||
|
||||
let flags = Flags {
|
||||
user_icons: user_datas
|
||||
.iter_mut()
|
||||
.map(|d| d.icon_opt.take().map(widget::image::Handle::from_bytes))
|
||||
.collect(),
|
||||
user_datas,
|
||||
sessions,
|
||||
greeter_config,
|
||||
|
|
@ -319,6 +323,7 @@ pub fn main() -> Result<(), Box<dyn Error>> {
|
|||
#[derive(Clone)]
|
||||
pub struct Flags {
|
||||
user_datas: Vec<UserData>,
|
||||
user_icons: Vec<Option<widget::image::Handle>>,
|
||||
sessions: HashMap<String, (Vec<String>, Vec<String>)>,
|
||||
greeter_config: CosmicGreeterConfig,
|
||||
greeter_config_handler: Option<cosmic_config::Config>,
|
||||
|
|
@ -438,18 +443,6 @@ pub struct App {
|
|||
accessibility: Accessibility,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
enum Randr {
|
||||
Mirror(OutputKey),
|
||||
Position(i32, i32),
|
||||
RefreshRate(u32),
|
||||
VariableRefreshRate(AdaptiveSyncState),
|
||||
Resolution(u32, u32),
|
||||
Scale(u32),
|
||||
Transform(Transform),
|
||||
Toggle(bool),
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct Accessibility {
|
||||
pub wayland_sender: Option<calloop::channel::Sender<AccessibilityRequest>>,
|
||||
|
|
@ -519,13 +512,13 @@ impl App {
|
|||
|
||||
let mut status_row = widget::row::with_capacity(2).padding(16.0).spacing(12.0);
|
||||
|
||||
if let Some(network_icon) = self.common.network_icon_opt {
|
||||
status_row = status_row.push(widget::icon::from_name(network_icon));
|
||||
if let Some(network_icon) = self.common.network_icon_opt.as_ref() {
|
||||
status_row = status_row.push(network_icon.clone());
|
||||
}
|
||||
|
||||
if let Some((power_icon, power_percent)) = &self.common.power_info_opt {
|
||||
status_row = status_row.push(iced::widget::row![
|
||||
widget::icon::from_name(power_icon.clone()),
|
||||
power_icon.clone(),
|
||||
widget::text(format!("{:.0}%", power_percent)),
|
||||
]);
|
||||
}
|
||||
|
|
@ -768,19 +761,21 @@ impl App {
|
|||
column = column.push(widget::text("Opening GREETD_SOCK"));
|
||||
}
|
||||
SocketState::Open => {
|
||||
for user_data in &self.flags.user_datas {
|
||||
for (user_data, user_icon) in self
|
||||
.flags
|
||||
.user_datas
|
||||
.iter()
|
||||
.zip(self.flags.user_icons.iter())
|
||||
{
|
||||
if !self.entering_name && user_data.name == self.selected_username.username
|
||||
{
|
||||
match &user_data.icon_opt {
|
||||
match user_icon {
|
||||
Some(icon) => {
|
||||
column = column.push(
|
||||
widget::container(
|
||||
widget::Image::new(
|
||||
//TODO: cache handle
|
||||
widget::image::Handle::from_bytes(icon.clone()),
|
||||
)
|
||||
.width(Length::Fixed(78.0))
|
||||
.height(Length::Fixed(78.0)),
|
||||
widget::image(icon)
|
||||
.width(Length::Fixed(78.0))
|
||||
.height(Length::Fixed(78.0)),
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.align_x(alignment::Horizontal::Center),
|
||||
|
|
|
|||
|
|
@ -88,6 +88,10 @@ pub fn main(user: pwd::Passwd) -> Result<(), Box<dyn std::error::Error>> {
|
|||
user_data.load_config_as_user();
|
||||
|
||||
let flags = Flags {
|
||||
user_icon: user_data
|
||||
.icon_opt
|
||||
.take()
|
||||
.map(|icon| widget::image::Handle::from_bytes(icon)),
|
||||
user_data,
|
||||
lockfile_opt: lockfile_opt(),
|
||||
};
|
||||
|
|
@ -208,6 +212,7 @@ impl pam_client::ConversationHandler for Conversation {
|
|||
#[derive(Clone)]
|
||||
pub struct Flags {
|
||||
user_data: UserData,
|
||||
user_icon: Option<widget::image::Handle>,
|
||||
lockfile_opt: Option<PathBuf>,
|
||||
}
|
||||
|
||||
|
|
@ -293,13 +298,13 @@ impl App {
|
|||
|
||||
let mut status_row = widget::row::with_capacity(2).padding(16.0).spacing(12.0);
|
||||
|
||||
if let Some(network_icon) = self.common.network_icon_opt {
|
||||
status_row = status_row.push(widget::icon::from_name(network_icon));
|
||||
if let Some(network_icon) = self.common.network_icon_opt.as_ref() {
|
||||
status_row = status_row.push(network_icon.clone());
|
||||
}
|
||||
|
||||
if let Some((power_icon, power_percent)) = &self.common.power_info_opt {
|
||||
status_row = status_row.push(iced::widget::row![
|
||||
widget::icon::from_name(power_icon.clone()),
|
||||
power_icon.clone(),
|
||||
widget::text(format!("{:.0}%", power_percent)),
|
||||
]);
|
||||
}
|
||||
|
|
@ -417,12 +422,11 @@ impl App {
|
|||
.spacing(12.0)
|
||||
.max_width(280.0);
|
||||
|
||||
match &self.flags.user_data.icon_opt {
|
||||
match &self.flags.user_icon {
|
||||
Some(icon) => {
|
||||
column = column.push(
|
||||
widget::container(
|
||||
//TODO: cache image handle?
|
||||
widget::Image::new(widget::image::Handle::from_bytes(icon.clone()))
|
||||
widget::image(icon)
|
||||
.width(Length::Fixed(78.0))
|
||||
.height(Length::Fixed(78.0)),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue