Skip to content

Commit

Permalink
make rfkill feature optional(enabled by default) as in some versions …
Browse files Browse the repository at this point in the history
…of nixos it is broken
  • Loading branch information
id3v1669 committed Jan 28, 2024
1 parent 30f25b5 commit 9701b3f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
DESTDIR ?= "/"
DAEMON_BINARY := swhkd
SERVER_BINARY := swhks
BUILDFLAGS := --release
BUILDFLAGS := --release # add --no-default-features to remove rfkill feature
POLKIT_DIR := /usr/share/polkit-1/actions
POLKIT_POLICY_FILE := com.github.swhkd.pkexec.policy
TARGET_DIR := /usr/bin
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

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

4 changes: 4 additions & 0 deletions swhkd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ authors = [
[build-dependencies]
flate2 = "1.0.24"

[features]
rfkill = []
default = ["rfkill"]

[dependencies]
clap = "3.1.6"
env_logger = "0.9.0"
Expand Down
16 changes: 13 additions & 3 deletions swhkd/src/uinput.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ use evdev::{
AttributeSet, Key, RelativeAxisType, SwitchType,
};

#[cfg(feature = "rfkill")]
use nix::ioctl_none;
#[cfg(feature = "rfkill")]
use std::fs::File;
#[cfg(feature = "rfkill")]
use std::os::unix::io::AsRawFd;

#[cfg(feature = "rfkill")]
ioctl_none!(rfkill_noinput, b'R', 1);

pub fn create_uinput_device() -> Result<VirtualDevice, Box<dyn std::error::Error>> {
Expand Down Expand Up @@ -45,10 +49,16 @@ pub fn create_uinput_switches_device() -> Result<VirtualDevice, Box<dyn std::err
// 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())?;
// Implemented as feature because in some versions of nixos rfkill is broken
// By default feature is enabled
#[cfg(feature = "rfkill")]
{
let rfkill_file = File::open("/dev/rfkill")?;
unsafe {
rfkill_noinput(rfkill_file.as_raw_fd())?;
}
}

let device = VirtualDeviceBuilder::new()?
.name("swhkd switches virtual output")
.with_switches(&switches)?
Expand Down

0 comments on commit 9701b3f

Please sign in to comment.