Skip to content

Commit

Permalink
feat: use human friendly monitor names (#1272)
Browse files Browse the repository at this point in the history
* feat: use human friendly monitor names

* refactor: capture anything that is not minimized on all platforms

* chore: delete unnecessary dependency

* fix: save _actual_ `is_focused` value instead of if window is valid

* chore: use same xcap version for all OSes

* fix: consider old macos as default behavior
  • Loading branch information
ologbonowiwi authored Feb 15, 2025
1 parent e6c9d04 commit 7f07416
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 25 deletions.
6 changes: 3 additions & 3 deletions screenpipe-vision/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ tracing = { workspace = true }
which = "6.0"
serde = "1.0.200"

# TO-DO: use a released version. Done for now to avoid waiting xcap release.
xcap = { package = "xcap", git = "https://github.com/nashaofu/xcap", rev = "214cb44" }

once_cell = { workspace = true }
chrono = { version = "0.4.39", features = ["serde"] }
base64 = "0.22.1"
Expand Down Expand Up @@ -96,13 +99,10 @@ windows = { version = "0.58", features = [
"Storage",
"Storage_Streams",
] }
xcap = "0.0.12"

[target.'cfg(target_os = "macos")'.dependencies]
libc = "=0.2.164"
xcap-macos = { package = "xcap", git = "https://github.com/mediar-ai/xcap", rev = "965bc99" }
cidre = { git = "https://github.com/yury/cidre.git", version = "0.5.0" }

[target.'cfg(target_os = "linux")'.dependencies]
libc = "=0.2.164"
xcap = "0.0.14"
11 changes: 1 addition & 10 deletions screenpipe-vision/src/capture_screenshot_by_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ use std::fmt;
use std::time::Duration;
use tokio::time;

#[cfg(target_os = "macos")]
use xcap_macos::{Monitor, Window, XCapError};

#[cfg(not(target_os = "macos"))]
use xcap::{Monitor, Window, XCapError};

#[derive(Debug)]
Expand Down Expand Up @@ -238,7 +234,7 @@ pub async fn capture_all_visible_windows(
image,
app_name: app_name.to_string(),
window_name: window_name.to_string(),
is_focused: is_valid,
is_focused: window.is_focused(),
});
}
Err(e) => error!(
Expand All @@ -260,13 +256,8 @@ pub fn is_valid_window(
capture_unfocused_windows: bool,
) -> bool {
if !capture_unfocused_windows {
// Early returns for simple checks
#[cfg(target_os = "macos")]
let is_focused = window.current_monitor().id() == monitor.id() && window.is_focused();

#[cfg(not(target_os = "macos"))]
let is_focused = window.current_monitor().id() == monitor.id() && !window.is_minimized();

if !is_focused {
return false;
}
Expand Down
4 changes: 0 additions & 4 deletions screenpipe-vision/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ use tokio::io::{AsyncBufReadExt, BufReader};
use tokio::sync::mpsc::Sender;
use tokio::time::sleep;

#[cfg(target_os = "macos")]
use xcap_macos::Monitor;

#[cfg(not(target_os = "macos"))]
use xcap::Monitor;

fn serialize_image<S>(image: &Option<DynamicImage>, serializer: S) -> Result<S::Ok, S::Error>
Expand Down
4 changes: 0 additions & 4 deletions screenpipe-vision/src/monitor.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
#[cfg(target_os = "macos")]
use xcap_macos::Monitor;

#[cfg(not(target_os = "macos"))]
use xcap::Monitor;

pub async fn list_monitors() -> Vec<Monitor> {
Expand Down
4 changes: 0 additions & 4 deletions screenpipe-vision/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ use log::{debug, error, warn};
use std::hash::{DefaultHasher, Hash, Hasher};
use std::time::{Duration, Instant};

#[cfg(target_os = "macos")]
use xcap_macos::Monitor;

#[cfg(not(target_os = "macos"))]
use xcap::Monitor;

#[derive(Clone, Debug, Default)]
Expand Down

0 comments on commit 7f07416

Please sign in to comment.