Skip to content

Commit

Permalink
Make zbus optional under "dbus" feature
Browse files Browse the repository at this point in the history
  • Loading branch information
YaLTeR committed Oct 10, 2023
1 parent 9d7fdc4 commit 082d734
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
14 changes: 8 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ edition = "2021"

[dependencies]
anyhow = { version = "1.0.75" }
async-channel = "1.9.0"
async-io = "1.13.0"
async-channel = { version = "1.9.0", optional = true }
async-io = { version = "1.13.0", optional = true }
bitflags = "2.4.0"
clap = { version = "4.4.6", features = ["derive"] }
directories = "5.0.1"
image = { version = "0.24.7", default-features = false, features = ["png"] }
keyframe = { version = "1.1.1", default-features = false }
knuffel = "3.2.0"
libc = "0.2.149"
logind-zbus = "3.1.2"
logind-zbus = { version = "3.1.2", optional = true }
log = { version = "0.4.20", features = ["max_level_trace", "release_max_level_debug"] }
miette = "5.10.0"
nix = { version = "0.27.1", default-features = false, features = ["time"] }
Expand All @@ -31,7 +31,7 @@ tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
tracing = { version = "0.1.37", features = ["max_level_trace", "release_max_level_debug"] }
tracy-client = { version = "0.16.3", default-features = false }
xcursor = "0.3.4"
zbus = { version = "3.14.1" }
zbus = { version = "3.14.1", optional = true }

[dependencies.smithay]
git = "https://github.com/Smithay/smithay.git"
Expand Down Expand Up @@ -62,9 +62,11 @@ proptest = "1.3.1"
proptest-derive = "0.4.0"

[features]
default = ["xdp-gnome-screencast"]
default = ["dbus", "xdp-gnome-screencast"]
# Enables DBus support (required for xdp-gnome and power button inhibiting).
dbus = ["zbus", "logind-zbus", "async-channel", "async-io"]
# Enables screencasting support through xdg-desktop-portal-gnome.
xdp-gnome-screencast = ["pipewire"]
xdp-gnome-screencast = ["dbus", "pipewire"]
# Enables the Tracy profiler instrumentation.
profile-with-tracy = ["profiling/profile-with-tracy", "tracy-client/default"]

Expand Down
1 change: 1 addition & 0 deletions src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ impl Backend {
}
}

