Skip to content
Merged
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
4 changes: 4 additions & 0 deletions assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3545,6 +3545,10 @@
"description": "Hide tray items whose StatusNotifierItem status is Passive",
"label": "Hide Passive Items"
},
"hide-when-adapter-off": {
"description": "Hide the Bluetooth widget when adapter is powered off",
"label": "Hide When Adapter Off"
},
"hide-when-empty": {
"description": "Hide workspace pills when there are no open windows",
"label": "Hide When Empty",
Expand Down
1 change: 1 addition & 0 deletions docs/user/bar/widgets/bluetooth.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Shows the Bluetooth adapter state and connected device. Left-click opens the Blu
| Setting | Type | Default | Description |
|---------|------|---------|-------------|
| `show_label` | bool | `false` | Show the connected device name next to the icon |
| `hide_when_adapter_off` | bool | `false` | Hide the widget when the adapter is powered off. While hidden, the widget's right-click power toggle is unavailable; re-enable Bluetooth from the control center. |
| `hide_when_no_connected_device` | bool | `false` | Hide the widget when no Bluetooth device is connected. |

```toml
Expand Down
5 changes: 3 additions & 2 deletions src/shell/bar/widgets/bluetooth_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace {
} // namespace

BluetoothWidget::BluetoothWidget(BluetoothService* bluetooth, wl_output* /*output*/, Options options)
: m_bluetooth(bluetooth), m_showLabel(options.showLabel),
: m_bluetooth(bluetooth), m_showLabel(options.showLabel), m_hideWhenAdapterOff(options.hideWhenAdapterOff),
m_hideWhenNoConnectedDevice(options.hideWhenNoConnectedDevice) {}

void BluetoothWidget::create() {
Expand Down Expand Up @@ -128,7 +128,8 @@ void BluetoothWidget::syncState(Renderer& renderer) {
m_lastConnectedAlias = alias;

const bool hasConnectedDevice = numConnected > 0;
const bool showWidget = s.adapterPresent && (!m_hideWhenNoConnectedDevice || hasConnectedDevice);
const bool showWidget =
s.adapterPresent && (!m_hideWhenAdapterOff || s.powered) && (!m_hideWhenNoConnectedDevice || hasConnectedDevice);
syncWidgetVisibility(showWidget);
if (!showWidget) {
if (Node* rootNode = root(); rootNode != nullptr) {
Expand Down
2 changes: 2 additions & 0 deletions src/shell/bar/widgets/bluetooth_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class BluetoothWidget : public Widget {
public:
struct Options {
bool showLabel = false;
bool hideWhenAdapterOff = false;
bool hideWhenNoConnectedDevice = false;
};

Expand All @@ -28,6 +29,7 @@ class BluetoothWidget : public Widget {

BluetoothService* m_bluetooth = nullptr;
bool m_showLabel = false;
bool m_hideWhenAdapterOff = false;
bool m_hideWhenNoConnectedDevice = false;
Glyph* m_glyph = nullptr;
Label* m_label = nullptr;
Expand Down
19 changes: 19 additions & 0 deletions src/shell/bar/widgets/bluetooth_widget_definition.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
#include "shell/bar/widgets/bluetooth_widget_definition.h"

namespace {

// A powered-off adapter has no connected device, so hiding on "no connected device"
// already covers the adapter-off case and makes this toggle inert.
settings::WidgetSettingVisibility connectedDeviceFilterOff() {
settings::WidgetSettingVisibility visibility;
visibility.all = {{"hide_when_no_connected_device", {"false"}}};
return visibility;
}

} // namespace

const noctalia::bar::WidgetDefinition<BluetoothWidget::Options>& bluetoothWidgetDefinition() {
using noctalia::bar::field;
using Options = BluetoothWidget::Options;
Expand All @@ -10,6 +22,13 @@ const noctalia::bar::WidgetDefinition<BluetoothWidget::Options>& bluetoothWidget
field<&Options::showLabel>({
.key = "show_label",
}),
field<&Options::hideWhenAdapterOff>({
.key = "hide_when_adapter_off",
.presentation =
settings::WidgetSettingPresentation{
.visibleWhen = connectedDeviceFilterOff(),
},
}),
field<&Options::hideWhenNoConnectedDevice>({
.key = "hide_when_no_connected_device",
}),
Expand Down