feat: rebase libcosmic onto iced 0.14

This commit is contained in:
Ashley Wulber 2026-03-18 12:23:49 -04:00 committed by GitHub
parent 6c3d0b2770
commit 6326f65d84
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 1379 additions and 1344 deletions

2442
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -4,7 +4,7 @@ version = "1.0.8"
authors = ["Jeremy Soller <jeremy@system76.com>"]
edition = "2024"
license = "GPL-3.0-only"
rust-version = "1.85"
rust-version = "1.90"
[dependencies]
dirs = "6"
@ -71,6 +71,6 @@ onig = { git = "https://github.com/rust-onig/rust-onig.git", branch = "main" }
onig_sys = { git = "https://github.com/rust-onig/rust-onig.git", branch = "main" }
# [patch.'https://github.com/pop-os/libcosmic']
# libcosmic = { path = "../libcosmic" }
# cosmic-config = { path = "../libcosmic/cosmic-config" }
# cosmic-theme = { path = "../libcosmic/cosmic-theme" }
# libcosmic = { git = "https://github.com/pop-os/libcosmic//" }
# cosmic-config = { git = "https://github.com/pop-os/libcosmic//" }
# cosmic-theme = { git = "https://github.com/pop-os/libcosmic//" }

View file

@ -28,6 +28,7 @@ use cosmic_files::{
use cosmic_text::{Cursor, Edit, Family, Selection, SwashCache, SyntaxSystem, ViMode};
use notify::{RecursiveMode, Watcher};
use serde::{Deserialize, Serialize};
use std::hash::Hash;
use std::{
any::TypeId,
collections::{HashMap, HashSet},
@ -466,7 +467,7 @@ pub struct App {
theme_names: Vec<String>,
context_page: ContextPage,
text_box_id: widget::Id,
auto_scroll: Option<f32>,
auto_scroll: Option<(f32, u32)>,
dialog_opt: Option<Dialog<Message>>,
dialog_page_opt: Option<DialogPage>,
find_opt: Option<FindField>,
@ -1092,7 +1093,7 @@ impl App {
widget::row::with_children(vec![
icon.into(),
widget::text(text.clone()).into(),
widget::horizontal_space().into(),
widget::space::horizontal().into(),
widget::button::standard(fl!("stage"))
.on_press(Message::GitStage(
project_path.clone(),
@ -1133,7 +1134,7 @@ impl App {
widget::row::with_children(vec![
icon.into(),
widget::text(text.clone()).into(),
widget::horizontal_space().into(),
widget::space::horizontal().into(),
widget::button::standard(fl!("unstage"))
.on_press(Message::GitUnstage(
project_path.clone(),
@ -1672,7 +1673,7 @@ impl Application for App {
if let Some(Tab::Editor(tab)) = self.tab_model.data::<Tab>(*entity) {
let mut row = widget::row::with_capacity(3).align_y(Alignment::Center);
row = row.push(widget::text(tab.title()));
row = row.push(widget::horizontal_space());
row = row.push(widget::space::horizontal());
if let Some(_path) = &tab.path_opt {
row = row.push(
widget::button::standard(fl!("save"))
@ -1741,7 +1742,14 @@ impl Application for App {
return self.update_config();
}
Message::AutoScroll(auto_scroll) => {
self.auto_scroll = auto_scroll;
self.auto_scroll = auto_scroll.map(|new| {
(
new,
self.auto_scroll
.map(|old| old.1.wrapping_add(1))
.unwrap_or_default(),
)
});
}
Message::Config(config) => {
if config != self.config {
@ -3186,7 +3194,7 @@ impl Application for App {
widget::tooltip::Position::Top,
)
.into(),
widget::horizontal_space().into(),
widget::space::horizontal().into(),
button::custom(icon_cache_get("window-close-symbolic", 16))
.on_press(Message::Find(None))
.padding(space_xxs)
@ -3243,13 +3251,16 @@ impl Application for App {
column = column.push(
widget::row::with_children(vec![
widget::checkbox(fl!("case-sensitive"), self.config.find_case_sensitive)
widget::checkbox(self.config.find_case_sensitive)
.label(fl!("case-sensitive"))
.on_toggle(Message::FindCaseSensitive)
.into(),
widget::checkbox(fl!("use-regex"), self.config.find_use_regex)
widget::checkbox(self.config.find_use_regex)
.label(fl!("use-regex"))
.on_toggle(Message::FindUseRegex)
.into(),
widget::checkbox(fl!("wrap-around"), self.config.find_wrap_around)
widget::checkbox(self.config.find_wrap_around)
.label(fl!("wrap-around"))
.on_toggle(Message::FindWrapAround)
.into(),
])
@ -3299,67 +3310,74 @@ impl Application for App {
}
_ => None,
}),
Subscription::run_with_id(
TypeId::of::<WatcherSubscription>(),
stream::channel(100, |mut output| async move {
let watcher_res = {
let mut output = output.clone();
//TODO: debounce
notify::recommended_watcher(
move |event_res: Result<notify::Event, notify::Error>| match event_res {
Ok(event) => {
match &event.kind {
notify::EventKind::Access(_)
| notify::EventKind::Modify(
notify::event::ModifyKind::Metadata(_),
) => {
// Data not mutated
return;
}
_ => {}
}
Subscription::run_with(TypeId::of::<WatcherSubscription>(), |_| {
stream::channel(
100,
|mut output: futures::channel::mpsc::Sender<Message>| async move {
let watcher_res = {
let mut output = output.clone();
//TODO: debounce
notify::recommended_watcher(
move |event_res: Result<notify::Event, notify::Error>| {
match event_res {
Ok(event) => {
match &event.kind {
notify::EventKind::Access(_)
| notify::EventKind::Modify(
notify::event::ModifyKind::Metadata(_),
) => {
// Data not mutated
return;
}
_ => {}
}
match futures::executor::block_on(async {
output.send(Message::NotifyEvent(event)).await
}) {
Ok(()) => {}
match futures::executor::block_on(async {
output.send(Message::NotifyEvent(event)).await
}) {
Ok(()) => {}
Err(err) => {
log::warn!(
"failed to send notify event: {:?}",
err
);
}
}
}
Err(err) => {
log::warn!("failed to send notify event: {:?}", err);
log::warn!("failed to watch files: {:?}", err);
}
}
}
Err(err) => {
log::warn!("failed to watch files: {:?}", err);
}
},
)
};
},
)
};
match watcher_res {
Ok(watcher) => {
match output
.send(Message::NotifyWatcher(WatcherWrapper {
watcher_opt: Some(watcher),
}))
.await
{
Ok(()) => {}
Err(err) => {
log::warn!("failed to send notify watcher: {:?}", err);
match watcher_res {
Ok(watcher) => {
match output
.send(Message::NotifyWatcher(WatcherWrapper {
watcher_opt: Some(watcher),
}))
.await
{
Ok(()) => {}
Err(err) => {
log::warn!("failed to send notify watcher: {:?}", err);
}
}
}
Err(err) => {
log::warn!("failed to create file watcher: {:?}", err);
}
}
Err(err) => {
log::warn!("failed to create file watcher: {:?}", err);
}
}
//TODO: how to properly kill this task?
loop {
time::sleep(time::Duration::new(1, 0)).await;
}
}),
),
//TODO: how to properly kill this task?
loop {
time::sleep(time::Duration::new(1, 0)).await;
}
},
)
}),
cosmic_config::config_subscription(
TypeId::of::<ConfigSubscription>(),
Self::APP_ID.into(),
@ -3403,9 +3421,24 @@ impl Application for App {
];
if let Some(auto_scroll) = self.auto_scroll {
#[derive(Clone, Copy)]
struct AutoScroll {
counter: u32,
auto_scroll: f32,
}
impl Hash for AutoScroll {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.counter.hash(state);
}
}
subscriptions.push(
iced::time::every(time::Duration::from_millis(10))
.map(move |_| Message::Scroll(auto_scroll)),
.with(AutoScroll {
auto_scroll: auto_scroll.0,
counter: auto_scroll.1,
})
.map(move |(auto_scroll, _)| Message::Scroll(auto_scroll.auto_scroll)),
);
}

View file

@ -9,9 +9,9 @@ use cosmic::{
iced_core::Border,
theme,
widget::{
self, divider, horizontal_space,
self, divider,
menu::{ItemHeight, ItemWidth, menu_button},
responsive_menu_bar, segmented_button,
responsive_menu_bar, segmented_button, space,
},
};
use std::{collections::HashMap, path::PathBuf, sync::LazyLock};
@ -132,7 +132,7 @@ pub fn context_menu<'a>(
}
menu_button(vec![
widget::text(menu_label).into(),
horizontal_space().into(),
space::horizontal().into(),
widget::text(key)
.class(theme::Text::Custom(key_style))
.into(),

View file

@ -273,7 +273,7 @@ where
}
fn layout(
&self,
&mut self,
_tree: &mut widget::Tree,
_renderer: &Renderer,
limits: &layout::Limits,
@ -303,15 +303,15 @@ where
}
fn operate(
&self,
&mut self,
tree: &mut widget::Tree,
_layout: Layout<'_>,
layout: Layout<'_>,
_renderer: &Renderer,
operation: &mut dyn Operation,
) {
let state = tree.state.downcast_mut::<State>();
operation.focusable(state, self.id.as_ref());
operation.focusable(self.id.as_ref(), layout.bounds(), state);
}
fn mouse_interaction(
@ -371,10 +371,10 @@ where
let view_position = layout.position() + [self.padding.left, self.padding.top].into();
let view_w = cmp::min(viewport.width as i32, layout.bounds().width as i32)
- self.padding.horizontal() as i32
- self.padding.x() as i32
- scrollbar_size;
let view_h = cmp::min(viewport.height as i32, layout.bounds().height as i32)
- self.padding.vertical() as i32;
- self.padding.y() as i32;
let scale_factor = style.scale_factor as f32;
let metrics = self.metrics.scale(scale_factor);
@ -657,18 +657,26 @@ where
renderer.with_transformation(Transformation::scale(1.0 / scale_factor), |renderer| {
// Draw cached image (only has line numbers)
if let Some(ref handle) = *handle_opt {
let image_size = image::Renderer::measure_image(renderer, handle);
let image_size = image::Renderer::measure_image(renderer, handle)
.unwrap_or_else(|| Size::new(1, 1));
image::Renderer::draw_image(
renderer,
handle.clone(),
image::FilterMethod::Nearest,
image::Image {
handle: handle.clone(),
filter_method: image::FilterMethod::Nearest,
rotation: Radians(0.0),
border_radius: [0.0; 4].into(),
opacity: 1.0,
snap: false,
},
Rectangle::new(
Point::new(0.0, 0.0),
Size::new(image_size.width as f32, image_size.height as f32),
),
Rectangle::new(
Point::new(0.0, 0.0),
Size::new(image_size.width as f32, image_size.height as f32),
),
Radians(0.0),
1.0,
[0.0; 4],
);
}
@ -722,7 +730,7 @@ where
renderer.fill_raw(Raw {
buffer: Arc::downgrade(&buffer),
position: pos,
color: Color::new(1.0, 1.0, 1.0, 1.0),
color: Color::from_rgba(1.0, 1.0, 1.0, 1.0),
clip_bounds,
});
}
@ -922,17 +930,17 @@ where
log::trace!("redraw {}, {}: {:?}", view_w, view_h, duration);
}
fn on_event(
fn update(
&mut self,
tree: &mut widget::Tree,
event: Event,
event: &Event,
layout: Layout<'_>,
cursor_position: mouse::Cursor,
_renderer: &Renderer,
_clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
_viewport: &Rectangle<f32>,
) -> Status {
) {
let state = tree.state.downcast_mut::<State>();
let editor_offset_x = state.editor_offset_x.get();
let scale_factor = state.scale_factor.get();
@ -1003,62 +1011,61 @@ where
shell.publish(on_focus.clone());
}
let mut status = Status::Ignored;
match event {
Event::Keyboard(KeyEvent::KeyPressed {
modified_key: Key::Named(key),
modifiers,
..
}) if state.is_focused && !matches!(key, Named::Space) => match key {
}) if state.is_focused => match key {
Named::ArrowLeft => {
motion_modifiers(&mut editor, Motion::Left, modifiers);
status = Status::Captured;
motion_modifiers(&mut editor, Motion::Left, *modifiers);
shell.capture_event();
}
Named::ArrowRight => {
motion_modifiers(&mut editor, Motion::Right, modifiers);
status = Status::Captured;
motion_modifiers(&mut editor, Motion::Right, *modifiers);
shell.capture_event();
}
Named::ArrowUp => {
motion_modifiers(&mut editor, Motion::Up, modifiers);
status = Status::Captured;
motion_modifiers(&mut editor, Motion::Up, *modifiers);
shell.capture_event();
}
Named::ArrowDown => {
motion_modifiers(&mut editor, Motion::Down, modifiers);
status = Status::Captured;
motion_modifiers(&mut editor, Motion::Down, *modifiers);
shell.capture_event();
}
Named::Home => {
motion_modifiers(&mut editor, Motion::Home, modifiers);
status = Status::Captured;
motion_modifiers(&mut editor, Motion::Home, *modifiers);
shell.capture_event();
}
Named::End => {
motion_modifiers(&mut editor, Motion::End, modifiers);
status = Status::Captured;
motion_modifiers(&mut editor, Motion::End, *modifiers);
shell.capture_event();
}
Named::PageUp => {
motion_modifiers(&mut editor, Motion::PageUp, modifiers);
status = Status::Captured;
motion_modifiers(&mut editor, Motion::PageUp, *modifiers);
shell.capture_event();
}
Named::PageDown => {
motion_modifiers(&mut editor, Motion::PageDown, modifiers);
status = Status::Captured;
motion_modifiers(&mut editor, Motion::PageDown, *modifiers);
shell.capture_event();
}
Named::Escape => {
editor.action(Action::Escape);
status = Status::Captured;
shell.capture_event();
}
Named::Enter => {
editor.action(Action::Enter);
status = Status::Captured;
shell.capture_event();
}
Named::Backspace => {
delete_modifiers(&mut editor, Motion::LeftWord, modifiers);
delete_modifiers(&mut editor, Motion::LeftWord, *modifiers);
editor.action(Action::Backspace);
status = Status::Captured;
shell.capture_event();
}
Named::Delete => {
delete_modifiers(&mut editor, Motion::RightWord, modifiers);
delete_modifiers(&mut editor, Motion::RightWord, *modifiers);
editor.action(Action::Delete);
status = Status::Captured;
shell.capture_event();
}
Named::Tab => {
if !modifiers.control() && !modifiers.alt() {
@ -1067,19 +1074,24 @@ where
} else {
editor.action(Action::Indent);
}
status = Status::Captured;
shell.capture_event();
}
}
_ => (),
},
Event::Keyboard(KeyEvent::KeyPressed { text, .. }) if state.is_focused => {
let character = text.unwrap_or_default().chars().next().unwrap_or_default();
let character = text
.clone()
.unwrap_or_default()
.chars()
.next()
.unwrap_or_default();
// Only parse keys when Super, Ctrl, and Alt are not pressed
if !state.modifiers.logo() && !state.modifiers.control() && !state.modifiers.alt() {
if !character.is_control() {
editor.action(Action::Insert(character));
}
status = Status::Captured;
shell.capture_event();
}
}
Event::Keyboard(KeyEvent::ModifiersChanged(modifiers)) => {
@ -1089,7 +1101,7 @@ where
} else if !modifiers.shift() && state.modifiers.shift() {
*state.shift_anchor.lock().unwrap() = None;
}
state.modifiers = modifiers;
state.modifiers = *modifiers;
}
Event::Mouse(MouseEvent::ButtonPressed(button)) => {
if let Some(p) = cursor_position.position_in(layout.bounds()) {
@ -1207,14 +1219,14 @@ where
}));
}
status = Status::Captured;
shell.capture_event();
} else {
state.is_focused = false;
}
}
Event::Mouse(MouseEvent::ButtonReleased(Button::Left)) => {
state.dragging = None;
status = Status::Captured;
shell.capture_event();
if let Some(on_auto_scroll) = &self.on_auto_scroll {
shell.publish(on_auto_scroll(None));
}
@ -1289,7 +1301,7 @@ where
}
}
}
status = Status::Captured;
shell.capture_event();
}
}
Event::Mouse(MouseEvent::WheelScrolled { delta }) => {
@ -1321,7 +1333,7 @@ where
.max(0.0);
buffer.set_scroll(scroll);
});
status = Status::Captured;
shell.capture_event();
}
}
_ => (),
@ -1336,8 +1348,6 @@ where
shell.publish(on_changed.clone());
}
}
status
}
}