mirror of
https://github.com/Zenithsiz/zsw.git
synced 2026-02-03 17:52:15 +00:00
Removed WindowMonitorNames.
This commit is contained in:
parent
1185a1b01b
commit
2edcce509c
@ -50,7 +50,6 @@ use {
|
||||
playlist::Playlists,
|
||||
profile::{ProfileName, Profiles},
|
||||
shared::{Shared, SharedWindow},
|
||||
window::WindowMonitorNames,
|
||||
},
|
||||
app_error::Context,
|
||||
args::Args,
|
||||
@ -222,8 +221,7 @@ impl WinitApp {
|
||||
profiles,
|
||||
panels: Arc::new(Panels::new()),
|
||||
metrics: Metrics::new(),
|
||||
window_monitor_names: WindowMonitorNames::new(),
|
||||
windows: Mutex::new(vec![]),
|
||||
windows: Mutex::new(HashMap::new()),
|
||||
};
|
||||
let shared = Arc::new(shared);
|
||||
|
||||
@ -252,10 +250,6 @@ impl WinitApp {
|
||||
let windows = window::create(event_loop, self.config.transparent_windows)
|
||||
.context("Unable to create winit event loop and window")?;
|
||||
for app_window in windows {
|
||||
self.shared
|
||||
.window_monitor_names
|
||||
.add(app_window.window.id(), app_window.monitor_name.clone());
|
||||
|
||||
let window = Arc::new(app_window.window);
|
||||
let wgpu_renderer =
|
||||
WgpuRenderer::new(Arc::clone(&window), &self.shared.wgpu).context("Unable to create wgpu renderer")?;
|
||||
@ -270,7 +264,7 @@ impl WinitApp {
|
||||
|
||||
let shared_window = Arc::new(SharedWindow {
|
||||
window,
|
||||
_monitor_name: app_window.monitor_name,
|
||||
monitor_name: app_window.monitor_name,
|
||||
monitor_geometry: Mutex::new(app_window.monitor_geometry),
|
||||
});
|
||||
|
||||
@ -294,7 +288,12 @@ impl WinitApp {
|
||||
egui_event_handler,
|
||||
renderer_event_tx,
|
||||
});
|
||||
self.shared.windows.lock().await.push(shared_window);
|
||||
_ = self
|
||||
.shared
|
||||
.windows
|
||||
.lock()
|
||||
.await
|
||||
.insert(shared_window.window.id(), shared_window);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@ -448,7 +447,7 @@ async fn paint_egui(
|
||||
&shared.profiles,
|
||||
&shared.panels,
|
||||
&shared.metrics,
|
||||
&shared.window_monitor_names,
|
||||
&shared.windows.lock().block_on(),
|
||||
&shared.event_loop_proxy,
|
||||
window_geometry,
|
||||
)
|
||||
|
||||
@ -19,16 +19,17 @@ use {
|
||||
panel::Panels,
|
||||
playlist::Playlists,
|
||||
profile::Profiles,
|
||||
window::WindowMonitorNames,
|
||||
shared::SharedWindow,
|
||||
},
|
||||
core::{ops::RangeInclusive, str::FromStr, time::Duration},
|
||||
egui::Widget,
|
||||
std::{
|
||||
collections::HashMap,
|
||||
path::Path,
|
||||
sync::{Arc, nonpoison::Mutex},
|
||||
},
|
||||
strum::IntoEnumIterator,
|
||||
winit::event_loop::EventLoopProxy,
|
||||
winit::{event_loop::EventLoopProxy, window::WindowId},
|
||||
zsw_util::{AppError, DurationDisplay, Rect},
|
||||
zsw_wgpu::Wgpu,
|
||||
};
|
||||
@ -62,7 +63,8 @@ impl Menu {
|
||||
profiles: &Arc<Profiles>,
|
||||
panels: &Arc<Panels>,
|
||||
metrics: &Metrics,
|
||||
window_monitor_names: &WindowMonitorNames,
|
||||
// TODO: Not pass in the shared window type here
|
||||
shared_windows: &HashMap<WindowId, Arc<SharedWindow>>,
|
||||
event_loop_proxy: &EventLoopProxy<AppEvent>,
|
||||
window_geometry: Rect<i32, u32>,
|
||||
) {
|
||||
@ -92,7 +94,7 @@ impl Menu {
|
||||
Tab::Displays => displays::draw_displays_tab(ui, displays),
|
||||
Tab::Playlists => playlists::draw_playlists_tab(ui, playlists),
|
||||
Tab::Profiles => profiles::draw_profiles_tab(ui, displays, playlists, profiles, panels),
|
||||
Tab::Metrics => metrics::draw_metrics_tab(ui, metrics, window_monitor_names),
|
||||
Tab::Metrics => metrics::draw_metrics_tab(ui, metrics, shared_windows),
|
||||
Tab::Settings => self::draw_settings_tab(ui, event_loop_proxy),
|
||||
}
|
||||
});
|
||||
|
||||
@ -5,14 +5,17 @@ mod frame_times;
|
||||
|
||||
// Imports
|
||||
use {
|
||||
crate::{metrics::Metrics, window::WindowMonitorNames},
|
||||
std::collections::BTreeSet,
|
||||
crate::{metrics::Metrics, shared::SharedWindow},
|
||||
std::{
|
||||
collections::{BTreeSet, HashMap},
|
||||
sync::Arc,
|
||||
},
|
||||
winit::window::WindowId,
|
||||
zsw_util::TokioTaskBlockOn,
|
||||
};
|
||||
|
||||
/// Draws the metrics tab
|
||||
pub fn draw_metrics_tab(ui: &mut egui::Ui, metrics: &Metrics, window_monitor_names: &WindowMonitorNames) {
|
||||
pub fn draw_metrics_tab(ui: &mut egui::Ui, metrics: &Metrics, shared_windows: &HashMap<WindowId, Arc<SharedWindow>>) {
|
||||
let cur_metric = super::get_data::<Metric>(ui, "metrics-tab-cur-metric");
|
||||
let mut cur_metric = cur_metric.lock();
|
||||
ui.horizontal(|ui| {
|
||||
@ -30,7 +33,7 @@ pub fn draw_metrics_tab(ui: &mut egui::Ui, metrics: &Metrics, window_monitor_nam
|
||||
match *cur_metric {
|
||||
Metric::Window(metric) => {
|
||||
// Get the window, otherwise we have nothing to render
|
||||
let Some(window_id) = self::draw_window_select(ui, metrics, window_monitor_names) else {
|
||||
let Some(window_id) = self::draw_window_select(ui, metrics, shared_windows) else {
|
||||
ui.weak("No window selected");
|
||||
return;
|
||||
};
|
||||
@ -49,15 +52,16 @@ pub fn draw_metrics_tab(ui: &mut egui::Ui, metrics: &Metrics, window_monitor_nam
|
||||
fn draw_window_select(
|
||||
ui: &mut egui::Ui,
|
||||
metrics: &Metrics,
|
||||
window_monitor_names: &WindowMonitorNames,
|
||||
shared_windows: &HashMap<WindowId, Arc<SharedWindow>>,
|
||||
) -> Option<WindowId> {
|
||||
let cur_window_id = super::get_data::<Option<WindowId>>(ui, "metrics-tab-cur-window");
|
||||
let mut cur_window_id = cur_window_id.lock();
|
||||
|
||||
let window_name = |window_id| {
|
||||
window_monitor_names
|
||||
.get(window_id)
|
||||
.unwrap_or_else(|| format!("{window_id:?}"))
|
||||
shared_windows.get(&window_id).map_or_else(
|
||||
|| format!("{window_id:?}"),
|
||||
|shared_window| shared_window.monitor_name.clone(),
|
||||
)
|
||||
};
|
||||
|
||||
let windows = metrics.window_ids::<BTreeSet<_>>().block_on();
|
||||
|
||||
@ -9,11 +9,13 @@ use {
|
||||
panel::{Panels, PanelsRendererShared},
|
||||
playlist::Playlists,
|
||||
profile::Profiles,
|
||||
window::WindowMonitorNames,
|
||||
},
|
||||
std::sync::Arc,
|
||||
std::{collections::HashMap, sync::Arc},
|
||||
tokio::sync::Mutex,
|
||||
winit::{event_loop::EventLoopProxy, window::Window},
|
||||
winit::{
|
||||
event_loop::EventLoopProxy,
|
||||
window::{Window, WindowId},
|
||||
},
|
||||
zsw_util::Rect,
|
||||
zsw_wgpu::Wgpu,
|
||||
};
|
||||
@ -34,9 +36,7 @@ pub struct Shared {
|
||||
|
||||
pub metrics: Metrics,
|
||||
|
||||
pub window_monitor_names: WindowMonitorNames,
|
||||
|
||||
pub windows: Mutex<Vec<Arc<SharedWindow>>>,
|
||||
pub windows: Mutex<HashMap<WindowId, Arc<SharedWindow>>>,
|
||||
}
|
||||
|
||||
/// Shared window data
|
||||
@ -46,7 +46,7 @@ pub struct SharedWindow {
|
||||
pub window: Arc<Window>,
|
||||
|
||||
/// Monitor name
|
||||
pub _monitor_name: String,
|
||||
pub monitor_name: String,
|
||||
|
||||
/// Monitor geometry
|
||||
pub monitor_geometry: Mutex<Rect<i32, u32>>,
|
||||
|
||||
@ -4,11 +4,10 @@
|
||||
use {
|
||||
app_error::Context,
|
||||
cgmath::{Point2, Vector2},
|
||||
std::{collections::HashMap, sync::nonpoison::Mutex},
|
||||
winit::{
|
||||
event_loop::ActiveEventLoop,
|
||||
monitor::MonitorHandle,
|
||||
window::{Fullscreen, Window, WindowAttributes, WindowId, WindowLevel},
|
||||
window::{Fullscreen, Window, WindowAttributes, WindowLevel},
|
||||
},
|
||||
zsw_util::{AppError, Rect},
|
||||
};
|
||||
@ -75,29 +74,3 @@ fn monitor_geometry(monitor: &MonitorHandle) -> Rect<i32, u32> {
|
||||
size: Vector2::new(monitor_size.width, monitor_size.height),
|
||||
}
|
||||
}
|
||||
|
||||
/// Window monitor names
|
||||
#[derive(Debug)]
|
||||
pub struct WindowMonitorNames {
|
||||
/// Inner
|
||||
inner: Mutex<HashMap<WindowId, String>>,
|
||||
}
|
||||
|
||||
impl WindowMonitorNames {
|
||||
/// Creates an empty map of window names
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
inner: Mutex::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds a window's monitor name
|
||||
pub fn add(&self, window_id: WindowId, name: impl Into<String>) {
|
||||
_ = self.inner.lock().insert(window_id, name.into())
|
||||
}
|
||||
|
||||
/// Gets a window's monitor name.
|
||||
pub fn get(&self, window_id: WindowId) -> Option<String> {
|
||||
self.inner.lock().get(&window_id).cloned()
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user