Skip to content

Commit

Permalink
feat: improve monitor selection (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrinux committed Jan 13, 2022
1 parent ac5c6d2 commit 5e89bb9
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 26 deletions.
7 changes: 0 additions & 7 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ v4l = { version = "0.12", features = ["libv4l"], default-features = false }
ddc-hi = "0.4"
log = "0.4"
env_logger = "0.9"
md5 = "0.7"

[dev-dependencies]
mockall = "0.10"
2 changes: 1 addition & 1 deletion config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ thresholds = [ 20, 80, 250, 500, 800 ]

# TODO multi-monitor setup is not supported, but wanted!
[[output.backlight]]
name = "Sharp Corporation 0x14A8"
name = "eDP-1"
path = "/sys/class/backlight/intel_backlight"

###################################################################
Expand Down
13 changes: 7 additions & 6 deletions src/brightness/ddcutil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,16 @@ fn get_max_brightness(display: &mut Display) -> Result<u64, Box<dyn Error>> {
.maximum() as u64)
}

fn find_display_by_sn(serial_number: &str) -> Option<Display> {
fn find_display_by_sn(name: &str) -> Option<Display> {
let model = |display: &Display| display.info.model_name.clone();
let serial = |display: &Display| display.info.serial_number.clone();

ddc_hi::Display::enumerate()
.into_iter()
.find_map(|mut display| {
display
.info
.serial_number
.as_ref()
.map(|v| v == serial_number)
model(&display)
.and_then(|model| serial(&display).map(|serial| format!("{} {}", model, serial)))
.and_then(|merged| merged.contains(name).then(|| ()))
.and_then(|_| display.update_capabilities().ok())
.map(|_| display)
})
Expand Down
32 changes: 23 additions & 9 deletions src/frame/capturer/wlroots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ use crate::frame::{object::Object, processor::Processor};
use crate::predictor::Controller;
use std::{cell::RefCell, rc::Rc, thread, time::Duration};
use wayland_client::{
protocol::{wl_output::Event::Geometry, wl_output::WlOutput, wl_registry::WlRegistry},
protocol::{wl_output::WlOutput, wl_registry::WlRegistry},
Display, EventQueue, GlobalManager, Main,
};
use wayland_protocols::wlr::unstable::export_dmabuf::v1::client::{
zwlr_export_dmabuf_frame_v1::{CancelReason, Event},
zwlr_export_dmabuf_manager_v1::ZwlrExportDmabufManagerV1,
};

use wayland_protocols::unstable::xdg_output::v1::client::zxdg_output_manager_v1::ZxdgOutputManagerV1;
use wayland_protocols::unstable::xdg_output::v1::client::zxdg_output_v1::Event::Description;

const DELAY_SUCCESS: Duration = Duration::from_millis(100);
const DELAY_FAILURE: Duration = Duration::from_millis(1000);

Expand All @@ -20,11 +23,13 @@ pub struct Capturer {
dmabuf_manager: Main<ZwlrExportDmabufManagerV1>,
processor: Rc<dyn Processor>,
registry: Main<WlRegistry>,
xdg_output_manager: Main<ZxdgOutputManagerV1>,
}

impl super::Capturer for Capturer {
fn run(&self, output_name: &str, controller: Controller) {
let controller = Rc::new(RefCell::new(controller));

self.globals
.list()
.iter()
Expand All @@ -34,16 +39,21 @@ impl super::Capturer for Capturer {
let capturer = Rc::new(self.clone());
let controller = controller.clone();
let desired_output = output_name.to_string();
output.clone().quick_assign(move |_, event, _| {
if let Geometry { make, model, .. } = event {
let actual_output = format!("{} {}", make, model);
if actual_output == desired_output {
self.xdg_output_manager
.get_xdg_output(&output)
.quick_assign(move |_, event, _| match event {
Description { description } if description.contains(&desired_output) => {
log::debug!(
"Using output '{}' for config '{}'",
description,
desired_output,
);
capturer
.clone()
.capture_frame(controller.clone(), output.clone())
.capture_frame(controller.clone(), output.clone());
}
}
})
_ => {}
});
});

loop {
Expand All @@ -69,12 +79,17 @@ impl Capturer {
.instantiate_exact::<ZwlrExportDmabufManagerV1>(1)
.expect("Unable to init export_dmabuf_manager");

let xdg_output_manager = globals
.instantiate_exact::<ZxdgOutputManagerV1>(3)
.expect("Unable to init xdg_output_manager");

Self {
event_queue: Rc::new(RefCell::new(event_queue)),
globals,
registry,
dmabuf_manager,
processor: processor.into(),
xdg_output_manager,
}
}

Expand All @@ -84,7 +99,6 @@ impl Capturer {
output: Rc<Main<WlOutput>>,
) {
let mut frame = Object::default();

self.dmabuf_manager
.capture_output(0, &output)
.quick_assign(move |data, event, _| match event {
Expand Down
5 changes: 3 additions & 2 deletions src/predictor/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use std::path::PathBuf;

#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct Data {
pub output_name: String,
pub entries: Vec<Entry>,
#[serde(skip)]
pub output_name: String,
}

#[derive(Debug, PartialEq, Eq, Hash, Serialize, Deserialize, Clone)]
Expand Down Expand Up @@ -54,7 +55,7 @@ impl Data {
}

fn path(output_name: &str) -> Result<PathBuf, Box<dyn Error>> {
let filename = format!("{:x}.yaml", md5::compute(output_name));
let filename = format!("{:}.yaml", output_name);
let datadir = dirs::data_dir()
.ok_or("Unable to get data dir")?
.join("wluma");
Expand Down

0 comments on commit 5e89bb9

Please sign in to comment.