Skip to content

Commit

Permalink
refactor(sctk): convert window actions
Browse files Browse the repository at this point in the history
  • Loading branch information
wash2 authored and ryanabx committed Jul 29, 2024
1 parent a67b7a5 commit 1f10abc
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 3 deletions.
88 changes: 88 additions & 0 deletions runtime/src/command/platform_specific/wayland/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ use std::marker::PhantomData;

use iced_core::layout::Limits;
use iced_core::window::Mode;
use iced_core::Size;
use iced_futures::MaybeSend;
use sctk::reexports::protocols::xdg::shell::client::xdg_toplevel::ResizeEdge;

use iced_core::window::Id;

use crate::window;

/// window settings
#[derive(Debug, Clone)]
pub struct SctkWindowSettings {
Expand Down Expand Up @@ -309,3 +312,88 @@ impl<T> fmt::Debug for Action<T> {
}
}
}

/// error type for unsupported actions
#[derive(Debug, Clone, thiserror::Error)]
pub enum Error {
/// Not supported
#[error("Not supported")]
NotSupported,
}

impl<T> TryFrom<window::Action<T>> for Action<T> {
type Error = Error;

fn try_from(value: window::Action<T>) -> Result<Self, Self::Error> {
match value {
window::Action::Spawn(id, settings) => {
let min = settings.min_size.unwrap_or(Size::new(1., 1.));
let max = settings.max_size.unwrap_or(Size::INFINITY);
let builder = SctkWindowSettings {
window_id: id,
app_id: Some(settings.platform_specific.application_id),
title: None,
parent: None,
autosize: false,
size_limits: Limits::NONE
.min_width(min.width)
.min_height(min.height)
.max_width(max.width)
.max_height(max.height),
size: (
settings.size.width.round() as u32,
settings.size.height.round() as u32,
),
resizable: settings
.resizable
.then_some(settings.resize_border as f64),
client_decorations: settings.decorations,
transparent: settings.transparent,
xdg_activation_token: None,
};
Ok(Action::Window {
builder,
_phantom: PhantomData,
})
}
window::Action::Close(id) => Ok(Action::Destroy(id)),
window::Action::Resize(id, size) => Ok(Action::Size {
id,
width: size.width.round() as u32,
height: size.height.round() as u32,
}),
window::Action::Drag(id) => Ok(Action::InteractiveMove { id }),
window::Action::FetchSize(_, _)
| window::Action::FetchMaximized(_, _)
| window::Action::Move(_, _)
| window::Action::FetchMode(_, _)
| window::Action::ToggleMaximize(_)
| window::Action::ToggleDecorations(_)
| window::Action::RequestUserAttention(_, _)
| window::Action::GainFocus(_)
| window::Action::ChangeLevel(_, _)
| window::Action::ShowWindowMenu(_)
| window::Action::FetchId(_, _)
| window::Action::ChangeIcon(_, _)
| window::Action::Screenshot(_, _)
| window::Action::FetchMinimized(_, _) => Err(Error::NotSupported),
window::Action::Maximize(id, maximized) => {
if maximized {
Ok(Action::Maximize { id })
} else {
Ok(Action::UnsetMaximize { id })
}
}
window::Action::Minimize(id, bool) => {
if bool {
Ok(Action::Minimize { id })
} else {
Err(Error::NotSupported)
}
}
window::Action::ChangeMode(id, mode) => {
Ok(Action::Mode(id, mode.into()))
}
}
}
}
10 changes: 7 additions & 3 deletions sctk/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use iced_runtime::{
self,
platform_specific::{
self,
wayland::{data_device::DndIcon, popup},
wayland::{data_device::DndIcon, popup, window},
},
},
core::{mouse::Interaction, touch, Color, Point, Size},
Expand Down Expand Up @@ -2073,9 +2073,12 @@ where
proxy.send_event(Event::Message(message));
},
},
command::Action::Window(..) => {
unimplemented!("Use platform specific events instead")
command::Action::Window(action) => {
if let Ok(a) = action.try_into() {
return handle_actions(application, cache, state, renderer, command::Action::PlatformSpecific(platform_specific::Action::Wayland(command::platform_specific::wayland::Action::Window(a))), runtime, proxy, debug, _graphics_info, auto_size_surfaces, clipboard);
}
}
command::Action::Window(action) => {}
command::Action::System(action) => match action {
system::Action::QueryInformation(_tag) => {
#[cfg(feature = "system")]
Expand Down Expand Up @@ -2230,6 +2233,7 @@ where
};
None
}

pub fn build_user_interfaces<'a, A, C>(
application: &'a A,
renderer: &mut A::Renderer,
Expand Down

0 comments on commit 1f10abc

Please sign in to comment.