mirror of
				https://github.com/Zedfrigg/ironbar.git
				synced 2025-11-04 07:21:54 +01:00 
			
		
		
		
	feat(networkmanager): add config for icons
This commit is contained in:
		
					parent
					
						
							
								4fe03031dd
							
						
					
				
			
			
				commit
				
					
						81900c6a29
					
				
			
		
					 3 changed files with 186 additions and 55 deletions
				
			
		| 
						 | 
				
			
			@ -10,64 +10,77 @@ Supports wired ethernet, wifi, cellular data and VPN connections among others.
 | 
			
		|||
 | 
			
		||||
> Type: `networkmanager`
 | 
			
		||||
 | 
			
		||||
| Name        | Type      | Default | Description             |
 | 
			
		||||
|-------------|-----------|---------|-------------------------|
 | 
			
		||||
| `icon_size` | `integer` | `24`    | Size to render icon at. |
 | 
			
		||||
| Name                          | Type       | Default                                               | Description                                       |
 | 
			
		||||
| ----------------------------- | ---------- | ----------------------------------------------------- | ------------------------------------------------- |
 | 
			
		||||
| `icon_size`                   | `integer`  | `24`                                                  | Size to render icon at.                           |
 | 
			
		||||
| `icons.wired.connected`       | `string`   | `icon:network-wired-symbolic`                         | Icon to show when there is a wired connection     |
 | 
			
		||||
| `icons.wired.disconnected`    | `string`   | `icon:network-wired-symbolic`                         | Icon to show when there is no wired connection    |
 | 
			
		||||
| `icons.wifi.levels`           | `string[]` | `["icon:network-wireless-signal-none-symbolic", ...]` | Icon to show when there is no wifi connection     |
 | 
			
		||||
| `icons.wifi.disconnected`     | `string`   | `icon:network-wireless-offline-symbolic`              | Icon to show when there is no wifi connection     |
 | 
			
		||||
| `icons.wifi.disabled`         | `string`   | `icon:network-wireless-hardware-disabled-symbolic`    | Icon to show when wifi is disabled                |
 | 
			
		||||
| `icons.cellular.connected`    | `string`   | `icon:network-cellular-connected-symbolic`            | Icon to show when there is a cellular connection  |
 | 
			
		||||
| `icons.cellular.disconnected` | `string`   | `icon:network-cellular-offline-symbolic`              | Icon to show when there is no cellular connection |
 | 
			
		||||
| `icons.cellular.disabled`     | `string`   | `icon:network-cellular-hardware-disabled-symbolic`    | Icon to show when cellular connection is disabled |
 | 
			
		||||
| `icons.vpn.connected`         | `string`   | `icon:network-vpn-symbolic`                           | Icon to show when there is a VPN connection       |
 | 
			
		||||
 | 
			
		||||
<details>
 | 
			
		||||
  <summary>JSON</summary>
 | 
			
		||||
<summary>JSON</summary>
 | 
			
		||||
 | 
			
		||||
```json
 | 
			
		||||
{
 | 
			
		||||
  "end": [
 | 
			
		||||
    {
 | 
			
		||||
      "type": "networkmanager",
 | 
			
		||||
      "icon_size": 32
 | 
			
		||||
    }
 | 
			
		||||
  ]
 | 
			
		||||
}
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
  ```json
 | 
			
		||||
  {
 | 
			
		||||
    "end": [
 | 
			
		||||
      {
 | 
			
		||||
        "type": "networkmanager",
 | 
			
		||||
        "icon_size": 32
 | 
			
		||||
      }
 | 
			
		||||
    ]
 | 
			
		||||
  }
 | 
			
		||||
  ```
 | 
			
		||||
</details>
 | 
			
		||||
 | 
			
		||||
<details>
 | 
			
		||||
  <summary>TOML</summary>
 | 
			
		||||
<summary>TOML</summary>
 | 
			
		||||
 | 
			
		||||
```toml
 | 
			
		||||
[[end]]
 | 
			
		||||
type = "networkmanager"
 | 
			
		||||
