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
libs/scrap/src/common
src/server

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

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

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