Skip to content

Commit

Permalink
fix: should always return something in channel
Browse files Browse the repository at this point in the history
or the channel will wait for timeout
  • Loading branch information
Decodetalkers committed Oct 20, 2024
1 parent fa84881 commit b2c0675
Show file tree
Hide file tree
Showing 7 changed files with 266 additions and 244 deletions.
30 changes: 15 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ authors = [
"Aakash Sen Sharma <[email protected]>",
]
edition = "2021"
version = "0.9.1"
version = "0.9.2"
license = "MIT"
repository = "https://github.com/waycrate/exwlshelleventloop"
description = "Wayland extra shell lib"
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"
Expand Down
3 changes: 2 additions & 1 deletion iced_layershell/src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ use iced_core::mouse::Interaction;
use layershellev::id::Id as LayerId;
use layershellev::NewLayerShellSettings;

pub(crate) type LayerShellActionVec<T> = Vec<LayerShellAction<T>>;
#[allow(unused)]
#[derive(Debug, Clone)]
pub(crate) enum LayerShellActions<INFO: Clone> {
pub(crate) enum LayerShellAction<INFO: Clone> {
Mouse(Interaction),
CustomActions(LayershellCustomActionsWithInfo<INFO>),
CustomActionsWithId(LayershellCustomActionsWithIdInner<INFO>),
Expand Down
127 changes: 66 additions & 61 deletions iced_layershell/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -180,7 +183,7 @@ where

let (mut event_sender, event_receiver) =
mpsc::unbounded::<IcedLayerEvent<Action<A::Message>, ()>>();
let (control_sender, mut control_receiver) = mpsc::unbounded::<LayerShellActions<()>>();
let (control_sender, mut control_receiver) = mpsc::unbounded::<LayerShellActionVec<()>>();

let mut instance = Box::pin(run_instance::<A, E, C>(
application,
Expand Down Expand Up @@ -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
});
Expand All @@ -322,7 +327,7 @@ async fn run_instance<A, E, C>(
mut runtime: SingleRuntime<E, A::Message>,
mut debug: Debug,
mut event_receiver: mpsc::UnboundedReceiver<IcedLayerEvent<Action<A::Message>, ()>>,
mut control_sender: mpsc::UnboundedSender<LayerShellActions<()>>,
mut control_sender: mpsc::UnboundedSender<LayerShellActionVec<()>>,
mut state: State<A>,
window: Arc<WindowWrapper>,
) where
Expand Down Expand Up @@ -416,7 +421,7 @@ async fn run_instance<A, E, C>(
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
Expand Down Expand Up @@ -462,7 +467,7 @@ async fn run_instance<A, E, C>(
"Error {error:?} when \
presenting surface."
);
custom_actions.push(LayerShellActions::RedrawAll);
custom_actions.push(LayerShellAction::RedrawAll);
}
},
}
Expand Down Expand Up @@ -547,13 +552,13 @@ async fn run_instance<A, E, C>(
&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));
Expand Down Expand Up @@ -624,7 +629,7 @@ pub(crate) fn run_action<A, C>(
event: Action<A::Message>,
messages: &mut Vec<A::Message>,
clipboard: &mut LayerShellClipboard,
custom_actions: &mut Vec<LayerShellActions<()>>,
custom_actions: &mut Vec<LayerShellAction<()>>,
should_exit: &mut bool,
debug: &mut Debug,
) where
Expand All @@ -640,7 +645,7 @@ pub(crate) fn run_action<A, C>(
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);
}
Expand Down
Loading

0 comments on commit b2c0675

Please sign in to comment.