icon_size = 32
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
  ```toml
 | 
			
		||||
  [[end]]
 | 
			
		||||
  type = "networkmanager"
 | 
			
		||||
  icon_size = 32
 | 
			
		||||
  ```
 | 
			
		||||
</details>
 | 
			
		||||
 | 
			
		||||
<details>
 | 
			
		||||
  <summary>YAML</summary>
 | 
			
		||||
<summary>YAML</summary>
 | 
			
		||||
 | 
			
		||||
```yaml
 | 
			
		||||
end:
 | 
			
		||||
  - type: "networkmanager"
 | 
			
		||||
    icon_size: 32
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
  ```yaml
 | 
			
		||||
  end:
 | 
			
		||||
    - type: "networkmanager"
 | 
			
		||||
      icon_size: 32
 | 
			
		||||
  ```
 | 
			
		||||
</details>
 | 
			
		||||
 | 
			
		||||
<details>
 | 
			
		||||
  <summary>Corn</summary>
 | 
			
		||||
<summary>Corn</summary>
 | 
			
		||||
 | 
			
		||||
```corn
 | 
			
		||||
{
 | 
			
		||||
  end = [
 | 
			
		||||
    {
 | 
			
		||||
      type = "networkmanager"
 | 
			
		||||
      icon_size = 32
 | 
			
		||||
    }
 | 
			
		||||
  ]
 | 
			
		||||
}
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
  ```corn
 | 
			
		||||
  {
 | 
			
		||||
    end = [
 | 
			
		||||
      {
 | 
			
		||||
        type = "networkmanager"
 | 
			
		||||
        icon_size = 32
 | 
			
		||||
      }
 | 
			
		||||
    ]
 | 
			
		||||
  }
 | 
			
		||||
  ```
 | 
			
		||||
</details>
 | 
			
		||||
 | 
			
		||||
## Styling
 | 
			
		||||
 | 
			
		||||
| Selector               | Description                      |
 | 
			
		||||
|------------------------|----------------------------------|
 | 
			
		||||
| ---------------------- | -------------------------------- |
 | 
			
		||||
| `.networkmanager`      | NetworkManager widget container. |
 | 
			
		||||
| `.networkmanger .icon` | NetworkManager widget icons.     |
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,3 +1,5 @@
 | 
			
		|||
mod config;
 | 
			
		||||
 | 
			
		||||
use color_eyre::Result;
 | 
			
		||||
use futures_lite::StreamExt;
 | 
			
		||||
use futures_signals::signal::SignalExt;
 | 
			
		||||
