forge
Explore
Log in

Don't you dare go Hollow

Make zbus optional under "dbus" feature

Browse files at this commit

082d734b2aa179b902837099b08244d8c2f16083Ivan MolodetskikhParent: 9d7fdc4
Cargo.tomlmodified+8 -6
@@ -8,8 +8,8 @@ edition = "2021"
8 8
9 [dependencies]9 [dependencies]
10 anyhow = { version = "1.0.75" }10 anyhow = { version = "1.0.75" }
11-async-channel = "1.9.0"11+async-channel = { version = "1.9.0", optional = true }
12-async-io = "1.13.0"12+async-io = { version = "1.13.0", optional = true }
13 bitflags = "2.4.0"13 bitflags = "2.4.0"
14 clap = { version = "4.4.6", features = ["derive"] }14 clap = { version = "4.4.6", features = ["derive"] }
15 directories = "5.0.1"15 directories = "5.0.1"
@@ -17,7 +17,7 @@ image = { version = "0.24.7", default-features = false, features = ["png"] }
17 keyframe = { version = "1.1.1", default-features = false }17 keyframe = { version = "1.1.1", default-features = false }
18 knuffel = "3.2.0"18 knuffel = "3.2.0"
19 libc = "0.2.149"19 libc = "0.2.149"
20-logind-zbus = "3.1.2"20+logind-zbus = { version = "3.1.2", optional = true }
21 log = { version = "0.4.20", features = ["max_level_trace", "release_max_level_debug"] }21 log = { version = "0.4.20", features = ["max_level_trace", "release_max_level_debug"] }
22 miette = "5.10.0"22 miette = "5.10.0"
23 nix = { version = "0.27.1", default-features = false, features = ["time"] }23 nix = { version = "0.27.1", default-features = false, features = ["time"] }
@@ -31,7 +31,7 @@ tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
31 tracing = { version = "0.1.37", features = ["max_level_trace", "release_max_level_debug"] }31 tracing = { version = "0.1.37", features = ["max_level_trace", "release_max_level_debug"] }
32 tracy-client = { version = "0.16.3", default-features = false }32 tracy-client = { version = "0.16.3", default-features = false }
33 xcursor = "0.3.4"33 xcursor = "0.3.4"
34-zbus = { version = "3.14.1" }34+zbus = { version = "3.14.1", optional = true }
35 35
36 [dependencies.smithay]36 [dependencies.smithay]
37 git = "https://github.com/Smithay/smithay.git"37 git = "https://github.com/Smithay/smithay.git"
@@ -62,9 +62,11 @@ proptest = "1.3.1"
62 proptest-derive = "0.4.0"62 proptest-derive = "0.4.0"
63 63
64 [features]64 [features]
65-default = ["xdp-gnome-screencast"]65+default = ["dbus", "xdp-gnome-screencast"]
66+# Enables DBus support (required for xdp-gnome and power button inhibiting).
67+dbus = ["zbus", "logind-zbus", "async-channel", "async-io"]
66 # Enables screencasting support through xdg-desktop-portal-gnome.68 # Enables screencasting support through xdg-desktop-portal-gnome.
67-xdp-gnome-screencast = ["pipewire"]69+xdp-gnome-screencast = ["dbus", "pipewire"]
68 # Enables the Tracy profiler instrumentation.70 # Enables the Tracy profiler instrumentation.
69 profile-with-tracy = ["profiling/profile-with-tracy", "tracy-client/default"]71 profile-with-tracy = ["profiling/profile-with-tracy", "tracy-client/default"]
70 72
src/backend/mod.rsmodified+1 -0
@@ -84,6 +84,7 @@ impl Backend {
84 }84 }
85 }85 }
86 86
87+ #[cfg_attr(not(feature = "dbus"), allow(unused))]
87 pub fn connectors(&self) -> Arc<Mutex<HashMap<String, Output>>> {88 pub fn connectors(&self) -> Arc<Mutex<HashMap<String, Output>>> {
88 match self {89 match self {
89 Backend::Tty(tty) => tty.connectors(),90 Backend::Tty(tty) => tty.connectors(),
src/backend/tty.rsmodified+2 -0
@@ -924,6 +924,7 @@ impl Tty {
924 }924 }
925 925
926 pub fn suspend(&self) {926 pub fn suspend(&self) {
927+ #[cfg(feature = "dbus")]
927 if let Err(err) = suspend() {928 if let Err(err) = suspend() {
928 warn!("error suspending: {err:?}");929 warn!("error suspending: {err:?}");
929 }930 }
@@ -1026,6 +1027,7 @@ fn refresh_interval(mode: DrmMode) -> Duration {
1026 Duration::from_nanos(refresh_interval)1027 Duration::from_nanos(refresh_interval)
1027 }1028 }
1028 1029
1030+#[cfg(feature = "dbus")]
1029 fn suspend() -> anyhow::Result<()> {1031 fn suspend() -> anyhow::Result<()> {
1030 let conn = zbus::blocking::Connection::system().context("error connecting to system bus")?;1032 let conn = zbus::blocking::Connection::system().context("error connecting to system bus")?;
1031 let manager = logind_zbus::manager::ManagerProxyBlocking::new(&conn)1033 let manager = logind_zbus::manager::ManagerProxyBlocking::new(&conn)
src/main.rsmodified+4 -3
@@ -5,6 +5,7 @@ mod animation;
5 mod backend;5 mod backend;
6 mod config;6 mod config;
7 mod cursor;7 mod cursor;
8+#[cfg(feature = "dbus")]
8 mod dbus;9 mod dbus;
9 mod frame_clock;10 mod frame_clock;
10 mod handlers;11 mod handlers;
@@ -37,8 +38,6 @@ use tracing_subscriber::EnvFilter;
37 use utils::spawn;38 use utils::spawn;
38 use watcher::Watcher;39 use watcher::Watcher;
39 40
40-use crate::dbus::DBusServers;
41-
42 #[derive(Parser)]41 #[derive(Parser)]
43 #[command(author, version, about, long_about = None)]42 #[command(author, version, about, long_about = None)]
44 struct Cli {43 struct Cli {
@@ -104,12 +103,14 @@ fn main() {
104 import_env_to_systemd();103 import_env_to_systemd();
105 104
106 // Inhibit power key handling so we can suspend on it.105 // Inhibit power key handling so we can suspend on it.
106+ #[cfg(feature = "dbus")]
107 if let Err(err) = state.niri.inhibit_power_key() {107 if let Err(err) = state.niri.inhibit_power_key() {
108 warn!("error inhibiting power key: {err:?}");108 warn!("error inhibiting power key: {err:?}");
109 }109 }
110 }110 }
111 111
112- DBusServers::start(&mut state, is_systemd_service);112+ #[cfg(feature = "dbus")]
113+ dbus::DBusServers::start(&mut state, is_systemd_service);
113 114
114 // Notify systemd we're ready.115 // Notify systemd we're ready.
115 if let Err(err) = sd_notify::notify(true, &[NotifyState::Ready]) {116 if let Err(err) = sd_notify::notify(true, &[NotifyState::Ready]) {
src/niri.rsmodified+14 -4
@@ -1,5 +1,4 @@
1 use std::cell::RefCell;1 use std::cell::RefCell;
2-use std::cmp::max;
3 use std::collections::HashMap;2 use std::collections::HashMap;
4 use std::ffi::OsString;3 use std::ffi::OsString;
5 use std::path::PathBuf;4 use std::path::PathBuf;
@@ -15,7 +14,6 @@ use smithay::backend::renderer::element::surface::{
15 render_elements_from_surface_tree, WaylandSurfaceRenderElement,14 render_elements_from_surface_tree, WaylandSurfaceRenderElement,
16 };15 };
17 use smithay::backend::renderer::element::texture::TextureRenderElement;16 use smithay::backend::renderer::element::texture::TextureRenderElement;
18-use smithay::backend::renderer::element::utils::{Relocate, RelocateRenderElement};
19 use smithay::backend::renderer::element::{17 use smithay::backend::renderer::element::{
20 default_primary_scanout_output_compare, render_elements, AsRenderElements, Kind, RenderElement,18 default_primary_scanout_output_compare, render_elements, AsRenderElements, Kind, RenderElement,
21 RenderElementStates,19 RenderElementStates,
@@ -74,10 +72,10 @@ use smithay::wayland::virtual_keyboard::VirtualKeyboardManagerState;
74 use crate::backend::{Backend, Tty, Winit};72 use crate::backend::{Backend, Tty, Winit};
75 use crate::config::Config;73 use crate::config::Config;
76 use crate::cursor::Cursor;74 use crate::cursor::Cursor;
75+#[cfg(feature = "dbus")]
77 use crate::dbus::gnome_shell_screenshot::{NiriToScreenshot, ScreenshotToNiri};76 use crate::dbus::gnome_shell_screenshot::{NiriToScreenshot, ScreenshotToNiri};
78 #[cfg(feature = "xdp-gnome-screencast")]77 #[cfg(feature = "xdp-gnome-screencast")]
79 use crate::dbus::mutter_screen_cast::{self, ScreenCastToNiri};78 use crate::dbus::mutter_screen_cast::{self, ScreenCastToNiri};
80-use crate::dbus::DBusServers;
81 use crate::frame_clock::FrameClock;79 use crate::frame_clock::FrameClock;
82 use crate::layout::{output_size, Layout, MonitorRenderElement};80 use crate::layout::{output_size, Layout, MonitorRenderElement};
83 use crate::pw_utils::{Cast, PipeWire};81 use crate::pw_utils::{Cast, PipeWire};
@@ -134,7 +132,9 @@ pub struct Niri {
134 pub cursor_image: CursorImageStatus,132 pub cursor_image: CursorImageStatus,
135 pub dnd_icon: Option<WlSurface>,133 pub dnd_icon: Option<WlSurface>,
136 134
137- pub dbus: Option<DBusServers>,135+ #[cfg(feature = "dbus")]
136+ pub dbus: Option<crate::dbus::DBusServers>,
137+ #[cfg(feature = "dbus")]
138 pub inhibit_power_key_fd: Option<zbus::zvariant::OwnedFd>,138 pub inhibit_power_key_fd: Option<zbus::zvariant::OwnedFd>,
139 139
140 // Casts are dropped before PipeWire to prevent a double-free (yay).140 // Casts are dropped before PipeWire to prevent a double-free (yay).
@@ -352,6 +352,7 @@ impl State {
352 }352 }
353 }353 }
354 354
355+ #[cfg(feature = "dbus")]
355 pub fn on_screen_shot_msg(356 pub fn on_screen_shot_msg(
356 &mut self,357 &mut self,
357 to_screenshot: &async_channel::Sender<NiriToScreenshot>,358 to_screenshot: &async_channel::Sender<NiriToScreenshot>,
@@ -533,13 +534,17 @@ impl Niri {
533 cursor_image: CursorImageStatus::default_named(),534 cursor_image: CursorImageStatus::default_named(),
534 dnd_icon: None,535 dnd_icon: None,
535 536
537+ #[cfg(feature = "dbus")]
536 dbus: None,538 dbus: None,
539+ #[cfg(feature = "dbus")]
537 inhibit_power_key_fd: None,540 inhibit_power_key_fd: None,
541+
538 pipewire,542 pipewire,
539 casts: vec![],543 casts: vec![],
540 }544 }
541 }545 }
542 546
547+ #[cfg(feature = "dbus")]
543 pub fn inhibit_power_key(&mut self) -> anyhow::Result<()> {548 pub fn inhibit_power_key(&mut self) -> anyhow::Result<()> {
544 let conn = zbus::blocking::ConnectionBuilder::system()?.build()?;549 let conn = zbus::blocking::ConnectionBuilder::system()?.build()?;
545 550
@@ -1520,12 +1525,17 @@ impl Niri {
1520 Ok(())1525 Ok(())
1521 }1526 }
1522 1527
1528+ #[cfg(feature = "dbus")]
1523 pub fn screenshot_all_outputs(1529 pub fn screenshot_all_outputs(
1524 &mut self,1530 &mut self,
1525 renderer: &mut GlesRenderer,1531 renderer: &mut GlesRenderer,
1526 include_pointer: bool,1532 include_pointer: bool,
1527 on_done: impl FnOnce(PathBuf) + Send + 'static,1533 on_done: impl FnOnce(PathBuf) + Send + 'static,
1528 ) -> anyhow::Result<()> {1534 ) -> anyhow::Result<()> {
1535+ use std::cmp::max;
1536+
1537+ use smithay::backend::renderer::element::utils::{Relocate, RelocateRenderElement};
1538+
1529 let _span = tracy_client::span!("Niri::screenshot_all_outputs");1539 let _span = tracy_client::span!("Niri::screenshot_all_outputs");
1530 1540
1531 let mut elements = vec![];1541 let mut elements = vec![];