feat, mouse wheel and touchpad scroll mode, default or reverse

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou
2023-09-10 14:14:57 +08:00
parent 405363da59
commit eb0a0662a3
7 changed files with 217 additions and 58 deletions

View File

@@ -1195,6 +1195,17 @@ impl LoginConfigHandler {
self.save_config(config);
}
/// Save mouse scroll mode("default", "reverse") to the current config.
///
/// # Arguments
///
/// * `value` - The view style to be saved.
pub fn save_scroll_mode(&mut self, value: String) {
let mut config = self.load_config();
config.scroll_mode = value;
self.save_config(config);
}
/// Save scroll style to the current config.
///
/// # Arguments

View File

@@ -21,8 +21,6 @@ use hbb_common::{
};
use std::{
collections::HashMap,
ffi::{CStr, CString},
os::raw::c_char,
str::FromStr,
sync::{
atomic::{AtomicI32, Ordering},
@@ -302,6 +300,20 @@ pub fn session_set_keyboard_mode(session_id: SessionID, value: String) {
}
}
pub fn session_get_scroll_mode(session_id: SessionID) -> Option<String> {
if let Some(session) = SESSIONS.read().unwrap().get(&session_id) {
Some(session.get_scroll_mode())
} else {
None
}
}
pub fn session_set_scroll_mode(session_id: SessionID, value: String) {
if let Some(session) = SESSIONS.write().unwrap().get_mut(&session_id) {
session.save_scroll_mode(value);
}
}
pub fn session_get_custom_image_quality(session_id: SessionID) -> Option<Vec<i32>> {
if let Some(session) = SESSIONS.read().unwrap().get(&session_id) {
Some(session.get_custom_image_quality())

View File

@@ -1,4 +1,4 @@
use crate::input::{MOUSE_BUTTON_LEFT, MOUSE_TYPE_DOWN, MOUSE_TYPE_UP};
use crate::input::{MOUSE_BUTTON_LEFT, MOUSE_TYPE_DOWN, MOUSE_TYPE_UP, MOUSE_TYPE_WHEEL};
#[cfg(not(any(target_os = "android", target_os = "ios")))]
use std::{collections::HashMap, sync::atomic::AtomicBool};
use std::{
@@ -175,6 +175,14 @@ impl<T: InvokeUiSession> Session<T> {
self.lc.write().unwrap().save_keyboard_mode(value);
}
pub fn get_scroll_mode(&self) -> String {
self.lc.read().unwrap().scroll_mode.clone()
}
pub fn save_scroll_mode(&mut self, value: String) {
self.lc.write().unwrap().save_scroll_mode(value);
}
pub fn save_view_style(&mut self, value: String) {
self.lc.write().unwrap().save_view_style(value);
}
@@ -730,6 +738,7 @@ impl<T: InvokeUiSession> Session<T> {
});
}
"pan_update" => {
let (x, y) = self.get_scroll_xy((x, y));
touch_evt.set_pan_update(TouchPanUpdate {
x,
y,
@@ -753,11 +762,26 @@ impl<T: InvokeUiSession> Session<T> {
send_pointer_device_event(evt, alt, ctrl, shift, command, self);
}
#[inline]
#[cfg(not(any(target_os = "android", target_os = "ios")))]
fn is_scroll_reverse_mode(&self) -> bool {
self.lc.read().unwrap().scroll_mode.eq("reverse")
}
#[inline]
fn get_scroll_xy(&self, xy: (i32, i32)) -> (i32, i32) {
#[cfg(not(any(target_os = "android", target_os = "ios")))]
if self.is_scroll_reverse_mode() {
return (-xy.0, -xy.1);
}
xy
}
pub fn send_mouse(
&self,
mask: i32,
x: i32,
y: i32,
mut x: i32,
mut y: i32,
alt: bool,
ctrl: bool,
shift: bool,
@@ -772,6 +796,12 @@ impl<T: InvokeUiSession> Session<T> {
}
}
let (x, y) = if mask == MOUSE_TYPE_WHEEL {
self.get_scroll_xy((x, y))
} else {
(x, y)
};
// #[cfg(not(any(target_os = "android", target_os = "ios")))]
let (alt, ctrl, shift, command) =
keyboard::client::get_modifiers_state(alt, ctrl, shift, command);