Skip to content

Commit

Permalink
feat: multi monitor support
Browse files Browse the repository at this point in the history
  • Loading branch information
decipher3114 committed Oct 23, 2024
1 parent b8d01cd commit 57d6340
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ iced = { version = "0.13", features = ["advanced", "canvas", "multi-window", "im
iced_anim = { version = "0.1", features = ["derive", "serde"] }
indexmap = "2.6"
interprocess = { version = "2.2", features = ["tokio"] }
mouse_position = "0.1"
rdev = { git = "https://github.com/rustdesk-org/rdev", branch = "master"}
rfd = { version = "0.14", features = ["gtk3", "tokio"], default-features = false }
serde = { version = "1.0", features = ["derive"] }
Expand Down
17 changes: 10 additions & 7 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use iced::{
},
Point, Size, Subscription, Task,
};
use mouse_position::mouse_position::Mouse;
use rfd::FileDialog;
use tray_icon::TrayIcon;
use xcap::Monitor;
Expand All @@ -33,7 +34,6 @@ pub struct App {
#[expect(dead_code)]
pub tray_icon: TrayIcon,
pub config: Config,
pub monitors: Vec<Monitor>,
pub windows: BTreeMap<Id, AppWindow>,
}

Expand All @@ -55,14 +55,13 @@ pub enum AppEvent {
}

impl App {
pub fn new(monitors: Vec<Monitor>) -> (App, Task<AppEvent>) {
pub fn new() -> (App, Task<AppEvent>) {
let (config, is_initial) = Config::new();
let tray_icon = create_tray_icon();
(
App {
tray_icon,
config,
monitors,
windows: BTreeMap::new(),
},
if is_initial {
Expand Down Expand Up @@ -155,11 +154,15 @@ impl App {
AppWindow::Capture(_)
)
{
let current_monitor = &self.monitors[0];
let (x, y) = match Mouse::get_mouse_position() {
Mouse::Position { x, y } => (x, y),
Mouse::Error => (0, 0),
};
let monitor = Monitor::from_point(x, y).unwrap();
let (id, open_task) = window::open(window::Settings {
position: Position::Specific(Point::new(
current_monitor.x() as f32,
current_monitor.y() as f32,
monitor.x() as f32,
monitor.y() as f32,
)),
transparent: true,
decorations: false,
Expand All @@ -171,7 +174,7 @@ impl App {
},
..Default::default()
});
let capture_window = CaptureWindow::new(current_monitor.clone());
let capture_window = CaptureWindow::new(monitor);
self.windows
.insert(id, AppWindow::Capture(Box::new(capture_window)));
return open_task
Expand Down
5 changes: 1 addition & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use app::App;
use consts::{APPNAME, FONT_BOLD, FONT_ICONS, FONT_MEDIUM, MEDIUM};
use iced::daemon;
use interprocess::local_socket::{traits::Stream, GenericNamespaced, ToNsName};
use xcap::Monitor;

mod app;
mod config;
Expand All @@ -22,8 +21,6 @@ pub fn main() -> Result<(), iced::Error> {
return Ok(());
};

let monitors = Monitor::all().unwrap();

daemon(App::title, App::update, App::view)
.font(FONT_MEDIUM)
.font(FONT_BOLD)
Expand All @@ -34,5 +31,5 @@ pub fn main() -> Result<(), iced::Error> {
.theme(App::theme)
.subscription(App::subscription)
.antialiasing(true)
.run_with(move || App::new(monitors))
.run_with(App::new)
}

0 comments on commit 57d6340

Please sign in to comment.