Skip to content

Commit

Permalink
Merge pull request #480 from JakeStanger/feat/swaync
Browse files Browse the repository at this point in the history
feat: swaync notifications module
  • Loading branch information
JakeStanger authored Mar 4, 2024
2 parents 660dc81 + 7742a46 commit 26677cd
Show file tree
Hide file tree
Showing 15 changed files with 592 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ default = [
"ipc",
"launcher",
"music+all",
"notifications",
"sys_info",
"tray",
"upower",
Expand Down Expand Up @@ -57,6 +58,8 @@ music = ["regex"]
"music+mpris" = ["music", "mpris"]
"music+mpd" = ["music", "mpd-utils"]

notifications = ["zbus"]

sys_info = ["sysinfo", "regex"]

tray = ["system-tray"]
Expand Down Expand Up @@ -133,7 +136,6 @@ system-tray = { version = "0.1.5", optional = true }
# upower
upower_dbus = { version = "0.3.2", optional = true }
futures-lite = { version = "2.2.0", optional = true }
zbus = { version = "3.15.2", optional = true }

# volume
libpulse-binding = { version = "2.28.1", optional = true }
Expand All @@ -148,3 +150,4 @@ futures-util = { version = "0.3.30", optional = true }
regex = { version = "1.10.3", default-features = false, features = [
"std",
], optional = true } # music, sys_info
zbus = { version = "3.15.2", optional = true } # notifications, upower
1 change: 1 addition & 0 deletions docs/_Sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- [Label](label)
- [Launcher](launcher)
- [Music](music)
- [Notifications](notifications)
- [Script](script)
- [Sys_Info](sys-info)
- [Tray](tray)
Expand Down
116 changes: 116 additions & 0 deletions docs/modules/Notifications.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
Displays information about the current SwayNC state such as notification count and DnD.
Clicking the widget opens the SwayNC panel.

[!Notifications widget in its closed state showing 3 notifications](https://f.jstanger.dev/github/ironbar/notifications.png)

> ![NOTE]
> This widget requires the [SwayNC](https://github.com/ErikReider/SwayNotificationCenter)
> daemon to be running to use.
## Configuration

> Type: `notifications`
| Name | Type | Default | Description |
|---------------------|-----------|---------|--------------------------------------------------------------------------------------------------------|
| `show_count` | `boolean` | `true` | Whether to show the current notification count. |
| `icons.closed_none` | `string` | `󰍥` | Icon to show when the panel is closed, with no notifications. |
| `icons.closed_some` | `string` | `󱥂` | Icon to show when the panel is closed, with notifications. |
| `icons.closed_dnd` | `string` | `󱅯` | Icon to show when the panel is closed, with DnD enabled. Takes higher priority than count-based icons. |
| `icons.open_none` | `string` | `󰍡` | Icon to show when the panel is open, with no notifications. |
| `icons.open_some` | `string` | `󱥁` | Icon to show when the panel is open, with notifications. |
| `icons.open_dnd` | `string` | `󱅮` | Icon to show when the panel is open, with DnD enabled. Takes higher priority than count-based icons. |


<details>
<summary>JSON</summary>

```json
{
"end": [
{
"type": "notifications",
"show_count": true,
"icons": {
"closed_none": "󰍥",
"closed_some": "󱥂",
"closed_dnd": "󱅯",
"open_none": "󰍡",
"open_some": "󱥁",
"open_dnd": "󱅮"
}
}
]
}
```

</details>

<details>
<summary>TOML</summary>

```toml
[[end]]
type = "notifications"
show_count = true

[[end.icons]]
closed_none = "󰍥"
closed_some = "󱥂"
closed_dnd = "󱅯"
open_none = "󰍡"
open_some = "󱥁"
open_dnd = "󱅮"
```

</details>

<details>
<summary>YAML</summary>

```yaml
end:
- type: notifications
show_count: true
icons:
closed_none: 󰍥
closed_some: 󱥂
closed_dnd: 󱅯
open_none: 󰍡
open_some: 󱥁
open_dnd: 󱅮
```
</details>
<details>
<summary>Corn</summary>
```corn
{
end = [
{
type = "notifications"
show_count = true

icons.closed_none = "󰍥"
icons.closed_some = "󱥂"
icons.closed_dnd = "󱅯"
icons.open_none = "󰍡"
icons.open_some = "󱥁"
icons.open_dnd = "󱅮"
}
]
}
```

</details>

## Styling

| Selector | Description |
|-------------------------|---------------------------------------|
| `.notifications` | Notifications widget button |
| `.notifications .count` | Notifications count indicator overlay |

For more information on styling, please see the [styling guide](styling-guide).
14 changes: 13 additions & 1 deletion examples/config.corn
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ let {
$mpd_local = { type = "music" player_type = "mpd" music_dir = "/home/jake/Music" truncate.mode = "end" truncate.max_length = 100 }
$mpd_server = { type = "music" player_type = "mpd" host = "chloe:6600" truncate = "end" }

$notifications = {
type = "notifications"
show_count = true

icons.closed_none = "󰍥"
icons.closed_some = "󱥂"
icons.closed_dnd = "󱅯"
icons.open_none = "󰍡"
icons.open_some = "󱥁"
icons.open_dnd = "󱅮"
}

$sys_info = {
type = "sys_info"

Expand Down Expand Up @@ -110,7 +122,7 @@ let {
// -- end custom --

$left = [ $workspaces $launcher $label ]
$right = [ $mpd_local $mpd_server $phone_battery $sys_info $volume $clipboard $power_menu $clock ]
$right = [ $mpd_local $mpd_server $phone_battery $sys_info $volume $clipboard $power_menu $clock $notifications ]
}
in {
anchor_to_edges = true
Expand Down
12 changes: 12 additions & 0 deletions examples/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,18 @@
},
{
"type": "clock"
},
{
"type": "notifications",
"show_count": true,
"icons": {
"closed_none": "󰍥",
"closed_some": "󱥂",
"closed_dnd": "󱅯",
"open_none": "󰍡",
"open_some": "󱥁",
"open_dnd": "󱅮"
}
}
]
}
12 changes: 12 additions & 0 deletions examples/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,15 @@ label = "Uptime: {{30000:uptime -p | cut -d ' ' -f2-}}"
[[end]]
type = "clock"

[[end]]
type = "notifications"
show_count = true

[end.icons]
closed_none = "󰍥"
closed_some = "󱥂"
closed_dnd = "󱅯"
open_none = "󰍡"
open_some = "󱥁"
open_dnd = "󱅮"

9 changes: 9 additions & 0 deletions examples/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,13 @@ end:
label: 'Uptime: {{30000:uptime -p | cut -d '' '' -f2-}}'
tooltip: 'Up: {{30000:uptime -p | cut -d '' '' -f2-}}'
- type: clock
- type: notifications
show_count: true
icons:
closed_none: 󰍥
closed_some: 󱥂
closed_dnd: 󱅯
open_none: 󰍡
open_some: 󱥁
open_dnd: 󱅮

14 changes: 14 additions & 0 deletions examples/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,20 @@ scale trough {
border-radius: 100%;
}

/* notifications */

.notifications .count {
font-size: 0.6rem;
background-color: @color_text;
color: @color_bg;
border-radius: 100%;
margin-right: 3px;
margin-top: 3px;
padding-left: 4px;
padding-right: 4px;
opacity: 0.7;
}

/* -- script -- */

.script {
Expand Down
2 changes: 2 additions & 0 deletions src/bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ fn add_modules(
ModuleConfig::Launcher(mut module) => add_module!(module, id),
#[cfg(feature = "music")]
ModuleConfig::Music(mut module) => add_module!(module, id),
#[cfg(feature = "notifications")]
ModuleConfig::Notifications(mut module) => add_module!(module, id),
ModuleConfig::Script(mut module) => add_module!(module, id),
#[cfg(feature = "sys_info")]
ModuleConfig::SysInfo(mut module) => add_module!(module, id),
Expand Down
15 changes: 14 additions & 1 deletion src/clients/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pub mod clipboard;
pub mod compositor;
#[cfg(feature = "music")]
pub mod music;
#[cfg(feature = "notifications")]
pub mod swaync;
#[cfg(feature = "tray")]
pub mod system_tray;
#[cfg(feature = "upower")]
Expand All @@ -25,6 +27,8 @@ pub struct Clients {
clipboard: Option<Arc<clipboard::Client>>,
#[cfg(feature = "music")]
music: std::collections::HashMap<music::ClientType, Arc<dyn music::MusicClient>>,
#[cfg(feature = "notifications")]
notifications: Option<Arc<swaync::Client>>,
#[cfg(feature = "tray")]
tray: Option<Arc<system_tray::TrayEventReceiver>>,
#[cfg(feature = "upower")]
Expand Down Expand Up @@ -71,6 +75,15 @@ impl Clients {
.clone()
}

#[cfg(feature = "notifications")]
pub fn notifications(&mut self) -> Arc<swaync::Client> {
self.notifications
.get_or_insert_with(|| {
Arc::new(crate::await_sync(async { swaync::Client::new().await }))
})
.clone()
}

#[cfg(feature = "tray")]
pub fn tray(&mut self) -> Arc<system_tray::TrayEventReceiver> {
self.tray
Expand Down Expand Up @@ -122,7 +135,7 @@ macro_rules! register_client {
where
TSend: Clone,
{
fn provide(&self) -> Arc<$ty> {
fn provide(&self) -> std::sync::Arc<$ty> {
self.ironbar.clients.borrow_mut().$method()
}
}
Expand Down
Loading

0 comments on commit 26677cd

Please sign in to comment.