From 78b51179ee82d7ddc1668cd63c227d9b1894be30 Mon Sep 17 00:00:00 2001 From: galister <22305755+galister@users.noreply.github.com> Date: Wed, 10 Apr 2024 08:33:27 +0900 Subject: [PATCH] fix: x11 builds --- src/backend/common.rs | 33 +++++++++++++++++++++++++++------ src/overlays/screen.rs | 29 ++++++++++++++++++----------- 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/src/backend/common.rs b/src/backend/common.rs index 934f1e0..c0d4c81 100644 --- a/src/backend/common.rs +++ b/src/backend/common.rs @@ -8,18 +8,17 @@ use std::{ #[cfg(feature = "openxr")] use openxr as xr; -use glam::{vec2, Affine3A, Vec2, Vec3A, Vec3Swizzles}; +use glam::{Affine3A, Vec2, Vec3A, Vec3Swizzles}; use idmap::IdMap; use serde::Deserialize; use thiserror::Error; -use wlx_capture::wayland::{OutputChangeEvent, WlxClient}; use crate::{ config::{AStrMapExt, AStrSetExt}, overlays::{ keyboard::{create_keyboard, KEYBOARD_NAME}, - screen::{create_screen_interaction, create_screen_renderer_wl, load_pw_token_config}, - watch::{create_watch, create_watch_canvas, WATCH_NAME}, + screen::WlxClientAlias, + watch::{create_watch, WATCH_NAME}, }, state::AppState, }; @@ -41,12 +40,22 @@ pub enum BackendError { Fatal(#[from] anyhow::Error), } +#[cfg(feature = "wayland")] +fn create_wl_client() -> Option { + wlx_capture::wayland::WlxClient::new() +} + +#[cfg(not(feature = "wayland"))] +fn create_wl_client() -> Option { + None +} + pub struct OverlayContainer where T: Default, { overlays: IdMap>, - wl: Option, + wl: Option, } impl OverlayContainer @@ -55,7 +64,7 @@ where { pub fn new(app: &mut AppState) -> anyhow::Result { let mut overlays = IdMap::new(); - let mut wl = WlxClient::new(); + let mut wl = create_wl_client(); app.screens.clear(); let data = if let Some(wl) = wl.as_mut() { @@ -111,7 +120,19 @@ where Ok(Self { overlays, wl }) } + #[cfg(not(feature = "wayland"))] + pub fn update(&mut self, _app: &mut AppState) -> anyhow::Result>> { + Ok(vec![]) + } + #[cfg(feature = "wayland")] pub fn update(&mut self, app: &mut AppState) -> anyhow::Result>> { + use crate::overlays::{ + screen::{create_screen_interaction, create_screen_renderer_wl, load_pw_token_config}, + watch::create_watch_canvas, + }; + use glam::vec2; + use wlx_capture::wayland::OutputChangeEvent; + let mut removed_overlays = vec![]; let Some(wl) = self.wl.as_mut() else { return Ok(removed_overlays); diff --git a/src/overlays/screen.rs b/src/overlays/screen.rs index 948b3a1..a549290 100644 --- a/src/overlays/screen.rs +++ b/src/overlays/screen.rs @@ -1,6 +1,7 @@ use core::slice; use serde::{Deserialize, Serialize}; use std::{ + f32::consts::PI, ops::Add, ptr, sync::Arc, @@ -21,9 +22,9 @@ use wlx_capture::{ #[cfg(feature = "wayland")] use { + crate::config::AStrMapExt, crate::config_io, - glam::Vec3, - std::{error::Error, f32::consts::PI, ops::Deref, path::PathBuf}, + std::{error::Error, ops::Deref, path::PathBuf}, wlx_capture::{ pipewire::{pipewire_select_screen, PipewireCapture}, wayland::{wayland_client::protocol::wl_output, WlxClient, WlxOutput}, @@ -35,19 +36,25 @@ use { #[cfg(feature = "x11")] use wlx_capture::xshm::{XshmCapture, XshmScreen}; -use glam::{vec2, vec3a, Affine2, Quat, Vec2}; +use glam::{vec2, vec3a, Affine2, Quat, Vec2, Vec3}; use crate::{ backend::{ input::{Haptics, InteractionHandler, PointerHit, PointerMode}, overlay::{OverlayRenderer, OverlayState, SplitOverlayBackend}, }, - config::{def_pw_tokens, AStrMapExt, PwTokenMap}, + config::{def_pw_tokens, PwTokenMap}, graphics::{fourcc_to_vk, WlxCommandBuffer, WlxPipeline, WlxPipelineLegacy}, hid::{MOUSE_LEFT, MOUSE_MIDDLE, MOUSE_RIGHT}, state::{AppSession, AppState, ScreenMeta}, }; +#[cfg(feature = "wayland")] +pub(crate) type WlxClientAlias = wlx_capture::wayland::WlxClient; + +#[cfg(not(feature = "wayland"))] +pub(crate) type WlxClientAlias = (); + const CURSOR_SIZE: f32 = 16. / 1440.; static DRM_FORMATS: once_cell::sync::OnceCell> = once_cell::sync::OnceCell::new(); @@ -90,9 +97,10 @@ impl InteractionHandler for ScreenInteractionHandler { fn on_hover(&mut self, app: &mut AppState, hit: &PointerHit) -> Option { #[cfg(debug_assertions)] log::trace!("Hover: {:?}", hit.uv); - if self.next_move < Instant::now() && - (!app.session.config.focus_follows_mouse_mode - || app.input_state.pointers[hit.pointer].now.move_mouse) { + if self.next_move < Instant::now() + && (!app.session.config.focus_follows_mouse_mode + || app.input_state.pointers[hit.pointer].now.move_mouse) + { let pos = self.mouse_transform.transform_point2(hit.uv); app.hid_provider.mouse_move(pos); } @@ -114,7 +122,6 @@ impl InteractionHandler for ScreenInteractionHandler { let pos = self.mouse_transform.transform_point2(hit.uv); app.hid_provider.mouse_move(pos); - } fn on_scroll(&mut self, app: &mut AppState, hit: &PointerHit, delta: f32) { if self.next_scroll > Instant::now() { @@ -653,15 +660,15 @@ pub(crate) struct ScreenCreateData { #[cfg(not(feature = "wayland"))] pub fn create_screens_wayland( - wl: &mut WlxClient, - app: &AppState, + _wl: &mut WlxClientAlias, + _app: &AppState, ) -> anyhow::Result { anyhow::bail!("Wayland support not enabled") } #[cfg(feature = "wayland")] pub fn create_screens_wayland( - wl: &mut WlxClient, + wl: &mut WlxClientAlias, app: &mut AppState, ) -> anyhow::Result { use crate::config::AStrMap;