Skip to content

Commit

Permalink
Update to latest libcosmic/iced
Browse files Browse the repository at this point in the history
  • Loading branch information
ids1024 committed Jan 17, 2024
1 parent 6f4d48a commit 74d293e
Show file tree
Hide file tree
Showing 9 changed files with 635 additions and 547 deletions.
1,103 changes: 586 additions & 517 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ cosmic-config = { git = "https://github.com/pop-os/libcosmic/", features = ["cal
cosmic-protocols = { git = "https://github.com/pop-os/cosmic-protocols", branch = "main", default-features = false, features = ["server"] }
libcosmic = { git = "https://github.com/pop-os/libcosmic/", default-features = false }
iced_tiny_skia = { git = "https://github.com/pop-os/libcosmic/" }
tiny-skia = "0.10"
tiny-skia = "0.11"
ordered-float = "4.0"
glow = "0.12.0"
tracing-subscriber = { version = "0.3.16", features = ["env-filter", "tracing-log"] }
Expand Down
3 changes: 2 additions & 1 deletion src/shell/element/stack/tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ where
Length::Fill
}

fn layout(&self, renderer: &Renderer, limits: &Limits) -> Node {
fn layout(&self, tree: &mut Tree, renderer: &Renderer, limits: &Limits) -> Node {
let min_size = Size {
height: TAB_HEIGHT as f32,
width: if self.active {
Expand Down Expand Up @@ -328,6 +328,7 @@ where
} else {
&self.elements[0..2]
},
&mut tree.children,
)
}

Expand Down
7 changes: 5 additions & 2 deletions src/shell/element/stack/tab_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,16 @@ where
tree.diff_children(std::slice::from_mut(&mut self.text))
}

fn layout(&self, renderer: &Renderer, limits: &Limits) -> Node {
fn layout(&self, tree: &mut Tree, renderer: &Renderer, limits: &Limits) -> Node {
let limits = limits.width(self.width).height(self.height);
let child_limits = Limits::new(
Size::new(limits.min().width, limits.min().height - 4.),
Size::new(limits.max().width * 2., limits.max().height - 4.),
);
let mut content = self.text.as_widget().layout(renderer, &child_limits);
let mut content =
self.text
.as_widget()
.layout(&mut tree.children[0], renderer, &child_limits);
content.move_to(Point::new(0., 2.));
let size = limits.resolve(content.size());

Expand Down
11 changes: 7 additions & 4 deletions src/shell/element/stack/tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ where
tree.diff_children(&mut self.elements)
}

fn layout(&self, renderer: &Renderer, limits: &Limits) -> Node {
fn layout(&self, tree: &mut Tree, renderer: &Renderer, limits: &Limits) -> Node {
let limits = limits.width(self.width).height(self.height);

// calculate the smallest possible size
Expand All @@ -372,7 +372,8 @@ where

let mut nodes = self.elements[2..self.elements.len() - 2]
.iter()
.map(|tab| tab.as_widget().layout(renderer, &child_limits))
.zip(tree.children.iter_mut())
.map(|(tab, tab_tree)| tab.as_widget().layout(tab_tree, renderer, &child_limits))
.collect::<Vec<_>>();

// sum up
Expand Down Expand Up @@ -401,6 +402,7 @@ where
0.,
cosmic::iced::Alignment::Center,
&self.elements[2..self.elements.len() - 2],
&mut tree.children[2..self.elements.len() - 2],
)
.children()
.to_vec()
Expand All @@ -412,15 +414,16 @@ where

let mut nodes = self.elements[2..self.elements.len() - 3]
.iter()
.map(|tab| {
.zip(tree.children[2..].iter_mut())
.map(|(tab, tab_tree)| {
let child_limits = Limits::new(
Size::new(min_width, limits.min().height),
Size::new(f32::INFINITY, limits.max().height),
)
.width(Length::Shrink)
.height(Length::Shrink);

let mut node = tab.as_widget().layout(renderer, &child_limits);
let mut node = tab.as_widget().layout(tab_tree, renderer, &child_limits);
node.move_to(Point::new(offset, 0.));
offset += node.bounds().width;
node
Expand Down
10 changes: 8 additions & 2 deletions src/shell/grabs/menu/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,14 @@ where
self.elem.as_widget().height()
}

fn layout(&self, renderer: &Renderer, limits: &layout::Limits) -> layout::Node {
let node = self.elem.as_widget().layout(renderer, limits);
fn layout(
&self,
state: &mut Tree,
renderer: &Renderer,
limits: &layout::Limits,
) -> layout::Node {
let state = &mut state.children[0];
let node = self.elem.as_widget().layout(state, renderer, limits);
layout::Node::with_children(node.size(), vec![node])
}

Expand Down
4 changes: 2 additions & 2 deletions src/shell/grabs/menu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
use calloop::LoopHandle;
use cosmic::{
iced::Background,
iced_core::{alignment::Horizontal, Length, Rectangle as IcedRectangle},
iced_core::{alignment::Horizontal, Length, Pixels, Rectangle as IcedRectangle},
iced_widget::{self, horizontal_rule, text::Appearance as TextAppearance, Column, Row},
theme,
widget::{button, horizontal_space, icon::from_name, text},
Expand Down Expand Up @@ -395,7 +395,7 @@ impl Program for ContextMenu {
if let Some(shortcut) = shortcut.as_ref() {
components.push(
text(shortcut)
.line_height(20.)
.line_height(Pixels(20.))
.size(14)
.horizontal_alignment(Horizontal::Right)
.width(Length::Shrink)
Expand Down
13 changes: 5 additions & 8 deletions src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@
// update a Arc<Mutex<Theme>> in the state on change of the theme and mark all interfaces for a redraw.

use calloop::LoopHandle;
use cosmic::cosmic_theme::{
palette::{self, Srgba},
Theme, ThemeMode,
};
use cosmic::cosmic_theme::{palette, Theme, ThemeMode};

use crate::state::State;

pub(crate) fn group_color(theme: &Theme<Srgba>) -> [f32; 3] {
pub(crate) fn group_color(theme: &Theme) -> [f32; 3] {
let neutral_8 = theme.palette.neutral_8;
[neutral_8.red, neutral_8.green, neutral_8.blue]
}

pub(crate) fn active_window_hint(theme: &Theme<Srgba>) -> palette::Srgba {
pub(crate) fn active_window_hint(theme: &Theme) -> palette::Srgba {
if let Some(hint) = theme.window_hint {
palette::Srgba::from(hint)
} else {
Expand All @@ -26,8 +23,8 @@ pub(crate) fn active_window_hint(theme: &Theme<Srgba>) -> palette::Srgba {
pub fn watch_theme(handle: LoopHandle<'_, State>) -> Result<(), cosmic_config::Error> {
let (ping_tx, ping_rx) = calloop::ping::make_ping().unwrap();
let config_mode_helper = ThemeMode::config()?;
let config_dark_helper = Theme::<palette::Srgba>::dark_config()?;
let config_light_helper = Theme::<palette::Srgba>::light_config()?;
let config_dark_helper = Theme::dark_config()?;
let config_light_helper = Theme::light_config()?;

if let Err(e) = handle.insert_source(ping_rx, move |_, _, state| {
let new_theme = cosmic::theme::system_preference();
Expand Down
29 changes: 19 additions & 10 deletions src/utils/iced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ use std::{

use cosmic::{
iced::{
advanced::widget::Tree,
event::Event,
keyboard::{Event as KeyboardEvent, Modifiers as IcedModifiers},
mouse::{Button as MouseButton, Cursor, Event as MouseEvent, ScrollDelta},
window::{Event as WindowEvent, Id},
Command, Limits, Point as IcedPoint, Rectangle as IcedRectangle, Size as IcedSize,
},
iced_core::{clipboard::Null as NullClipboard, renderer::Style, Color, Length},
iced_core::{clipboard::Null as NullClipboard, renderer::Style, Color, Font, Length, Pixels},
iced_renderer::{graphics::Renderer as IcedGraphicsRenderer, Renderer as IcedRenderer},
iced_runtime::{
command::Action,
Expand Down Expand Up @@ -128,7 +129,7 @@ impl<P: Program> IcedProgram for ProgramWrapper<P> {
self.0.update(message, &self.1)
}

fn view(&self, _id: Id) -> Element<'_, Self::Message> {
fn view(&self) -> Element<'_, Self::Message> {
self.0.view()
}
}
Expand Down Expand Up @@ -170,11 +171,14 @@ impl<P: Program + Send + Clone + 'static> Clone for IcedElementInternal<P> {
if !self.state.is_queue_empty() {
tracing::warn!("Missing force_update call");
}
let mut renderer =
IcedRenderer::TinySkia(IcedGraphicsRenderer::new(Backend::new(Default::default())));
let mut renderer = IcedRenderer::TinySkia(IcedGraphicsRenderer::new(
Backend::new(),
Font::default(),
Pixels(16.0),
));
let mut debug = Debug::new();
let state = State::new(
Id(0),
Id::MAIN,
ProgramWrapper(self.state.program().0.clone(), handle.clone()),
IcedSize::new(self.size.w as f32, self.size.h as f32),
&mut renderer,
Expand Down Expand Up @@ -232,12 +236,15 @@ impl<P: Program + Send + 'static> IcedElement<P> {
theme: cosmic::Theme,
) -> IcedElement<P> {
let size = size.into();
let mut renderer =
IcedRenderer::TinySkia(IcedGraphicsRenderer::new(Backend::new(Default::default())));
let mut renderer = IcedRenderer::TinySkia(IcedGraphicsRenderer::new(
Backend::new(),
Font::default(),
Pixels(16.0),
));
let mut debug = Debug::new();

let state = State::new(
Id(0),
Id::MAIN,
ProgramWrapper(program, handle.clone()),
IcedSize::new(size.w as f32, size.h as f32),
&mut renderer,
Expand Down Expand Up @@ -283,6 +290,8 @@ impl<P: Program + Send + 'static> IcedElement<P> {
let node = element
.as_widget()
.layout(
// TODO Avoid creating a new tree here?
&mut Tree::new(element.as_widget()),
&internal.renderer,
&Limits::new(IcedSize::ZERO, IcedSize::INFINITY)
.width(Length::Shrink)
Expand Down Expand Up @@ -368,7 +377,7 @@ impl<P: Program + Send + 'static> IcedElementInternal<P> {
let actions = self
.state
.update(
Id(0),
Id::MAIN,
IcedSize::new(self.size.w as f32, self.size.h as f32),
cursor,
&mut self.renderer,
Expand Down Expand Up @@ -636,7 +645,7 @@ impl<P: Program + Send + 'static> SpaceElement for IcedElement<P> {
fn set_activate(&self, activated: bool) {
let mut internal = self.0.lock().unwrap();
internal.state.queue_event(Event::Window(
Id(0),
Id::MAIN,
if activated {
WindowEvent::Focused
} else {
Expand Down

0 comments on commit 74d293e

Please sign in to comment.