Skip to content

Commit 903106b

Browse files
committed
[+] feat: cursor monitor for ubuntu
1 parent 651af49 commit 903106b

File tree

7 files changed

+293
-15
lines changed

7 files changed

+293
-15
lines changed

Cargo.lock

Lines changed: 145 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ platform-dirs = "0.3"
8484

8585
yuv = "0.8"
8686
mp4 = "0.14"
87+
nix = "0.30"
8788
x264 = "0.5"
89+
rdev = "0.5"
8890
open = "5.3"
8991
cpal = "0.16"
9092
hound = "3.5"
@@ -103,10 +105,9 @@ nnnoiseless = "0.5"
103105
derive_builder = "0.20"
104106
wayland-client = "0.31"
105107
fast_image_resize = "5.3"
106-
nix = { version = "0.30", features = ["fs"] }
108+
wayland-protocols = "0.32"
109+
wayland-protocols-wlr = "0.3"
107110
rodio = { version = "0.21", default-features = false }
108-
wayland-protocols-wlr = { version = "0.3", features = ["client"] }
109-
wayland-protocols = { version = "0.32", features = ["client", "unstable"] }
110111

111112
mp4m = { path = "lib/mp4m" }
112113
cutil = { path = "lib/cutil" }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.mcp.json

lib/screen-capture-wayland-portal/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ screen-capture.workspace = true
2525
derive_setters.workspace = true
2626
tokio = { workspace = true, features = ["full"] }
2727
serde = { workspace = true, features = ["derive"] }
28+
rdev = { workspace = true, features = ["unstable_grab"] }
2829

2930
[dev-dependencies]
31+
ctrlc.workspace = true
3032
env_logger.workspace = true
3133
tokio = { workspace = true, features = ["full"] }
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
use screen_capture::MonitorCursorPositionConfig;
2+
use screen_capture_wayland_portal::{available_screens, monitor_cursor_position};
3+
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
4+
5+
fn main() -> Result<(), Box<dyn std::error::Error>> {
6+
env_logger::init();
7+
8+
let screens = available_screens()?;
9+
if screens.is_empty() {
10+
log::warn!("No screens found!");
11+
return Ok(());
12+
}
13+
14+
log::debug!("Available screens:");
15+
for (i, screen) in screens.iter().enumerate() {
16+
log::debug!(
17+
"{}: {} ({}x{} at {},{})",
18+
i,
19+
screen.name,
20+
screen.logical_size.width,
21+
screen.logical_size.height,
22+
screen.position.x,
23+
screen.position.y
24+
);
25+
}
26+
27+
let screen_info = screens[0].clone();
28+
log::debug!("\nUsing screen: {}", screen_info.name);
29+
30+
let stop_signal = std::sync::Arc::new(AtomicBool::new(false));
31+
let stop_signal_clone = stop_signal.clone();
32+
33+
ctrlc::set_handler(move || {
34+
log::debug!("\nReceived Ctrl+C, stopping...");
35+
stop_signal_clone.store(true, Ordering::Relaxed);
36+
})?;
37+
38+
log::debug!("Starting cursor position tracking... Move your mouse around!");
39+
log::debug!("Press Ctrl+C to stop.");
40+
41+
let config = MonitorCursorPositionConfig::new(screen_info, stop_signal.clone());
42+
43+
let position_count = std::sync::Arc::new(AtomicU64::new(0));
44+
let position_count_clone = position_count.clone();
45+
46+
if let Err(e) = monitor_cursor_position(config, move |position| {
47+
let count = position_count_clone.fetch_add(1, Ordering::Relaxed) + 1;
48+
49+
log::debug!(
50+
"Cursor #{}: x={}, y={} (output: {},{} size: {}x{})",
51+
count,
52+
position.x,
53+
position.y,
54+
position.output_x,
55+
position.output_y,
56+
position.output_width,
57+
position.output_height
58+
);
59+
}) {
60+
log::warn!("Cursor monitoring error: {}", e);
61+
}
62+
63+
let total_positions = position_count.load(Ordering::Relaxed);
64+
log::debug!("Received {} cursor position updates.", total_positions);
65+
66+
Ok(())
67+
}

0 commit comments

Comments
 (0)