Repository navigation
Unmask ThinkPad Bluetooth F10 via thinkpad_acpi bit 20 #13615
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
AnPod
wants to merge
3
commits into
omacom:quattro
Choose a base branch
from
AnPod:cursor/fix-thinkpad-bt-hotkey-e0d3
base: quattro
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
default/systemd/system/omarchy-thinkpad-bluetooth-hotkey.service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| [Unit] | ||
| Description=Enable the ThinkPad Bluetooth hotkey | ||
| After=systemd-modules-load.service | ||
| ConditionPathExists=/sys/devices/platform/thinkpad_acpi/hotkey_mask | ||
|
|
||
| [Service] | ||
| Type=oneshot | ||
| ExecStart=/bin/bash /usr/local/lib/omarchy/thinkpad-bluetooth-hotkey.sh | ||
|
|
||
| [Install] | ||
| WantedBy=multi-user.target |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Preserve the model's current mask, enabling only the Bluetooth hotkey. | ||
| mask_path=/sys/devices/platform/thinkpad_acpi/hotkey_mask | ||
| if [[ -e $mask_path ]]; then | ||
| if current=$(cat "$mask_path" 2>/dev/null); then | ||
| if [[ $current =~ ^0[xX][0-9a-fA-F]+$ ]]; then | ||
| if ! printf '%#x\n' "$((current | 0x00100000))" | tee "$mask_path" >/dev/null; then | ||
| printf 'Warning: failed to write ThinkPad hotkey mask to %s\n' "$mask_path" >&2 | ||
| fi | ||
| else | ||
| printf 'Warning: invalid hexadecimal ThinkPad hotkey mask in %s\n' "$mask_path" >&2 | ||
| fi | ||
| else | ||
| printf 'Warning: failed to read ThinkPad hotkey mask from %s\n' "$mask_path" >&2 | ||
| fi | ||
| fi | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # Unmask the ThinkPad Bluetooth F10 hotkey (thinkpad_acpi bit 20). | ||
|
|
||
| if ! omarchy-hw-match "ThinkPad" && [[ ! -d /sys/module/thinkpad_acpi ]]; then | ||
| return 0 | ||
| fi | ||
|
|
||
| # Copy the helper to a root-owned path before using it at boot. | ||
| sudo install -Dm644 "$OMARCHY_PATH/default/systemd/thinkpad-bluetooth-hotkey.sh" /usr/local/lib/omarchy/thinkpad-bluetooth-hotkey.sh | ||
| sudo install -Dm644 "$OMARCHY_PATH/default/systemd/system/omarchy-thinkpad-bluetooth-hotkey.service" /etc/systemd/system/omarchy-thinkpad-bluetooth-hotkey.service | ||
| sudo systemctl daemon-reload | ||
| sudo systemctl enable omarchy-thinkpad-bluetooth-hotkey.service | ||
| sudo /bin/bash /usr/local/lib/omarchy/thinkpad-bluetooth-hotkey.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| echo "Unmask the ThinkPad Bluetooth F10 hotkey (thinkpad_acpi bit 20)" | ||
|
|
||
| if ! omarchy-hw-match "ThinkPad" && [[ ! -d /sys/module/thinkpad_acpi ]]; then | ||
| exit 0 | ||
| fi | ||
|
|
||
| source "$OMARCHY_PATH/install/hardware/lenovo/fix-thinkpad-bluetooth-hotkey.sh" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" | ||
|
|
||
| leaf=install/hardware/lenovo/fix-thinkpad-bluetooth-hotkey.sh | ||
| migration=migrations/1790544300.sh | ||
| helper=default/systemd/thinkpad-bluetooth-hotkey.sh | ||
| unit=default/systemd/system/omarchy-thinkpad-bluetooth-hotkey.service | ||
| [[ ! -e $ROOT/default/modprobe.d/omarchy-thinkpad-bluetooth-hotkey.conf ]] || | ||
| fail "no model-specific boot mask is shipped" | ||
| rg -Fq 'lenovo/fix-thinkpad-bluetooth-hotkey.sh' "$ROOT/install/hardware/all.sh" || | ||
| fail "hardware setup runs the ThinkPad leaf" | ||
| for line in 'After=systemd-modules-load.service' 'ConditionPathExists=/sys/devices/platform/thinkpad_acpi/hotkey_mask' 'Type=oneshot' 'ExecStart=/bin/bash /usr/local/lib/omarchy/thinkpad-bluetooth-hotkey.sh' 'WantedBy=multi-user.target'; do | ||
| rg -Fxq "$line" "$ROOT/$unit" || fail "boot unit contains $line" | ||
| done | ||
|
|
||
| test_tmp=$(mktemp -d) | ||
| trap 'chmod -R u+rwX "$test_tmp"; rm -rf "$test_tmp"' EXIT | ||
| export OMARCHY_PATH="$test_tmp/repo" TEST_LOG="$test_tmp/calls" TEST_MASK="$test_tmp/mask" | ||
| export TEST_SYS="$test_tmp/sys" TEST_READ_FAIL=0 TEST_WRITE_FAIL=0 TEST_THINKPAD=1 | ||
| mkdir -p "$test_tmp/bin" "$TEST_SYS/module/thinkpad_acpi" "$TEST_SYS/devices/platform/thinkpad_acpi" | ||
| # Redirect filesystem boundaries; execute the actual scripts and copied helper. | ||
| for script in "$leaf" "$migration" "$helper" "$unit"; do | ||
| mkdir -p "$OMARCHY_PATH/$(dirname "$script")" | ||
| sed -e "s|/sys/|$TEST_SYS/|g" -e "s|/etc/|$test_tmp/etc/|g" \ | ||
| -e "s|/usr/local/|$test_tmp/usr/local/|g" "$ROOT/$script" >"$OMARCHY_PATH/$script" | ||
| done | ||
| mkdir -p "$test_tmp/etc/modprobe.d" | ||
| printf 'administrator configuration\n' >"$test_tmp/etc/modprobe.d/omarchy-thinkpad-hotkey.conf" | ||
|
|
||
| cat >"$test_tmp/bin/sudo" <<'STUB' | ||
| #!/bin/bash | ||
| printf '%s\n' "$*" >>"$TEST_LOG" | ||
| case $1 in | ||
| install|/bin/bash) "$@" ;; | ||
| systemctl) ;; | ||
| *) exit 99 ;; | ||
| esac | ||
| STUB | ||
| cat >"$test_tmp/bin/cat" <<'STUB' | ||
| #!/bin/bash | ||
| # Simulate root access to sysfs, including a read failure, even in root-run CI. | ||
| (( TEST_READ_FAIL == 0 )) || exit 1 | ||
| /bin/cat "$TEST_MASK" | ||
| STUB | ||
| cat >"$test_tmp/bin/tee" <<'STUB' | ||
| #!/bin/bash | ||
| (( TEST_WRITE_FAIL == 0 )) || exit 1 | ||
| /usr/bin/tee "$TEST_MASK" | ||
| STUB | ||
| cat >"$test_tmp/bin/omarchy-hw-match" <<'STUB' | ||
| #!/bin/bash | ||
| [[ $1 == "ThinkPad" ]] && (( TEST_THINKPAD == 1 )) | ||
| STUB | ||
| chmod +x "$test_tmp/bin/"* | ||
| export PATH="$test_tmp/bin:$PATH" | ||
| mask_path="$TEST_SYS/devices/platform/thinkpad_acpi/hotkey_mask" | ||
| installed_helper="$test_tmp/usr/local/lib/omarchy/thinkpad-bluetooth-hotkey.sh" | ||
| installed_unit="$test_tmp/etc/systemd/system/omarchy-thinkpad-bluetooth-hotkey.service" | ||
|
|
||
| run_script() { | ||
| bash -euo pipefail -c 'source "$1"; echo survived' bash "$OMARCHY_PATH/$1" >"$test_tmp/output" | ||
| rg -q '^survived$' "$test_tmp/output" || fail "script completes under strict mode" | ||
| cmp "$OMARCHY_PATH/$helper" "$installed_helper" || fail "shared helper is installed" | ||
| cmp "$OMARCHY_PATH/$unit" "$installed_unit" || fail "boot unit is installed" | ||
| rg -Fxq 'systemctl daemon-reload' "$TEST_LOG" || fail "system units are reloaded" | ||
| rg -Fxq 'systemctl enable omarchy-thinkpad-bluetooth-hotkey.service' "$TEST_LOG" || fail "boot unit is enabled" | ||
| rg -Fxq "/bin/bash $installed_helper" "$TEST_LOG" || fail "live mask is applied with root privileges" | ||
| if rg -q 'modprobe|mkinitcpio' "$TEST_LOG"; then fail "no modprobe mask or initramfs rebuild is requested"; fi | ||
| } | ||
|
|
||
| for script in "$leaf" "$migration"; do | ||
| for mask in 0xff8c7ffb 0x00000005 0x00100005; do | ||
| printf '%s\n' "$mask" >"$TEST_MASK" | ||
| if [[ -e $mask_path ]]; then chmod 644 "$mask_path"; fi | ||
| cp "$TEST_MASK" "$mask_path" | ||
| chmod 444 "$mask_path" | ||
| : >"$TEST_LOG" | ||
| run_script "$script" | ||
| expected=$(printf '%#x' "$((mask | 0x00100000))") | ||
| [[ $(<"$TEST_MASK") == "$expected" ]] || fail "only bit 20 changes for $mask" | ||
| run_script "$script" | ||
| [[ $(<"$TEST_MASK") == "$expected" ]] || fail "repeated execution preserves mask" | ||
|
|
||
| # Simulate a reboot resetting the mask, then run the unit's actual ExecStart. | ||
| printf '%s\n' "$mask" >"$TEST_MASK" | ||
| boot_command=$(sed -n 's/^ExecStart=//p' "$installed_unit") | ||
| bash -euo pipefail -c "$boot_command" | ||
| [[ $(<"$TEST_MASK") == "$expected" ]] || fail "boot restores only bit 20 for $mask" | ||
| done | ||
|
|
||
| for failure in read write; do | ||
| export TEST_READ_FAIL=0 TEST_WRITE_FAIL=0 | ||
| if [[ $failure == "read" ]]; then export TEST_READ_FAIL=1; else export TEST_WRITE_FAIL=1; fi | ||
| printf '0x5\n' >"$TEST_MASK" | ||
| : >"$TEST_LOG" | ||
| run_script "$script" 2>"$test_tmp/stderr" | ||
| rg -Fq "Warning: failed to $failure ThinkPad hotkey mask" "$test_tmp/stderr" || fail "failed $failure warns during setup" | ||
| rg -Fq "$mask_path" "$test_tmp/stderr" || fail "failed $failure warning names mask path during setup" | ||
| bash -euo pipefail "$installed_helper" 2>"$test_tmp/stderr" || fail "failed $failure exits successfully" | ||
| rg -Fq "Warning: failed to $failure ThinkPad hotkey mask" "$test_tmp/stderr" || fail "failed $failure warns" | ||
| rg -Fq "$mask_path" "$test_tmp/stderr" || fail "failed $failure warning names mask path" | ||
| [[ $(<"$TEST_MASK") == "0x5" ]] || fail "failed $failure preserves mask" | ||
| done | ||
| export TEST_READ_FAIL=0 TEST_WRITE_FAIL=0 | ||
|
|
||
| printf '0xinvalid\n' >"$TEST_MASK" | ||
| bash -euo pipefail "$installed_helper" 2>"$test_tmp/stderr" || fail "invalid hexadecimal mask exits successfully" | ||
| rg -Fq 'Warning: invalid hexadecimal ThinkPad hotkey mask' "$test_tmp/stderr" || fail "invalid hexadecimal mask warns" | ||
| rg -Fq "$mask_path" "$test_tmp/stderr" || fail "invalid hexadecimal warning names mask path" | ||
| [[ $(<"$TEST_MASK") == "0xinvalid" ]] || fail "invalid hexadecimal mask is preserved" | ||
| printf '0x5\n' >"$TEST_MASK" | ||
|
|
||
| rm -f "$mask_path" | ||
| : >"$TEST_LOG" | ||
| run_script "$script" | ||
| bash -euo pipefail "$installed_helper" | ||
| [[ $(<"$TEST_MASK") == "0x5" ]] || fail "missing sysfs preserves mask" | ||
|
|
||
| rmdir "$TEST_SYS/module/thinkpad_acpi" | ||
| export TEST_THINKPAD=0 | ||
| : >"$TEST_LOG" | ||
| bash -euo pipefail -c 'source "$1"' bash "$OMARCHY_PATH/$script" >"$test_tmp/output" | ||
| [[ ! -s $TEST_LOG ]] || fail "unrelated hardware is untouched" | ||
| export TEST_THINKPAD=1 | ||
| mkdir -p "$TEST_SYS/module/thinkpad_acpi" | ||
|
|
||
| [[ $(<"$test_tmp/etc/modprobe.d/omarchy-thinkpad-hotkey.conf") == "administrator configuration" ]] || | ||
| fail "unrelated configuration is preserved" | ||
| [[ ! -e $test_tmp/etc/modprobe.d/omarchy-thinkpad-bluetooth-hotkey.conf ]] || | ||
| fail "no modprobe configuration is installed" | ||
| pass "$script installs persistence and safely applies the ThinkPad mask under strict mode" | ||
| done |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.