#[cfg_attr(not(feature = "dbus"), allow(unused))]
pub fn connectors(&self) -> Arc<Mutex<HashMap<String, Output>>> {
match self {
Backend::Tty(tty) => tty.connectors(),
Expand Down
2 changes: 2 additions & 0 deletions src/backend/tty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,7 @@ impl Tty {
}

pub fn suspend(&self) {
#[cfg(feature = "dbus")]
if let Err(err) = suspend() {
warn!("error suspending: {err:?}");
}
Expand Down Expand Up @@ -1026,6 +1027,7 @@ fn refresh_interval(mode: DrmMode) -> Duration {
Duration::from_nanos(refresh_interval)
}

#[cfg(feature = "dbus")]
fn suspend() -> anyhow::Result<()> {
let conn = zbus::blocking::Connection::system().context("error connecting to system bus")?;
let manager = logind_zbus::manager::ManagerProxyBlocking::new(&conn)
Expand Down
7 changes: 4 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod animation;
mod backend;
mod config;
mod cursor;
#[cfg(feature = "dbus")]
mod dbus;
mod frame_clock;
mod handlers;
Expand Down Expand Up @@ -37,8 +38,6 @@ use tracing_subscriber::EnvFilter;
use utils::spawn;
use watcher::Watcher;

use crate::dbus::DBusServers;

#[derive(Parser)]
#[command(author, version, about, long_about = None)]
struct Cli {
Expand Down Expand Up @@ -104,12 +103,14 @@ fn main() {
import_env_to_systemd();

// Inhibit power key handling so we can suspend on it.
#[cfg(feature = "dbus")]
if let Err(err) = state.niri.inhibit_power_key() {
warn!("error inhibiting power key: {err:?}");
}
}

DBusServers::start(&mut state, is_systemd_service);
#[cfg(feature = "dbus")]
dbus::DBusServers::start(&mut state, is_systemd_service);

// Notify systemd we're ready.
if let Err(err) = sd_notify::notify(true, &[NotifyState::Ready]) {
Expand Down
18 changes: 14 additions & 4 deletions src/niri.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::cell::RefCell;
use std::cmp::max;
use std::collections::HashMap;
use std::ffi::OsString;
use std::path::PathBuf;
Expand All @@ -15,7 +14,6 @@ use smithay::backend::renderer::element::surface::{
render_elements_from_surface_tree, WaylandSurfaceRenderElement,
};
use smithay::backend::renderer::element::texture::TextureRenderElement;
use smithay::backend::renderer::element::utils::{Relocate, RelocateRenderElement};
use smithay::backend::renderer::element::{
default_primary_scanout_output_compare, render_elements, AsRenderElements, Kind, RenderElement,
RenderElementStates,
Expand Down Expand Up @@ -74,10 +72,10 @@ use smithay::wayland::virtual_keyboard::VirtualKeyboardManagerState;
use crate::backend::{Backend, Tty, Winit};
use crate::config::Config;
use crate::cursor::Cursor;
#[cfg(feature = "dbus")]
use crate::dbus::gnome_shell_screenshot::{NiriToScreenshot, ScreenshotToNiri};
#[cfg(feature = "xdp-gnome-screencast")]
use crate::dbus::mutter_screen_cast::{self, ScreenCastToNiri};
use crate::dbus::DBusServers;
use crate::frame_clock::FrameClock;
use crate::layout::{output_size, Layout, MonitorRenderElement};
use crate::pw_utils::{Cast, PipeWire};
Expand Down Expand Up @@ -134,7 +132,9 @@ pub struct Niri {
pub cursor_image: CursorImageStatus,
pub dnd_icon: Option<WlSurface>,

pub dbus: Option<DBusServers>,
#[cfg(feature = "dbus")]
pub dbus: Option<crate::dbus::DBusServers>,
#[cfg(feature = "dbus")]
pub inhibit_power_key_fd: Option<zbus::zvariant::OwnedFd>,

// Casts are dropped before PipeWire to prevent a double-free (yay).
Expand Down Expand Up @@ -352,6 +352,7 @@ impl State {
}
}

#[cfg(feature = "dbus")]
pub fn on_screen_shot_msg(
&mut self,
to_screenshot: &async_channel::Sender<NiriToScreenshot>,
Expand Down Expand Up @@ -533,13 +534,17 @@ impl Niri {
cursor_image: CursorImageStatus::default_named(),
dnd_icon: None,

#[cfg(feature = "dbus")]
dbus: None,
#[cfg(feature = "dbus")]
inhibit_power_key_fd: None,

pipewire,
casts: vec![],
}
}

#[cfg(feature = "dbus")]
pub fn inhibit_power_key(&mut self) -> anyhow::Result<()> {
let conn = zbus::blocking::ConnectionBuilder::system()?.build()?;

Expand Down Expand Up @@ -1520,12 +1525,17 @@ impl Niri {
Ok(())
}

#[cfg(feature = "dbus")]
pub fn screenshot_all_outputs(
&mut self,
renderer: &mut GlesRenderer,
include_pointer: bool,
on_done: impl FnOnce(PathBuf) + Send + 'static,
) -> anyhow::Result<()> {
use std::cmp::max;

use smithay::backend::renderer::element::utils::{Relocate, RelocateRenderElement};

let _span = tracy_client::span!("Niri::screenshot_all_outputs");

let mut elements = vec![];
Expand Down

0 comments on commit 082d734

Please sign in to comment.