Skip to content

bluetooth: resync adapter power state via GetAll after InterfacesAdded - #1372

Open
fjgarciainclan wants to merge 1 commit into
quickshell-mirror:masterfrom
fjgarciainclan:fix/bluetooth-adapter-stale-power-state
Open

fjgarciainclan wants to merge 1 commit into
quickshell-mirror:masterfrom
fjgarciainclan:fix/bluetooth-adapter-stale-power-state

Conversation

@fjgarciainclan

Copy link
Copy Markdown

Summary

Fixes #1156 — the Bluetooth adapter's enabled/state can get permanently
stuck on a transitional power state (Enabling/Disabling) even though the
adapter is actually powered and in use, most commonly after sleep/resume when
BlueZ removes and re-registers the adapter object.

Root cause: BluetoothAdapter::addInterface() (src/bluetooth/adapter.cpp)
applies the property values bundled inside the InterfacesAdded D-Bus signal
as the adapter's entire initial state, once, and never re-reads it. That
bundled snapshot is whatever BlueZ's internal state was at the instant it
emitted the signal. If the adapter was still mid-transition at that moment,
and the PropertiesChanged signal that completes the transition reaches the
bus before our subscription (set up in the constructor, immediately before
addInterface runs) is fully installed on the bus daemon, that completing
signal is missed — nothing afterward ever triggers a re-read, so the panel
is stuck showing "off" forever despite bluetoothctl/busctl reporting the
adapter correctly as powered on.

Reproduced and diagnosed from a report on the Omarchy shell (same bug
reported from the shell side: omacom/omarchy#9561), confirmed via
bluetoothctl show / busctl get-property .../Adapter1 Powered showing
Powered: true while the panel (bound to Quickshell's cached adapter state)
displayed "Turned Off".

Fix

After applying the InterfacesAdded snapshot, issue one GetAll call via
the already-existing DBusPropertyGroup::updateAllViaGetAll() to reconcile
with BlueZ's actual current state. Because D-Bus delivers messages from a
single client to the daemon in order, this GetAll request is guaranteed to
be processed only after our PropertiesChanged subscription (sent moments
earlier, in the constructor) is already in effect at the daemon. So either:

  • the adapter had already finished transitioning by the time the GetAll
    reply arrives, and we get the correct state directly, or
  • it's still transitioning, but we're now definitely subscribed, so the real
    completion signal (previously missed) will arrive normally.

This is a single event-triggered read fired once per adapter by the
InterfacesAdded event itself — not a timer-based poll, per the concern
raised on #1156 about a polling approach.

Testing

Built clean against Qt 6.12 (cmake -GNinja -DCMAKE_BUILD_TYPE=Debug /
ninja, 1339/1339 targets, exit 0). I don't have a controllable repro
environment to force BlueZ into emitting an InterfacesAdded with a stuck
transitional snapshot, so this hasn't been runtime-verified against the
original failure yet — flagging that explicitly for review.

The properties bundled with InterfacesAdded are a snapshot BlueZ took at
signal-emission time. If the adapter was still mid-transition (PowerState
"off-enabling"/"on-disabling") at that instant, and the PropertiesChanged
that completes the transition reaches the bus before our PropertiesChanged
subscription (registered in the constructor, just before addInterface runs)
is fully installed, we never see it and are stuck showing the stale
transitional state forever - this is what issue quickshell-mirror#1156 and several Omarchy
duplicates describe.

Re-fetch once via GetAll right after applying the InterfacesAdded snapshot,
now that the subscription is guaranteed live, so we reconcile with BlueZ's
actual current state instead of trusting a possibly-outdated snapshot. This
is a single query triggered by the InterfacesAdded event itself, not a poll.

Fixes quickshell-mirror#1156

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@tangos974

Copy link
Copy Markdown

Tested, and I confirm this fixes it.

Setup: quickshell 0.3.2.r7.g2b4501a (Omarchy 4.0.6), BlueZ 5.87, kernel 7.2.8, Intel AX201.

I hit the bug twice after resume from hibernate; the dead shell's log (qs log … -r "quickshell.bluetooth*.debug=true;quickshell.dbus.properties.debug=true") shows Tracked new adapter, Powered to false, then no Adapter1 property update ever again while bluetoothctl show says Powered: yes

Deterministic repro without sleeping:

rfkill block bluetooth; sleep 2
pkill -STOP quickshell
rfkill unblock bluetooth; sleep 6
pkill -CONT quickshell

Unpatched its stuck at enabled=false state=Enabling. Same revision with this PR applied: GetAll reply arrives 3 ms after Tracked new adapter and sets Powered=true, PowerState=Enabled

bbedward pushed a commit to duxlabs-dev/dux-qt-base that referenced this pull request Nov 7, 2026
The properties bundled with InterfacesAdded are a snapshot BlueZ took at
signal-emission time. If the adapter was still mid-transition (PowerState
"off-enabling"/"on-disabling") at that instant, and the PropertiesChanged
that completes the transition reaches the bus before our PropertiesChanged
subscription (registered in the constructor, just before addInterface runs)
is fully installed, we never see it and are stuck showing the stale
transitional state forever - this is what issue #1156 and several Omarchy
duplicates describe.

Re-fetch once via GetAll right after applying the InterfacesAdded snapshot,
now that the subscription is guaranteed live, so we reconcile with BlueZ's
actual current state instead of trusting a possibly-outdated snapshot. This
is a single query triggered by the InterfacesAdded event itself, not a poll.

Fixes #1156

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

upstream: quickshell-mirror/quickshell#1372
@ademb2

ademb2 commented Nov 12, 2026

Copy link
Copy Markdown

Tested this on a machine that reproduced the bug on 3 of 3 S3 resumes.

Setup: Omarchy 4.5.0-3, kernel 7.2.15-1-omarchy, BlueZ 5.87-2, Realtek RTL8852AU (USB). Quickshell 0.3.2.r7.g2b4501a-8, rebuilt from the same revision Omarchy packages (2b4501a) with only this patch and Omarchy's Qt 6.12 loader patch applied.

Before the patch (official -1 build): after every resume the stock panel showed "Turned Off" while bluetoothctl show reported Powered: yes, and both paired devices reconnected normally. adapter.enabled stayed false until omarchy restart shell. Reproduced 3/3.

An independent GDBus client recorded the adapter re-registration on every wake, at the same /org/bluez/hci0 path (not an hci0→hci1 change):

InterfacesAdded:     Powered=false, PowerState="on"
PropertiesChanged:   Powered=false, PowerState="off-enabling"
PropertiesChanged:   Powered=true,  PowerState="on"

So BlueZ did emit the completing transition, but Quickshell did not reconcile it. This is the same race the PR describes, with the adapter path unchanged. (I did not capture Quickshell's own debug log, so I can't distinguish a missed signal from a received-and-discarded one.)

After the patch, 3 of 3 S3 resumes with the same re-registration sequence:

  • adapter.enabled stayed true across every wake, with no shell restart;
  • the bar and toggle stayed correct;
  • one wake also passed briefly through PowerState="off-blocked", and the cache still ended correct;
  • device connections dropped and recovered normally (2 → 0 → 1 → 2).

The GetAll was enough even though the adapter snapshot was still transitional at InterfacesAdded time, which is the case this PR targets.

Caveat: one machine, three wakes. A 5-second poller never observed false, so a sub-5-second blip could in principle have been missed. I did not test the device list; this PR only re-reads Adapter1, so a stale Device1.Connected could still be a separate issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants