ensure init cursor embedded

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2023-01-29 10:58:04 +08:00
parent 340897ab18
commit d1090fc62c
3 changed files with 22 additions and 19 deletions

View File

@ -12,7 +12,7 @@ cfg_if! {
mod x11;
pub use self::linux::*;
pub use self::x11::Frame;
pub use self::wayland::{set_map_err, detect_cursor_embedded};
pub use self::wayland::set_map_err;
} else {
mod x11;
pub use self::x11::*;
@ -76,7 +76,7 @@ pub fn is_cursor_embedded() -> bool {
if is_x11() {
x11::IS_CURSOR_EMBEDDED
} else {
unsafe { wayland::IS_CURSOR_EMBEDDED }
wayland::is_cursor_embedded()
}
}

View File

@ -4,22 +4,29 @@ use std::{io, sync::RwLock, time::Duration};
pub struct Capturer(Display, Box<dyn Recorder>, bool, Vec<u8>);
pub static mut IS_CURSOR_EMBEDDED: bool = true;
static mut IS_CURSOR_EMBEDDED: Option<bool> = None;
lazy_static::lazy_static! {
static ref MAP_ERR: RwLock<Option<fn(err: String)-> io::Error>> = Default::default();
}
pub fn detect_cursor_embedded() {
if unsafe { IS_CURSOR_EMBEDDED } {
use crate::common::wayland::pipewire::get_available_cursor_modes;
match get_available_cursor_modes() {
Ok(modes) => unsafe {
IS_CURSOR_EMBEDDED = (modes & 0x02) > 0;
},
Err(..) => unsafe {
IS_CURSOR_EMBEDDED = false;
},
pub fn is_cursor_embedded() -> bool {
unsafe {
if IS_CURSOR_EMBEDDED.is_none() {
init_cursor_embedded();
}
IS_CURSOR_EMBEDDED.unwrap_or(false)
}
}
unsafe fn init_cursor_embedded() {
use crate::common::wayland::pipewire::get_available_cursor_modes;
match get_available_cursor_modes() {
Ok(modes) => {
IS_CURSOR_EMBEDDED = Some((modes & 0x02) > 0);
}
Err(..) => {
IS_CURSOR_EMBEDDED = Some(false);
}
}
}
@ -88,7 +95,7 @@ impl Display {
}
pub fn all() -> io::Result<Vec<Display>> {
Ok(pipewire::get_capturables(unsafe { IS_CURSOR_EMBEDDED })
Ok(pipewire::get_capturables(is_cursor_embedded())
.map_err(map_err)?
.drain(..)
.map(|x| Display(x))

View File

@ -1,9 +1,6 @@
use super::*;
use hbb_common::{allow_err, platform::linux::DISTRO};
use scrap::{
detect_cursor_embedded, is_cursor_embedded, set_map_err, Capturer, Display, Frame,
TraitCapturer,
};
use scrap::{is_cursor_embedded, set_map_err, Capturer, Display, Frame, TraitCapturer};
use std::io;
use super::video_service::{
@ -16,7 +13,6 @@ lazy_static::lazy_static! {
}
pub fn init() {
detect_cursor_embedded();
set_map_err(map_err_scrap);
}