From f029b9324dfaa6637f401eff71c73ae17120c6b9 Mon Sep 17 00:00:00 2001 From: galister <22305755+galister@users.noreply.github.com> Date: Sat, 17 Feb 2024 19:57:26 +0100 Subject: [PATCH] option to build with only wayland or x11 support --- Cargo.toml | 4 +++- src/backend/common.rs | 5 ++--- src/overlays/screen.rs | 22 ++++++++++++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e4f93a5..eafeda9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,5 +52,7 @@ xdg = "2.5.2" openvr = ["dep:ovr_overlay", "dep:json"] openxr = ["dep:openxr"] osc = ["dep:rosc"] -default = ["openvr", "openxr", "osc"] +x11 = ["wlx-capture/xshm"] +wayland = ["wlx-capture/pipewire", "wlx-capture/wlr"] +default = ["openvr", "openxr", "osc", "x11", "wayland"] diff --git a/src/backend/common.rs b/src/backend/common.rs index f693c21..bed7135 100644 --- a/src/backend/common.rs +++ b/src/backend/common.rs @@ -10,7 +10,6 @@ use idmap::IdMap; use crate::{ overlays::{ keyboard::create_keyboard, - screen::{get_screens_wayland, get_screens_x11}, toast::Toast, watch::{create_watch, WATCH_NAME, WATCH_SCALE}, }, @@ -41,9 +40,9 @@ where pub fn new(app: &mut AppState) -> Self { let mut overlays = IdMap::new(); let (screens, extent) = if std::env::var("WAYLAND_DISPLAY").is_ok() { - get_screens_wayland(&app.session) + crate::overlays::screen::get_screens_wayland(&app.session) } else { - get_screens_x11(&app.session) + crate::overlays::screen::get_screens_x11(&app.session) }; let mut watch = create_watch::(&app, &screens); diff --git a/src/overlays/screen.rs b/src/overlays/screen.rs index f007b37..352a295 100644 --- a/src/overlays/screen.rs +++ b/src/overlays/screen.rs @@ -229,6 +229,7 @@ pub struct ScreenRenderer { } impl ScreenRenderer { + #[cfg(feature = "wayland")] pub fn new_wlr(output: &WlxOutput) -> Option { let client = WlxClient::new()?; let capture = WlrDmabufCapture::new(client, output.id); @@ -243,6 +244,7 @@ impl ScreenRenderer { }) } + #[cfg(feature = "wayland")] pub fn new_pw( output: &WlxOutput, token: Option<&str>, @@ -269,6 +271,7 @@ impl ScreenRenderer { )) } + #[cfg(feature = "x11")] pub fn new_xshm(screen: Arc) -> Option { let capture = XshmCapture::new(screen.clone()); @@ -441,6 +444,7 @@ impl OverlayRenderer for ScreenRenderer { } } +#[cfg(feature = "wayland")] fn try_create_screen( wl: &WlxClient, id: u32, @@ -608,6 +612,15 @@ pub fn load_pw_token_config() -> Result, Box> Ok(map) } +#[cfg(not(feature = "wayland"))] +pub fn get_screens_wayland(_session: &AppSession) -> (Vec>, Vec2) +where + O: Default, +{ + panic!("Wayland support not enabled") +} + +#[cfg(feature = "wayland")] pub fn get_screens_wayland(session: &AppSession) -> (Vec>, Vec2) where O: Default, @@ -641,6 +654,15 @@ where (overlays, Vec2::new(extent.0 as f32, extent.1 as f32)) } +#[cfg(not(feature = "x11"))] +pub fn get_screens_x11(session: &AppSession) -> (Vec>, Vec2) +where + O: Default, +{ + panic!("X11 support not enabled") +} + +#[cfg(feature = "x11")] pub fn get_screens_x11(session: &AppSession) -> (Vec>, Vec2) where O: Default,