chore: feature gates
This commit is contained in:
parent
654ae0bf5d
commit
03a66751ea
5 changed files with 27 additions and 27 deletions
|
|
@ -535,14 +535,14 @@ where
|
|||
// popup pipeline. Drained before the creation queue so a
|
||||
// destroy-then-recreate (a second right-click reusing the same id)
|
||||
// keeps its order.
|
||||
#[cfg(all(feature = "wayland", target_os = "linux"))]
|
||||
#[cfg(all(wayland_platform, target_os = "linux"))]
|
||||
for id in crate::widget::text_context_menu::take_popup_destroys() {
|
||||
task = task.chain(iced_winit::commands::popup::destroy_popup(id));
|
||||
}
|
||||
|
||||
// Drain any text context-menu popup requests queued by widgets during
|
||||
// `app.update()` and create them through the normal popup pipeline.
|
||||
#[cfg(all(feature = "wayland", target_os = "linux"))]
|
||||
#[cfg(all(wayland_platform, target_os = "linux"))]
|
||||
for req in crate::widget::text_context_menu::take_popup_requests() {
|
||||
let (settings, view) =
|
||||
crate::widget::text_context_menu::into_popup_view::<T::Message>(req);
|
||||
|
|
@ -723,7 +723,7 @@ where
|
|||
// Drives the text context-menu popup queues: a right-click queues a
|
||||
// popup but publishes no message, so this re-emits `Action::None` to
|
||||
// make `update()` run and drain the queue.
|
||||
#[cfg(all(feature = "wayland", target_os = "linux"))]
|
||||
#[cfg(all(wayland_platform, target_os = "linux"))]
|
||||
subscriptions.push(crate::widget::text_context_menu::wake_subscription::<
|
||||
T::Message,
|
||||
>());
|
||||
|
|
@ -743,7 +743,7 @@ where
|
|||
|
||||
#[cfg(feature = "multi-window")]
|
||||
pub fn view(&self, id: window::Id) -> Element<'_, crate::Action<T::Message>> {
|
||||
#[cfg(all(feature = "wayland", target_os = "linux"))]
|
||||
#[cfg(all(wayland_platform, target_os = "linux"))]
|
||||
if let Some((_, _, _, Some(v))) = self.surface_views.get(&id) {
|
||||
return v(&self.app);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ impl<'a> SelectableText<'a> {
|
|||
}
|
||||
|
||||
fn uses_popup_context_menu(&self) -> bool {
|
||||
#[cfg(all(feature = "wayland", feature = "winit"))]
|
||||
#[cfg(all(wayland_platform, feature = "winit"))]
|
||||
if matches!(
|
||||
crate::app::cosmic::WINDOWING_SYSTEM.get(),
|
||||
Some(crate::app::cosmic::WindowingSystem::Wayland)
|
||||
|
|
@ -329,7 +329,7 @@ impl<'a, Message: Clone + 'static> Widget<Message, crate::Theme, Renderer> for S
|
|||
viewport,
|
||||
);
|
||||
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
if self.uses_popup_context_menu() {
|
||||
use iced_core::widget::text::HasSelectableText;
|
||||
|
||||
|
|
|
|||
|
|
@ -51,13 +51,13 @@ thread_local! {
|
|||
static CURRENT_WINDOW_ID: Cell<iced_core::window::Id> = const { Cell::new(iced_core::window::Id::NONE) };
|
||||
}
|
||||
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
use iced_runtime::platform_specific::wayland::popup::SctkPopupSettings;
|
||||
|
||||
/// A request to create a text context-menu popup surface, queued by a widget
|
||||
/// during `update()` and drained by `Cosmic::update()` so the popup goes
|
||||
/// through the normal `get_popup()` Task + `surface_views` pipeline.
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
pub(crate) struct PopupRequest {
|
||||
settings: SctkPopupSettings,
|
||||
menu: Menu<'static, TextCtxAction>,
|
||||
|
|
@ -65,7 +65,7 @@ pub(crate) struct PopupRequest {
|
|||
pending_action: PendingAction,
|
||||
}
|
||||
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
thread_local! {
|
||||
static PENDING_POPUP_REQUESTS: std::cell::RefCell<Vec<PopupRequest>> =
|
||||
const { std::cell::RefCell::new(Vec::new()) };
|
||||
|
|
@ -80,7 +80,7 @@ pub(crate) fn current_window_id() -> iced_core::window::Id {
|
|||
}
|
||||
|
||||
/// Drains all popup requests queued by widgets this frame.
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
pub(crate) fn take_popup_requests() -> Vec<PopupRequest> {
|
||||
PENDING_POPUP_REQUESTS.with(|q| std::mem::take(&mut *q.borrow_mut()))
|
||||
}
|
||||
|
|
@ -88,7 +88,7 @@ pub(crate) fn take_popup_requests() -> Vec<PopupRequest> {
|
|||
/// Consumes a [`PopupRequest`], returning the popup settings plus a view
|
||||
/// builder. The builder rebuilds the menu element each frame from the
|
||||
/// captured content, independent of app state.
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub(crate) fn into_popup_view<Message: Clone + 'static>(
|
||||
req: PopupRequest,
|
||||
|
|
@ -117,7 +117,7 @@ pub(crate) fn into_popup_view<Message: Clone + 'static>(
|
|||
(settings, view)
|
||||
}
|
||||
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
thread_local! {
|
||||
static PENDING_POPUP_DESTROYS: std::cell::RefCell<Vec<iced_core::window::Id>> =
|
||||
const { std::cell::RefCell::new(Vec::new()) };
|
||||
|
|
@ -129,22 +129,22 @@ thread_local! {
|
|||
/// inside `update()` can't reach `Cosmic` to issue a Task, so they push the
|
||||
/// id here and `Cosmic::update()` drains it into a `destroy_popup` Task that
|
||||
/// flows through the normal surface pipeline.
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
fn queue_destroy_popup(id: iced_core::window::Id) {
|
||||
PENDING_POPUP_DESTROYS.with(|q| q.borrow_mut().push(id));
|
||||
wake_runtime();
|
||||
}
|
||||
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
static WAKE_TX: std::sync::OnceLock<iced_futures::futures::channel::mpsc::Sender<()>> =
|
||||
std::sync::OnceLock::new();
|
||||
|
||||
/// Stable identity for [`wake_subscription`].
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
struct PopupWake;
|
||||
|
||||
/// Nudges the runtime so `Cosmic::update()` runs and drains the popup queues.
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
fn wake_runtime() {
|
||||
if let Some(tx) = WAKE_TX.get() {
|
||||
let _ = tx.clone().try_send(());
|
||||
|
|
@ -155,7 +155,7 @@ fn wake_runtime() {
|
|||
/// wake channel and re-emits each ping as [`crate::Action::None`]. Add it to
|
||||
/// the app's subscriptions (done by `Cosmic::subscription`) so popup creation
|
||||
/// and teardown queued from widget `update()` get drained promptly.
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
pub(crate) fn wake_subscription<Message: Send + 'static>()
|
||||
-> iced_futures::Subscription<crate::Action<Message>> {
|
||||
use iced_futures::futures::{SinkExt, StreamExt};
|
||||
|
|
@ -466,7 +466,7 @@ where
|
|||
/// Pushes a [`PopupRequest`] onto the request queue; `Cosmic::update()`
|
||||
/// drains it and creates the popup through `get_popup()`, so it flows
|
||||
/// through the normal Task + `surface_views` pipeline.
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
pub(crate) fn create_text_context_popup(
|
||||
click_position: Point,
|
||||
selected_text: Option<String>,
|
||||
|
|
@ -602,7 +602,7 @@ pub(crate) fn create_text_context_popup(
|
|||
|
||||
/// Dismisses this widget's open context-menu popup on an outside click,
|
||||
/// touch, or Escape.
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
pub(crate) fn dismiss_popup_on_event(menu_bar_state: &MenuBarState, event: &event::Event) {
|
||||
let is_dismiss = matches!(
|
||||
event,
|
||||
|
|
@ -710,7 +710,7 @@ impl<Message: Clone + 'static> iced_core::widget::Widget<Message, crate::Theme,
|
|||
shell: &mut Shell<'_, Message>,
|
||||
viewport: &Rectangle,
|
||||
) {
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
{
|
||||
use iced_core::event::wayland::PopupEvent;
|
||||
let popup_event = match event {
|
||||
|
|
@ -736,7 +736,7 @@ impl<Message: Clone + 'static> iced_core::widget::Widget<Message, crate::Theme,
|
|||
|
||||
// Escape dismisses the popup. Under the grab, keyboard input is
|
||||
// delivered to the popup surface, so handle it here.
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
if matches!(
|
||||
event,
|
||||
event::Event::Keyboard(iced_core::keyboard::Event::KeyPressed {
|
||||
|
|
@ -812,7 +812,7 @@ impl<Message: Clone + 'static> iced_core::widget::Widget<Message, crate::Theme,
|
|||
// popup must tear itself down once its menu has closed — whether an
|
||||
// item was chosen (`click_inside`) or the user clicked away
|
||||
// (`click_outside`).
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
{
|
||||
let menu_closed = self.menu.tree.inner.with_data(|state| !state.open);
|
||||
if menu_closed {
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ impl<'a, Message: Clone + 'static> TextEditor<'a, Message> {
|
|||
}
|
||||
|
||||
fn uses_popup_context_menu(&self) -> bool {
|
||||
#[cfg(all(feature = "wayland", feature = "winit"))]
|
||||
#[cfg(all(wayland_platform, feature = "winit"))]
|
||||
if matches!(
|
||||
crate::app::cosmic::WINDOWING_SYSTEM.get(),
|
||||
Some(crate::app::cosmic::WindowingSystem::Wayland)
|
||||
|
|
@ -275,7 +275,7 @@ impl<'a, Message: Clone + 'static> Widget<Message, crate::Theme, crate::Renderer
|
|||
crate::widget::text_input::notify_focus_change();
|
||||
}
|
||||
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
if self.uses_popup_context_menu() {
|
||||
if self
|
||||
.inner
|
||||
|
|
|
|||
|
|
@ -585,7 +585,7 @@ where
|
|||
}
|
||||
|
||||
fn uses_popup_context_menu(&self) -> bool {
|
||||
#[cfg(all(feature = "wayland", feature = "winit"))]
|
||||
#[cfg(all(wayland_platform, feature = "winit"))]
|
||||
if matches!(
|
||||
crate::app::cosmic::WINDOWING_SYSTEM.get(),
|
||||
Some(crate::app::cosmic::WindowingSystem::Wayland)
|
||||
|
|
@ -919,7 +919,7 @@ where
|
|||
shell: &mut Shell<'_, Message>,
|
||||
viewport: &Rectangle,
|
||||
) {
|
||||
#[cfg(all(feature = "wayland", feature = "winit"))]
|
||||
#[cfg(all(wayland_platform, feature = "winit"))]
|
||||
if self.uses_popup_context_menu() {
|
||||
let menu_bar_state = tree.state.downcast_ref::<State>().menu_bar_state.clone();
|
||||
crate::widget::text_context_menu::dismiss_popup_on_event(&menu_bar_state, event);
|
||||
|
|
@ -1036,7 +1036,7 @@ where
|
|||
);
|
||||
|
||||
// On Wayland: if right-click just set context_menu_position, create a popup instead.
|
||||
#[cfg(all(feature = "wayland", feature = "winit"))]
|
||||
#[cfg(all(wayland_platform, feature = "winit"))]
|
||||
if matches!(
|
||||
crate::app::cosmic::WINDOWING_SYSTEM.get(),
|
||||
Some(crate::app::cosmic::WindowingSystem::Wayland)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue