From 86b76a9862336715ecfdf7e35ebec3a6990ca718 Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Sat, 7 Sep 2024 12:26:22 +0859 Subject: [PATCH] fix: send not work --- iced_layershell/src/application.rs | 38 ++++++++++++++++---- iced_layershell/src/multi_window.rs | 53 +++++++++++++++++----------- iced_layershell/src/proxy.rs | 6 ++++ iced_sessionlock/src/multi_window.rs | 29 ++++++--------- iced_sessionlock/src/proxy.rs | 6 ++++ 5 files changed, 86 insertions(+), 46 deletions(-) diff --git a/iced_layershell/src/application.rs b/iced_layershell/src/application.rs index bb4e11d..b980545 100644 --- a/iced_layershell/src/application.rs +++ b/iced_layershell/src/application.rs @@ -10,7 +10,7 @@ use crate::{ settings::VirtualKeyboardSettings, }; -use iced_graphics::Compositor; +use iced_graphics::{compositor, Compositor}; use state::State; use iced_core::{time::Instant, window as IcedCoreWindow, Event as IcedCoreEvent, Size}; @@ -27,7 +27,7 @@ use layershellev::{ LayerEvent, ReturnData, WindowWrapper, }; -use futures::{channel::mpsc, SinkExt, StreamExt}; +use futures::{channel::mpsc, StreamExt}; use crate::{event::IcedLayerEvent, proxy::IcedProxy, settings::Settings}; @@ -452,7 +452,30 @@ async fn run_instance( &debug.overlay(), ) .ok(); - debug.render_finished(); + match compositor.present( + &mut renderer, + &mut surface, + state.viewport(), + state.background_color(), + &debug.overlay(), + ) { + Ok(()) => { + debug.render_finished(); + } + Err(error) => match error { + compositor::SurfaceError::OutOfMemory => { + panic!("{:?}", error); + } + _ => { + debug.render_finished(); + log::error!( + "Error {error:?} when \ + presenting surface." + ); + custom_actions.push(LayerShellActions::RedrawAll); + } + }, + } } IcedLayerEvent::Window(event) => { state.update(&event); @@ -602,7 +625,6 @@ pub(crate) fn update( runtime.track(subscription.into_recipes()); } -#[allow(unused)] #[allow(clippy::too_many_arguments)] pub(crate) fn run_command( application: &A, @@ -643,7 +665,7 @@ pub(crate) fn run_command( clipboard::Action::Read(tag, kind) => { let message = tag(clipboard.read(kind)); - proxy.send(message); + proxy.send_event(message).ok(); } clipboard::Action::Write(contents, kind) => { clipboard.write(kind, contents); @@ -691,7 +713,9 @@ pub(crate) fn run_command( &debug.overlay(), ); - proxy.send(tag(window::Screenshot::new(bytes, state.physical_size()))); + proxy + .send_event(tag(window::Screenshot::new(bytes, state.physical_size()))) + .ok(); } _ => {} }, @@ -701,7 +725,7 @@ pub(crate) fn run_command( // TODO: Error handling (?) renderer.load_font(bytes); - proxy.send(tagger(Ok(()))); + proxy.send_event(tagger(Ok(()))).ok(); } command::Action::Custom(custom) => { if let Some(action) = custom.downcast_ref::>() { diff --git a/iced_layershell/src/multi_window.rs b/iced_layershell/src/multi_window.rs index ae7ea13..b9d501a 100644 --- a/iced_layershell/src/multi_window.rs +++ b/iced_layershell/src/multi_window.rs @@ -16,7 +16,7 @@ use crate::{ error::Error, }; -use iced_graphics::Compositor; +use iced_graphics::{compositor, Compositor}; use iced_core::{time::Instant, Size}; @@ -32,7 +32,7 @@ use layershellev::{ LayerEvent, NewPopUpSettings, ReturnData, WindowState, WindowWrapper, }; -use futures::{channel::mpsc, SinkExt, StreamExt}; +use futures::{channel::mpsc, StreamExt}; use crate::{ event::{IcedLayerEvent, MultiWindowIcedLayerEvent}, @@ -553,8 +553,7 @@ async fn run_instance( let (id, window) = window_manager.get_mut_alias(wrapper.id()).unwrap(); let ui = user_interfaces.remove(&id).expect("Get User interface"); window.state.update_view_port(width, height); - #[allow(unused)] - let renderer = &window.renderer; + let _ = user_interfaces.insert( id, ui.relayout( @@ -614,19 +613,32 @@ async fn run_instance( ); debug.draw_finished(); if !is_new_window { - compositor - .present( - &mut window.renderer, - &mut window.surface, - window.state.viewport(), - window.state.background_color(), - &debug.overlay(), - ) - .ok(); + match compositor.present( + &mut window.renderer, + &mut window.surface, + window.state.viewport(), + window.state.background_color(), + &debug.overlay(), + ) { + Ok(()) => { + debug.render_finished(); + } + Err(error) => match error { + compositor::SurfaceError::OutOfMemory => { + panic!("{:?}", error); + } + _ => { + debug.render_finished(); + log::error!( + "Error {error:?} when \ + presenting surface." + ); + custom_actions.push(LayerShellActions::RedrawAll); + } + }, + } } - debug.render_finished(); - if is_created && is_new_window { let cached_interfaces: HashMap = ManuallyDrop::into_inner(user_interfaces) @@ -908,7 +920,6 @@ pub(crate) fn update( runtime.track(subscription.into_recipes()); } -#[allow(unused)] #[allow(clippy::too_many_arguments)] pub(crate) fn run_command( application: &A, @@ -949,7 +960,7 @@ pub(crate) fn run_command( clipboard::Action::Read(tag, kind) => { let message = tag(clipboard.read(kind)); - proxy.send(message); + proxy.send_event(message).ok(); } clipboard::Action::Write(contents, kind) => { clipboard.write(kind, contents); @@ -973,7 +984,7 @@ pub(crate) fn run_command( match operation.finish() { operation::Outcome::None => {} operation::Outcome::Some(message) => { - proxy.send(message); + proxy.send_event(message).ok(); // operation completed, don't need to try to operate on rest of UIs break 'operate; @@ -1014,10 +1025,10 @@ pub(crate) fn run_command( &debug.overlay(), ); - proxy.send(tag(window::Screenshot::new( + proxy.send_event(tag(window::Screenshot::new( bytes, window.state.physical_size(), - ))); + ))).ok(); } _ => {} }, @@ -1030,7 +1041,7 @@ pub(crate) fn run_command( window.renderer.load_font(bytes.clone()); } - proxy.send(tagger(Ok(()))); + proxy.send_event(tagger(Ok(()))).ok(); } command::Action::Custom(custom) => { if let Some(action) = diff --git a/iced_layershell/src/proxy.rs b/iced_layershell/src/proxy.rs index 0ec209f..87659a2 100644 --- a/iced_layershell/src/proxy.rs +++ b/iced_layershell/src/proxy.rs @@ -12,6 +12,12 @@ use std::sync::mpsc as stdmpsc; #[derive(Debug)] pub struct IcedProxy(stdmpsc::Sender); +impl IcedProxy { + pub fn send_event(&self, event: Message) -> Result<(), stdmpsc::SendError> { + self.0.send(event) + } +} + impl Clone for IcedProxy { fn clone(&self) -> Self { Self(self.0.clone()) diff --git a/iced_sessionlock/src/multi_window.rs b/iced_sessionlock/src/multi_window.rs index bc397bb..d5aedd6 100644 --- a/iced_sessionlock/src/multi_window.rs +++ b/iced_sessionlock/src/multi_window.rs @@ -18,7 +18,7 @@ use iced_futures::{Executor, Runtime, Subscription}; use sessionlockev::{ReturnData, SessionLockEvent, WindowState, WindowWrapper}; -use futures::{channel::mpsc, SinkExt, StreamExt}; +use futures::{channel::mpsc, StreamExt}; use crate::{ event::{IcedSessionLockEvent, MultiWindowIcedSessionLockEvent}, @@ -328,7 +328,6 @@ async fn run_instance( init_command, &mut runtime, &mut clipboard, - &mut custom_actions, &mut should_exit, &mut proxy, &mut debug, @@ -336,7 +335,6 @@ async fn run_instance( &mut ui_caches, ); - // TODO: run_command runtime.track(application.subscription().into_recipes()); while let Some(event) = event_receiver.next().await { match event { @@ -388,8 +386,6 @@ async fn run_instance( let (id, window) = window_manager.get_mut_alias(wrapper.id()).unwrap(); let ui = user_interfaces.remove(&id).expect("Get User interface"); window.state.update_view_port(width, height); - #[allow(unused)] - let renderer = &window.renderer; let _ = user_interfaces.insert( id, ui.relayout( @@ -535,7 +531,6 @@ async fn run_instance( &mut proxy, &mut debug, &mut messages, - &mut custom_actions, &mut window_manager, &mut cached_interfaces, ); @@ -629,7 +624,6 @@ pub(crate) fn update( proxy: &mut IcedProxy, debug: &mut Debug, messages: &mut Vec, - custom_actions: &mut [SessionShellActions], window_manager: &mut WindowManager, ui_caches: &mut HashMap, ) where @@ -650,7 +644,6 @@ pub(crate) fn update( command, runtime, clipboard, - custom_actions, should_exit, proxy, debug, @@ -663,7 +656,6 @@ pub(crate) fn update( runtime.track(subscription.into_recipes()); } -#[allow(unused)] #[allow(clippy::too_many_arguments)] pub(crate) fn run_command( application: &A, @@ -671,7 +663,6 @@ pub(crate) fn run_command( command: Command, runtime: &mut Runtime, A::Message>, clipboard: &mut SessionLockClipboard, - custom_actions: &mut [SessionShellActions], should_exit: &mut bool, proxy: &mut IcedProxy, debug: &mut Debug, @@ -702,7 +693,7 @@ pub(crate) fn run_command( clipboard::Action::Read(tag, kind) => { let message = tag(clipboard.read(kind)); - proxy.send(message); + proxy.send_event(message).ok(); } clipboard::Action::Write(contents, kind) => { clipboard.write(kind, contents); @@ -726,7 +717,7 @@ pub(crate) fn run_command( match operation.finish() { operation::Outcome::None => {} operation::Outcome::Some(message) => { - proxy.send(message); + proxy.send_event(message).ok(); // operation completed, don't need to try to operate on rest of UIs break 'operate; @@ -757,10 +748,12 @@ pub(crate) fn run_command( &debug.overlay(), ); - proxy.send(tag(window::Screenshot::new( - bytes, - window.state.physical_size(), - ))); + proxy + .send_event(tag(window::Screenshot::new( + bytes, + window.state.physical_size(), + ))) + .ok(); } _ => {} }, @@ -773,10 +766,10 @@ pub(crate) fn run_command( window.renderer.load_font(bytes.clone()); } - proxy.send(tagger(Ok(()))); + proxy.send_event(tagger(Ok(()))).ok(); } command::Action::Custom(custom) => { - if let Some(action) = custom.downcast_ref::() { + if let Some(_action) = custom.downcast_ref::() { *should_exit = true; } } diff --git a/iced_sessionlock/src/proxy.rs b/iced_sessionlock/src/proxy.rs index 0ec209f..87659a2 100644 --- a/iced_sessionlock/src/proxy.rs +++ b/iced_sessionlock/src/proxy.rs @@ -12,6 +12,12 @@ use std::sync::mpsc as stdmpsc; #[derive(Debug)] pub struct IcedProxy(stdmpsc::Sender); +impl IcedProxy { + pub fn send_event(&self, event: Message) -> Result<(), stdmpsc::SendError> { + self.0.send(event) + } +} + impl Clone for IcedProxy { fn clone(&self) -> Self { Self(self.0.clone())