mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-03-21 04:00:55 +03:00
Compare commits
3 Commits
revert-scr
...
fix-scroll
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b03c7d8bd5 | ||
|
|
0dd413e989 | ||
|
|
4e5a66340a |
@@ -343,9 +343,10 @@ impl Emulation for MacOSEmulation {
|
|||||||
event.post(CGEventTapLocation::HID);
|
event.post(CGEventTapLocation::HID);
|
||||||
}
|
}
|
||||||
PointerEvent::AxisDiscrete120 { axis, value } => {
|
PointerEvent::AxisDiscrete120 { axis, value } => {
|
||||||
|
const LINES_PER_STEP: i32 = 3;
|
||||||
let (count, wheel1, wheel2, wheel3) = match axis {
|
let (count, wheel1, wheel2, wheel3) = match axis {
|
||||||
0 => (1, value, 0, 0), // 0 = vertical => 1 scroll wheel device (y axis)
|
0 => (1, value / (120 / LINES_PER_STEP), 0, 0), // 0 = vertical => 1 scroll wheel device (y axis)
|
||||||
1 => (2, 0, value, 0), // 1 = horizontal => 2 scroll wheel devices (y, x) -> (0, x)
|
1 => (2, 0, value / (120 / LINES_PER_STEP), 0), // 1 = horizontal => 2 scroll wheel devices (y, x) -> (0, x)
|
||||||
_ => {
|
_ => {
|
||||||
log::warn!("invalid scroll event: {axis}, {value}");
|
log::warn!("invalid scroll event: {axis}, {value}");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
@@ -353,7 +354,7 @@ impl Emulation for MacOSEmulation {
|
|||||||
};
|
};
|
||||||
let event = match CGEvent::new_scroll_event(
|
let event = match CGEvent::new_scroll_event(
|
||||||
self.event_source.clone(),
|
self.event_source.clone(),
|
||||||
ScrollEventUnit::PIXEL,
|
ScrollEventUnit::LINE,
|
||||||
count,
|
count,
|
||||||
wheel1,
|
wheel1,
|
||||||
wheel2,
|
wheel2,
|
||||||
|
|||||||
@@ -474,6 +474,9 @@ impl Window {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn request_authorization(&self, fingerprint: &str) {
|
pub(super) fn request_authorization(&self, fingerprint: &str) {
|
||||||
|
if let Some(w) = self.imp().authorization_window.borrow_mut().take() {
|
||||||
|
w.close();
|
||||||
|
}
|
||||||
let window = AuthorizationWindow::new(fingerprint);
|
let window = AuthorizationWindow::new(fingerprint);
|
||||||
window.set_transient_for(Some(self));
|
window.set_transient_for(Some(self));
|
||||||
window.connect_closure(
|
window.connect_closure(
|
||||||
@@ -496,5 +499,6 @@ impl Window {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
window.present();
|
window.present();
|
||||||
|
self.imp().authorization_window.replace(Some(window));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ use gtk::{gdk, gio, glib, Button, CompositeTemplate, Entry, Image, Label, ListBo
|
|||||||
|
|
||||||
use lan_mouse_ipc::{FrontendRequestWriter, DEFAULT_PORT};
|
use lan_mouse_ipc::{FrontendRequestWriter, DEFAULT_PORT};
|
||||||
|
|
||||||
|
use crate::authorization_window::AuthorizationWindow;
|
||||||
|
|
||||||
#[derive(CompositeTemplate, Default)]
|
#[derive(CompositeTemplate, Default)]
|
||||||
#[template(resource = "/de/feschber/LanMouse/window.ui")]
|
#[template(resource = "/de/feschber/LanMouse/window.ui")]
|
||||||
pub struct Window {
|
pub struct Window {
|
||||||
@@ -49,6 +51,7 @@ pub struct Window {
|
|||||||
pub port: Cell<u16>,
|
pub port: Cell<u16>,
|
||||||
pub capture_active: Cell<bool>,
|
pub capture_active: Cell<bool>,
|
||||||
pub emulation_active: Cell<bool>,
|
pub emulation_active: Cell<bool>,
|
||||||
|
pub authorization_window: RefCell<Option<AuthorizationWindow>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[glib::object_subclass]
|
#[glib::object_subclass]
|
||||||
|
|||||||
@@ -128,6 +128,7 @@ impl ListenTask {
|
|||||||
async fn run(mut self) {
|
async fn run(mut self) {
|
||||||
let mut interval = tokio::time::interval(Duration::from_secs(5));
|
let mut interval = tokio::time::interval(Duration::from_secs(5));
|
||||||
let mut last_response = HashMap::new();
|
let mut last_response = HashMap::new();
|
||||||
|
let mut rejected_connections = HashMap::new();
|
||||||
loop {
|
loop {
|
||||||
select! {
|
select! {
|
||||||
e = self.listener.next() => {match e {
|
e = self.listener.next() => {match e {
|
||||||
@@ -156,7 +157,10 @@ impl ListenTask {
|
|||||||
self.event_tx.send(EmulationEvent::Connected { addr, fingerprint }).expect("channel closed");
|
self.event_tx.send(EmulationEvent::Connected { addr, fingerprint }).expect("channel closed");
|
||||||
}
|
}
|
||||||
Some(ListenEvent::Rejected { fingerprint }) => {
|
Some(ListenEvent::Rejected { fingerprint }) => {
|
||||||
self.event_tx.send(EmulationEvent::ConnectionAttempt { fingerprint }).expect("channel closed");
|
if rejected_connections.insert(fingerprint.clone(), Instant::now())
|
||||||
|
.is_none_or(|i| i.elapsed() >= Duration::from_secs(2)) {
|
||||||
|
self.event_tx.send(EmulationEvent::ConnectionAttempt { fingerprint }).expect("channel closed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
None => break
|
None => break
|
||||||
}}
|
}}
|
||||||
|
|||||||
Reference in New Issue
Block a user