option to build with only wayland or x11 support

This commit is contained in:
galister
2024-02-17 19:57:26 +01:00
parent 5bbaf59790
commit f029b9324d
3 changed files with 27 additions and 4 deletions

View File

@@ -52,5 +52,7 @@ xdg = "2.5.2"
openvr = ["dep:ovr_overlay", "dep:json"] openvr = ["dep:ovr_overlay", "dep:json"]
openxr = ["dep:openxr"] openxr = ["dep:openxr"]
osc = ["dep:rosc"] osc = ["dep:rosc"]
default = ["openvr", "openxr", "osc"] x11 = ["wlx-capture/xshm"]
wayland = ["wlx-capture/pipewire", "wlx-capture/wlr"]
default = ["openvr", "openxr", "osc", "x11", "wayland"]

View File

@@ -10,7 +10,6 @@ use idmap::IdMap;
use crate::{ use crate::{
overlays::{ overlays::{
keyboard::create_keyboard, keyboard::create_keyboard,
screen::{get_screens_wayland, get_screens_x11},
toast::Toast, toast::Toast,
watch::{create_watch, WATCH_NAME, WATCH_SCALE}, watch::{create_watch, WATCH_NAME, WATCH_SCALE},
}, },
@@ -41,9 +40,9 @@ where
pub fn new(app: &mut AppState) -> Self { pub fn new(app: &mut AppState) -> Self {
let mut overlays = IdMap::new(); let mut overlays = IdMap::new();
let (screens, extent) = if std::env::var("WAYLAND_DISPLAY").is_ok() { 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 { } else {
get_screens_x11(&app.session) crate::overlays::screen::get_screens_x11(&app.session)
}; };
let mut watch = create_watch::<T>(&app, &screens); let mut watch = create_watch::<T>(&app, &screens);

View File

@@ -229,6 +229,7 @@ pub struct ScreenRenderer {
} }
impl ScreenRenderer { impl ScreenRenderer {
#[cfg(feature = "wayland")]
pub fn new_wlr(output: &WlxOutput) -> Option<ScreenRenderer> { pub fn new_wlr(output: &WlxOutput) -> Option<ScreenRenderer> {
let client = WlxClient::new()?; let client = WlxClient::new()?;
let capture = WlrDmabufCapture::new(client, output.id); let capture = WlrDmabufCapture::new(client, output.id);
@@ -243,6 +244,7 @@ impl ScreenRenderer {
}) })
} }
#[cfg(feature = "wayland")]
pub fn new_pw( pub fn new_pw(
output: &WlxOutput, output: &WlxOutput,
token: Option<&str>, token: Option<&str>,
@@ -269,6 +271,7 @@ impl ScreenRenderer {
)) ))
} }
#[cfg(feature = "x11")]
pub fn new_xshm(screen: Arc<XshmScreen>) -> Option<ScreenRenderer> { pub fn new_xshm(screen: Arc<XshmScreen>) -> Option<ScreenRenderer> {
let capture = XshmCapture::new(screen.clone()); let capture = XshmCapture::new(screen.clone());
@@ -441,6 +444,7 @@ impl OverlayRenderer for ScreenRenderer {
} }
} }
#[cfg(feature = "wayland")]
fn try_create_screen<O>( fn try_create_screen<O>(
wl: &WlxClient, wl: &WlxClient,
id: u32, id: u32,
@@ -608,6 +612,15 @@ pub fn load_pw_token_config() -> Result<HashMap<String, String>, Box<dyn Error>>
Ok(map) Ok(map)
} }
#[cfg(not(feature = "wayland"))]
pub fn get_screens_wayland<O>(_session: &AppSession) -> (Vec<OverlayData<O>>, Vec2)
where
O: Default,
{
panic!("Wayland support not enabled")
}
#[cfg(feature = "wayland")]
pub fn get_screens_wayland<O>(session: &AppSession) -> (Vec<OverlayData<O>>, Vec2) pub fn get_screens_wayland<O>(session: &AppSession) -> (Vec<OverlayData<O>>, Vec2)
where where
O: Default, O: Default,
@@ -641,6 +654,15 @@ where
(overlays, Vec2::new(extent.0 as f32, extent.1 as f32)) (overlays, Vec2::new(extent.0 as f32, extent.1 as f32))
} }
#[cfg(not(feature = "x11"))]
pub fn get_screens_x11<O>(session: &AppSession) -> (Vec<OverlayData<O>>, Vec2)
where
O: Default,
{
panic!("X11 support not enabled")
}
#[cfg(feature = "x11")]
pub fn get_screens_x11<O>(session: &AppSession) -> (Vec<OverlayData<O>>, Vec2) pub fn get_screens_x11<O>(session: &AppSession) -> (Vec<OverlayData<O>>, Vec2)
where where
O: Default, O: Default,