Changes for multiple Application support
- Add Application::main_window_id to allow ids other than MAIN - Make Cosmic and Cosmic::app public to allow custom use
This commit is contained in:
parent
cc8033d74b
commit
3c5dcecf2b
2 changed files with 24 additions and 19 deletions
|
|
@ -75,8 +75,8 @@ pub enum Message {
|
|||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub(crate) struct Cosmic<App> {
|
||||
pub(crate) app: App,
|
||||
pub struct Cosmic<App> {
|
||||
pub app: App,
|
||||
}
|
||||
|
||||
impl<T: Application> IcedApplication for Cosmic<T>
|
||||
|
|
@ -228,7 +228,7 @@ where
|
|||
|
||||
#[cfg(any(feature = "multi-window", feature = "wayland"))]
|
||||
fn view(&self, id: window::Id) -> Element<Self::Message> {
|
||||
if id != window::Id::MAIN {
|
||||
if id != self.app.main_window_id() {
|
||||
return self.app.view_window(id).map(super::Message::App);
|
||||
}
|
||||
|
||||
|
|
@ -248,26 +248,26 @@ where
|
|||
impl<T: Application> Cosmic<T> {
|
||||
#[cfg(feature = "wayland")]
|
||||
pub fn close(&mut self) -> iced::Command<super::Message<T::Message>> {
|
||||
iced_sctk::commands::window::close_window(window::Id::MAIN)
|
||||
iced_sctk::commands::window::close_window(self.app.main_window_id())
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "wayland"))]
|
||||
#[allow(clippy::unused_self)]
|
||||
pub fn close(&mut self) -> iced::Command<super::Message<T::Message>> {
|
||||
iced::Command::single(Action::Window(WindowAction::Close(window::Id::MAIN)))
|
||||
iced::Command::single(Action::Window(WindowAction::Close(self.app.main_window_id())))
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
fn cosmic_update(&mut self, message: Message) -> iced::Command<super::Message<T::Message>> {
|
||||
match message {
|
||||
Message::WindowMaximized(id, maximized) => {
|
||||
if window::Id::MAIN == id {
|
||||
if self.app.main_window_id() == id {
|
||||
self.app.core_mut().window.sharp_corners = maximized;
|
||||
}
|
||||
}
|
||||
|
||||
Message::WindowResize(id, width, height) => {
|
||||
if window::Id::MAIN == id {
|
||||
if self.app.main_window_id() == id {
|
||||
self.app.core_mut().set_window_width(width);
|
||||
self.app.core_mut().set_window_height(height);
|
||||
}
|
||||
|
|
@ -283,7 +283,7 @@ impl<T: Application> Cosmic<T> {
|
|||
|
||||
#[cfg(feature = "wayland")]
|
||||
Message::WindowState(id, state) => {
|
||||
if window::Id::MAIN == id {
|
||||
if self.app.main_window_id() == id {
|
||||
self.app.core_mut().window.sharp_corners = state.intersects(
|
||||
WindowState::MAXIMIZED
|
||||
| WindowState::FULLSCREEN
|
||||
|
|
@ -298,7 +298,7 @@ impl<T: Application> Cosmic<T> {
|
|||
|
||||
#[cfg(feature = "wayland")]
|
||||
Message::WmCapabilities(id, capabilities) => {
|
||||
if window::Id::MAIN == id {
|
||||
if self.app.main_window_id() == id {
|
||||
self.app.core_mut().window.show_maximize =
|
||||
capabilities.contains(WindowManagerCapabilities::MAXIMIZE);
|
||||
self.app.core_mut().window.show_minimize =
|
||||
|
|
@ -321,7 +321,7 @@ impl<T: Application> Cosmic<T> {
|
|||
keyboard_nav::Message::Escape => return self.app.on_escape(),
|
||||
keyboard_nav::Message::Search => return self.app.on_search(),
|
||||
|
||||
keyboard_nav::Message::Fullscreen => return command::toggle_maximize(None),
|
||||
keyboard_nav::Message::Fullscreen => return command::toggle_maximize(Some(self.app.main_window_id())),
|
||||
},
|
||||
|
||||
Message::ContextDrawer(show) => {
|
||||
|
|
@ -329,11 +329,11 @@ impl<T: Application> Cosmic<T> {
|
|||
return self.app.on_context_drawer();
|
||||
}
|
||||
|
||||
Message::Drag => return command::drag(None),
|
||||
Message::Drag => return command::drag(Some(self.app.main_window_id())),
|
||||
|
||||
Message::Minimize => return command::minimize(None),
|
||||
Message::Minimize => return command::minimize(Some(self.app.main_window_id())),
|
||||
|
||||
Message::Maximize => return command::toggle_maximize(None),
|
||||
Message::Maximize => return command::toggle_maximize(Some(self.app.main_window_id())),
|
||||
|
||||
Message::NavBar(key) => {
|
||||
self.app.core_mut().nav_bar_set_toggled_condensed(false);
|
||||
|
|
@ -403,7 +403,7 @@ impl<T: Application> Cosmic<T> {
|
|||
Message::Activate(_token) => {
|
||||
#[cfg(feature = "wayland")]
|
||||
return iced_sctk::commands::activation::activate(
|
||||
iced::window::Id::MAIN,
|
||||
self.app.main_window_id(),
|
||||
#[allow(clippy::used_underscore_binding)]
|
||||
_token,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -433,6 +433,11 @@ where
|
|||
Vec::new()
|
||||
}
|
||||
|
||||
/// Get the main [`window::Id`], which is [`window::Id::MAIN`] by default
|
||||
fn main_window_id(&self) -> window::Id {
|
||||
window::Id::MAIN
|
||||
}
|
||||
|
||||
/// Allows overriding the default nav bar widget
|
||||
fn nav_bar(&self) -> Option<Element<Message<Self::Message>>> {
|
||||
if !self.core().nav_bar_active() {
|
||||
|
|
@ -571,15 +576,15 @@ pub trait ApplicationExt: Application {
|
|||
|
||||
impl<App: Application> ApplicationExt for App {
|
||||
fn drag(&mut self) -> iced::Command<Message<Self::Message>> {
|
||||
command::drag(Some(window::Id::MAIN))
|
||||
command::drag(Some(self.main_window_id()))
|
||||
}
|
||||
|
||||
fn maximize(&mut self) -> iced::Command<Message<Self::Message>> {
|
||||
command::maximize(Some(window::Id::MAIN), true)
|
||||
command::maximize(Some(self.main_window_id()), true)
|
||||
}
|
||||
|
||||
fn minimize(&mut self) -> iced::Command<Message<Self::Message>> {
|
||||
command::minimize(Some(window::Id::MAIN))
|
||||
command::minimize(Some(self.main_window_id()))
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "multi-window", feature = "wayland"))]
|
||||
|
|
@ -606,7 +611,7 @@ impl<App: Application> ApplicationExt for App {
|
|||
fn set_window_title(&mut self, title: String) -> iced::Command<Message<Self::Message>> {
|
||||
self.core_mut()
|
||||
.title
|
||||
.insert(window::Id::MAIN, title.clone());
|
||||
.insert(self.main_window_id(), title.clone());
|
||||
iced::Command::none()
|
||||
}
|
||||
|
||||
|
|
@ -658,7 +663,7 @@ impl<App: Application> ApplicationExt for App {
|
|||
.push_maybe(if core.window.show_headerbar {
|
||||
Some({
|
||||
let mut header = crate::widget::header_bar()
|
||||
.window_id(window::Id::MAIN)
|
||||
.window_id(self.main_window_id())
|
||||
.title(&core.window.header_title)
|
||||
.on_drag(Message::Cosmic(cosmic::Message::Drag))
|
||||
.on_close(Message::Cosmic(cosmic::Message::Close))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue