fix: x11 builds

This commit is contained in:
galister
2024-04-10 08:33:27 +09:00
parent 0283916ffa
commit 78b51179ee
2 changed files with 45 additions and 17 deletions

View File

@@ -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<WlxClientAlias> {
wlx_capture::wayland::WlxClient::new()
}
#[cfg(not(feature = "wayland"))]
fn create_wl_client() -> Option<WlxClientAlias> {
None
}
pub struct OverlayContainer<T>
where
T: Default,
{
overlays: IdMap<usize, OverlayData<T>>,
wl: Option<WlxClient>,
wl: Option<WlxClientAlias>,
}
impl<T> OverlayContainer<T>
@@ -55,7 +64,7 @@ where
{
pub fn new(app: &mut AppState) -> anyhow::Result<Self> {
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<Vec<OverlayData<T>>> {
Ok(vec![])
}
#[cfg(feature = "wayland")]
pub fn update(&mut self, app: &mut AppState) -> anyhow::Result<Vec<OverlayData<T>>> {
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);

View File

@@ -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<Vec<DrmFormat>> = once_cell::sync::OnceCell::new();
@@ -90,9 +97,10 @@ impl InteractionHandler for ScreenInteractionHandler {
fn on_hover(&mut self, app: &mut AppState, hit: &PointerHit) -> Option<Haptics> {
#[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<ScreenCreateData> {
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<ScreenCreateData> {
use crate::config::AStrMap;