Skip to content

Commit

Permalink
Actually, verifiably fix #63, #20
Browse files Browse the repository at this point in the history
  • Loading branch information
TTWNO committed Dec 23, 2022
1 parent 1cb4ebc commit a73c58b
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions sohkd/src/uinput.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,6 @@ pub fn create_uinput_device() -> Result<VirtualDevice, Box<dyn std::error::Error
relative_axes.insert(axis);
}

// We have to disable rfkill-input to avoid blocking all radio devices. When
// a new device (virtual or physical) with the SW_RFKILL_ALL capability bit
// set appears, rfkill reacts immediately depending on the value bit. This
// value bit defaults to unset, which causes rfkill to use its default mode
// (which is eop - emergency power off). The uinput API does not give any
// way to set the corresponding value bit before creating the device, and we
// have no way to avoid rfkill acting upon the device creation or to change
// its default mode. Thus, we disable rfkill-input temporarily, hopefully
// fast enough that it won't impact anyone. rfkill-input will be enabled
// again when the file gets closed.
let rfkill_file = File::open("/dev/rfkill")?;
unsafe {
rfkill_noinput(rfkill_file.as_raw_fd())?;
}

let device = VirtualDeviceBuilder::new()?
.name("sohkd virtual output")
.with_keys(&keys)?
Expand All @@ -50,6 +35,20 @@ pub fn create_uinput_switches_device() -> Result<VirtualDevice, Box<dyn std::err
switches.insert(switch);
}

// We have to disable rfkill-input to avoid blocking all radio devices. When
// a new device (virtual or physical) with the SW_RFKILL_ALL capability bit
// set appears, rfkill reacts immediately depending on the value bit. This
// value bit defaults to unset, which causes rfkill to use its default mode
// (which is eop - emergency power off). The uinput API does not give any
// way to set the corresponding value bit before creating the device, and we
// have no way to avoid rfkill acting upon the device creation or to change
// its default mode. Thus, we disable rfkill-input temporarily, hopefully
// fast enough that it won't impact anyone. rfkill-input will be enabled
// again when the file gets closed.
let rfkill_file = File::open("/dev/rfkill")?;
unsafe {
rfkill_noinput(rfkill_file.as_raw_fd())?;
}
let device = VirtualDeviceBuilder::new()?
.name("sohkd switches virtual output")
.with_switches(&switches)?
Expand Down

0 comments on commit a73c58b

Please sign in to comment.