chore: cleanup platform specific code
This commit is contained in:
parent
a11b828280
commit
3b7f0bec0e
18 changed files with 109 additions and 101 deletions
|
|
@ -178,7 +178,7 @@ pub fn window_attributes(
|
|||
),
|
||||
));
|
||||
}
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(all(feature = "cctk", target_os = "linux"))]
|
||||
{
|
||||
use winit::platform::wayland::WindowAttributesWayland;
|
||||
|
||||
|
|
@ -424,7 +424,7 @@ pub fn window_event(
|
|||
WindowEvent::ScaleFactorChanged { scale_factor, .. } => {
|
||||
Some(Event::Window(window::Event::Rescaled(scale_factor as f32)))
|
||||
}
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(all(feature = "cctk", target_os = "linux"))]
|
||||
WindowEvent::SuggestedBounds(bounds) => {
|
||||
let size = bounds.map(|bounds| {
|
||||
let size = bounds.to_logical(scale_factor);
|
||||
|
|
@ -437,7 +437,7 @@ pub fn window_event(
|
|||
),
|
||||
)))
|
||||
}
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(all(feature = "cctk", target_os = "linux"))]
|
||||
WindowEvent::WindowStateChanged => {
|
||||
use cctk::sctk::reexports::csd_frame::WindowState;
|
||||
use winit::platform::wayland::WindowExtWayland;
|
||||
|
|
@ -1491,7 +1491,7 @@ pub fn winit_key_code(
|
|||
})
|
||||
}
|
||||
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(all(feature = "cctk", target_os = "linux"))]
|
||||
fn winit_native_key_code(
|
||||
keycode: keyboard::key::NativeCode,
|
||||
) -> winit::keyboard::NativeKeyCode {
|
||||
|
|
@ -1515,7 +1515,7 @@ fn winit_native_key_code(
|
|||
}
|
||||
|
||||
/// Reconstruct the raw keycode
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(all(feature = "cctk", target_os = "linux"))]
|
||||
pub fn physical_to_scancode(physical: keyboard::key::Physical) -> Option<u32> {
|
||||
let Some(physical_key) = (match physical {
|
||||
keyboard::key::Physical::Code(code) => {
|
||||
|
|
|
|||
|
|
@ -98,10 +98,10 @@ where
|
|||
|
||||
let event_loop = EventLoop::new().expect("Create event loop");
|
||||
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(all(feature = "cctk", target_os = "linux"))]
|
||||
let is_wayland =
|
||||
winit::platform::wayland::EventLoopExtWayland::is_wayland(&event_loop);
|
||||
#[cfg(not(feature = "wayland"))]
|
||||
#[cfg(not(all(feature = "cctk", target_os = "linux")))]
|
||||
let is_wayland = false;
|
||||
|
||||
// TODO this is new..
|
||||
|
|
@ -193,7 +193,10 @@ 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)>,
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
is_booted: std::rc::Rc<std::cell::RefCell<bool>>,
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
|
|
@ -216,6 +219,9 @@ where
|
|||
error: None,
|
||||
system_theme: Some(system_theme_sender),
|
||||
|
||||
#[cfg(feature = "a11y")]
|
||||
adapters: Default::default(),
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
canvas: None,
|
||||
};
|
||||
|
|
@ -257,7 +263,7 @@ where
|
|||
| winit::event::WindowEvent::Moved(_)
|
||||
);
|
||||
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(all(feature = "cctk", target_os = "linux"))]
|
||||
{
|
||||
if matches!(event, WindowEvent::RedrawRequested) {
|
||||
for id in
|
||||
|
|
@ -558,7 +564,7 @@ where
|
|||
.expect("Send event");
|
||||
}
|
||||
Control::Winit(id, e) => {
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(all(feature = "cctk", target_os = "linux"))]
|
||||
{
|
||||
if matches!(e, WindowEvent::RedrawRequested)
|
||||
{
|
||||
|
|
@ -621,22 +627,23 @@ where
|
|||
proxy: self.control_sender.clone(),
|
||||
};
|
||||
|
||||
self.sender
|
||||
.start_send(Event::A11yAdapter(
|
||||
id,
|
||||
(
|
||||
node_id,
|
||||
Adapter::with_direct_handlers(
|
||||
event_loop,
|
||||
window.as_ref(),
|
||||
activation_handler,
|
||||
action_handler,
|
||||
deactivation_handler,
|
||||
),
|
||||
_ = self.adapters.insert(
|
||||
id,
|
||||
(
|
||||
node_id,
|
||||
Adapter::with_direct_handlers(
|
||||
event_loop,
|
||||
window.as_ref(),
|
||||
activation_handler,
|
||||
action_handler,
|
||||
deactivation_handler,
|
||||
),
|
||||
))
|
||||
.expect("send event");
|
||||
),
|
||||
);
|
||||
}
|
||||
Control::Cleanup(id) => {
|
||||
_ = self.adapters.remove(&id);
|
||||
},
|
||||
},
|
||||
_ => {
|
||||
break;
|
||||
|
|
@ -680,11 +687,11 @@ enum Event<Message: 'static> {
|
|||
Accessibility(window::Id, iced_accessibility::accesskit::ActionRequest),
|
||||
#[cfg(feature = "a11y")]
|
||||
AccessibilityEnabled(bool),
|
||||
#[cfg(feature = "a11y")]
|
||||
A11yAdapter(
|
||||
window::Id,
|
||||
(u64, iced_accessibility::accesskit_winit::Adapter),
|
||||
),
|
||||
// #[cfg(feature = "a11y")]
|
||||
// A11yAdapter(
|
||||
// window::Id,
|
||||
// (u64, iced_accessibility::accesskit_winit::Adapter),
|
||||
// ),
|
||||
Winit(winit::window::WindowId, winit::event::WindowEvent),
|
||||
AboutToWait,
|
||||
UserEvent(Action<Message>),
|
||||
|
|
@ -697,6 +704,7 @@ enum Control {
|
|||
ChangeFlow(winit::event_loop::ControlFlow),
|
||||
Exit,
|
||||
Crash(Error),
|
||||
Cleanup(window::Id),
|
||||
CreateWindow {
|
||||
id: window::Id,
|
||||
settings: window::Settings,
|
||||
|
|
@ -743,7 +751,7 @@ async fn run_instance<P>(
|
|||
|
||||
let mut platform_specific_handler =
|
||||
crate::platform_specific::PlatformSpecific::default();
|
||||
#[cfg(all(feature = "wayland", target_os = "linux"))]
|
||||
#[cfg(all(feature = "cctk", target_os = "linux"))]
|
||||
if is_wayland {
|
||||
platform_specific_handler = platform_specific_handler.with_wayland(
|
||||
control_sender.clone(),
|
||||
|
|
@ -774,7 +782,7 @@ async fn run_instance<P>(
|
|||
let mut dnd_surface_id: Option<window::Id> = None;
|
||||
|
||||
#[cfg(feature = "a11y")]
|
||||
let (mut adapters, mut a11y_enabled) = (Default::default(), false);
|
||||
let mut a11y_enabled = false;
|
||||
|
||||
#[cfg(all(feature = "linux-theme-detection", target_os = "linux"))]
|
||||
let mut system_theme = {
|
||||
|
|
@ -836,7 +844,7 @@ async fn run_instance<P>(
|
|||
control_sender
|
||||
.start_send(Control::InitAdapter(id, window.clone()))
|
||||
.expect("Send control message");
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(all(feature = "cctk", target_os = "linux"))]
|
||||
platform_specific_handler.send_wayland(
|
||||
platform_specific::Action::TrackWindow(window.clone(), id),
|
||||
);
|
||||
|
|
@ -1012,7 +1020,7 @@ async fn run_instance<P>(
|
|||
continue;
|
||||
}
|
||||
// XX must force update to corner radius before the surface is committed.
|
||||
#[cfg(feature = "wayland")]
|
||||
#[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)
|
||||
|
|
@ -1382,7 +1390,7 @@ async fn run_instance<P>(
|
|||
}
|
||||
});
|
||||
let no_window_events = window_events.is_empty();
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(all(feature = "cctk", target_os = "linux"))]
|
||||
window_events.push(core::Event::PlatformSpecific(
|
||||
core::event::PlatformSpecific::Wayland(
|
||||
core::event::wayland::Event::RequestResize,
|
||||
|
|
@ -1646,8 +1654,6 @@ async fn run_instance<P>(
|
|||
&mut window_manager,
|
||||
&mut user_interfaces,
|
||||
&mut clipboard,
|
||||
#[cfg(feature = "a11y")]
|
||||
&mut adapters,
|
||||
CreateCompositor {
|
||||
proxy: &proxy,
|
||||
display_handle: &display_handle,
|
||||
|
|
@ -1884,10 +1890,6 @@ async fn run_instance<P>(
|
|||
}
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "a11y")]
|
||||
Event::A11yAdapter(id, adapter) => {
|
||||
_ = adapters.insert(id, adapter);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
@ -2124,8 +2126,9 @@ where
|
|||
window::Action::Close(id) => {
|
||||
let _ = ui_caches.remove(&id);
|
||||
let _ = interfaces.remove(&id);
|
||||
_ = control_sender.start_send(Control::Cleanup(id)).ok();
|
||||
let proxy = clipboard.proxy();
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(all(feature = "cctk", target_os = "linux"))]
|
||||
platform_specific
|
||||
.send_wayland(platform_specific::Action::RemoveWindow(id));
|
||||
if let Some(window) = window_manager.remove(id) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
use std::{borrow::Cow, collections::HashMap, sync::Arc};
|
||||
|
||||
#[cfg(all(feature = "wayland", target_os = "linux"))]
|
||||
#[cfg(all(feature = "cctk", target_os = "linux"))]
|
||||
use cctk::sctk::reexports::client::Connection;
|
||||
use iced_graphics::{Compositor, compositor};
|
||||
use iced_runtime::{
|
||||
|
|
@ -12,12 +12,12 @@ use iced_runtime::{
|
|||
};
|
||||
use winit::raw_window_handle::HasWindowHandle;
|
||||
|
||||
#[cfg(all(feature = "wayland", target_os = "linux"))]
|
||||
#[cfg(all(feature = "cctk", target_os = "linux"))]
|
||||
pub mod wayland;
|
||||
|
||||
#[cfg(all(feature = "wayland", target_os = "linux"))]
|
||||
#[cfg(all(feature = "cctk", target_os = "linux"))]
|
||||
pub use wayland::*;
|
||||
#[cfg(all(feature = "wayland", target_os = "linux"))]
|
||||
#[cfg(all(feature = "cctk", target_os = "linux"))]
|
||||
use wayland_backend::client::Backend;
|
||||
|
||||
use crate::{CreateCompositor, Program, WindowManager};
|
||||
|
|
@ -35,7 +35,7 @@ pub type UserInterfaces<'a, P> = HashMap<
|
|||
|
||||
#[derive(Debug)]
|
||||
pub enum Event {
|
||||
#[cfg(all(feature = "wayland", target_os = "linux"))]
|
||||
#[cfg(all(feature = "cctk", target_os = "linux"))]
|
||||
Wayland(sctk_event::SctkEvent),
|
||||
}
|
||||
|
||||
|
|
@ -61,7 +61,7 @@ impl SurfaceIdWrapper {
|
|||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct PlatformSpecific {
|
||||
#[cfg(all(feature = "wayland", target_os = "linux"))]
|
||||
#[cfg(all(feature = "cctk", target_os = "linux"))]
|
||||
wayland: WaylandSpecific,
|
||||
}
|
||||
|
||||
|
|
@ -71,7 +71,7 @@ impl PlatformSpecific {
|
|||
action: iced_runtime::platform_specific::Action,
|
||||
) {
|
||||
match action {
|
||||
#[cfg(all(feature = "wayland", target_os = "linux"))]
|
||||
#[cfg(all(feature = "cctk", target_os = "linux"))]
|
||||
iced_runtime::platform_specific::Action::Wayland(a) => {
|
||||
self.send_wayland(wayland::Action::Action(a));
|
||||
}
|
||||
|
|
@ -82,14 +82,14 @@ impl PlatformSpecific {
|
|||
&mut self,
|
||||
keep: F,
|
||||
) {
|
||||
#[cfg(all(feature = "wayland", target_os = "linux"))]
|
||||
#[cfg(all(feature = "cctk", target_os = "linux"))]
|
||||
{
|
||||
self.wayland.retain_subsurfaces(keep);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn clear_subsurface_list(&mut self) {
|
||||
#[cfg(all(feature = "wayland", target_os = "linux"))]
|
||||
#[cfg(all(feature = "cctk", target_os = "linux"))]
|
||||
{
|
||||
self.wayland.clear_subsurface_list();
|
||||
}
|
||||
|
|
@ -100,7 +100,7 @@ impl PlatformSpecific {
|
|||
id: window::Id,
|
||||
window: &dyn HasWindowHandle,
|
||||
) {
|
||||
#[cfg(all(feature = "wayland", target_os = "linux"))]
|
||||
#[cfg(all(feature = "cctk", target_os = "linux"))]
|
||||
{
|
||||
use cctk::sctk::reexports::client::{
|
||||
Proxy, protocol::wl_surface::WlSurface,
|
||||
|
|
@ -151,7 +151,7 @@ impl PlatformSpecific {
|
|||
pub(crate) fn create_surface(
|
||||
&mut self,
|
||||
) -> Option<Box<dyn HasWindowHandle + Send + Sync + 'static>> {
|
||||
#[cfg(all(feature = "wayland", target_os = "linux"))]
|
||||
#[cfg(all(feature = "cctk", target_os = "linux"))]
|
||||
{
|
||||
return self.wayland.create_surface();
|
||||
}
|
||||
|
|
@ -167,7 +167,7 @@ impl PlatformSpecific {
|
|||
data: &[u8],
|
||||
offset: Vector,
|
||||
) {
|
||||
#[cfg(all(feature = "wayland", target_os = "linux"))]
|
||||
#[cfg(all(feature = "cctk", target_os = "linux"))]
|
||||
{
|
||||
return self.wayland.update_surface_shm(
|
||||
surface, width, height, scale, data, offset,
|
||||
|
|
@ -190,16 +190,12 @@ pub(crate) async fn handle_event<'a, 'b, P>(
|
|||
>,
|
||||
user_interfaces: &mut UserInterfaces<'a, P>,
|
||||
clipboard: &mut crate::Clipboard,
|
||||
#[cfg(feature = "a11y")] adapters: &mut std::collections::HashMap<
|
||||
window::Id,
|
||||
(u64, iced_accessibility::accesskit_winit::Adapter),
|
||||
>,
|
||||
create_compositor: CreateCompositor<'b, P>,
|
||||
) where
|
||||
P: Program,
|
||||
{
|
||||
match e {
|
||||
#[cfg(all(feature = "wayland", target_os = "linux"))]
|
||||
#[cfg(all(feature = "cctk", target_os = "linux"))]
|
||||
Event::Wayland(e) => {
|
||||
platform_specific
|
||||
.wayland
|
||||
|
|
@ -211,8 +207,6 @@ pub(crate) async fn handle_event<'a, 'b, P>(
|
|||
window_manager,
|
||||
user_interfaces,
|
||||
clipboard,
|
||||
#[cfg(feature = "a11y")]
|
||||
adapters,
|
||||
create_compositor,
|
||||
)
|
||||
.await;
|
||||
|
|
|
|||
|
|
@ -164,10 +164,6 @@ impl WaylandSpecific {
|
|||
>,
|
||||
user_interfaces: &mut UserInterfaces<'a, P>,
|
||||
clipboard: &mut crate::Clipboard,
|
||||
#[cfg(feature = "a11y")] adapters: &mut HashMap<
|
||||
window::Id,
|
||||
(u64, iced_accessibility::accesskit_winit::Adapter),
|
||||
>,
|
||||
create_compositor: CreateCompositor<'b, P>,
|
||||
) where
|
||||
P: Program,
|
||||
|
|
@ -213,8 +209,6 @@ impl WaylandSpecific {
|
|||
events,
|
||||
clipboard,
|
||||
subsurface_state,
|
||||
#[cfg(feature = "a11y")]
|
||||
adapters,
|
||||
create_compositor,
|
||||
)
|
||||
.await;
|
||||
|
|
|
|||
|
|
@ -361,10 +361,6 @@ impl SctkEvent {
|
|||
events: &mut Vec<(Option<window::Id>, iced_runtime::core::Event)>,
|
||||
clipboard: &mut Clipboard,
|
||||
subsurface_state: &mut Option<SubsurfaceState>,
|
||||
#[cfg(feature = "a11y")] adapters: &mut HashMap<
|
||||
window::Id,
|
||||
(u64, iced_accessibility::accesskit_winit::Adapter),
|
||||
>,
|
||||
create_compositor_data: CreateCompositor<'b, P>,
|
||||
) where
|
||||
P: Program,
|
||||
|
|
@ -472,8 +468,7 @@ impl SctkEvent {
|
|||
x: -horizontal.value120 as f32 / 120.,
|
||||
y: -vertical.value120 as f32 / 120.,
|
||||
}
|
||||
} else if horizontal.discrete != 0
|
||||
|| vertical.discrete != 0
|
||||
} else if horizontal.discrete != 0 || vertical.discrete != 0
|
||||
{
|
||||
mouse::ScrollDelta::Lines {
|
||||
x: -horizontal.discrete as f32,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue