From 2a5f48bb13a6d238ac592a39d2b822bd25c757fe Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Wed, 23 Oct 2024 11:14:38 -0400 Subject: [PATCH] feat: feature gates --- Cargo.toml | 12 +--- cosmic-settings/Cargo.toml | 6 +- cosmic-settings/src/app.rs | 68 ++++++++++++------- cosmic-settings/src/main.rs | 12 +++- cosmic-settings/src/pages/desktop/mod.rs | 18 +++-- cosmic-settings/src/pages/mod.rs | 9 ++- .../src/pages/networking/vpn/mod.rs | 2 +- .../src/pages/power/backend/mod.rs | 2 +- 8 files changed, 84 insertions(+), 45 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 87e4230..b53bc00 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,17 +11,7 @@ cosmic-randr = { git = "https://github.com/pop-os/cosmic-randr" } tokio = { version = "1.40.0", features = ["macros"] } [workspace.dependencies.libcosmic] -features = [ - "a11y", - "dbus-config", - "single-instance", - "multi-window", - "winit", - "tokio", - "wayland", - "wgpu", - "xdg-portal", -] +features = ["multi-window", "winit", "tokio", "xdg-portal"] git = "https://github.com/pop-os/libcosmic" [workspace.dependencies.cosmic-config] diff --git a/cosmic-settings/Cargo.toml b/cosmic-settings/Cargo.toml index 3af60d5..8d33ee3 100644 --- a/cosmic-settings/Cargo.toml +++ b/cosmic-settings/Cargo.toml @@ -76,6 +76,10 @@ version = "0.15.0" features = ["fluent-system", "desktop-requester"] [features] -default = [] +default = ["wayland", "dbus-config", "single-instance", "a11y", "wgpu"] +wayland = ["libcosmic/wayland"] +dbus-config = ["libcosmic/dbus-config"] +single-instance = ["libcosmic/single-instance"] +a11y = ["libcosmic/a11y"] wgpu = ["libcosmic/wgpu"] test = [] diff --git a/cosmic-settings/src/app.rs b/cosmic-settings/src/app.rs index a04aeec..2b1c537 100644 --- a/cosmic-settings/src/app.rs +++ b/cosmic-settings/src/app.rs @@ -2,19 +2,17 @@ // SPDX-License-Identifier: GPL-3.0-only use crate::config::Config; -use crate::pages::desktop::{ - self, appearance, dock, - panel::{self, applets_inner, inner as _panel}, -}; +use crate::pages::desktop::{self, appearance}; use crate::pages::input::{self}; use crate::pages::{self, bluetooth, display, networking, power, sound, system, time}; use crate::subscription::desktop_files; use crate::widget::{page_title, search_header}; use crate::PageCommands; use cosmic::app::command::set_theme; +#[cfg(feature = "single-instance")] use cosmic::app::DbusActivationMessage; -use cosmic::cctk::sctk::output::OutputInfo; -use cosmic::cctk::wayland_client::protocol::wl_output::WlOutput; +#[cfg(feature = "wayland")] +use cosmic::cctk::{sctk::output::OutputInfo, wayland_client::protocol::wl_output::WlOutput}; use cosmic::iced::futures::SinkExt; use cosmic::iced::{stream, Subscription}; use cosmic::widget::{self, button, row, text_input}; @@ -22,7 +20,7 @@ use cosmic::{ app::{Core, Task}, iced::{ self, - event::{self, wayland, PlatformSpecific}, + event::{self, PlatformSpecific}, window, Length, }, prelude::*, @@ -33,6 +31,13 @@ use cosmic::{ }; use cosmic_panel_config::CosmicPanelConfig; use cosmic_settings_page::{self as page, section}; +#[cfg(feature = "wayland")] +use desktop::{ + dock, + panel::{self, applets_inner, inner as _panel}, +}; +#[cfg(feature = "wayland")] +use event::wayland; use page::Entity; use std::{borrow::Cow, str::FromStr}; @@ -60,12 +65,14 @@ impl SettingsApp { PageCommands::DateTime => self.pages.page_id::(), PageCommands::Desktop => self.pages.page_id::(), PageCommands::Displays => self.pages.page_id::(), + #[cfg(feature = "wayland")] PageCommands::Dock => self.pages.page_id::(), PageCommands::Firmware => self.pages.page_id::(), PageCommands::Input => self.pages.page_id::(), PageCommands::Keyboard => self.pages.page_id::(), PageCommands::Mouse => self.pages.page_id::(), PageCommands::Network => self.pages.page_id::(), + #[cfg(feature = "wayland")] PageCommands::Panel => self.pages.page_id::(), PageCommands::Power => self.pages.page_id::(), PageCommands::RegionLanguage => self.pages.page_id::(), @@ -95,14 +102,18 @@ impl SettingsApp { pub enum Message { CloseContextDrawer, DelayedInit(page::Entity), + #[cfg(feature = "wayland")] DesktopInfo, Error(String), None, OpenContextDrawer(Cow<'static, str>), + #[cfg(feature = "wayland")] OutputAdded(OutputInfo, WlOutput), + #[cfg(feature = "wayland")] OutputRemoved(WlOutput), Page(page::Entity), PageMessage(crate::pages::Message), + #[cfg(feature = "wayland")] PanelConfig(CosmicPanelConfig), RegisterSubscriptionSender(tokio::sync::mpsc::Sender), SearchActivate, @@ -216,18 +227,6 @@ impl cosmic::Application for SettingsApp { } fn subscription(&self) -> Subscription { - // Handling of Wayland-specific events received. - let wayland_events = - event::listen_with(|event, _, _id| match event { - iced::Event::PlatformSpecific(PlatformSpecific::Wayland( - wayland::Event::Output(wayland::OutputEvent::Created(Some(info)), o), - )) if info.name.is_some() => Some(Message::OutputAdded(info, o)), - iced::Event::PlatformSpecific(PlatformSpecific::Wayland( - wayland::Event::Output(wayland::OutputEvent::Removed, o), - )) => Some(Message::OutputRemoved(o)), - _ => None, - }); - Subscription::batch(vec![ // Creates a channel that listens to messages from pages. // The sender is given back to the application so that it may pass it on. @@ -242,7 +241,7 @@ impl cosmic::Application for SettingsApp { let _res = output.send(Message::PageMessage(event)).await; } - futures::future::pending().await + futures::future::pending::<()>().await; }), ), crate::subscription::daytime().map(|daytime| { @@ -250,10 +249,23 @@ impl cosmic::Application for SettingsApp { daytime, ))) }), - wayland_events, + #[cfg(feature = "wayland")] + event::listen_with(|event, _, _id| match event { + #[cfg(feature = "wayland")] + iced::Event::PlatformSpecific(PlatformSpecific::Wayland( + wayland::Event::Output(wayland::OutputEvent::Created(Some(info)), o), + )) if info.name.is_some() => Some(Message::OutputAdded(info, o)), + #[cfg(feature = "wayland")] + iced::Event::PlatformSpecific(PlatformSpecific::Wayland( + wayland::Event::Output(wayland::OutputEvent::Removed, o), + )) => Some(Message::OutputRemoved(o)), + _ => None, + }), + #[cfg(feature = "wayland")] // Watch for changes to installed desktop entries desktop_files(0).map(|_| Message::DesktopInfo), // Watch for configuration changes to the panel. + #[cfg(feature = "wayland")] self.core() .watch_config::("com.system76.CosmicPanel.Panel") .map(|update| { @@ -263,7 +275,7 @@ impl cosmic::Application for SettingsApp { Message::PanelConfig(update.config) }), - // Watch for configuration changes to the dock + #[cfg(feature = "wayland")] self.core() .watch_config::("com.system76.CosmicPanel.Dock") .map(|update| { @@ -353,12 +365,14 @@ impl cosmic::Application for SettingsApp { } } + #[cfg(feature = "wayland")] crate::pages::Message::Dock(message) => { if let Some(page) = self.pages.page_mut::() { return page.update(message).map(Into::into); } } + #[cfg(feature = "wayland")] crate::pages::Message::DockApplet(message) => { if let Some(page) = self.pages.page_mut::() { return page.update(message).map(Into::into); @@ -457,12 +471,14 @@ impl cosmic::Application for SettingsApp { } } + #[cfg(feature = "wayland")] crate::pages::Message::Panel(message) => { if let Some(page) = self.pages.page_mut::() { return page.update(message).map(Into::into); } } + #[cfg(feature = "wayland")] crate::pages::Message::PanelApplet(message) => { if let Some(page) = self.pages.page_mut::() { return page.update(message).map(Into::into); @@ -496,6 +512,7 @@ impl cosmic::Application for SettingsApp { } }, + #[cfg(feature = "wayland")] Message::OutputAdded(info, output) => { let mut commands = vec![]; if let Some(page) = self.pages.page_mut::() { @@ -520,6 +537,7 @@ impl cosmic::Application for SettingsApp { return Task::batch(commands); } + #[cfg(feature = "wayland")] Message::OutputRemoved(output) => { let mut commands = vec![]; if let Some(page) = self.pages.page_mut::() { @@ -540,6 +558,7 @@ impl cosmic::Application for SettingsApp { return Task::batch(commands); } + #[cfg(feature = "wayland")] Message::PanelConfig(config) if config.name.to_lowercase().contains("panel") => { let mut tasks = Vec::new(); @@ -560,6 +579,7 @@ impl cosmic::Application for SettingsApp { return Task::batch(tasks); } + #[cfg(feature = "wayland")] Message::PanelConfig(config) if config.name.to_lowercase().contains("dock") => { let mut tasks = Vec::new(); @@ -584,8 +604,9 @@ impl cosmic::Application for SettingsApp { return Task::batch(tasks); } + #[cfg(feature = "wayland")] Message::PanelConfig(_) => {} - + #[cfg(feature = "wayland")] Message::DesktopInfo => { let info_list: Vec<_> = freedesktop_desktop_entry::Iter::new( freedesktop_desktop_entry::default_paths(), @@ -637,6 +658,7 @@ impl cosmic::Application for SettingsApp { Task::none() } + #[cfg(feature = "single-instance")] fn dbus_activation(&mut self, msg: DbusActivationMessage) -> Task { match msg.msg { cosmic::app::DbusActivationDetails::Activate diff --git a/cosmic-settings/src/main.rs b/cosmic-settings/src/main.rs index 19a5e66..8914f80 100644 --- a/cosmic-settings/src/main.rs +++ b/cosmic-settings/src/main.rs @@ -50,6 +50,7 @@ pub enum PageCommands { Desktop, /// Displays settings page Displays, + #[cfg(feature = "wayland")] /// Dock settings page Dock, /// Firmware settings page @@ -62,6 +63,7 @@ pub enum PageCommands { Mouse, /// Network settings page Network, + #[cfg(feature = "wayland")] /// Panel settings page Panel, /// Power settings page @@ -133,8 +135,14 @@ pub fn main() -> color_eyre::Result<()> { let settings = cosmic::app::Settings::default() .size_limits(Limits::NONE.min_width(360.0).min_height(300.0)); - cosmic::app::run_single_instance::(settings, args)?; - + #[cfg(feature = "single-instance")] + { + cosmic::app::run_single_instance::(settings, args)?; + } + #[cfg(not(feature = "single-instance"))] + { + cosmic::app::run::(settings, args)?; + } Ok(()) } diff --git a/cosmic-settings/src/pages/desktop/mod.rs b/cosmic-settings/src/pages/desktop/mod.rs index 6374bec..070afa6 100644 --- a/cosmic-settings/src/pages/desktop/mod.rs +++ b/cosmic-settings/src/pages/desktop/mod.rs @@ -2,7 +2,9 @@ // SPDX-License-Identifier: GPL-3.0-only pub mod appearance; +#[cfg(feature = "wayland")] pub mod dock; +#[cfg(feature = "wayland")] pub mod panel; pub mod wallpaper; pub mod window_management; @@ -23,11 +25,17 @@ impl page::Page for Page { impl page::AutoBind for Page { fn sub_pages(page: page::Insert) -> page::Insert { - page.sub_page::() - .sub_page::() - .sub_page::() - .sub_page::() - .sub_page::() + let mut page = page + .sub_page::() + .sub_page::(); + + #[cfg(feature = "wayland")] + { + page = page.sub_page::(); + page = page.sub_page::(); + } + + page.sub_page::() .sub_page::() } } diff --git a/cosmic-settings/src/pages/mod.rs b/cosmic-settings/src/pages/mod.rs index 0c07def..dc2b2b5 100644 --- a/cosmic-settings/src/pages/mod.rs +++ b/cosmic-settings/src/pages/mod.rs @@ -24,9 +24,14 @@ pub enum Message { DesktopWallpaper(desktop::wallpaper::Message), DesktopWorkspaces(desktop::workspaces::Message), Displays(display::Message), + #[cfg(feature = "wayland")] Dock(desktop::dock::Message), + #[cfg(feature = "wayland")] DockApplet(desktop::dock::applets::Message), - External { id: String, message: Vec }, + External { + id: String, + message: Vec, + }, Input(input::Message), Keyboard(input::keyboard::Message), KeyboardShortcuts(input::keyboard::shortcuts::Message), @@ -35,7 +40,9 @@ pub enum Message { NavShortcuts(input::keyboard::shortcuts::ShortcutMessage), Networking(networking::Message), Page(Entity), + #[cfg(feature = "wayland")] Panel(desktop::panel::Message), + #[cfg(feature = "wayland")] PanelApplet(desktop::panel::applets_inner::Message), Power(power::Message), Sound(sound::Message), diff --git a/cosmic-settings/src/pages/networking/vpn/mod.rs b/cosmic-settings/src/pages/networking/vpn/mod.rs index 415e67b..3ae5dcc 100644 --- a/cosmic-settings/src/pages/networking/vpn/mod.rs +++ b/cosmic-settings/src/pages/networking/vpn/mod.rs @@ -220,7 +220,7 @@ impl page::Page for Page { fn dialog(&self) -> Option> { self.dialog.as_ref().map(|dialog| match dialog { VpnDialog::Error(error_kind, message) => { - let reason = widget::text::body(message.as_str()).wrap(Wrap::Word); + let reason = widget::text::body(message.as_str()).wrapping(Wrapping::Word); let primary_action = widget::button::standard(fl!("ok")).on_press(Message::CancelDialog); diff --git a/cosmic-settings/src/pages/power/backend/mod.rs b/cosmic-settings/src/pages/power/backend/mod.rs index 6badc34..b6d60d7 100644 --- a/cosmic-settings/src/pages/power/backend/mod.rs +++ b/cosmic-settings/src/pages/power/backend/mod.rs @@ -1,6 +1,6 @@ use chrono::{Duration, TimeDelta}; -use futures::FutureExt; use futures::future::join_all; +use futures::FutureExt; use upower_dbus::{BatteryState, BatteryType, DeviceProxy}; use zbus::Connection;