| 
						 | 
				
			
			@ -22,6 +24,9 @@ pub struct NetworkManagerModule {
 | 
			
		|||
    #[serde(default = "default_icon_size")]
 | 
			
		||||
    icon_size: i32,
 | 
			
		||||
 | 
			
		||||
    #[serde(default)]
 | 
			
		||||
    icons: config::IconsConfig,
 | 
			
		||||
 | 
			
		||||
    #[serde(flatten)]
 | 
			
		||||
    pub common: Option<CommonConfig>,
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -106,34 +111,27 @@ impl Module<GtkBox> for NetworkManagerModule {
 | 
			
		|||
            }
 | 
			
		||||
 | 
			
		||||
            update_icon!(wired_icon, wired, {
 | 
			
		||||
                WiredState::Connected => "icon:network-wired-symbolic",
 | 
			
		||||
                WiredState::Disconnected => "icon:network-wired-disconnected-symbolic",
 | 
			
		||||
                WiredState::Connected => &self.icons.wired.connected,
 | 
			
		||||
                WiredState::Disconnected => &self.icons.wired.disconnected,
 | 
			
		||||
                WiredState::NotPresent | WiredState::Unknown => "",
 | 
			
		||||
            });
 | 
			
		||||
            update_icon!(wifi_icon, wifi, {
 | 
			
		||||
                WifiState::Connected(state) => {
 | 
			
		||||
                    let icons = [
 | 
			
		||||
                        "icon:network-wireless-signal-none-symbolic",
 | 
			
		||||
                        "icon:network-wireless-signal-weak-symbolic",
 | 
			
		||||
                        "icon:network-wireless-signal-ok-symbolic",
 | 
			
		||||
                        "icon:network-wireless-signal-good-symbolic",
 | 
			
		||||
                        "icon:network-wireless-signal-excellent-symbolic",
 | 
			
		||||
                    ];
 | 
			
		||||
                    let n = strengh_to_level(state.strength, icons.len());
 | 
			
		||||
                    icons[n]
 | 
			
		||||
                    let n = strengh_to_level(state.strength, self.icons.wifi.levels.len());
 | 
			
		||||
                    &self.icons.wifi.levels[n]
 | 
			
		||||
                },
 | 
			
		||||
                WifiState::Disconnected => "icon:network-wireless-offline-symbolic",
 | 
			
		||||
                WifiState::Disabled => "icon:network-wireless-hardware-disabled-symbolic",
 | 
			
		||||
                WifiState::Disconnected => &self.icons.wifi.disconnected,
 | 
			
		||||
                WifiState::Disabled => &self.icons.wifi.disabled,
 | 
			
		||||
                WifiState::NotPresent | WifiState::Unknown => "",
 | 
			
		||||
            });
 | 
			
		||||
            update_icon!(cellular_icon, cellular, {
 | 
			
		||||
                CellularState::Connected => "icon:network-cellular-connected-symbolic",
 | 
			
		||||
                CellularState::Disconnected => "icon:network-cellular-offline-symbolic",
 | 
			
		||||
                CellularState::Disabled => "icon:network-cellular-hardware-disabled-symbolic",
 | 
			
		||||
                CellularState::Connected => &self.icons.cellular.connected,
 | 
			
		||||
                CellularState::Disconnected => &self.icons.cellular.disconnected,
 | 
			
		||||
                CellularState::Disabled => &self.icons.cellular.disabled,
 | 
			
		||||
                CellularState::NotPresent | CellularState::Unknown => "",
 | 
			
		||||
            });
 | 
			
		||||
            update_icon!(vpn_icon, vpn, {
 | 
			
		||||
                VpnState::Connected(_) => "icon:network-vpn-symbolic",
 | 
			
		||||
                VpnState::Connected(_) => &self.icons.vpn.connected,
 | 
			
		||||
                VpnState::Disconnected | VpnState::Unknown => "",
 | 
			
		||||
            });
 | 
			
		||||
        });
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										120
									
								
								src/modules/networkmanager/config.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										120
									
								
								src/modules/networkmanager/config.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,120 @@
 | 
			
		|||
use serde::Deserialize;
 | 
			
		||||
 | 
			
		||||
macro_rules! default_function {
 | 
			
		||||
    ($(($name:ident, $default:expr),)*) => {
 | 
			
		||||
        $(
 | 
			
		||||
            fn $name() -> String {
 | 
			
		||||
                ($default).to_string()
 | 
			
		||||
            }
 | 
			
		||||
        )*
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Deserialize, Clone, Default)]
 | 
			
		||||
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
 | 
			
		||||
pub struct IconsConfig {
 | 
			
		||||
    #[serde(default)]
 | 
			
		||||
    pub wired: IconsConfigWired,
 | 
			
		||||
    #[serde(default)]
 | 
			
		||||
    pub wifi: IconsConfigWifi,
 | 
			
		||||
    #[serde(default)]
 | 
			
		||||
    pub cellular: IconsConfigCellular,
 | 
			
		||||
    #[serde(default)]
 | 
			
		||||
    pub vpn: IconsConfigVpn,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Deserialize, Clone)]
 | 
			
		||||
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
 | 
			
		||||
pub struct IconsConfigWired {
 | 
			
		||||
    #[serde(default = "default_wired_connected")]
 | 
			
		||||
    pub connected: String,
 | 
			
		||||
    #[serde(default = "default_wired_disconnected")]
 | 
			
		||||
    pub disconnected: String,
 | 
			
		||||
}
 | 
			
		||||
