Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display wakeup on Linux #126

Merged
merged 4 commits into from
Oct 22, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move mouse instead of keyboard input
haimgel committed Oct 22, 2023
commit 578132248a34ae5149e83ce188287e3c0dbf20eb
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ on: [push, pull_request]

env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
RUST_BACKTRACE: full

jobs:
build:
22 changes: 14 additions & 8 deletions src/platform/wake_displays.rs
Original file line number Diff line number Diff line change
@@ -42,22 +42,28 @@ pub fn wake_displays() -> Result<()> {
pub fn wake_displays() -> Result<()> {
use anyhow::Context;
use std::{thread, time};
use uinput::{Device, event::keyboard};
use uinput::event::controller::Controller::Mouse;
use uinput::event::controller::Mouse::Left;
use uinput::event::Event::{Controller, Relative};
use uinput::event::relative::Position::X;
use uinput::event::relative::Relative::Position;

fn make_kbd_device() -> Result<Device> {
Ok(uinput::default()?
let mut device = uinput::default()?
.name("display-switch")?
.event(uinput::event::Keyboard::All)?
.create()?)
}
// It's necessary to enable any mouse button. Otherwise Relative events would not work.
.event(Controller(Mouse(Left)))?
.event(Relative(Position(X)))?
.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.send(X, -1)?;
device.synchronize()?;
thread::sleep(time::Duration::from_millis(50));
device.send(X, 1)?;
device.synchronize()?;
Ok(())
}