Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2022-12-29 14:28:15 +08:00
parent 1651cef4f3
commit 01ade73304
5 changed files with 20 additions and 11 deletions

2
Cargo.lock generated
View File

@ -4305,7 +4305,7 @@ dependencies = [
[[package]] [[package]]
name = "rdev" name = "rdev"
version = "0.5.0-2" version = "0.5.0-2"
source = "git+https://github.com/fufesou/rdev#bc2db2f13dfdc95df8a02eb03f71325c173283dc" source = "git+https://github.com/fufesou/rdev#edddb71a88bd8a4737ef4216861b426490c49f2e"
dependencies = [ dependencies = [
"cocoa", "cocoa",
"core-foundation 0.9.3", "core-foundation 0.9.3",

View File

@ -40,6 +40,7 @@ const BUF_LEN: usize = 4;
#[allow(improper_ctypes)] #[allow(improper_ctypes)]
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[link(name = "ApplicationServices", kind = "framework")] #[link(name = "ApplicationServices", kind = "framework")]
#[link(name = "Carbon", kind = "framework")]
extern "C" { extern "C" {
fn CFDataGetBytePtr(theData: CFDataRef) -> *const u8; fn CFDataGetBytePtr(theData: CFDataRef) -> *const u8;
fn TISCopyCurrentKeyboardInputSource() -> TISInputSourceRef; fn TISCopyCurrentKeyboardInputSource() -> TISInputSourceRef;

View File

@ -288,6 +288,7 @@ fn modifier_sleep() {
} }
#[inline] #[inline]
#[cfg(not(target_os = "macos"))]
fn is_pressed(key: &Key, en: &mut Enigo) -> bool { fn is_pressed(key: &Key, en: &mut Enigo) -> bool {
get_modifier_state(key.clone(), en) get_modifier_state(key.clone(), en)
} }
@ -780,13 +781,13 @@ fn click_capslock(en: &mut Enigo) {
#[cfg(not(targe_os = "macos"))] #[cfg(not(targe_os = "macos"))]
en.key_click(enigo::Key::CapsLock); en.key_click(enigo::Key::CapsLock);
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
en.key_down(enigo::Key::CapsLock); let _ = en.key_down(enigo::Key::CapsLock);
} }
fn click_numlock(en: &mut Enigo) { fn click_numlock(_en: &mut Enigo) {
// without numlock in macos // without numlock in macos
#[cfg(not(target_os = "macos"))] #[cfg(not(target_os = "macos"))]
en.key_click(enigo::Key::NumLock); _en.key_click(enigo::Key::NumLock);
} }
fn sync_numlock_capslock_status(key_event: &KeyEvent) { fn sync_numlock_capslock_status(key_event: &KeyEvent) {
@ -872,6 +873,7 @@ fn is_altgr_pressed() -> bool {
.is_some() .is_some()
} }
#[cfg(not(target_os = "macos"))]
fn press_modifiers(en: &mut Enigo, key_event: &KeyEvent, to_release: &mut Vec<Key>) { fn press_modifiers(en: &mut Enigo, key_event: &KeyEvent, to_release: &mut Vec<Key>) {
for ref ck in key_event.modifiers.iter() { for ref ck in key_event.modifiers.iter() {
if let Some(key) = control_key_value_to_key(ck.value()) { if let Some(key) = control_key_value_to_key(ck.value()) {
@ -889,14 +891,14 @@ fn press_modifiers(en: &mut Enigo, key_event: &KeyEvent, to_release: &mut Vec<Ke
} }
} }
fn sync_modifiers(en: &mut Enigo, key_event: &KeyEvent, to_release: &mut Vec<Key>) { fn sync_modifiers(en: &mut Enigo, key_event: &KeyEvent, _to_release: &mut Vec<Key>) {
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
add_flags_to_enigo(en, key_event); add_flags_to_enigo(en, key_event);
if key_event.down { if key_event.down {
release_unpressed_modifiers(en, key_event); release_unpressed_modifiers(en, key_event);
#[cfg(not(target_os = "macos"))] #[cfg(not(target_os = "macos"))]
press_modifiers(en, key_event, to_release); press_modifiers(en, key_event, _to_release);
} }
} }
@ -944,6 +946,7 @@ fn process_seq(en: &mut Enigo, sequence: &str) {
en.key_sequence(&sequence); en.key_sequence(&sequence);
} }
#[cfg(not(target_os = "macos"))]
fn release_keys(en: &mut Enigo, to_release: &Vec<Key>) { fn release_keys(en: &mut Enigo, to_release: &Vec<Key>) {
for key in to_release { for key in to_release {
en.key_up(key.clone()); en.key_up(key.clone());

View File

@ -1,3 +1,4 @@
#[cfg(any(target_os = "linux", target_os = "windows"))]
use super::ui_interface::get_option_opt; use super::ui_interface::get_option_opt;
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
use hbb_common::log::{debug, error, info}; use hbb_common::log::{debug, error, info};
@ -44,7 +45,7 @@ pub fn start_tray() {
} else { } else {
*control_flow = ControlFlow::Wait; *control_flow = ControlFlow::Wait;
} }
let stopped = is_service_stoped(); let stopped = is_service_stopped();
let state = if stopped { 2 } else { 1 }; let state = if stopped { 2 } else { 1 };
let old = *old_state.lock().unwrap(); let old = *old_state.lock().unwrap();
if state != old { if state != old {
@ -101,7 +102,7 @@ pub fn start_tray() {
} }
if let Some(mut appindicator) = get_default_app_indicator() { if let Some(mut appindicator) = get_default_app_indicator() {
let mut menu = gtk::Menu::new(); let mut menu = gtk::Menu::new();
let stoped = is_service_stoped(); let stoped = is_service_stopped();
// start/stop service // start/stop service
let label = if stoped { let label = if stoped {
crate::client::translate("Start Service".to_owned()) crate::client::translate("Start Service".to_owned())
@ -137,7 +138,7 @@ pub fn start_tray() {
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn change_service_state() { fn change_service_state() {
if is_service_stoped() { if is_service_stopped() {
debug!("Now try to start service"); debug!("Now try to start service");
crate::ipc::set_option("stop-service", ""); crate::ipc::set_option("stop-service", "");
} else { } else {
@ -151,7 +152,7 @@ fn change_service_state() {
fn update_tray_service_item(item: &gtk::MenuItem) { fn update_tray_service_item(item: &gtk::MenuItem) {
use gtk::traits::GtkMenuItemExt; use gtk::traits::GtkMenuItemExt;
if is_service_stoped() { if is_service_stopped() {
item.set_label(&crate::client::translate("Start Service".to_owned())); item.set_label(&crate::client::translate("Start Service".to_owned()));
} else { } else {
item.set_label(&crate::client::translate("Stop service".to_owned())); item.set_label(&crate::client::translate("Stop service".to_owned()));
@ -194,7 +195,8 @@ fn get_default_app_indicator() -> Option<AppIndicator> {
/// Check if service is stoped. /// Check if service is stoped.
/// Return [`true`] if service is stoped, [`false`] otherwise. /// Return [`true`] if service is stoped, [`false`] otherwise.
#[inline] #[inline]
fn is_service_stoped() -> bool { #[cfg(any(target_os = "linux", target_os = "windows"))]
fn is_service_stopped() -> bool {
if let Some(v) = get_option_opt("stop-service") { if let Some(v) = get_option_opt("stop-service") {
v == "Y" v == "Y"
} else { } else {

View File

@ -158,6 +158,7 @@ pub fn get_license() -> String {
} }
#[inline] #[inline]
#[cfg(any(target_os = "linux", target_os = "windows"))]
pub fn get_option_opt(key: &str) -> Option<String> { pub fn get_option_opt(key: &str) -> Option<String> {
OPTIONS.lock().unwrap().get(key).map(|x| x.clone()) OPTIONS.lock().unwrap().get(key).map(|x| x.clone())
} }
@ -199,11 +200,13 @@ pub fn set_local_flutter_config(key: String, value: String) {
LocalConfig::set_flutter_config(key, value); LocalConfig::set_flutter_config(key, value);
} }
#[cfg(feature = "flutter")]
#[inline] #[inline]
pub fn get_kb_layout_type() -> String { pub fn get_kb_layout_type() -> String {
LocalConfig::get_kb_layout_type() LocalConfig::get_kb_layout_type()
} }
#[cfg(feature = "flutter")]
#[inline] #[inline]
pub fn set_kb_layout_type(kb_layout_type: String) { pub fn set_kb_layout_type(kb_layout_type: String) {
LocalConfig::set_kb_layout_type(kb_layout_type); LocalConfig::set_kb_layout_type(kb_layout_type);