impl Default for IconsConfigWired {
 | 
			
		||||
    fn default() -> Self {
 | 
			
		||||
        Self {
 | 
			
		||||
            connected: default_wired_connected(),
 | 
			
		||||
            disconnected: default_wired_disconnected(),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Deserialize, Clone)]
 | 
			
		||||
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
 | 
			
		||||
pub struct IconsConfigWifi {
 | 
			
		||||
    #[serde(default = "default_wifi_levels")]
 | 
			
		||||
    pub levels: Vec<String>,
 | 
			
		||||
    #[serde(default = "default_wifi_disconnected")]
 | 
			
		||||
    pub disconnected: String,
 | 
			
		||||
    #[serde(default = "default_wifi_disabled")]
 | 
			
		||||
    pub disabled: String,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Default for IconsConfigWifi {
 | 
			
		||||
    fn default() -> Self {
 | 
			
		||||
        Self {
 | 
			
		||||
            levels: default_wifi_levels(),
 | 
			
		||||
            disconnected: default_wifi_disconnected(),
 | 
			
		||||
            disabled: default_wifi_disabled(),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Deserialize, Clone)]
 | 
			
		||||
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
 | 
			
		||||
pub struct IconsConfigCellular {
 | 
			
		||||
    #[serde(default = "default_cellular_connected")]
 | 
			
		||||
    pub connected: String,
 | 
			
		||||
    #[serde(default = "default_cellular_disconnected")]
 | 
			
		||||
    pub disconnected: String,
 | 
			
		||||
    #[serde(default = "default_cellular_disabled")]
 | 
			
		||||
    pub disabled: String,
 | 
			
		||||
}
 | 
			
		||||
impl Default for IconsConfigCellular {
 | 
			
		||||
    fn default() -> Self {
 | 
			
		||||
        Self {
 | 
			
		||||
            connected: default_cellular_connected(),
 | 
			
		||||
            disconnected: default_cellular_disconnected(),
 | 
			
		||||
            disabled: default_cellular_disabled(),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Deserialize, Clone)]
 | 
			
		||||
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
 | 
			
		||||
pub struct IconsConfigVpn {
 | 
			
		||||
    #[serde(default = "default_vpn_connected")]
 | 
			
		||||
    pub connected: String,
 | 
			
		||||
}
 | 
			
		||||
impl Default for IconsConfigVpn {
 | 
			
		||||
    fn default() -> Self {
 | 
			
		||||
        Self {
 | 
			
		||||
            connected: default_vpn_connected(),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn default_wifi_levels() -> Vec<String> {
 | 
			
		||||
    vec![
 | 
			
		||||
        "icon:network-wireless-signal-none-symbolic".to_string(),
 | 
			
		||||
        "icon:network-wireless-signal-weak-symbolic".to_string(),
 | 
			
		||||
        "icon:network-wireless-signal-ok-symbolic".to_string(),
 | 
			
		||||
        "icon:network-wireless-signal-good-symbolic".to_string(),
 | 
			
		||||
        "icon:network-wireless-signal-excellent-symbolic".to_string(),
 | 
			
		||||
    ]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
default_function! {
 | 
			
		||||
    (default_wired_connected,  "icon:network-wired-symbolic"),
 | 
			
		||||
    (default_wired_disconnected,  "icon:network-wired-disconnected-symbolic"),
 | 
			
		||||
 | 
			
		||||
    (default_wifi_disconnected, "icon:network-wireless-offline-symbolic"),
 | 
			
		||||
    (default_wifi_disabled, "icon:network-wireless-hardware-disabled-symbolic"),
 | 
			
		||||
 | 
			
		||||
    (default_cellular_connected,"icon:network-cellular-connected-symbolic"),
 | 
			
		||||
    (default_cellular_disconnected,"icon:network-cellular-offline-symbolic"),
 | 
			
		||||
    (default_cellular_disabled,"icon:network-cellular-hardware-disabled-symbolic"),
 | 
			
		||||
 | 
			
		||||
    (default_vpn_connected, "icon:network-vpn-symbolic"),
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue