feat: feature gates

This commit is contained in:
Ashley Wulber 2024-10-23 11:14:38 -04:00 committed by Ashley Wulber
parent 3cadfec2fb
commit 2a5f48bb13
8 changed files with 84 additions and 45 deletions

View file

@ -11,17 +11,7 @@ cosmic-randr = { git = "https://github.com/pop-os/cosmic-randr" }
tokio = { version = "1.40.0", features = ["macros"] } tokio = { version = "1.40.0", features = ["macros"] }
[workspace.dependencies.libcosmic] [workspace.dependencies.libcosmic]
features = [ features = ["multi-window", "winit", "tokio", "xdg-portal"]
"a11y",
"dbus-config",
"single-instance",
"multi-window",
"winit",
"tokio",
"wayland",
"wgpu",
"xdg-portal",
]
git = "https://github.com/pop-os/libcosmic" git = "https://github.com/pop-os/libcosmic"
[workspace.dependencies.cosmic-config] [workspace.dependencies.cosmic-config]

View file

@ -76,6 +76,10 @@ version = "0.15.0"
features = ["fluent-system", "desktop-requester"] features = ["fluent-system", "desktop-requester"]
[features] [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"] wgpu = ["libcosmic/wgpu"]
test = [] test = []

View file

@ -2,19 +2,17 @@
// SPDX-License-Identifier: GPL-3.0-only // SPDX-License-Identifier: GPL-3.0-only
use crate::config::Config; use crate::config::Config;
use crate::pages::desktop::{ use crate::pages::desktop::{self, appearance};
self, appearance, dock,
panel::{self, applets_inner, inner as _panel},
};
use crate::pages::input::{self}; use crate::pages::input::{self};
use crate::pages::{self, bluetooth, display, networking, power, sound, system, time}; use crate::pages::{self, bluetooth, display, networking, power, sound, system, time};
use crate::subscription::desktop_files; use crate::subscription::desktop_files;
use crate::widget::{page_title, search_header}; use crate::widget::{page_title, search_header};
use crate::PageCommands; use crate::PageCommands;
use cosmic::app::command::set_theme; use cosmic::app::command::set_theme;
#[cfg(feature = "single-instance")]
use cosmic::app::DbusActivationMessage; use cosmic::app::DbusActivationMessage;
use cosmic::cctk::sctk::output::OutputInfo; #[cfg(feature = "wayland")]
use cosmic::cctk::wayland_client::protocol::wl_output::WlOutput; use cosmic::cctk::{sctk::output::OutputInfo, wayland_client::protocol::wl_output::WlOutput};
use cosmic::iced::futures::SinkExt; use cosmic::iced::futures::SinkExt;
use cosmic::iced::{stream, Subscription}; use cosmic::iced::{stream, Subscription};
use cosmic::widget::{self, button, row, text_input}; use cosmic::widget::{self, button, row, text_input};
@ -22,7 +20,7 @@ use cosmic::{
app::{Core, Task}, app::{Core, Task},
iced::{ iced::{
self, self,
event::{self, wayland, PlatformSpecific}, event::{self, PlatformSpecific},
window, Length, window, Length,
}, },
prelude::*, prelude::*,
@ -33,6 +31,13 @@ use cosmic::{
}; };
use cosmic_panel_config::CosmicPanelConfig; use cosmic_panel_config::CosmicPanelConfig;
use cosmic_settings_page::{self as page, section}; 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 page::Entity;
use std::{borrow::Cow, str::FromStr}; use std::{borrow::Cow, str::FromStr};
@ -60,12 +65,14 @@ impl SettingsApp {
PageCommands::DateTime => self.pages.page_id::<time::date::Page>(), PageCommands::DateTime => self.pages.page_id::<time::date::Page>(),
PageCommands::Desktop => self.pages.page_id::<desktop::Page>(), PageCommands::Desktop => self.pages.page_id::<desktop::Page>(),
PageCommands::Displays => self.pages.page_id::<display::Page>(), PageCommands::Displays => self.pages.page_id::<display::Page>(),
#[cfg(feature = "wayland")]
PageCommands::Dock => self.pages.page_id::<desktop::dock::Page>(), PageCommands::Dock => self.pages.page_id::<desktop::dock::Page>(),
PageCommands::Firmware => self.pages.page_id::<system::firmware::Page>(), PageCommands::Firmware => self.pages.page_id::<system::firmware::Page>(),
PageCommands::Input => self.pages.page_id::<input::Page>(), PageCommands::Input => self.pages.page_id::<input::Page>(),
PageCommands::Keyboard => self.pages.page_id::<input::keyboard::Page>(), PageCommands::Keyboard => self.pages.page_id::<input::keyboard::Page>(),
PageCommands::Mouse => self.pages.page_id::<input::mouse::Page>(), PageCommands::Mouse => self.pages.page_id::<input::mouse::Page>(),
PageCommands::Network => self.pages.page_id::<networking::Page>(), PageCommands::Network => self.pages.page_id::<networking::Page>(),
#[cfg(feature = "wayland")]
PageCommands::Panel => self.pages.page_id::<desktop::panel::Page>(), PageCommands::Panel => self.pages.page_id::<desktop::panel::Page>(),
PageCommands::Power => self.pages.page_id::<power::Page>(), PageCommands::Power => self.pages.page_id::<power::Page>(),
PageCommands::RegionLanguage => self.pages.page_id::<time::region::Page>(), PageCommands::RegionLanguage => self.pages.page_id::<time::region::Page>(),
@ -95,14 +102,18 @@ impl SettingsApp {
pub enum Message { pub enum Message {
CloseContextDrawer, CloseContextDrawer,
DelayedInit(page::Entity), DelayedInit(page::Entity),
#[cfg(feature = "wayland")]
DesktopInfo, DesktopInfo,
Error(String), Error(String),
None, None,
OpenContextDrawer(Cow<'static, str>), OpenContextDrawer(Cow<'static, str>),
#[cfg(feature = "wayland")]
OutputAdded(OutputInfo, WlOutput), OutputAdded(OutputInfo, WlOutput),
#[cfg(feature = "wayland")]
OutputRemoved(WlOutput), OutputRemoved(WlOutput),
Page(page::Entity), Page(page::Entity),
PageMessage(crate::pages::Message), PageMessage(crate::pages::Message),
#[cfg(feature = "wayland")]
PanelConfig(CosmicPanelConfig), PanelConfig(CosmicPanelConfig),
RegisterSubscriptionSender(tokio::sync::mpsc::Sender<pages::Message>), RegisterSubscriptionSender(tokio::sync::mpsc::Sender<pages::Message>),
SearchActivate, SearchActivate,
@ -216,18 +227,6 @@ impl cosmic::Application for SettingsApp {
} }
fn subscription(&self) -> Subscription<Message> { fn subscription(&self) -> Subscription<Message> {
// 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![ Subscription::batch(vec![
// Creates a channel that listens to messages from pages. // Creates a channel that listens to messages from pages.
// The sender is given back to the application so that it may pass it on. // 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; let _res = output.send(Message::PageMessage(event)).await;
} }
futures::future::pending().await futures::future::pending::<()>().await;
}), }),
), ),
crate::subscription::daytime().map(|daytime| { crate::subscription::daytime().map(|daytime| {
@ -250,10 +249,23 @@ impl cosmic::Application for SettingsApp {
daytime, 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 // Watch for changes to installed desktop entries
desktop_files(0).map(|_| Message::DesktopInfo), desktop_files(0).map(|_| Message::DesktopInfo),
// Watch for configuration changes to the panel. // Watch for configuration changes to the panel.
#[cfg(feature = "wayland")]
self.core() self.core()
.watch_config::<CosmicPanelConfig>("com.system76.CosmicPanel.Panel") .watch_config::<CosmicPanelConfig>("com.system76.CosmicPanel.Panel")
.map(|update| { .map(|update| {
@ -263,7 +275,7 @@ impl cosmic::Application for SettingsApp {
Message::PanelConfig(update.config) Message::PanelConfig(update.config)
}), }),
// Watch for configuration changes to the dock #[cfg(feature = "wayland")]
self.core() self.core()
.watch_config::<CosmicPanelConfig>("com.system76.CosmicPanel.Dock") .watch_config::<CosmicPanelConfig>("com.system76.CosmicPanel.Dock")
.map(|update| { .map(|update| {
@ -353,12 +365,14 @@ impl cosmic::Application for SettingsApp {
} }
} }
#[cfg(feature = "wayland")]
crate::pages::Message::Dock(message) => { crate::pages::Message::Dock(message) => {
if let Some(page) = self.pages.page_mut::<dock::Page>() { if let Some(page) = self.pages.page_mut::<dock::Page>() {
return page.update(message).map(Into::into); return page.update(message).map(Into::into);
} }
} }
#[cfg(feature = "wayland")]
crate::pages::Message::DockApplet(message) => { crate::pages::Message::DockApplet(message) => {
if let Some(page) = self.pages.page_mut::<dock::applets::Page>() { if let Some(page) = self.pages.page_mut::<dock::applets::Page>() {
return page.update(message).map(Into::into); return page.update(message).map(Into::into);
@ -457,12 +471,14 @@ impl cosmic::Application for SettingsApp {
} }
} }
#[cfg(feature = "wayland")]
crate::pages::Message::Panel(message) => { crate::pages::Message::Panel(message) => {
if let Some(page) = self.pages.page_mut::<panel::Page>() { if let Some(page) = self.pages.page_mut::<panel::Page>() {
return page.update(message).map(Into::into); return page.update(message).map(Into::into);
} }
} }
#[cfg(feature = "wayland")]
crate::pages::Message::PanelApplet(message) => { crate::pages::Message::PanelApplet(message) => {
if let Some(page) = self.pages.page_mut::<applets_inner::Page>() { if let Some(page) = self.pages.page_mut::<applets_inner::Page>() {
return page.update(message).map(Into::into); return page.update(message).map(Into::into);
@ -496,6 +512,7 @@ impl cosmic::Application for SettingsApp {
} }
}, },
#[cfg(feature = "wayland")]
Message::OutputAdded(info, output) => { Message::OutputAdded(info, output) => {
let mut commands = vec![]; let mut commands = vec![];
if let Some(page) = self.pages.page_mut::<panel::Page>() { if let Some(page) = self.pages.page_mut::<panel::Page>() {
@ -520,6 +537,7 @@ impl cosmic::Application for SettingsApp {
return Task::batch(commands); return Task::batch(commands);
} }
#[cfg(feature = "wayland")]
Message::OutputRemoved(output) => { Message::OutputRemoved(output) => {
let mut commands = vec![]; let mut commands = vec![];
if let Some(page) = self.pages.page_mut::<panel::Page>() { if let Some(page) = self.pages.page_mut::<panel::Page>() {
@ -540,6 +558,7 @@ impl cosmic::Application for SettingsApp {
return Task::batch(commands); return Task::batch(commands);
} }
#[cfg(feature = "wayland")]
Message::PanelConfig(config) if config.name.to_lowercase().contains("panel") => { Message::PanelConfig(config) if config.name.to_lowercase().contains("panel") => {
let mut tasks = Vec::new(); let mut tasks = Vec::new();
@ -560,6 +579,7 @@ impl cosmic::Application for SettingsApp {
return Task::batch(tasks); return Task::batch(tasks);
} }
#[cfg(feature = "wayland")]
Message::PanelConfig(config) if config.name.to_lowercase().contains("dock") => { Message::PanelConfig(config) if config.name.to_lowercase().contains("dock") => {
let mut tasks = Vec::new(); let mut tasks = Vec::new();
@ -584,8 +604,9 @@ impl cosmic::Application for SettingsApp {
return Task::batch(tasks); return Task::batch(tasks);
} }
#[cfg(feature = "wayland")]
Message::PanelConfig(_) => {} Message::PanelConfig(_) => {}
#[cfg(feature = "wayland")]
Message::DesktopInfo => { Message::DesktopInfo => {
let info_list: Vec<_> = freedesktop_desktop_entry::Iter::new( let info_list: Vec<_> = freedesktop_desktop_entry::Iter::new(
freedesktop_desktop_entry::default_paths(), freedesktop_desktop_entry::default_paths(),
@ -637,6 +658,7 @@ impl cosmic::Application for SettingsApp {
Task::none() Task::none()
} }
#[cfg(feature = "single-instance")]
fn dbus_activation(&mut self, msg: DbusActivationMessage) -> Task<Self::Message> { fn dbus_activation(&mut self, msg: DbusActivationMessage) -> Task<Self::Message> {
match msg.msg { match msg.msg {
cosmic::app::DbusActivationDetails::Activate cosmic::app::DbusActivationDetails::Activate

View file

@ -50,6 +50,7 @@ pub enum PageCommands {
Desktop, Desktop,
/// Displays settings page /// Displays settings page
Displays, Displays,
#[cfg(feature = "wayland")]
/// Dock settings page /// Dock settings page
Dock, Dock,
/// Firmware settings page /// Firmware settings page
@ -62,6 +63,7 @@ pub enum PageCommands {
Mouse, Mouse,
/// Network settings page /// Network settings page
Network, Network,
#[cfg(feature = "wayland")]
/// Panel settings page /// Panel settings page
Panel, Panel,
/// Power settings page /// Power settings page
@ -133,8 +135,14 @@ pub fn main() -> color_eyre::Result<()> {
let settings = cosmic::app::Settings::default() let settings = cosmic::app::Settings::default()
.size_limits(Limits::NONE.min_width(360.0).min_height(300.0)); .size_limits(Limits::NONE.min_width(360.0).min_height(300.0));
cosmic::app::run_single_instance::<app::SettingsApp>(settings, args)?; #[cfg(feature = "single-instance")]
{
cosmic::app::run_single_instance::<app::SettingsApp>(settings, args)?;
}
#[cfg(not(feature = "single-instance"))]
{
cosmic::app::run::<app::SettingsApp>(settings, args)?;
}
Ok(()) Ok(())
} }

View file

@ -2,7 +2,9 @@
// SPDX-License-Identifier: GPL-3.0-only // SPDX-License-Identifier: GPL-3.0-only
pub mod appearance; pub mod appearance;
#[cfg(feature = "wayland")]
pub mod dock; pub mod dock;
#[cfg(feature = "wayland")]
pub mod panel; pub mod panel;
pub mod wallpaper; pub mod wallpaper;
pub mod window_management; pub mod window_management;
@ -23,11 +25,17 @@ impl page::Page<crate::pages::Message> for Page {
impl page::AutoBind<crate::pages::Message> for Page { impl page::AutoBind<crate::pages::Message> for Page {
fn sub_pages(page: page::Insert<crate::pages::Message>) -> page::Insert<crate::pages::Message> { fn sub_pages(page: page::Insert<crate::pages::Message>) -> page::Insert<crate::pages::Message> {
page.sub_page::<wallpaper::Page>() let mut page = page
.sub_page::<appearance::Page>() .sub_page::<wallpaper::Page>()
.sub_page::<panel::Page>() .sub_page::<appearance::Page>();
.sub_page::<dock::Page>()
.sub_page::<window_management::Page>() #[cfg(feature = "wayland")]
{
page = page.sub_page::<panel::Page>();
page = page.sub_page::<dock::Page>();
}
page.sub_page::<window_management::Page>()
.sub_page::<workspaces::Page>() .sub_page::<workspaces::Page>()
} }
} }

View file

@ -24,9 +24,14 @@ pub enum Message {
DesktopWallpaper(desktop::wallpaper::Message), DesktopWallpaper(desktop::wallpaper::Message),
DesktopWorkspaces(desktop::workspaces::Message), DesktopWorkspaces(desktop::workspaces::Message),
Displays(display::Message), Displays(display::Message),
#[cfg(feature = "wayland")]
Dock(desktop::dock::Message), Dock(desktop::dock::Message),
#[cfg(feature = "wayland")]
DockApplet(desktop::dock::applets::Message), DockApplet(desktop::dock::applets::Message),
External { id: String, message: Vec<u8> }, External {
id: String,
message: Vec<u8>,
},
Input(input::Message), Input(input::Message),
Keyboard(input::keyboard::Message), Keyboard(input::keyboard::Message),
KeyboardShortcuts(input::keyboard::shortcuts::Message), KeyboardShortcuts(input::keyboard::shortcuts::Message),
@ -35,7 +40,9 @@ pub enum Message {
NavShortcuts(input::keyboard::shortcuts::ShortcutMessage), NavShortcuts(input::keyboard::shortcuts::ShortcutMessage),
Networking(networking::Message), Networking(networking::Message),
Page(Entity), Page(Entity),
#[cfg(feature = "wayland")]
Panel(desktop::panel::Message), Panel(desktop::panel::Message),
#[cfg(feature = "wayland")]
PanelApplet(desktop::panel::applets_inner::Message), PanelApplet(desktop::panel::applets_inner::Message),
Power(power::Message), Power(power::Message),
Sound(sound::Message), Sound(sound::Message),

View file

@ -220,7 +220,7 @@ impl page::Page<crate::pages::Message> for Page {
fn dialog(&self) -> Option<Element<crate::pages::Message>> { fn dialog(&self) -> Option<Element<crate::pages::Message>> {
self.dialog.as_ref().map(|dialog| match dialog { self.dialog.as_ref().map(|dialog| match dialog {
VpnDialog::Error(error_kind, message) => { 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 = let primary_action =
widget::button::standard(fl!("ok")).on_press(Message::CancelDialog); widget::button::standard(fl!("ok")).on_press(Message::CancelDialog);

View file

@ -1,6 +1,6 @@
use chrono::{Duration, TimeDelta}; use chrono::{Duration, TimeDelta};
use futures::FutureExt;
use futures::future::join_all; use futures::future::join_all;
use futures::FutureExt;
use upower_dbus::{BatteryState, BatteryType, DeviceProxy}; use upower_dbus::{BatteryState, BatteryType, DeviceProxy};
use zbus::Connection; use zbus::Connection;