Skip to content

Commit

Permalink
Copy & paste from #94, since that PR was abandoned by its author.
Browse files Browse the repository at this point in the history
  • Loading branch information
haimgel committed Oct 21, 2023
1 parent 77b63a9 commit bc6aa19
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 2 deletions.
102 changes: 100 additions & 2 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 @@ -31,6 +31,7 @@ ddc-macos = "^0.2"
[target.'cfg(target_os = "linux")'.dependencies]
ddc-i2c = "^0.2"
nvapi = "^0.1"
uinput = "^0.1"

[target.'cfg(target_os = "windows")'.dependencies]
winapi = { version = "^0.3", features = ["winuser", "libloaderapi"] }
Expand Down
19 changes: 19 additions & 0 deletions src/platform/wake_displays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,25 @@ pub fn wake_displays() -> Result<()> {

#[cfg(target_os = "linux")]
pub fn wake_displays() -> Result<()> {
use anyhow::Context;
use std::{thread, time};
use uinput::{Device, event::keyboard};

fn make_kbd_device() -> Result<Device> {
Ok(uinput::default()?
.name("display-switch")?
.event(uinput::event::Keyboard::All)?
.create()?)
}

let mut device = make_kbd_device().context("Couldn't wake displays: couldn't configure uinput")?;

// This sleep appears to be necessary based on testing.
// Possibly X does not immediately recognize the new device?
thread::sleep(time::Duration::from_secs(1));

device.click(&keyboard::Key::RightAlt)?;
device.synchronize()?;
Ok(())
}

Expand Down

0 comments on commit bc6aa19

Please sign in to comment.