chore: cargo fmt

This commit is contained in:
Ashley Wulber 2026-06-25 15:27:31 -04:00 committed by Ashley Wulber
parent 633ed14411
commit c781ff6199
24 changed files with 192 additions and 172 deletions

View file

@ -40,12 +40,6 @@ pub mod clipboard;
pub mod conversion;
pub mod platform_specific;
#[cfg(feature = "program")]
pub mod program;
#[cfg(feature = "system")]
pub mod system;
mod error;
mod proxy;
mod window;
@ -193,10 +187,13 @@ where
error: Option<Error>,
system_theme: Option<oneshot::Sender<theme::Mode>>,
control_sender: mpsc::UnboundedSender<Control>,
#[cfg(feature = "a11y")]
adapters: std::collections::HashMap<window::Id, (u64, iced_accessibility::accesskit_winit::Adapter)>,
adapters: std::collections::HashMap<
window::Id,
(u64, iced_accessibility::accesskit_winit::Adapter),
>,
#[cfg(target_arch = "wasm32")]
is_booted: std::rc::Rc<std::cell::RefCell<bool>>,
#[cfg(target_arch = "wasm32")]
@ -501,9 +498,15 @@ where
}
};
}
let window: Arc<dyn winit::window::Window + 'static> = Arc::from(window);
let window: Arc<
dyn winit::window::Window + 'static,
> = Arc::from(window);
#[cfg(feature = "a11y")]
self.init_adapter(event_loop, id, window.clone());
self.init_adapter(
event_loop,
id,
window.clone(),
);
self.process_event(
event_loop,
@ -572,11 +575,13 @@ where
.expect("Send event");
}
Control::Winit(id, e) => {
#[cfg(all(feature = "cctk", target_os = "linux"))]
#[cfg(all(
feature = "cctk",
target_os = "linux"
))]
{
if matches!(e, WindowEvent::RedrawRequested)
{
{
for id in crate::subsurface_widget::subsurface_ids(id) {
_ = self.sender
.unbounded_send(Event::Winit(
@ -597,7 +602,7 @@ where
}
}
}
self.sender
.start_send(Event::Winit(id, e))
.expect("Send event");
@ -610,7 +615,7 @@ where
#[cfg(feature = "a11y")]
Control::InitAdapter(id, window) => {
self.init_adapter(event_loop, id, window);
self.process_event(
event_loop,
Some(Event::A11yAdapter(id)),
@ -618,8 +623,8 @@ where
}
#[cfg(feature = "a11y")]
Control::Cleanup(id) => {
_ = self.adapters.remove(&id);
},
_ = self.adapters.remove(&id);
}
},
_ => {
break;
@ -633,34 +638,35 @@ where
}
}
#[cfg(feature = "a11y")]
fn init_adapter(&mut self, event_loop: &(dyn winit::event_loop::ActiveEventLoop + 'static), id: core::window::Id, window: Arc<dyn winit::window::Window + 'static>) {
#[cfg(feature = "a11y")]
fn init_adapter(
&mut self,
event_loop: &(dyn winit::event_loop::ActiveEventLoop + 'static),
id: core::window::Id,
window: Arc<dyn winit::window::Window + 'static>,
) {
use crate::a11y::*;
use iced_accessibility::accesskit::{
ActivationHandler, Node, NodeId, Role,
Tree, TreeUpdate,
ActivationHandler, Node, NodeId, Role, Tree, TreeUpdate,
};
use iced_accessibility::accesskit_winit::Adapter;
let node_id =
iced_runtime::core::id::window_node_id();
let activation_handler =
WinitActivationHandler {
proxy: self.control_sender.clone(),
title: String::new(),
};
let node_id = iced_runtime::core::id::window_node_id();
let activation_handler = WinitActivationHandler {
proxy: self.control_sender.clone(),
title: String::new(),
};
let action_handler = WinitActionHandler {
id,
proxy: self.control_sender.clone(),
};
let deactivation_handler =
WinitDeactivationHandler {
proxy: self.control_sender.clone(),
};
let deactivation_handler = WinitDeactivationHandler {
proxy: self.control_sender.clone(),
};
_ = self.adapters.insert(
id,
(
@ -674,8 +680,6 @@ where
),
),
);
}
}
@ -879,9 +883,8 @@ async fn run_instance<P>(
exit_on_close_request,
make_visible,
on_open,
resize_border
resize_border,
} => {
#[cfg(all(feature = "cctk", target_os = "linux"))]
platform_specific_handler.send_wayland(
platform_specific::Action::TrackWindow(window.clone(), id),
@ -937,7 +940,7 @@ async fn run_instance<P>(
compositor,
exit_on_close_request,
system_theme,
resize_border
resize_border,
);
window.raw.set_theme(conversion::window_theme(
@ -1034,7 +1037,7 @@ async fn run_instance<P>(
continue;
};
let Some((id, mut window)) =
let Some((id, mut window)) =
window_manager.get_mut_alias(window_id)
else {
continue;
@ -1049,12 +1052,12 @@ async fn run_instance<P>(
))
.expect("Send redraw event");
continue;
}
}
// XX must force update to corner radius before the surface is committed.
#[cfg(all(feature = "cctk", target_os = "linux"))]
if (window.surface_version != window.state.surface_version()
|| window.logical_size() != window.state.logical_size()
) && !crate::subsurface_widget::is_subsurface(window_id)
|| window.logical_size() != window.state.logical_size())
&& !crate::subsurface_widget::is_subsurface(window_id)
{
platform_specific_handler.send_wayland(
platform_specific::Action::ResizeWindow(id),
@ -1320,9 +1323,7 @@ async fn run_instance<P>(
continue;
};
// Initiates a drag resize window state when found.
if let Some(func) =
window.drag_resize_window_func.as_mut()
{
if let Some(func) = window.drag_resize_window_func.as_mut() {
if func(window.raw.as_ref(), &event) {
continue;
}
@ -1348,7 +1349,9 @@ async fn run_instance<P>(
if matches!(event, winit::event::WindowEvent::CloseRequested)
&& window.exit_on_close_request
{
_ = run_action!(Action::Window(runtime::window::Action::Close(id)));
_ = run_action!(Action::Window(
runtime::window::Action::Close(id)
));
} else {
window.state.update(&program, window.raw.as_ref(), &event);
@ -1736,7 +1739,6 @@ async fn run_instance<P>(
};
// search windows for widget with operation
if result.is_none() {
log::warn!(
"start_dnd: widget {:?} not found; drag will fail",
@ -2113,7 +2115,7 @@ where
on_open: channel,
})
.expect("Send control action");
*is_window_opening = true;
}
window::Action::Close(id) => {

View file

@ -1,8 +1,8 @@
use crate::core::window::Id as SurfaceId;
use iced_runtime::{
self,
self, Action, Task,
platform_specific::{self, wayland},
task, Action, Task,
task,
};
pub fn request_token(

View file

@ -1,11 +1,11 @@
use iced_futures::core::window;
use iced_runtime::{
self,
self, Action, Task,
platform_specific::{
self,
wayland::{self, CornerRadius},
},
task, Action, Task,
task,
};
pub fn corner_radius(

View file

@ -1,7 +1,7 @@
use iced_runtime::{
self,
self, Action, Task,
platform_specific::{self, wayland},
task, Action, Task,
task,
};
pub fn inhibit_shortcuts(inhibit: bool) -> Task<()> {

View file

@ -1,7 +1,8 @@
use iced_futures::core::window::Id;
use iced_runtime::{
Action, Task,
platform_specific::{self, wayland},
task, Action, Task,
task,
};
/// Request subscription for overlap notification events on the surface

View file

@ -1,9 +1,9 @@
use crate::core::window::Id as SurfaceId;
use cctk::sctk::reexports::client::protocol::wl_output::WlOutput;
use iced_runtime::{
self,
self, Action, Task,
platform_specific::{self, wayland},
task, Action, Task,
task,
};
pub fn lock<Message>() -> Task<Message> {

View file

@ -1,12 +1,12 @@
use crate::core::window::Id as SurfaceId;
pub use cctk::sctk::shell::wlr_layer::{Anchor, KeyboardInteractivity, Layer};
use iced_runtime::{
self,
self, Action, Task,
platform_specific::{
self,
wayland::{self, subsurface::SctkSubsurfaceSettings},
},
task, Action, Task,
task,
};
pub fn get_subsurface<Message>(

View file

@ -1,8 +1,8 @@
use cctk::sctk::reexports::calloop;
use iced_futures::futures::{
Sink,
channel::mpsc,
task::{Context, Poll},
Sink,
};
use std::pin::Pin;

View file

@ -1,7 +1,11 @@
use crate::{
Control,
handlers::{
activation::IcedRequestData, ext_background_effect, overlap::{OverlapNotificationV1, OverlapNotifyV1}, shell::corner_radius::CornerRadiusWrapper, text_input::{Preedit, TextInputManager}
activation::IcedRequestData,
ext_background_effect,
overlap::{OverlapNotificationV1, OverlapNotifyV1},
shell::corner_radius::CornerRadiusWrapper,
text_input::{Preedit, TextInputManager},
},
platform_specific::{
Event,
@ -37,11 +41,10 @@ use winit::{
use cctk::{
cosmic_protocols::{
corner_radius::v1::client::{
cosmic_corner_radius_manager_v1::CosmicCornerRadiusManagerV1,
},
corner_radius::v1::client::cosmic_corner_radius_manager_v1::CosmicCornerRadiusManagerV1,
overlap_notify::v1::client::zcosmic_overlap_notification_v1::ZcosmicOverlapNotificationV1,
}, sctk::{
},
sctk::{
activation::{ActivationState, RequestData},
compositor::CompositorState,
error::GlobalError,
@ -59,7 +62,8 @@ use cctk::{
wl_surface::{self, WlSurface},
wl_touch::WlTouch,
},
}, protocols_wlr::layer_shell::v1::client::zwlr_layer_surface_v1::ZwlrLayerSurfaceV1,
},
protocols_wlr::layer_shell::v1::client::zwlr_layer_surface_v1::ZwlrLayerSurfaceV1,
},
registry::RegistryState,
seat::{
@ -84,7 +88,9 @@ use cctk::{
},
},
shm::{Shm, multi::MultiPool},
}, toplevel_info::ToplevelInfoState, toplevel_management::ToplevelManagerState
},
toplevel_info::ToplevelInfoState,
toplevel_management::ToplevelManagerState,
};
use iced_runtime::{
core::{self, Point, touch},
@ -99,7 +105,10 @@ use iced_runtime::{
},
};
use wayland_protocols::{
ext::background_effect::v1::client::{ext_background_effect_manager_v1, ext_background_effect_surface_v1::ExtBackgroundEffectSurfaceV1},
ext::background_effect::v1::client::{
ext_background_effect_manager_v1,
ext_background_effect_surface_v1::ExtBackgroundEffectSurfaceV1,
},
wp::{
fractional_scale::v1::client::wp_fractional_scale_v1::WpFractionalScaleV1,
keyboard_shortcuts_inhibit::zv1::client::{
@ -333,7 +342,6 @@ pub struct SctkPopupData {
pub(crate) grab: bool,
}
#[derive(Debug, Clone)]
pub struct SctkCornerRadius(Arc<CornerRadiusWrapper>);
@ -865,13 +873,11 @@ impl SctkState {
}
_ = wl_surface.frame(&self.queue_handle, wl_surface.clone());
if let Some(blur) = self.pending_blur.remove(&settings.id) {
self.apply_blur(settings.id, Some(blur), &wl_surface);
}
let wp_viewport = self.viewporter_state.as_ref().map(|state| {
let viewport =
state.get_viewport(popup.wl_surface(), &self.queue_handle);
@ -902,9 +908,9 @@ impl SctkState {
common: common.clone(),
close_with_children: settings.close_with_children,
});
if let Some(corners) = self.pending_corner_radius.remove(&settings.id) {
self.handle_action(Action::RoundedCorners (
self.handle_action(Action::RoundedCorners(
settings.id,
Some(corners),
));
@ -1008,7 +1014,6 @@ impl SctkState {
if let Some(blur) = self.pending_blur.remove(&id) {
self.apply_blur(id, Some(blur), &wl_surface);
}
let wp_viewport = self.viewporter_state.as_ref().map(|state| {
state.get_viewport(layer_surface.wl_surface(), &self.queue_handle)
@ -1043,10 +1048,7 @@ impl SctkState {
common: common.clone(),
});
if let Some(corners) = self.pending_corner_radius.remove(&id) {
_ = self.handle_action(Action::RoundedCorners(
id,
Some(corners),
));
_ = self.handle_action(Action::RoundedCorners(id, Some(corners)));
}
layer_surface.commit();
Ok((id, CommonSurface::Layer(layer_surface), common))
@ -1139,7 +1141,7 @@ impl SctkState {
platform_specific::wayland::layer_surface::Action::Destroy(id) => {
if let Some(p) = self
.popups
.iter().find_map(|p|
.iter().find_map(|p|
self.layer_surfaces.iter().find_map(|l| if l.id == id && l.surface.wl_surface() == p.data.parent.wl_surface() {Some(p.data.id)} else {None})) {
_ = self.handle_action(Action::Popup(platform_specific::wayland::popup::Action::Destroy { id: p }));
}
@ -1173,7 +1175,6 @@ impl SctkState {
_ = self.destroyed.insert(destroyed);
}
send_event(&self.events_sender, &self.proxy, SctkEvent::LayerSurfaceEvent {
variant: LayerSurfaceEventVariant::Done,
id: l.surface.wl_surface().clone(),
@ -1492,7 +1493,6 @@ impl SctkState {
// update positioner
sctk_popup.data.positioner.set_size(w as i32, h as i32);
sctk_popup.popup.reposition(&sctk_popup.data.positioner, TOKEN_CTR.fetch_add(1, std::sync::atomic::Ordering::Relaxed)); let surface = sctk_popup.popup.wl_surface().clone();
dbg!("repositioning...");
_ = send_event(&self.events_sender, &self.proxy,
SctkEvent::PopupEvent { variant: crate::sctk_event::PopupEventVariant::Size(size.0, size.1), toplevel_id: sctk_popup.data.parent.wl_surface().clone(), parent_id: sctk_popup.data.parent.wl_surface().clone(), id: surface });
}
@ -1832,19 +1832,24 @@ impl SctkState {
Ok(())
}
fn apply_blur(&mut self, id: core::window::Id, rectangles: Option<Vec<Rectangle>>, s: &WlSurface) {
fn apply_blur(
&mut self,
id: core::window::Id,
rectangles: Option<Vec<Rectangle>>,
s: &WlSurface,
) {
let existing_blur = self.blur_surfaces.entry(id);
match (existing_blur, rectangles) {
(Entry::Occupied(occupied_entry), None) => {
let blur_surface = occupied_entry.remove();
blur_surface.destroy();
},
}
(Entry::Occupied(mut occupied_entry), Some(rectangles)) => {
let blur_surface = occupied_entry.get_mut();
let region = self
.compositor_state
.wl_compositor()
.create_region(&self.queue_handle, ());
.compositor_state
.wl_compositor()
.create_region(&self.queue_handle, ());
for rect in rectangles.into_iter() {
region.add(
rect.x.round() as i32,
@ -1853,41 +1858,40 @@ impl SctkState {
rect.height.round() as i32,
);
}
// update existing blur surfaces
blur_surface.set_blur_region(Some(&region));
},
}
(Entry::Vacant(..), None) => {
// nothing to remove
},
}
(Entry::Vacant(vacant_entry), Some(rectangles)) => {
if self.ext_background_effect_manager.is_none() {
log::error!("Blur effect is not supported.");
return;
}
let region = self
.compositor_state
.wl_compositor()
.create_region(&self.queue_handle, ());
for rect in rectangles {
region.add(
rect.x.round() as i32,
rect.y.round() as i32,
rect.width.round() as i32,
rect.height.round() as i32,
);
}
let blur_manager = self.ext_background_effect_manager.as_mut().unwrap();
let blur_surface = blur_manager.blur(s, &self.queue_handle);
blur_surface.set_blur_region(Some(&region));
let region = self
.compositor_state
.wl_compositor()
.create_region(&self.queue_handle, ());
for rect in rectangles {
region.add(
rect.x.round() as i32,
rect.y.round() as i32,
rect.width.round() as i32,
rect.height.round() as i32,
);
}
let blur_manager =
self.ext_background_effect_manager.as_mut().unwrap();
let blur_surface = blur_manager.blur(s, &self.queue_handle);
blur_surface.set_blur_region(Some(&region));
_ = vacant_entry.insert(blur_surface);
},
}
}
}
pub fn get_subsurface(
&mut self,
settings: SctkSubsurfaceSettings,
@ -2020,7 +2024,6 @@ impl SctkState {
if let Some(blur) = self.pending_blur.remove(&settings.id) {
_ = self.apply_blur(settings.id, Some(blur), &wl_surface);
}
let wp_viewport = subsurface_state.wp_viewporter.get_viewport(
&wl_surface,
@ -2097,10 +2100,7 @@ impl SctkState {
self.subsurfaces
.sort_by(|a, b| b.instance.z.cmp(&a.instance.z));
if let Some(corners) = self.pending_corner_radius.remove(&id) {
self.handle_action(Action::RoundedCorners (
id,
Some(corners),
));
self.handle_action(Action::RoundedCorners(id, Some(corners)));
}
wl_surface.commit();

View file

@ -9,12 +9,12 @@ use crate::{
use cctk::sctk::{
delegate_touch,
reexports::client::{
protocol::{wl_surface::WlSurface, wl_touch::WlTouch},
Connection, Proxy, QueueHandle,
protocol::{wl_surface::WlSurface, wl_touch::WlTouch},
},
seat::touch::TouchHandler,
};
use iced_runtime::core::{touch, Point};
use iced_runtime::core::{Point, touch};
impl TouchHandler for SctkState {
fn down(

View file

@ -1,8 +1,7 @@
use crate::{
event_loop::state::CommonSurface,
platform_specific::wayland::{
event_loop::state::receive_frame,
handlers::SctkState,
event_loop::state::receive_frame, handlers::SctkState,
sctk_event::SctkEvent,
},
};

View file

@ -1,13 +1,13 @@
use crate::platform_specific::wayland::{
event_loop::state::{receive_frame, SctkState},
event_loop::state::{SctkState, receive_frame},
sctk_event::{LayerSurfaceEventVariant, SctkEvent},
};
use cctk::sctk::{
delegate_layer,
reexports::client::Proxy,
shell::{
wlr_layer::{Anchor, KeyboardInteractivity, LayerShellHandler},
WaylandSurface,
wlr_layer::{Anchor, KeyboardInteractivity, LayerShellHandler},
},
};
use std::fmt::Debug;

View file

@ -1,4 +1,4 @@
pub mod corner_radius;
pub mod layer;
pub mod xdg_popup;
pub mod xdg_window;
pub mod corner_radius;

View file

@ -1,10 +1,10 @@
//! Handling of the wp-viewporter.
use cctk::sctk::reexports::client::Dispatch;
use cctk::sctk::reexports::client::globals::{BindError, GlobalList};
use cctk::sctk::reexports::client::protocol::wl_surface::WlSurface;
use cctk::sctk::reexports::client::Dispatch;
use cctk::sctk::reexports::client::{
delegate_dispatch, Connection, Proxy, QueueHandle,
Connection, Proxy, QueueHandle, delegate_dispatch,
};
use cctk::sctk::reexports::protocols::wp::viewporter::client::wp_viewport::WpViewport;
use cctk::sctk::reexports::protocols::wp::viewporter::client::wp_viewporter::WpViewporter;

View file

@ -21,6 +21,7 @@ use iced_runtime::core::{Vector, window};
use raw_window_handle::{DisplayHandle, HasDisplayHandle, HasWindowHandle};
use raw_window_handle::{HasRawDisplayHandle, RawWindowHandle};
use sctk_event::SctkEvent;
use std::sync::OnceLock;
use std::{collections::HashMap, sync::Arc};
use subsurface_widget::{SubsurfaceInstance, SubsurfaceState};
use wayland_backend::client::ObjectId;