diff --git a/Cargo.lock b/Cargo.lock index 5748ac8..7ef3ab1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -116,7 +116,7 @@ dependencies = [ [[package]] name = "application-launcher" -version = "0.9.1" +version = "0.9.2" dependencies = [ "gio", "iced", @@ -411,7 +411,7 @@ dependencies = [ [[package]] name = "bottom_panel" -version = "0.9.1" +version = "0.9.2" dependencies = [ "gio", "iced", @@ -789,7 +789,7 @@ dependencies = [ [[package]] name = "counter" -version = "0.9.1" +version = "0.9.2" dependencies = [ "iced", "iced_layershell", @@ -798,7 +798,7 @@ dependencies = [ [[package]] name = "counter_lock" -version = "0.9.1" +version = "0.9.2" dependencies = [ "iced", "iced_runtime", @@ -807,7 +807,7 @@ dependencies = [ [[package]] name = "counter_multi" -version = "0.9.1" +version = "0.9.2" dependencies = [ "iced", "iced_layershell", @@ -1806,7 +1806,7 @@ dependencies = [ [[package]] name = "iced_layershell" -version = "0.9.1" +version = "0.9.2" dependencies = [ "futures", "iced", @@ -1825,7 +1825,7 @@ dependencies = [ [[package]] name = "iced_layershell_macros" -version = "0.9.1" +version = "0.9.2" dependencies = [ "darling", "manyhow", @@ -1862,7 +1862,7 @@ dependencies = [ [[package]] name = "iced_sessionlock" -version = "0.9.1" +version = "0.9.2" dependencies = [ "futures", "iced", @@ -1881,7 +1881,7 @@ dependencies = [ [[package]] name = "iced_sessionlock_macros" -version = "0.9.1" +version = "0.9.2" dependencies = [ "darling", "manyhow", @@ -1909,7 +1909,7 @@ dependencies = [ [[package]] name = "iced_virtualkeyboard" -version = "0.9.1" +version = "0.9.2" dependencies = [ "iced", "iced_layershell", @@ -2127,7 +2127,7 @@ dependencies = [ [[package]] name = "layershellev" -version = "0.9.1" +version = "0.9.2" dependencies = [ "bitflags 2.6.0", "calloop 0.14.1", @@ -3478,7 +3478,7 @@ dependencies = [ [[package]] name = "sessionlockev" -version = "0.9.1" +version = "0.9.2" dependencies = [ "bitflags 2.6.0", "calloop 0.14.1", @@ -3690,7 +3690,7 @@ dependencies = [ [[package]] name = "starcolorkeyboard" -version = "0.9.1" +version = "0.9.2" dependencies = [ "bitflags 2.6.0", "cairo-rs", @@ -4232,7 +4232,7 @@ dependencies = [ [[package]] name = "waycrate_xkbkeycode" -version = "0.9.1" +version = "0.9.2" dependencies = [ "bitflags 2.6.0", "log", @@ -4997,7 +4997,7 @@ dependencies = [ [[package]] name = "zbus_invoked_widget" -version = "0.9.1" +version = "0.9.2" dependencies = [ "futures", "iced", diff --git a/Cargo.toml b/Cargo.toml index aef0d4c..fae6872 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ authors = [ "Aakash Sen Sharma ", ] edition = "2021" -version = "0.9.1" +version = "0.9.2" license = "MIT" repository = "https://github.com/waycrate/exwlshelleventloop" description = "Wayland extra shell lib" @@ -26,14 +26,14 @@ keywords = ["wayland", "wlroots"] readme = "README.md" [workspace.dependencies] -layershellev = { version = "0.9.1", path = "./layershellev" } -sessionlockev = { version = "0.9.1", path = "./sessionlockev" } - -iced_layershell = { version = "0.9.1", path = "./iced_layershell" } -iced_layershell_macros = { version = "0.9.1", path = "./iced_layershell_macros" } -iced_sessionlock = { version = "0.9.1", path = "./iced_sessionlock" } -iced_sessionlock_macros = { version = "0.9.1", path = "./iced_sessionlock_macros" } -waycrate_xkbkeycode = { version = "0.9.1", path = "./waycrate_xkbkeycode" } +layershellev = { version = "0.9.2", path = "./layershellev" } +sessionlockev = { version = "0.9.2", path = "./sessionlockev" } + +iced_layershell = { version = "0.9.2", path = "./iced_layershell" } +iced_layershell_macros = { version = "0.9.2", path = "./iced_layershell_macros" } +iced_sessionlock = { version = "0.9.2", path = "./iced_sessionlock" } +iced_sessionlock_macros = { version = "0.9.2", path = "./iced_sessionlock_macros" } +waycrate_xkbkeycode = { version = "0.9.2", path = "./waycrate_xkbkeycode" } tempfile = "3.13.0" thiserror = "1.0.63" diff --git a/iced_layershell/src/actions.rs b/iced_layershell/src/actions.rs index 80698a8..12f721f 100644 --- a/iced_layershell/src/actions.rs +++ b/iced_layershell/src/actions.rs @@ -4,9 +4,10 @@ use iced_core::mouse::Interaction; use layershellev::id::Id as LayerId; use layershellev::NewLayerShellSettings; +pub(crate) type LayerShellActionVec = Vec>; #[allow(unused)] #[derive(Debug, Clone)] -pub(crate) enum LayerShellActions { +pub(crate) enum LayerShellAction { Mouse(Interaction), CustomActions(LayershellCustomActionsWithInfo), CustomActionsWithId(LayershellCustomActionsWithIdInner), diff --git a/iced_layershell/src/application.rs b/iced_layershell/src/application.rs index 96dcd6d..31eacf5 100644 --- a/iced_layershell/src/application.rs +++ b/iced_layershell/src/application.rs @@ -3,7 +3,10 @@ mod state; use std::{mem::ManuallyDrop, os::fd::AsFd, sync::Arc, time::Duration}; use crate::{ - actions::{LayerShellActions, LayershellCustomActions, LayershellCustomActionsWithInfo}, + actions::{ + LayerShellAction, LayerShellActionVec, LayershellCustomActions, + LayershellCustomActionsWithInfo, + }, clipboard::LayerShellClipboard, conversion, error::Error, @@ -180,7 +183,7 @@ where let (mut event_sender, event_receiver) = mpsc::unbounded::, ()>>(); - let (control_sender, mut control_receiver) = mpsc::unbounded::>(); + let (control_sender, mut control_receiver) = mpsc::unbounded::>(); let mut instance = Box::pin(run_instance::( application, @@ -252,63 +255,65 @@ where return ReturnData::RequestExit; }; - let Ok(Some(flow)) = control_receiver.try_next() else { + let Ok(Some(flows)) = control_receiver.try_next() else { return def_returndata; }; - match flow { - LayerShellActions::CustomActions(action) => match action { - LayershellCustomActionsWithInfo::AnchorChange(anchor) => { - ev.main_window().set_anchor(anchor); - } - LayershellCustomActionsWithInfo::AnchorSizeChange(anchor, size) => { - ev.main_window().set_anchor_with_size(anchor, size); - } - LayershellCustomActionsWithInfo::LayerChange(layer) => { - ev.main_window().set_layer(layer); - } - LayershellCustomActionsWithInfo::MarginChange(margin) => { - ev.main_window().set_margin(margin); + for flow in flows { + match flow { + LayerShellAction::CustomActions(action) => match action { + LayershellCustomActionsWithInfo::AnchorChange(anchor) => { + ev.main_window().set_anchor(anchor); + } + LayershellCustomActionsWithInfo::AnchorSizeChange(anchor, size) => { + ev.main_window().set_anchor_with_size(anchor, size); + } + LayershellCustomActionsWithInfo::LayerChange(layer) => { + ev.main_window().set_layer(layer); + } + LayershellCustomActionsWithInfo::MarginChange(margin) => { + ev.main_window().set_margin(margin); + } + LayershellCustomActionsWithInfo::SizeChange((width, height)) => { + ev.main_window().set_size((width, height)); + } + LayershellCustomActionsWithInfo::VirtualKeyboardPressed { time, key } => { + use layershellev::reexport::wayland_client::KeyState; + let ky = ev.get_virtual_keyboard().unwrap(); + ky.key(time, key, KeyState::Pressed.into()); + + let eh = ev.get_loop_handler().unwrap(); + eh.insert_source( + Timer::from_duration(Duration::from_micros(100)), + move |_, _, state| { + let ky = state.get_virtual_keyboard().unwrap(); + + ky.key(time, key, KeyState::Released.into()); + TimeoutAction::Drop + }, + ) + .ok(); + } + _ => {} + }, + LayerShellAction::Mouse(mouse) => { + let Some(pointer) = ev.get_pointer() else { + return ReturnData::None; + }; + + ev.append_return_data(ReturnData::RequestSetCursorShape(( + conversion::mouse_interaction(mouse), + pointer.clone(), + pointer_serial, + ))); } - LayershellCustomActionsWithInfo::SizeChange((width, height)) => { - ev.main_window().set_size((width, height)); + LayerShellAction::RedrawAll => { + ev.append_return_data(ReturnData::RedrawAllRequest); } - LayershellCustomActionsWithInfo::VirtualKeyboardPressed { time, key } => { - use layershellev::reexport::wayland_client::KeyState; - let ky = ev.get_virtual_keyboard().unwrap(); - ky.key(time, key, KeyState::Pressed.into()); - - let eh = ev.get_loop_handler().unwrap(); - eh.insert_source( - Timer::from_duration(Duration::from_micros(100)), - move |_, _, state| { - let ky = state.get_virtual_keyboard().unwrap(); - - ky.key(time, key, KeyState::Released.into()); - TimeoutAction::Drop - }, - ) - .ok(); + LayerShellAction::RedrawWindow(index) => { + ev.append_return_data(ReturnData::RedrawIndexRequest(index)); } _ => {} - }, - LayerShellActions::Mouse(mouse) => { - let Some(pointer) = ev.get_pointer() else { - return ReturnData::None; - }; - - ev.append_return_data(ReturnData::RequestSetCursorShape(( - conversion::mouse_interaction(mouse), - pointer.clone(), - pointer_serial, - ))); - } - LayerShellActions::RedrawAll => { - ev.append_return_data(ReturnData::RedrawAllRequest); } - LayerShellActions::RedrawWindow(index) => { - ev.append_return_data(ReturnData::RedrawIndexRequest(index)); - } - _ => {} } def_returndata }); @@ -322,7 +327,7 @@ async fn run_instance( mut runtime: SingleRuntime, mut debug: Debug, mut event_receiver: mpsc::UnboundedReceiver, ()>>, - mut control_sender: mpsc::UnboundedSender>, + mut control_sender: mpsc::UnboundedSender>, mut state: State, window: Arc, ) where @@ -416,7 +421,7 @@ async fn run_instance( debug.draw_finished(); if new_mouse_interaction != mouse_interaction { - custom_actions.push(LayerShellActions::Mouse(new_mouse_interaction)); + custom_actions.push(LayerShellAction::Mouse(new_mouse_interaction)); mouse_interaction = new_mouse_interaction; } // TODO: check mouse_interaction @@ -462,7 +467,7 @@ async fn run_instance( "Error {error:?} when \ presenting surface." ); - custom_actions.push(LayerShellActions::RedrawAll); + custom_actions.push(LayerShellAction::RedrawAll); } }, } @@ -547,13 +552,13 @@ async fn run_instance( &mut debug, )); } - custom_actions.push(LayerShellActions::RedrawAll); + custom_actions.push(LayerShellAction::RedrawAll); } _ => unreachable!(), } - for action in custom_actions.drain(..) { - control_sender.start_send(action).ok(); - } + let mut copyactions = vec![]; + std::mem::swap(&mut copyactions, &mut custom_actions); + control_sender.start_send(copyactions).ok(); } drop(ManuallyDrop::into_inner(user_interface)); @@ -624,7 +629,7 @@ pub(crate) fn run_action( event: Action, messages: &mut Vec, clipboard: &mut LayerShellClipboard, - custom_actions: &mut Vec>, + custom_actions: &mut Vec>, should_exit: &mut bool, debug: &mut Debug, ) where @@ -640,7 +645,7 @@ pub(crate) fn run_action( use iced_runtime::Action; match event { Action::Output(stream) => match stream.try_into() { - Ok(action) => custom_actions.push(LayerShellActions::CustomActions(action)), + Ok(action) => custom_actions.push(LayerShellAction::CustomActions(action)), Err(stream) => { messages.push(stream); } diff --git a/iced_layershell/src/multi_window.rs b/iced_layershell/src/multi_window.rs index c1a5c69..9c16bdf 100644 --- a/iced_layershell/src/multi_window.rs +++ b/iced_layershell/src/multi_window.rs @@ -1,8 +1,8 @@ mod state; use crate::{ actions::{ - IcedNewMenuSettings, IcedNewPopupSettings, LayershellCustomActionsWithIdAndInfo, - LayershellCustomActionsWithIdInner, MenuDirection, + IcedNewMenuSettings, IcedNewPopupSettings, LayerShellActionVec, + LayershellCustomActionsWithIdAndInfo, LayershellCustomActionsWithIdInner, MenuDirection, }, multi_window::window_manager::WindowManager, settings::VirtualKeyboardSettings, @@ -11,7 +11,7 @@ use crate::{ use std::{collections::HashMap, f64, mem::ManuallyDrop, os::fd::AsFd, sync::Arc, time::Duration}; use crate::{ - actions::{LayerShellActions, LayershellCustomActionsWithInfo}, + actions::{LayerShellAction, LayershellCustomActionsWithInfo}, clipboard::LayerShellClipboard, conversion, error::Error, @@ -203,7 +203,7 @@ where let (mut event_sender, event_receiver) = mpsc::unbounded::, A::WindowInfo>>(); let (control_sender, mut control_receiver) = - mpsc::unbounded::>(); + mpsc::unbounded::>(); let mut instance = Box::pin(run_instance::( application, @@ -312,140 +312,146 @@ where return ReturnData::RequestExit; }; - let Ok(Some(flow)) = control_receiver.try_next() else { + let Ok(Some(flows)) = control_receiver.try_next() else { return def_returndata; }; - match flow { - LayerShellActions::CustomActionsWithId(LayershellCustomActionsWithIdInner( - id, - option_id, - action, - )) => 'out: { - match action { - LayershellCustomActionsWithInfo::AnchorChange(anchor) => { - let Some(id) = id else { - break 'out; - }; - let Some(window) = ev.get_window_with_id(id) else { - break 'out; - }; - window.set_anchor(anchor); - } - LayershellCustomActionsWithInfo::AnchorSizeChange(anchor, size) => { - let Some(id) = id else { - break 'out; - }; - let Some(window) = ev.get_window_with_id(id) else { - break 'out; - }; - window.set_anchor_with_size(anchor, size); - } - LayershellCustomActionsWithInfo::LayerChange(layer) => { - let Some(id) = id else { - break 'out; - }; - let Some(window) = ev.get_window_with_id(id) else { - break 'out; - }; - window.set_layer(layer); - } - LayershellCustomActionsWithInfo::MarginChange(margin) => { - let Some(id) = id else { - break 'out; - }; - let Some(window) = ev.get_window_with_id(id) else { - break 'out; - }; - window.set_margin(margin); - } - LayershellCustomActionsWithInfo::SizeChange((width, height)) => { - let Some(id) = id else { - break 'out; - }; - let Some(window) = ev.get_window_with_id(id) else { - break 'out; - }; - window.set_size((width, height)); - } - LayershellCustomActionsWithInfo::VirtualKeyboardPressed { time, key } => { - use layershellev::reexport::wayland_client::KeyState; - let ky = ev.get_virtual_keyboard().unwrap(); - ky.key(time, key, KeyState::Pressed.into()); - - let eh = ev.get_loop_handler().unwrap(); - eh.insert_source( - Timer::from_duration(Duration::from_micros(100)), - move |_, _, state| { - let ky = state.get_virtual_keyboard().unwrap(); - - ky.key(time, key, KeyState::Released.into()); - TimeoutAction::Drop - }, - ) - .ok(); - } - LayershellCustomActionsWithInfo::NewLayerShell((settings, info)) => { - ev.append_return_data(ReturnData::NewLayerShell((settings, Some(info)))); - } - LayershellCustomActionsWithInfo::RemoveWindow(id) => { - ev.remove_shell(option_id.unwrap()); - event_sender - .start_send(MultiWindowIcedLayerEvent( - None, - IcedLayerEvent::WindowRemoved(id), - )) + for flow in flows { + match flow { + LayerShellAction::CustomActionsWithId( + LayershellCustomActionsWithIdInner(id, option_id, action), + ) => 'out: { + match action { + LayershellCustomActionsWithInfo::AnchorChange(anchor) => { + let Some(id) = id else { + break 'out; + }; + let Some(window) = ev.get_window_with_id(id) else { + break 'out; + }; + window.set_anchor(anchor); + } + LayershellCustomActionsWithInfo::AnchorSizeChange(anchor, size) => { + let Some(id) = id else { + break 'out; + }; + let Some(window) = ev.get_window_with_id(id) else { + break 'out; + }; + window.set_anchor_with_size(anchor, size); + } + LayershellCustomActionsWithInfo::LayerChange(layer) => { + let Some(id) = id else { + break 'out; + }; + let Some(window) = ev.get_window_with_id(id) else { + break 'out; + }; + window.set_layer(layer); + } + LayershellCustomActionsWithInfo::MarginChange(margin) => { + let Some(id) = id else { + break 'out; + }; + let Some(window) = ev.get_window_with_id(id) else { + break 'out; + }; + window.set_margin(margin); + } + LayershellCustomActionsWithInfo::SizeChange((width, height)) => { + let Some(id) = id else { + break 'out; + }; + let Some(window) = ev.get_window_with_id(id) else { + break 'out; + }; + window.set_size((width, height)); + } + LayershellCustomActionsWithInfo::VirtualKeyboardPressed { time, key } => { + use layershellev::reexport::wayland_client::KeyState; + let ky = ev.get_virtual_keyboard().unwrap(); + ky.key(time, key, KeyState::Pressed.into()); + + let eh = ev.get_loop_handler().unwrap(); + eh.insert_source( + Timer::from_duration(Duration::from_micros(100)), + move |_, _, state| { + let ky = state.get_virtual_keyboard().unwrap(); + + ky.key(time, key, KeyState::Released.into()); + TimeoutAction::Drop + }, + ) .ok(); - } - LayershellCustomActionsWithInfo::NewPopUp((menusettings, info)) => { - let IcedNewPopupSettings { size, position } = menusettings; - let Some(id) = ev.current_surface_id() else { - break 'out; - }; - let popup_settings = NewPopUpSettings { size, position, id }; - ev.append_return_data(ReturnData::NewPopUp((popup_settings, Some(info)))); - } - LayershellCustomActionsWithInfo::NewMenu((menusetting, info)) => { - let Some(id) = ev.current_surface_id() else { - break 'out; - }; - event_sender - .start_send(MultiWindowIcedLayerEvent( - Some(id), - IcedLayerEvent::NewMenu((menusetting, info)), - )) - .expect("Cannot send"); - } - LayershellCustomActionsWithInfo::ForgetLastOutput => { - ev.forget_last_output(); + } + LayershellCustomActionsWithInfo::NewLayerShell((settings, info)) => { + ev.append_return_data(ReturnData::NewLayerShell(( + settings, + Some(info), + ))); + } + LayershellCustomActionsWithInfo::RemoveWindow(id) => { + ev.remove_shell(option_id.unwrap()); + event_sender + .start_send(MultiWindowIcedLayerEvent( + None, + IcedLayerEvent::WindowRemoved(id), + )) + .ok(); + } + LayershellCustomActionsWithInfo::NewPopUp((menusettings, info)) => { + let IcedNewPopupSettings { size, position } = menusettings; + let Some(id) = ev.current_surface_id() else { + break 'out; + }; + let popup_settings = NewPopUpSettings { size, position, id }; + ev.append_return_data(ReturnData::NewPopUp(( + popup_settings, + Some(info), + ))); + } + LayershellCustomActionsWithInfo::NewMenu((menusetting, info)) => { + let Some(id) = ev.current_surface_id() else { + break 'out; + }; + event_sender + .start_send(MultiWindowIcedLayerEvent( + Some(id), + IcedLayerEvent::NewMenu((menusetting, info)), + )) + .expect("Cannot send"); + } + LayershellCustomActionsWithInfo::ForgetLastOutput => { + ev.forget_last_output(); + } } } + LayerShellAction::NewMenu((menusettings, info)) => 'out: { + let IcedNewPopupSettings { size, position } = menusettings; + let Some(id) = ev.current_surface_id() else { + break 'out; + }; + let popup_settings = NewPopUpSettings { size, position, id }; + ev.append_return_data(ReturnData::NewPopUp((popup_settings, Some(info)))) + } + LayerShellAction::Mouse(mouse) => { + let Some(pointer) = ev.get_pointer() else { + return ReturnData::None; + }; + + ev.append_return_data(ReturnData::RequestSetCursorShape(( + conversion::mouse_interaction(mouse), + pointer.clone(), + pointer_serial, + ))); + } + LayerShellAction::RedrawAll => { + ev.append_return_data(ReturnData::RedrawAllRequest); + } + LayerShellAction::RedrawWindow(index) => { + ev.append_return_data(ReturnData::RedrawIndexRequest(index)); + } + _ => {} } - LayerShellActions::NewMenu((menusettings, info)) => 'out: { - let IcedNewPopupSettings { size, position } = menusettings; - let Some(id) = ev.current_surface_id() else { - break 'out; - }; - let popup_settings = NewPopUpSettings { size, position, id }; - ev.append_return_data(ReturnData::NewPopUp((popup_settings, Some(info)))) - } - LayerShellActions::Mouse(mouse) => { - let Some(pointer) = ev.get_pointer() else { - return ReturnData::None; - }; - - ev.append_return_data(ReturnData::RequestSetCursorShape(( - conversion::mouse_interaction(mouse), - pointer.clone(), - pointer_serial, - ))); - } - LayerShellActions::RedrawAll => { - ev.append_return_data(ReturnData::RedrawAllRequest); - } - LayerShellActions::RedrawWindow(index) => { - ev.append_return_data(ReturnData::RedrawIndexRequest(index)); - } - _ => {} } def_returndata }); @@ -461,7 +467,7 @@ async fn run_instance( mut event_receiver: mpsc::UnboundedReceiver< MultiWindowIcedLayerEvent, A::WindowInfo>, >, - mut control_sender: mpsc::UnboundedSender>, + mut control_sender: mpsc::UnboundedSender>, window: Arc, is_background_mode: bool, ) where @@ -585,7 +591,7 @@ async fn run_instance( debug.draw_finished(); if new_mouse_interaction != window.mouse_interaction { - custom_actions.push(LayerShellActions::Mouse(new_mouse_interaction)); + custom_actions.push(LayerShellAction::Mouse(new_mouse_interaction)); window.mouse_interaction = new_mouse_interaction; } @@ -633,7 +639,7 @@ async fn run_instance( "Error {error:?} when \ presenting surface." ); - custom_actions.push(LayerShellActions::RedrawAll); + custom_actions.push(LayerShellAction::RedrawAll); } }, } @@ -754,7 +760,7 @@ async fn run_instance( // any window will not get Outdated state. // So here just check if there is window_events if is_background_mode && has_window_event { - custom_actions.push(LayerShellActions::RedrawAll); + custom_actions.push(LayerShellAction::RedrawAll); } // TODO mw application update returns which window IDs to update @@ -773,7 +779,7 @@ async fn run_instance( } if !is_background_mode { - custom_actions.push(LayerShellActions::RedrawAll); + custom_actions.push(LayerShellAction::RedrawAll); } user_interfaces = ManuallyDrop::new(build_user_interfaces( @@ -822,7 +828,7 @@ async fn run_instance( if let MenuDirection::Up = direction { y -= height as i32; } - custom_actions.push(LayerShellActions::NewMenu(( + custom_actions.push(LayerShellAction::NewMenu(( IcedNewPopupSettings { size: (width, height), position: (x, y), @@ -832,9 +838,9 @@ async fn run_instance( } _ => {} } - for action in custom_actions.drain(..) { - control_sender.start_send(action).ok(); - } + let mut copyactions = vec![]; + std::mem::swap(&mut copyactions, &mut custom_actions); + control_sender.start_send(copyactions).ok(); } let _ = ManuallyDrop::into_inner(user_interfaces); } @@ -929,7 +935,7 @@ pub(crate) fn run_action( event: Action, messages: &mut Vec, clipboard: &mut LayerShellClipboard, - custom_actions: &mut Vec>, + custom_actions: &mut Vec>, should_exit: &mut bool, debug: &mut Debug, window_manager: &mut WindowManager, @@ -957,7 +963,7 @@ pub(crate) fn run_action( } else { None }; - custom_actions.push(LayerShellActions::CustomActionsWithId( + custom_actions.push(LayerShellAction::CustomActionsWithId( LayershellCustomActionsWithIdInner( action.0.and_then(|id| window_manager.get_layer_id(id)), option_id, @@ -1014,7 +1020,7 @@ pub(crate) fn run_action( Action::Window(action) => match action { WinowAction::Close(id) => { if let Some(layerid) = window_manager.get_layer_id(id) { - custom_actions.push(LayerShellActions::CustomActionsWithId( + custom_actions.push(LayerShellAction::CustomActionsWithId( LayershellCustomActionsWithIdInner( Some(layerid), Some(layerid), diff --git a/iced_sessionlock/src/actions.rs b/iced_sessionlock/src/actions.rs index 4622bbc..7c502ce 100644 --- a/iced_sessionlock/src/actions.rs +++ b/iced_sessionlock/src/actions.rs @@ -1,8 +1,9 @@ use iced_core::mouse::Interaction; use sessionlockev::id::Id as SessionId; +pub(crate) type SessionShellActionVec = Vec; #[allow(unused)] #[derive(Debug, Clone)] -pub(crate) enum SessionShellActions { +pub(crate) enum SessionShellAction { Mouse(Interaction), RedrawAll, RedrawWindow(SessionId), diff --git a/iced_sessionlock/src/multi_window.rs b/iced_sessionlock/src/multi_window.rs index 3ada3dd..aae174b 100644 --- a/iced_sessionlock/src/multi_window.rs +++ b/iced_sessionlock/src/multi_window.rs @@ -1,9 +1,12 @@ mod state; -use crate::{actions::UnLockAction, multi_window::window_manager::WindowManager}; +use crate::{ + actions::{SessionShellActionVec, UnLockAction}, + multi_window::window_manager::WindowManager, +}; use std::{collections::HashMap, f64, mem::ManuallyDrop, sync::Arc}; use crate::{ - actions::SessionShellActions, clipboard::SessionLockClipboard, conversion, error::Error, + actions::SessionShellAction, clipboard::SessionLockClipboard, conversion, error::Error, }; use super::{Appearance, DefaultStyle}; @@ -163,7 +166,7 @@ where let (mut event_sender, event_receiver) = mpsc::unbounded::>>(); - let (control_sender, mut control_receiver) = mpsc::unbounded::(); + let (control_sender, mut control_receiver) = mpsc::unbounded::(); let mut instance = Box::pin(run_instance::( application, @@ -240,9 +243,14 @@ where let poll = instance.as_mut().poll(&mut context); match poll { task::Poll::Pending => 'peddingBlock: { - if let Ok(Some(flow)) = control_receiver.try_next() { + if let Some(flow) = control_receiver + .try_next() + .ok() + .flatten() + .and_then(|flows| flows.into_iter().next()) + { match flow { - SessionShellActions::Mouse(mouse) => { + SessionShellAction::Mouse(mouse) => { let Some(pointer) = ev.get_pointer() else { break 'peddingBlock ReturnData::None; }; @@ -253,10 +261,10 @@ where pointer_serial, )); } - SessionShellActions::RedrawAll => { + SessionShellAction::RedrawAll => { break 'peddingBlock ReturnData::RedrawAllRequest; } - SessionShellActions::RedrawWindow(index) => { + SessionShellAction::RedrawWindow(index) => { break 'peddingBlock ReturnData::RedrawIndexRequest(index); } } @@ -278,7 +286,7 @@ async fn run_instance( mut event_receiver: mpsc::UnboundedReceiver< MultiWindowIcedSessionLockEvent>, >, - mut control_sender: mpsc::UnboundedSender, + mut control_sender: mpsc::UnboundedSender, window: Arc, ) where A: Application + 'static, @@ -392,7 +400,7 @@ async fn run_instance( debug.draw_finished(); if new_mouse_interaction != window.mouse_interaction { - custom_actions.push(SessionShellActions::Mouse(new_mouse_interaction)); + custom_actions.push(SessionShellAction::Mouse(new_mouse_interaction)); window.mouse_interaction = new_mouse_interaction; } @@ -536,7 +544,7 @@ async fn run_instance( window.state.synchronize(&application); } - custom_actions.push(SessionShellActions::RedrawAll); + custom_actions.push(SessionShellAction::RedrawAll); user_interfaces = ManuallyDrop::new(build_user_interfaces( &application, @@ -548,9 +556,10 @@ async fn run_instance( } _ => {} } - for action in custom_actions.drain(..) { - control_sender.start_send(action).ok(); - } + + let mut copyactions = vec![]; + std::mem::swap(&mut copyactions, &mut custom_actions); + control_sender.start_send(copyactions).ok(); } let _ = ManuallyDrop::into_inner(user_interfaces); }