Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: try to fix something #79

Merged
merged 4 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion iced_layershell/src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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 LayerShellAction<INFO: Clone> {
Mouse(Interaction),
Expand Down
6 changes: 4 additions & 2 deletions iced_layershell/src/multi_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ async fn run_instance<A, E, C>(
while let Some(event) = event_receiver.next().await {
match event {
MultiWindowIcedLayerEvent(
_id,
id,
IcedLayerEvent::RequestRefreshWithWrapper {
width,
height,
Expand All @@ -516,6 +516,7 @@ async fn run_instance<A, E, C>(
info,
},
) => {
let layerid = id.expect("should make sure here be some");
let mut is_new_window = false;
let (id, window) = if window_manager.get_mut_alias(wrapper.id()).is_none() {
is_new_window = true;
Expand Down Expand Up @@ -639,7 +640,7 @@ async fn run_instance<A, E, C>(
"Error {error:?} when \
presenting surface."
);
custom_actions.push(LayerShellAction::RedrawAll);
custom_actions.push(LayerShellAction::RedrawWindow(layerid));
}
},
}
Expand Down Expand Up @@ -741,6 +742,7 @@ async fn run_instance<A, E, C>(
&mut messages,
);

custom_actions.push(LayerShellAction::RedrawWindow(window.id));
if !uis_stale {
uis_stale = matches!(ui_state, user_interface::State::Outdated);
}
Expand Down
35 changes: 33 additions & 2 deletions layershellev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ use calloop::{
Error as CallLoopError, EventLoop, LoopHandle,
};
use calloop_wayland_source::WaylandSource;
use std::f64;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::sync::Mutex;
use std::time::Duration;

#[derive(Debug, thiserror::Error)]
Expand Down Expand Up @@ -1950,6 +1952,7 @@ impl<T: 'static> WindowState<T> {
event_handler: F,
) -> Result<(), LayerEventError>
where
Message: std::marker::Send + 'static,
F: FnMut(LayerEvent<T, Message>, &mut WindowState<T>, Option<id::Id>) -> ReturnData<T>,
{
self.running_with_proxy_option(Some(message_receiver), event_handler)
Expand All @@ -1973,6 +1976,7 @@ impl<T: 'static> WindowState<T> {
mut event_handler: F,
) -> Result<(), LayerEventError>
where
Message: std::marker::Send + 'static,
F: FnMut(LayerEvent<T, Message>, &mut WindowState<T>, Option<id::Id>) -> ReturnData<T>,
{
let globals = self.globals.take().unwrap();
Expand Down Expand Up @@ -2020,6 +2024,26 @@ impl<T: 'static> WindowState<T> {

self.loop_handler = Some(event_loop.handle());

let to_exit = Arc::new(AtomicBool::new(false));

let events: Arc<Mutex<Vec<Message>>> = Arc::new(Mutex::new(Vec::new()));

let to_exit2 = to_exit.clone();
let events_2 = events.clone();
let thread = std::thread::spawn(move || {
let to_exit = to_exit2;
let events = events_2;
let Some(message_receiver) = message_receiver else {
return;
};
for message in message_receiver.iter() {
if to_exit.load(Ordering::Relaxed) {
break;
}
let mut events_local = events.lock().unwrap();
events_local.push(message);
}
});
'out: loop {
event_loop.dispatch(Duration::from_millis(1), &mut self)?;

Expand Down Expand Up @@ -2217,7 +2241,12 @@ impl<T: 'static> WindowState<T> {
}
}
}
if let Some(event) = message_receiver.as_ref().and_then(|rv| rv.try_recv().ok()) {

let mut local_events = events.lock().unwrap();
let mut swapped_events: Vec<Message> = vec![];
std::mem::swap(&mut *local_events, &mut swapped_events);
drop(local_events);
for event in swapped_events {
match event_handler(LayerEvent::UserEvent(event), &mut self, None) {
ReturnData::RequestExit => {
break 'out;
Expand Down Expand Up @@ -2485,6 +2514,8 @@ impl<T: 'static> WindowState<T> {
}
continue;
}
to_exit.store(true, Ordering::Relaxed);
let _ = thread.join();
Ok(())
}
}
Expand Down
33 changes: 32 additions & 1 deletion sessionlockev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ use wayland_protocols::wp::fractional_scale::v1::client::{
wp_fractional_scale_v1::{self, WpFractionalScaleV1},
};

use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering;
use std::sync::Arc;
use std::sync::Mutex;
use std::time::Duration;

pub use calloop;
Expand Down Expand Up @@ -1196,6 +1200,7 @@ impl<T: 'static> WindowState<T> {
event_handler: F,
) -> Result<(), SessonLockEventError>
where
Message: std::marker::Send + 'static,
F: FnMut(SessionLockEvent<T, Message>, &mut WindowState<T>, Option<id::Id>) -> ReturnData,
{
self.running_with_proxy_option(Some(message_receiver), event_handler)
Expand All @@ -1218,6 +1223,7 @@ impl<T: 'static> WindowState<T> {
mut event_handler: F,
) -> Result<(), SessonLockEventError>
where
Message: std::marker::Send + 'static,
F: FnMut(SessionLockEvent<T, Message>, &mut WindowState<T>, Option<id::Id>) -> ReturnData,
{
let globals = self.globals.take().unwrap();
Expand Down Expand Up @@ -1261,7 +1267,26 @@ impl<T: 'static> WindowState<T> {
.expect("Failed to init Wayland Source");

self.loop_handler = Some(event_loop.handle());
let to_exit = Arc::new(AtomicBool::new(false));

let events: Arc<Mutex<Vec<Message>>> = Arc::new(Mutex::new(Vec::new()));

let to_exit2 = to_exit.clone();
let events_2 = events.clone();
let thread = std::thread::spawn(move || {
let to_exit = to_exit2;
let events = events_2;
let Some(message_receiver) = message_receiver else {
return;
};
for message in message_receiver.iter() {
if to_exit.load(Ordering::Relaxed) {
break;
}
let mut events_local = events.lock().unwrap();
events_local.push(message);
}
});
'out: loop {
event_loop.dispatch(Duration::from_millis(1), &mut self)?;
let mut messages = Vec::new();
Expand Down Expand Up @@ -1387,7 +1412,11 @@ impl<T: 'static> WindowState<T> {
}
}
}
if let Some(event) = message_receiver.as_ref().and_then(|rv| rv.try_recv().ok()) {
let mut local_events = events.lock().unwrap();
let mut swapped_events: Vec<Message> = vec![];
std::mem::swap(&mut *local_events, &mut swapped_events);
drop(local_events);
for event in swapped_events {
match event_handler(SessionLockEvent::UserEvent(event), &mut self, None) {
ReturnData::RequestUnlockAndExist => {
lock.unlock_and_destroy();
Expand Down Expand Up @@ -1512,6 +1541,8 @@ impl<T: 'static> WindowState<T> {
return_data = replace_data;
}
}
to_exit.store(true, Ordering::Relaxed);
let _ = thread.join();
Ok(())
}
}
Expand Down