2023-08-02 11:54:07 +02:00
|
|
|
// Copyright 2023 System76 <info@system76.com>
|
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
|
2023-12-07 15:27:52 -05:00
|
|
|
use iced::window;
|
|
|
|
|
|
2023-08-15 10:51:59 +02:00
|
|
|
/// Asynchronous actions for COSMIC applications.
|
|
|
|
|
use super::Message;
|
2023-08-02 11:54:07 +02:00
|
|
|
|
2023-08-15 10:51:59 +02:00
|
|
|
/// Commands for COSMIC applications.
|
|
|
|
|
pub type Command<M> = iced::Command<Message<M>>;
|
2023-08-02 11:54:07 +02:00
|
|
|
|
|
|
|
|
/// Creates a command which yields a [`crate::app::Message`].
|
|
|
|
|
pub fn message<M: Send + 'static>(message: Message<M>) -> Command<M> {
|
|
|
|
|
crate::command::message(message)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Convenience methods for building message-based commands.
|
|
|
|
|
pub mod message {
|
|
|
|
|
/// Creates a command which yields an application message.
|
|
|
|
|
pub fn app<M: Send + 'static>(message: M) -> crate::app::Command<M> {
|
|
|
|
|
super::message(super::Message::App(message))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Creates a command which yields a cosmic message.
|
|
|
|
|
pub fn cosmic<M: Send + 'static>(
|
|
|
|
|
message: crate::app::cosmic::Message,
|
|
|
|
|
) -> crate::app::Command<M> {
|
|
|
|
|
super::message(super::Message::Cosmic(message))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-07 15:27:52 -05:00
|
|
|
pub fn drag<M: Send + 'static>(id: Option<window::Id>) -> iced::Command<Message<M>> {
|
|
|
|
|
crate::command::drag(id).map(Message::Cosmic)
|
2023-08-02 11:54:07 +02:00
|
|
|
}
|
|
|
|
|
|
2023-12-07 15:27:52 -05:00
|
|
|
pub fn fullscreen<M: Send + 'static>(id: Option<window::Id>) -> iced::Command<Message<M>> {
|
|
|
|
|
crate::command::fullscreen(id).map(Message::Cosmic)
|
2023-08-02 11:54:07 +02:00
|
|
|
}
|
|
|
|
|
|
2023-12-07 15:27:52 -05:00
|
|
|
pub fn minimize<M: Send + 'static>(id: Option<window::Id>) -> iced::Command<Message<M>> {
|
|
|
|
|
crate::command::minimize(id).map(Message::Cosmic)
|
2023-08-02 11:54:07 +02:00
|
|
|
}
|
|
|
|
|
|
2023-09-13 15:21:58 +02:00
|
|
|
pub fn set_scaling_factor<M: Send + 'static>(factor: f32) -> iced::Command<Message<M>> {
|
|
|
|
|
message::cosmic(super::cosmic::Message::ScaleFactor(factor))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn set_theme<M: Send + 'static>(theme: crate::Theme) -> iced::Command<Message<M>> {
|
2023-09-14 01:25:01 +02:00
|
|
|
message::cosmic(super::cosmic::Message::AppThemeChange(theme))
|
2023-09-13 15:21:58 +02:00
|
|
|
}
|
|
|
|
|
|
2023-12-07 15:27:52 -05:00
|
|
|
pub fn set_title<M: Send + 'static>(
|
|
|
|
|
id: Option<window::Id>,
|
|
|
|
|
title: String,
|
|
|
|
|
) -> iced::Command<Message<M>> {
|
|
|
|
|
crate::command::set_title(id, title).map(Message::Cosmic)
|
2023-08-02 11:54:07 +02:00
|
|
|
}
|
|
|
|
|
|
2023-12-07 15:27:52 -05:00
|
|
|
pub fn set_windowed<M: Send + 'static>(id: Option<window::Id>) -> iced::Command<Message<M>> {
|
|
|
|
|
crate::command::set_windowed(id).map(Message::Cosmic)
|
2023-08-02 11:54:07 +02:00
|
|
|
}
|
|
|
|
|
|
2023-12-07 15:27:52 -05:00
|
|
|
pub fn toggle_fullscreen<M: Send + 'static>(id: Option<window::Id>) -> iced::Command<Message<M>> {
|
|
|
|
|
crate::command::toggle_fullscreen(id).map(Message::Cosmic)
|
2023-08-02 11:54:07 +02:00
|
|
|
}
|