fix is x11, on conn
Signed-off-by: dignow <linlong1265@gmail.com>
This commit is contained in:
		
							parent
							
								
									aa3c58917b
								
							
						
					
					
						commit
						b3948910ff
					
				| @ -108,7 +108,7 @@ impl Drop for SimpleCallOnReturn { | |||||||
| pub fn global_init() -> bool { | pub fn global_init() -> bool { | ||||||
|     #[cfg(target_os = "linux")] |     #[cfg(target_os = "linux")] | ||||||
|     { |     { | ||||||
|         if !*IS_X11 { |         if !crate::platform::linux::is_x11() { | ||||||
|             crate::server::wayland::init(); |             crate::server::wayland::init(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @ -956,7 +956,10 @@ pub async fn post_request_sync(url: String, body: String, header: &str) -> Resul | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[inline] | #[inline] | ||||||
| pub fn make_privacy_mode_msg_with_details(state: back_notification::PrivacyModeState, details: String) -> Message { | pub fn make_privacy_mode_msg_with_details( | ||||||
|  |     state: back_notification::PrivacyModeState, | ||||||
|  |     details: String, | ||||||
|  | ) -> Message { | ||||||
|     let mut misc = Misc::new(); |     let mut misc = Misc::new(); | ||||||
|     let mut back_notification = BackNotification { |     let mut back_notification = BackNotification { | ||||||
|         details, |         details, | ||||||
| @ -990,17 +993,6 @@ pub fn get_supported_keyboard_modes(version: i64) -> Vec<KeyboardMode> { | |||||||
|         .collect::<Vec<_>>() |         .collect::<Vec<_>>() | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[cfg(not(target_os = "linux"))] |  | ||||||
| lazy_static::lazy_static! { |  | ||||||
|     pub static ref IS_X11: bool = false; |  | ||||||
| 
 |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| #[cfg(target_os = "linux")] |  | ||||||
| lazy_static::lazy_static! { |  | ||||||
|     pub static ref IS_X11: bool = hbb_common::platform::linux::is_x11_or_headless(); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| pub fn make_fd_to_json(id: i32, path: String, entries: &Vec<FileEntry>) -> String { | pub fn make_fd_to_json(id: i32, path: String, entries: &Vec<FileEntry>) -> String { | ||||||
|     use serde_json::json; |     use serde_json::json; | ||||||
|     let mut fd_json = serde_json::Map::new(); |     let mut fd_json = serde_json::Map::new(); | ||||||
|  | |||||||
| @ -1584,7 +1584,7 @@ pub fn main_is_installed() -> SyncReturn<bool> { | |||||||
| 
 | 
 | ||||||
| pub fn main_start_grab_keyboard() -> SyncReturn<bool> { | pub fn main_start_grab_keyboard() -> SyncReturn<bool> { | ||||||
|     #[cfg(target_os = "linux")] |     #[cfg(target_os = "linux")] | ||||||
|     if !*crate::common::IS_X11 { |     if !crate::platform::linux::is_x11() { | ||||||
|         return SyncReturn(false); |         return SyncReturn(false); | ||||||
|     } |     } | ||||||
|     crate::keyboard::client::start_grab_loop(); |     crate::keyboard::client::start_grab_loop(); | ||||||
|  | |||||||
| @ -35,6 +35,10 @@ type Xdo = *const c_void; | |||||||
| pub const PA_SAMPLE_RATE: u32 = 48000; | pub const PA_SAMPLE_RATE: u32 = 48000; | ||||||
| static mut UNMODIFIED: bool = true; | static mut UNMODIFIED: bool = true; | ||||||
| 
 | 
 | ||||||
|  | lazy_static::lazy_static! { | ||||||
|  |     pub static ref IS_X11: bool = hbb_common::platform::linux::is_x11_or_headless(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| thread_local! { | thread_local! { | ||||||
|     static XDO: RefCell<Xdo> = RefCell::new(unsafe { xdo_new(std::ptr::null()) }); |     static XDO: RefCell<Xdo> = RefCell::new(unsafe { xdo_new(std::ptr::null()) }); | ||||||
|     static DISPLAY: RefCell<*mut c_void> = RefCell::new(unsafe { XOpenDisplay(std::ptr::null())}); |     static DISPLAY: RefCell<*mut c_void> = RefCell::new(unsafe { XOpenDisplay(std::ptr::null())}); | ||||||
| @ -1360,3 +1364,8 @@ impl Drop for WallPaperRemover { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | #[inline] | ||||||
|  | pub fn is_x11() -> bool { | ||||||
|  |     *IS_X11 | ||||||
|  | } | ||||||
|  | |||||||
| @ -1,16 +1,14 @@ | |||||||
| use super::*; | use super::*; | ||||||
|  | #[cfg(target_os = "linux")] | ||||||
|  | use crate::platform::linux::is_x11; | ||||||
| #[cfg(all(windows, feature = "virtual_display_driver"))] | #[cfg(all(windows, feature = "virtual_display_driver"))] | ||||||
| use crate::virtual_display_manager; | use crate::virtual_display_manager; | ||||||
| #[cfg(windows)] | #[cfg(windows)] | ||||||
| use hbb_common::get_version_number; | use hbb_common::get_version_number; | ||||||
| use hbb_common::protobuf::MessageField; | use hbb_common::protobuf::MessageField; | ||||||
| use scrap::Display; | use scrap::Display; | ||||||
| #[cfg(target_os = "linux")] |  | ||||||
| use std::sync::atomic::{AtomicBool, Ordering}; |  | ||||||
| 
 | 
 | ||||||
| // https://github.com/rustdesk/rustdesk/discussions/6042, avoiding dbus call
 | // https://github.com/rustdesk/rustdesk/discussions/6042, avoiding dbus call
 | ||||||
| #[cfg(target_os = "linux")] |  | ||||||
| pub(super) static IS_X11: AtomicBool = AtomicBool::new(false); |  | ||||||
| 
 | 
 | ||||||
| pub const NAME: &'static str = "display"; | pub const NAME: &'static str = "display"; | ||||||
| 
 | 
 | ||||||
| @ -71,7 +69,7 @@ pub(super) fn check_display_changed( | |||||||
|     #[cfg(target_os = "linux")] |     #[cfg(target_os = "linux")] | ||||||
|     { |     { | ||||||
|         // wayland do not support changing display for now
 |         // wayland do not support changing display for now
 | ||||||
|         if !IS_X11.load(Ordering::SeqCst) { |         if !is_x11() { | ||||||
|             return None; |             return None; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @ -176,11 +174,6 @@ pub fn try_plug_out_virtual_display() { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn run(sp: EmptyExtraFieldService) -> ResultType<()> { | fn run(sp: EmptyExtraFieldService) -> ResultType<()> { | ||||||
|     #[cfg(target_os = "linux")] |  | ||||||
|     { |  | ||||||
|         IS_X11.store(scrap::is_x11(), Ordering::SeqCst); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     while sp.ok() { |     while sp.ok() { | ||||||
|         sp.snapshot(|sps| { |         sp.snapshot(|sps| { | ||||||
|             if sps.has_subscribes() { |             if sps.has_subscribes() { | ||||||
| @ -274,7 +267,7 @@ pub(super) fn check_update_displays(all: &Vec<Display>) { | |||||||
| 
 | 
 | ||||||
| pub fn is_inited_msg() -> Option<Message> { | pub fn is_inited_msg() -> Option<Message> { | ||||||
|     #[cfg(target_os = "linux")] |     #[cfg(target_os = "linux")] | ||||||
|     if !IS_X11.load(Ordering::SeqCst) { |     if !is_x11() { | ||||||
|         return super::wayland::is_inited(); |         return super::wayland::is_inited(); | ||||||
|     } |     } | ||||||
|     None |     None | ||||||
| @ -283,7 +276,7 @@ pub fn is_inited_msg() -> Option<Message> { | |||||||
| pub async fn update_get_sync_displays() -> ResultType<Vec<DisplayInfo>> { | pub async fn update_get_sync_displays() -> ResultType<Vec<DisplayInfo>> { | ||||||
|     #[cfg(target_os = "linux")] |     #[cfg(target_os = "linux")] | ||||||
|     { |     { | ||||||
|         if !IS_X11.load(Ordering::SeqCst) { |         if !is_x11() { | ||||||
|             return super::wayland::get_displays().await; |             return super::wayland::get_displays().await; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @ -295,7 +288,7 @@ pub async fn update_get_sync_displays() -> ResultType<Vec<DisplayInfo>> { | |||||||
| pub fn get_primary() -> usize { | pub fn get_primary() -> usize { | ||||||
|     #[cfg(target_os = "linux")] |     #[cfg(target_os = "linux")] | ||||||
|     { |     { | ||||||
|         if !IS_X11.load(Ordering::SeqCst) { |         if !is_x11() { | ||||||
|             return match super::wayland::get_primary() { |             return match super::wayland::get_primary() { | ||||||
|                 Ok(n) => n, |                 Ok(n) => n, | ||||||
|                 Err(_) => 0, |                 Err(_) => 0, | ||||||
|  | |||||||
| @ -1,8 +1,6 @@ | |||||||
| use super::*; | use super::*; | ||||||
| #[cfg(target_os = "macos")] | #[cfg(target_os = "macos")] | ||||||
| use crate::common::is_server; | use crate::common::is_server; | ||||||
| #[cfg(target_os = "linux")] |  | ||||||
| use crate::common::IS_X11; |  | ||||||
| use crate::input::*; | use crate::input::*; | ||||||
| #[cfg(target_os = "macos")] | #[cfg(target_os = "macos")] | ||||||
| use dispatch::Queue; | use dispatch::Queue; | ||||||
| @ -1152,7 +1150,7 @@ fn map_keyboard_mode(evt: &KeyEvent) { | |||||||
| 
 | 
 | ||||||
|     // Wayland
 |     // Wayland
 | ||||||
|     #[cfg(target_os = "linux")] |     #[cfg(target_os = "linux")] | ||||||
|     if !*IS_X11 { |     if !crate::platform::linux::is_x11() { | ||||||
|         let mut en = ENIGO.lock().unwrap(); |         let mut en = ENIGO.lock().unwrap(); | ||||||
|         let code = evt.chr() as u16; |         let code = evt.chr() as u16; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -18,8 +18,6 @@ | |||||||
| // to-do:
 | // to-do:
 | ||||||
| // https://slhck.info/video/2017/03/01/rate-control.html
 | // https://slhck.info/video/2017/03/01/rate-control.html
 | ||||||
| 
 | 
 | ||||||
| #[cfg(target_os = "linux")] |  | ||||||
| use super::display_service::IS_X11; |  | ||||||
| use super::{ | use super::{ | ||||||
|     display_service::{check_display_changed, get_display_info}, |     display_service::{check_display_changed, get_display_info}, | ||||||
|     service::ServiceTmpl, |     service::ServiceTmpl, | ||||||
| @ -28,6 +26,8 @@ use super::{ | |||||||
| }; | }; | ||||||
| #[cfg(target_os = "linux")] | #[cfg(target_os = "linux")] | ||||||
| use crate::common::SimpleCallOnReturn; | use crate::common::SimpleCallOnReturn; | ||||||
|  | #[cfg(target_os = "linux")] | ||||||
|  | use crate::platform::linux::is_x11; | ||||||
| #[cfg(windows)] | #[cfg(windows)] | ||||||
| use crate::{platform::windows::is_process_consent_running, privacy_win_mag}; | use crate::{platform::windows::is_process_consent_running, privacy_win_mag}; | ||||||
| use hbb_common::{ | use hbb_common::{ | ||||||
| @ -46,8 +46,6 @@ use scrap::{ | |||||||
|     vpxcodec::{VpxEncoderConfig, VpxVideoCodecId}, |     vpxcodec::{VpxEncoderConfig, VpxVideoCodecId}, | ||||||
|     CodecName, Display, TraitCapturer, |     CodecName, Display, TraitCapturer, | ||||||
| }; | }; | ||||||
| #[cfg(target_os = "linux")] |  | ||||||
| use std::sync::atomic::Ordering; |  | ||||||
| #[cfg(windows)] | #[cfg(windows)] | ||||||
| use std::sync::Once; | use std::sync::Once; | ||||||
| use std::{ | use std::{ | ||||||
| @ -329,7 +327,7 @@ fn get_capturer( | |||||||
| ) -> ResultType<CapturerInfo> { | ) -> ResultType<CapturerInfo> { | ||||||
|     #[cfg(target_os = "linux")] |     #[cfg(target_os = "linux")] | ||||||
|     { |     { | ||||||
|         if !IS_X11.load(Ordering::SeqCst) { |         if !is_x11() { | ||||||
|             return super::wayland::get_capturer(); |             return super::wayland::get_capturer(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @ -571,7 +569,7 @@ fn run(vs: VideoService) -> ResultType<()> { | |||||||
|                 #[cfg(target_os = "linux")] |                 #[cfg(target_os = "linux")] | ||||||
|                 { |                 { | ||||||
|                     would_block_count += 1; |                     would_block_count += 1; | ||||||
|                     if !IS_X11.load(Ordering::SeqCst) { |                     if !is_x11() { | ||||||
|                         if would_block_count >= 100 { |                         if would_block_count >= 100 { | ||||||
|                             // to-do: Unknown reason for WouldBlock 100 times (seconds = 100 * 1 / fps)
 |                             // to-do: Unknown reason for WouldBlock 100 times (seconds = 100 * 1 / fps)
 | ||||||
|                             // https://github.com/rustdesk/rustdesk/blob/63e6b2f8ab51743e77a151e2b7ff18816f5fa2fb/libs/scrap/src/common/wayland.rs#L81
 |                             // https://github.com/rustdesk/rustdesk/blob/63e6b2f8ab51743e77a151e2b7ff18816f5fa2fb/libs/scrap/src/common/wayland.rs#L81
 | ||||||
| @ -751,7 +749,7 @@ fn handle_one_frame( | |||||||
| 
 | 
 | ||||||
| pub fn is_inited_msg() -> Option<Message> { | pub fn is_inited_msg() -> Option<Message> { | ||||||
|     #[cfg(target_os = "linux")] |     #[cfg(target_os = "linux")] | ||||||
|     if !IS_X11.load(Ordering::SeqCst) { |     if !is_x11() { | ||||||
|         return super::wayland::is_inited(); |         return super::wayland::is_inited(); | ||||||
|     } |     } | ||||||
|     None |     None | ||||||
|  | |||||||
| @ -4,8 +4,11 @@ use scrap::{is_cursor_embedded, set_map_err, Capturer, Display, Frame, TraitCapt | |||||||
| use std::io; | use std::io; | ||||||
| use std::process::{Command, Output}; | use std::process::{Command, Output}; | ||||||
| 
 | 
 | ||||||
| use crate::client::{ | use crate::{ | ||||||
|     SCRAP_OTHER_VERSION_OR_X11_REQUIRED, SCRAP_UBUNTU_HIGHER_REQUIRED, SCRAP_X11_REQUIRED, |     client::{ | ||||||
|  |         SCRAP_OTHER_VERSION_OR_X11_REQUIRED, SCRAP_UBUNTU_HIGHER_REQUIRED, SCRAP_X11_REQUIRED, | ||||||
|  |     }, | ||||||
|  |     platform::linux::is_x11, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| lazy_static::lazy_static! { | lazy_static::lazy_static! { | ||||||
| @ -96,7 +99,7 @@ pub(super) async fn ensure_inited() -> ResultType<()> { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub(super) fn is_inited() -> Option<Message> { | pub(super) fn is_inited() -> Option<Message> { | ||||||
|     if scrap::is_x11() { |     if is_x11() { | ||||||
|         None |         None | ||||||
|     } else { |     } else { | ||||||
|         if *CAP_DISPLAY_INFO.read().unwrap() == 0 { |         if *CAP_DISPLAY_INFO.read().unwrap() == 0 { | ||||||
| @ -133,7 +136,7 @@ fn get_max_desktop_resolution() -> Option<String> { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub(super) async fn check_init() -> ResultType<()> { | pub(super) async fn check_init() -> ResultType<()> { | ||||||
|     if !scrap::is_x11() { |     if !is_x11() { | ||||||
|         let mut minx = 0; |         let mut minx = 0; | ||||||
|         let mut maxx = 0; |         let mut maxx = 0; | ||||||
|         let mut miny = 0; |         let mut miny = 0; | ||||||
| @ -246,7 +249,7 @@ pub(super) fn get_primary() -> ResultType<usize> { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub fn clear() { | pub fn clear() { | ||||||
|     if scrap::is_x11() { |     if is_x11() { | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|     let mut write_lock = CAP_DISPLAY_INFO.write().unwrap(); |     let mut write_lock = CAP_DISPLAY_INFO.write().unwrap(); | ||||||
| @ -261,7 +264,7 @@ pub fn clear() { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub(super) fn get_capturer() -> ResultType<super::video_service::CapturerInfo> { | pub(super) fn get_capturer() -> ResultType<super::video_service::CapturerInfo> { | ||||||
|     if scrap::is_x11() { |     if is_x11() { | ||||||
|         bail!("Do not call this function if not wayland"); |         bail!("Do not call this function if not wayland"); | ||||||
|     } |     } | ||||||
|     let addr = *CAP_DISPLAY_INFO.read().unwrap(); |     let addr = *CAP_DISPLAY_INFO.read().unwrap(); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user