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

wayland: ensure external loop is notified with pump_events #4185

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kchibisov
Copy link
Member

Fixes #4183.

Copy link
Contributor

@mahkoh mahkoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't tested it.

Comment on lines 241 to 245
if let Some(pump_event_notifier) = self.pump_event_notifier.as_ref() {
// Notify that we should start waiting, since we're in winit.
*pump_event_notifier.control.0.lock().unwrap() = true;
pump_event_notifier.control.1.notify_one();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if let Some(pump_event_notifier) = self.pump_event_notifier.as_ref() {
// Notify that we should start waiting, since we're in winit.
*pump_event_notifier.control.0.lock().unwrap() = true;
pump_event_notifier.control.1.notify_one();
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, that is redundant, though, I left for consistency.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't wake up the thread before having dispatched all messages since it will just immediately trigger a notification again.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would have been blocked in read_events, otherwise we'd had events to read and thus wake-up would have been needed anyway. But yeah should be fine.

Comment on lines 283 to 284
let mut source = wayland_dispatcher.as_source_mut();
let _ = winit_state.dispatch_pending(source.queue());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems unnecessary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's necessary. The dispatch isn't done otherwise IIRC, but I can test one more time though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't pump_app_events always dispatch events?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's required. I think it's a bug though, should be fixed on calloop end.

Copy link
Contributor

@mahkoh mahkoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't tested it.

}

if let Some(read_guard) = connection.prepare_read() {
let _ = connection.flush();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be a loop with polling until flush returns Ok.

Copy link
Member Author

@kchibisov kchibisov Mar 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs should likely mention that, but I've never seen a wayland loop that flush in a loop until it works. I'd also assume that it may fail in a non-recoverable way.

_handle: JoinHandle<()>,
}

fn spawn_wakeup_thread(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thread needs to be shut down at some point.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I just put it as a draft for now due to that.

@kchibisov kchibisov force-pushed the wayland-pump-event-thread branch 2 times, most recently from 69201e9 to b8f2792 Compare March 27, 2025 16:22
@kchibisov kchibisov force-pushed the wayland-pump-event-thread branch from b8f2792 to 20ef834 Compare April 6, 2025 09:21
@kchibisov
Copy link
Member Author

I think now it should work, though, I'll need a patch for wayland-sys.

@kchibisov kchibisov force-pushed the wayland-pump-event-thread branch from 6011e7b to a2629e8 Compare April 6, 2025 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Cannot integrate winit wayland backend into existing event loop
2 participants