Fix Monitor::connector None on plugging in new monitor
This commit is contained in:
17
src/ui.rs
17
src/ui.rs
@@ -12,6 +12,7 @@ use gtk4_layer_shell::{Edge, KeyboardMode, Layer, LayerShell};
|
|||||||
use jmb_logger_rs::*;
|
use jmb_logger_rs::*;
|
||||||
use mpris::PlayerFinder;
|
use mpris::PlayerFinder;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::rc::Rc;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
@@ -25,7 +26,7 @@ mod workspaces_panel;
|
|||||||
pub fn create_bars(app: &Application, backend: Backend) {
|
pub fn create_bars(app: &Application, backend: Backend) {
|
||||||
let display = Display::default().expect("Couldn't find GDK Display");
|
let display = Display::default().expect("Couldn't find GDK Display");
|
||||||
let app_clone = app.clone();
|
let app_clone = app.clone();
|
||||||
let bars: Mutex<HashMap<u32, ApplicationWindow>> = Mutex::new(HashMap::new());
|
let bars: Rc<Mutex<HashMap<u32, ApplicationWindow>>> = Rc::new(Mutex::new(HashMap::new()));
|
||||||
let ac_channels = backend.subscribe();
|
let ac_channels = backend.subscribe();
|
||||||
let action_centre = ActionCentre::create_action_centre(app.clone(), ac_channels);
|
let action_centre = ActionCentre::create_action_centre(app.clone(), ac_channels);
|
||||||
for monitor in 0..display.monitors().n_items() {
|
for monitor in 0..display.monitors().n_items() {
|
||||||
@@ -52,17 +53,17 @@ pub fn create_bars(app: &Application, backend: Backend) {
|
|||||||
}
|
}
|
||||||
} else if added == 1 {
|
} else if added == 1 {
|
||||||
debug!(&LOGGER, "Detected new monitor: {pos}");
|
debug!(&LOGGER, "Detected new monitor: {pos}");
|
||||||
|
let app_clone = app_clone.clone();
|
||||||
|
let action_centre = action_centre.clone();
|
||||||
let channels = backend.subscribe();
|
let channels = backend.subscribe();
|
||||||
|
let bars = bars.clone();
|
||||||
|
let display = display.clone();
|
||||||
|
glib::idle_add_local_once(move || {
|
||||||
bars.lock().expect("Couldn't get active bars").insert(
|
bars.lock().expect("Couldn't get active bars").insert(
|
||||||
pos,
|
pos,
|
||||||
create_bar(
|
create_bar(app_clone, &display, pos, action_centre, channels),
|
||||||
app_clone.clone(),
|
|
||||||
&display,
|
|
||||||
pos,
|
|
||||||
action_centre.clone(),
|
|
||||||
channels,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,10 +62,20 @@ pub fn build(
|
|||||||
String::new()
|
String::new()
|
||||||
};
|
};
|
||||||
let monitor_valid = !monitor.is_empty();
|
let monitor_valid = !monitor.is_empty();
|
||||||
|
println!(
|
||||||
|
"{:?}",
|
||||||
|
monitors
|
||||||
|
.item(monitor_idx)
|
||||||
|
.unwrap()
|
||||||
|
.downcast::<gdk::Monitor>()
|
||||||
|
.unwrap()
|
||||||
|
.connector()
|
||||||
|
);
|
||||||
if monitor_valid {
|
if monitor_valid {
|
||||||
let _ = channels
|
let _ = channels
|
||||||
.br_tx()
|
.br_tx()
|
||||||
.send(BrightnessMessage::Request(monitor.clone()));
|
.send(BrightnessMessage::Request(monitor.clone()));
|
||||||
|
println!("req");
|
||||||
}
|
}
|
||||||
|
|
||||||
let volume_adjustment = Adjustment::new(60.0, 1.0, 100.0, 1.0, 5.0, 0.0);
|
let volume_adjustment = Adjustment::new(60.0, 1.0, 100.0, 1.0, 5.0, 0.0);
|
||||||
|
|||||||
Reference in New Issue
Block a user