Merge remote-tracking branch 'upstream/master'

# Conflicts:
#	iced
This commit is contained in:
Lionel DARNIS 2026-08-27 07:49:01 +02:00
commit 173d6ebd32
9 changed files with 105 additions and 108 deletions

View file

@ -88,7 +88,4 @@ pub fn main() {
println!("Testing state");
test_config(Config::new_state("com.system76.Example", 1).unwrap());
println!("Testing data");
test_config(Config::new_data("com.system76.Example", 1).unwrap());
}

View file

@ -30,6 +30,7 @@ pub enum Message {
WindowClose,
Surface(cosmic::surface::Action),
ToggleHideContent,
ToggleSomeAction,
WindowNew,
}
@ -82,6 +83,7 @@ impl cosmic::Application for App {
/// Handle application events here.
fn update(&mut self, message: Self::Message) -> Task<Self::Message> {
tracing::error!("Clicked {message:?}");
match message {
Message::Clicked => {
self.button_label = format!("Clicked {message:?}");
@ -91,9 +93,10 @@ impl cosmic::Application for App {
cosmic::app::Action::Surface(action),
));
}
Message::WindowClose => {}
Message::ToggleHideContent => {}
Message::WindowNew => {}
Message::WindowClose
| Message::ToggleHideContent
| Message::ToggleSomeAction
| Message::WindowNew => {}
}
Task::none()
@ -102,7 +105,7 @@ impl cosmic::Application for App {
/// Creates a view after each update.
fn view(&self) -> Element<'_, Self::Message> {
let widget = cosmic::widget::context_menu(
cosmic::widget::button::text(self.button_label.to_string()).on_press(Message::Clicked),
cosmic::widget::button::text(self.button_label.clone()).on_press(Message::Clicked),
self.context_menu(),
)
.on_surface_action(Message::Surface);
@ -126,12 +129,20 @@ impl App {
menu::Item::Divider,
menu::Item::Folder(
"View",
vec![menu::Item::CheckBox(
"Hide content",
None,
self.hide_content,
ContextMenuAction::ToggleHideContent,
)],
vec![
menu::Item::CheckBox(
"Hide content",
None,
self.hide_content,
ContextMenuAction::ToggleHideContent,
),
menu::Item::CheckBox(
"Test content",
None,
self.hide_content,
ContextMenuAction::ToggleSomeAction,
),
],
),
menu::Item::Divider,
menu::Item::Button("Quit", None, ContextMenuAction::WindowClose),
@ -144,6 +155,7 @@ impl App {
pub enum ContextMenuAction {
WindowClose,
ToggleHideContent,
ToggleSomeAction,
WindowNew,
}
@ -153,6 +165,7 @@ impl menu::Action for ContextMenuAction {
match self {
ContextMenuAction::WindowClose => Message::WindowClose,
ContextMenuAction::ToggleHideContent => Message::ToggleHideContent,
ContextMenuAction::ToggleSomeAction => Message::ToggleSomeAction,
ContextMenuAction::WindowNew => Message::WindowNew,
}
}

View file

@ -9,7 +9,7 @@ use std::{env, process};
use cosmic::app::{Core, Settings, Task};
use cosmic::iced::alignment::{Horizontal, Vertical};
use cosmic::iced::keyboard::Key;
use cosmic::iced::{window, Length, Size};
use cosmic::iced::{event, keyboard, window, Event, Length, Size, Subscription};
use cosmic::widget::menu::action::MenuAction;
use cosmic::widget::menu::key_bind::{KeyBind, Modifier};
use cosmic::widget::menu::{self, ItemHeight, ItemWidth};
@ -112,6 +112,26 @@ impl cosmic::Application for App {
vec![menu_bar(&self.config, &self.key_binds)]
}
fn subscription(&self) -> Subscription<Self::Message> {
event::listen_with(|event, _status, _window_id| {
let Event::Keyboard(keyboard::Event::KeyPressed {
key,
modifiers,
physical_key,
..
}) = event
else {
return None;
};
let key_binds = key_binds();
key_binds
.iter()
.find(|(key_bind, _)| key_bind.matches(modifiers, &key, Some(&physical_key)))
.map(|(_, action)| action.message())
})
}
/// Handle application events here.
fn update(&mut self, message: Self::Message) -> Task<Self::Message> {
match message {