Skip to content

Fix: Added rfkill support as a feature flag #298

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ We have packaged `swhkd-git`. `swhkd-bin` has been packaged separately by a user

`swhkd` and `swhks` install to `/usr/local/bin/` by default. You can change this behaviour by editing the [Makefile](../Makefile) variable, `DESTDIR`, which acts as a prefix for all installed files. You can also specify it in the make command line, e.g. to install everything in `subdir`: `make DESTDIR="subdir" install`.

Note: On some systems swhkd daemon might disable wifi due to issues with rfkill, you could pass `make NO_RFKILL_SW_SUPPORT=1` while buliding to disable rfkill support.

# Dependencies:

**Runtime:**
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ MAN1_DIR := /usr/share/man/man1
MAN5_DIR := /usr/share/man/man5
VERSION = $(shell awk -F ' = ' '$$1 ~ /version/ { gsub(/["]/, "", $$2); printf("%s",$$2) }' Cargo.toml)

ifneq ($(NO_RFKILL_SW_SUPPORT),)
BUILDFLAGS += --features "no_rfkill"
endif

all: build

build:
Expand Down
4 changes: 2 additions & 2 deletions contrib/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

_pkgname="swhkd"
pkgname="${_pkgname}-git"
pkgver=1.2.1.r17.g022466e
pkgver=1.2.1.r92.ge972f55
pkgrel=1
arch=("x86_64")
url="https://github.com/waycrate/swhkd"
Expand All @@ -21,7 +21,7 @@ sha256sums=("SKIP"
build(){
cd "$_pkgname"
make setup
make
make NO_RFKILL_SW_SUPPORT=1
}

package() {
Expand Down
3 changes: 3 additions & 0 deletions swhkd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ authors = [
[build-dependencies]
flate2 = "1.0.24"

[features]
no_rfkill = []

[dependencies]
clap = { version = "4.1.0", features = ["derive"] }
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(not(feature = "no_rfkill"))]
use nix::ioctl_none;
#[cfg(not(feature = "no_rfkill"))]
use std::fs::File;
#[cfg(not(feature = "no_rfkill"))]
use std::os::unix::io::AsRawFd;

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

pub fn create_uinput_device() -> Result<VirtualDevice, Box<dyn std::error::Error>> {
Expand Down Expand Up @@ -36,10 +40,15 @@ 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 for it causes issues with radio on some platforms.
#[cfg(not(feature = "no_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 Expand Up @@ -622,6 +631,7 @@ pub fn get_all_switches() -> &'static [SwitchType] {
SwitchType::SW_LID,
SwitchType::SW_TABLET_MODE,
SwitchType::SW_HEADPHONE_INSERT,
#[cfg(not(feature = "no_rfkill"))]
SwitchType::SW_RFKILL_ALL,
SwitchType::SW_MICROPHONE_INSERT,
SwitchType::SW_DOCK,
Expand Down
Loading