Skip to content

Commit

Permalink
fix: send not work
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Sep 7, 2024
1 parent 62a4194 commit 86b76a9
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 46 deletions.
38 changes: 31 additions & 7 deletions iced_layershell/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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};

Expand Down Expand Up @@ -452,7 +452,30 @@ async fn run_instance<A, E, C>(
&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);
Expand Down Expand Up @@ -602,7 +625,6 @@ pub(crate) fn update<A: Application, C, E: Executor>(
runtime.track(subscription.into_recipes());
}

#[allow(unused)]
#[allow(clippy::too_many_arguments)]
pub(crate) fn run_command<A, C, E>(
application: &A,
Expand Down Expand Up @@ -643,7 +665,7 @@ pub(crate) fn run_command<A, C, E>(
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);
Expand Down Expand Up @@ -691,7 +713,9 @@ pub(crate) fn run_command<A, C, E>(
&debug.overlay(),
);

proxy.send(tag(window::Screenshot::new(bytes, state.physical_size())));
proxy
.send_event(tag(window::Screenshot::new(bytes, state.physical_size())))
.ok();
}
_ => {}
},
Expand All @@ -701,7 +725,7 @@ pub(crate) fn run_command<A, C, E>(
// 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::<LayershellCustomActionsWithInfo<()>>() {
Expand Down
53 changes: 32 additions & 21 deletions iced_layershell/src/multi_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
error::Error,
};

use iced_graphics::Compositor;
use iced_graphics::{compositor, Compositor};

use iced_core::{time::Instant, Size};

Expand All @@ -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},
Expand Down Expand Up @@ -553,8 +553,7 @@ async fn run_instance<A, E, C>(
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(
Expand Down Expand Up @@ -614,19 +613,32 @@ async fn run_instance<A, E, C>(
);
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<window::Id, user_interface::Cache> =
ManuallyDrop::into_inner(user_interfaces)
Expand Down Expand Up @@ -908,7 +920,6 @@ pub(crate) fn update<A: Application, C, E: Executor>(
runtime.track(subscription.into_recipes());
}

#[allow(unused)]
#[allow(clippy::too_many_arguments)]
pub(crate) fn run_command<A, C, E>(
application: &A,
Expand Down Expand Up @@ -949,7 +960,7 @@ pub(crate) fn run_command<A, C, E>(
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);
Expand All @@ -973,7 +984,7 @@ pub(crate) fn run_command<A, C, E>(
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;
Expand Down Expand Up @@ -1014,10 +1025,10 @@ pub(crate) fn run_command<A, C, E>(
&debug.overlay(),
);

proxy.send(tag(window::Screenshot::new(
proxy.send_event(tag(window::Screenshot::new(
bytes,
window.state.physical_size(),
)));
))).ok();
}
_ => {}
},
Expand All @@ -1030,7 +1041,7 @@ pub(crate) fn run_command<A, C, E>(
window.renderer.load_font(bytes.clone());
}

proxy.send(tagger(Ok(())));
proxy.send_event(tagger(Ok(()))).ok();
}
command::Action::Custom(custom) => {
if let Some(action) =
Expand Down
6 changes: 6 additions & 0 deletions iced_layershell/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ use std::sync::mpsc as stdmpsc;
#[derive(Debug)]
pub struct IcedProxy<Message: 'static>(stdmpsc::Sender<Message>);

impl<Message: 'static> IcedProxy<Message> {
pub fn send_event(&self, event: Message) -> Result<(), stdmpsc::SendError<Message>> {
self.0.send(event)
}
}

impl<Message: 'static> Clone for IcedProxy<Message> {
fn clone(&self) -> Self {
Self(self.0.clone())
Expand Down
29 changes: 11 additions & 18 deletions iced_sessionlock/src/multi_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -328,15 +328,13 @@ async fn run_instance<A, E, C>(
init_command,
&mut runtime,
&mut clipboard,
&mut custom_actions,
&mut should_exit,
&mut proxy,
&mut debug,
&mut window_manager,
&mut ui_caches,
);

// TODO: run_command
runtime.track(application.subscription().into_recipes());
while let Some(event) = event_receiver.next().await {
match event {
Expand Down Expand Up @@ -388,8 +386,6 @@ async fn run_instance<A, E, C>(
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(
Expand Down Expand Up @@ -535,7 +531,6 @@ async fn run_instance<A, E, C>(
&mut proxy,
&mut debug,
&mut messages,
&mut custom_actions,
&mut window_manager,
&mut cached_interfaces,
);
Expand Down Expand Up @@ -629,7 +624,6 @@ pub(crate) fn update<A: Application, C, E: Executor>(
proxy: &mut IcedProxy<A::Message>,
debug: &mut Debug,
messages: &mut Vec<A::Message>,
custom_actions: &mut [SessionShellActions],
window_manager: &mut WindowManager<A, C>,
ui_caches: &mut HashMap<iced::window::Id, user_interface::Cache>,
) where
Expand All @@ -650,7 +644,6 @@ pub(crate) fn update<A: Application, C, E: Executor>(
command,
runtime,
clipboard,
custom_actions,
should_exit,
proxy,
debug,
Expand All @@ -663,15 +656,13 @@ pub(crate) fn update<A: Application, C, E: Executor>(
runtime.track(subscription.into_recipes());
}

#[allow(unused)]
#[allow(clippy::too_many_arguments)]
pub(crate) fn run_command<A, C, E>(
application: &A,
compositor: &mut C,
command: Command<A::Message>,
runtime: &mut Runtime<E, IcedProxy<A::Message>, A::Message>,
clipboard: &mut SessionLockClipboard,
custom_actions: &mut [SessionShellActions],
should_exit: &mut bool,
proxy: &mut IcedProxy<A::Message>,
debug: &mut Debug,
Expand Down Expand Up @@ -702,7 +693,7 @@ pub(crate) fn run_command<A, C, E>(
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);
Expand All @@ -726,7 +717,7 @@ pub(crate) fn run_command<A, C, E>(
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;
Expand Down Expand Up @@ -757,10 +748,12 @@ pub(crate) fn run_command<A, C, E>(
&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();
}
_ => {}
},
Expand All @@ -773,10 +766,10 @@ pub(crate) fn run_command<A, C, E>(
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::<UnLockAction>() {
if let Some(_action) = custom.downcast_ref::<UnLockAction>() {
*should_exit = true;
}
}
Expand Down
6 changes: 6 additions & 0 deletions iced_sessionlock/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ use std::sync::mpsc as stdmpsc;
#[derive(Debug)]
pub struct IcedProxy<Message: 'static>(stdmpsc::Sender<Message>);

impl<Message: 'static> IcedProxy<Message> {
pub fn send_event(&self, event: Message) -> Result<(), stdmpsc::SendError<Message>> {
self.0.send(event)
}
}

impl<Message: 'static> Clone for IcedProxy<Message> {
fn clone(&self) -> Self {
Self(self.0.clone())
Expand Down

0 comments on commit 86b76a9

Please sign in to comment.