Skip to content

Commit

Permalink
Merge pull request #512 from JakeStanger/refactor/tray-rewrite
Browse files Browse the repository at this point in the history
System tray rewrite
  • Loading branch information
JakeStanger authored Mar 29, 2024
2 parents c7b6ee8 + ba00445 commit b48ba4c
Show file tree
Hide file tree
Showing 10 changed files with 209 additions and 259 deletions.
36 changes: 6 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ mpris = { version = "2.0.1", optional = true }
sysinfo = { version = "0.29.11", optional = true }

# tray
system-tray = { version = "0.1.5", optional = true }
system-tray = { version = "0.2.0", optional = true }

# upower
upower_dbus = { version = "0.3.2", optional = true }
Expand Down
20 changes: 10 additions & 10 deletions docs/modules/Tray.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
Displays a fully interactive icon tray using the KDE `libappindicator` protocol.
Displays a fully interactive icon tray using the KDE `libappindicator` protocol.

![Screenshot showing icon tray widget](https://user-images.githubusercontent.com/5057870/184540135-78ffd79d-f802-4c79-b09a-05a733dadc55.png)

## Configuration

> Type: `tray`

| Name | Type | Default | Description |
|-------------|-----------|-----------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------|
| `direction` | `string` | `left_to_right` if bar is horizontal, `top_to_bottom` otherwise | Direction to display the tray items. Possible values: `top_to_bottom`, `bottom_to_top`, `left_to_right`, `right_to_left` |
| `icon_size` | `integer` | `16` | Size in pixels to display tray icons as |
| Name | Type | Default | Description |
|----------------------|-----------|-----------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `direction` | `string` | `left_to_right` if bar is horizontal, `top_to_bottom` otherwise | Direction to display the tray items. Possible values: `top_to_bottom`, `bottom_to_top`, `left_to_right`, `right_to_left` |
| `icon_size` | `integer` | `16` | Size in pixels to display tray icons as. |
| `prefer_theme_icons` | `bool` | `true` | Requests that icons from the theme be used over the item-provided item. Most items only provide one or the other so this will have no effect in most circumstances. |

<details>
<summary>JSON</summary>
Expand Down Expand Up @@ -55,12 +55,12 @@ end:
```corn
{
end = [
end = [
{
type = "tray"
direction = "top_to_bottom"
type = "tray"
direction = "top_to_bottom"
}
]
]
}
```

Expand Down
15 changes: 11 additions & 4 deletions src/clients/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::Ironbar;
use std::sync::Arc;

#[cfg(feature = "clipboard")]
Expand All @@ -9,7 +10,7 @@ pub mod music;
#[cfg(feature = "notifications")]
pub mod swaync;
#[cfg(feature = "tray")]
pub mod system_tray;
pub mod tray;
#[cfg(feature = "upower")]
pub mod upower;
#[cfg(feature = "volume")]
Expand All @@ -30,7 +31,7 @@ pub struct Clients {
#[cfg(feature = "notifications")]
notifications: Option<Arc<swaync::Client>>,
#[cfg(feature = "tray")]
tray: Option<Arc<system_tray::TrayEventReceiver>>,
tray: Option<Arc<tray::Client>>,
#[cfg(feature = "upower")]
upower: Option<Arc<zbus::fdo::PropertiesProxy<'static>>>,
#[cfg(feature = "volume")]
Expand Down Expand Up @@ -85,11 +86,17 @@ impl Clients {
}

#[cfg(feature = "tray")]
pub fn tray(&mut self) -> Arc<system_tray::TrayEventReceiver> {
pub fn tray(&mut self) -> Arc<tray::Client> {
// TODO: Error handling here isn't great - should throw a user-friendly error
self.tray
.get_or_insert_with(|| {
Arc::new(crate::await_sync(async {
system_tray::create_client().await
let service_name =
format!("{}-{}", env!("CARGO_CRATE_NAME"), Ironbar::unique_id());

tray::Client::new(&service_name)
.await
.expect("to be able to start client")
}))
})
.clone()
Expand Down
127 changes: 0 additions & 127 deletions src/clients/system_tray.rs

This file was deleted.

4 changes: 4 additions & 0 deletions src/clients/tray.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
use crate::register_client;
pub use system_tray::client::Client;

register_client!(Client, tray);
10 changes: 5 additions & 5 deletions src/modules/tray/diff.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use system_tray::message::menu::{MenuItem as MenuItemInfo, ToggleState};
use system_tray::menu::{MenuItem, ToggleState};

/// Diff change type and associated info.
#[derive(Debug, Clone)]
pub enum Diff {
Add(MenuItemInfo),
Add(MenuItem),
Update(i32, MenuItemDiff),
Remove(i32),
}
Expand All @@ -12,7 +12,7 @@ pub enum Diff {
#[derive(Debug, Clone)]
pub struct MenuItemDiff {
/// Text of the item,
pub label: Option<String>,
pub label: Option<Option<String>>,
/// Whether the item can be activated or not.
pub enabled: Option<bool>,
/// True if the item is visible in the menu.
Expand All @@ -29,7 +29,7 @@ pub struct MenuItemDiff {
}

impl MenuItemDiff {
fn new(old: &MenuItemInfo, new: &MenuItemInfo) -> Self {
fn new(old: &MenuItem, new: &MenuItem) -> Self {
macro_rules! diff {
($field:ident) => {
if old.$field == new.$field {
Expand Down Expand Up @@ -70,7 +70,7 @@ impl MenuItemDiff {
}

/// Gets a diff set between old and new state.
pub fn get_diffs(old: &[MenuItemInfo], new: &[MenuItemInfo]) -> Vec<Diff> {
pub fn get_diffs(old: &[MenuItem], new: &[MenuItem]) -> Vec<Diff> {
let mut diffs = vec![];

for new_item in new {
Expand Down
Loading

0 comments on commit b48ba4c

Please sign in to comment.