mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-07-02 19:21:03 +02:00
Merge branch 'master' into feat/volume-icon
This commit is contained in:
commit
75e61cfd93
16 changed files with 556 additions and 126 deletions
10
src/bar.rs
10
src/bar.rs
|
@ -78,10 +78,6 @@ impl Bar {
|
|||
let center = create_container("center", orientation);
|
||||
let end = create_container("end", orientation);
|
||||
|
||||
content.add(&start);
|
||||
content.set_center_widget(Some(¢er));
|
||||
content.pack_end(&end, false, false, 0);
|
||||
|
||||
window.add(&content);
|
||||
|
||||
window.connect_destroy_event(|_, _| {
|
||||
|
@ -273,16 +269,22 @@ impl Bar {
|
|||
let popup = Rc::new(popup);
|
||||
|
||||
if let Some(modules) = config.start {
|
||||
self.content.add(&self.start);
|
||||
|
||||
let info = info!(ModuleLocation::Left);
|
||||
add_modules(&self.start, modules, &info, &self.ironbar, &popup)?;
|
||||
}
|
||||
|
||||
if let Some(modules) = config.center {
|
||||
self.content.set_center_widget(Some(&self.center));
|
||||
|
||||
let info = info!(ModuleLocation::Center);
|
||||
add_modules(&self.center, modules, &info, &self.ironbar, &popup)?;
|
||||
}
|
||||
|
||||
if let Some(modules) = config.end {
|
||||
self.content.pack_end(&self.end, false, true, 0);
|
||||
|
||||
let info = info!(ModuleLocation::Right);
|
||||
add_modules(&self.end, modules, &info, &self.ironbar, &popup)?;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@ pub mod compositor;
|
|||
pub mod lua;
|
||||
#[cfg(feature = "music")]
|
||||
pub mod music;
|
||||
#[cfg(feature = "network_manager")]
|
||||
pub mod networkmanager;
|
||||
#[cfg(feature = "notifications")]
|
||||
pub mod swaync;
|
||||
#[cfg(feature = "tray")]
|
||||
|
@ -35,6 +37,8 @@ pub struct Clients {
|
|||
lua: Option<Rc<lua::LuaEngine>>,
|
||||
#[cfg(feature = "music")]
|
||||
music: std::collections::HashMap<music::ClientType, Arc<dyn music::MusicClient>>,
|
||||
#[cfg(feature = "network_manager")]
|
||||
network_manager: Option<Arc<networkmanager::Client>>,
|
||||
#[cfg(feature = "notifications")]
|
||||
notifications: Option<Arc<swaync::Client>>,
|
||||
#[cfg(feature = "tray")]
|
||||
|
@ -96,6 +100,18 @@ impl Clients {
|
|||
.clone()
|
||||
}
|
||||
|
||||
#[cfg(feature = "network_manager")]
|
||||
pub fn network_manager(&mut self) -> ClientResult<networkmanager::Client> {
|
||||
match &self.network_manager {
|
||||
Some(client) => Ok(client.clone()),
|
||||
None => {
|
||||
let client = networkmanager::create_client()?;
|
||||
self.network_manager = Some(client.clone());
|
||||
Ok(client)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "notifications")]
|
||||
pub fn notifications(&mut self) -> ClientResult<swaync::Client> {
|
||||
let client = match &self.notifications {
|
||||
|
|
169
src/clients/networkmanager.rs
Normal file
169
src/clients/networkmanager.rs
Normal file
|
@ -0,0 +1,169 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use color_eyre::Result;
|
||||
use futures_signals::signal::{Mutable, MutableSignalCloned};
|
||||
use tracing::error;
|
||||
use zbus::blocking::fdo::PropertiesProxy;
|
||||
use zbus::blocking::Connection;
|
||||
use zbus::{
|
||||
dbus_proxy,
|
||||
names::InterfaceName,
|
||||
zvariant::{ObjectPath, Str},
|
||||
};
|
||||
|
||||
use crate::{register_fallible_client, spawn_blocking};
|
||||
|
||||
const DBUS_BUS: &str = "org.freedesktop.NetworkManager";
|
||||
const DBUS_PATH: &str = "/org/freedesktop/NetworkManager";
|
||||
const DBUS_INTERFACE: &str = "org.freedesktop.NetworkManager";
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Client {
|
||||
client_state: Mutable<ClientState>,
|
||||
interface_name: InterfaceName<'static>,
|
||||
dbus_connection: Connection,
|
||||
props_proxy: PropertiesProxy<'static>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum ClientState {
|
||||
WiredConnected,
|
||||
WifiConnected,
|
||||
CellularConnected,
|
||||
VpnConnected,
|
||||
WifiDisconnected,
|
||||
Offline,
|
||||
Unknown,
|
||||
}
|
||||
|
||||
#[dbus_proxy(
|
||||
default_service = "org.freedesktop.NetworkManager",
|
||||
interface = "org.freedesktop.NetworkManager",
|
||||
default_path = "/org/freedesktop/NetworkManager"
|
||||
)]
|
||||
trait NetworkManagerDbus {
|
||||
#[dbus_proxy(property)]
|
||||
fn active_connections(&self) -> Result<Vec<ObjectPath>>;
|
||||
|
||||
#[dbus_proxy(property)]
|
||||
fn devices(&self) -> Result<Vec<ObjectPath>>;
|
||||
|
||||
#[dbus_proxy(property)]
|
||||
fn networking_enabled(&self) -> Result<bool>;
|
||||
|
||||
#[dbus_proxy(property)]
|
||||
fn primary_connection(&self) -> Result<ObjectPath>;
|
||||
|
||||
#[dbus_proxy(property)]
|
||||
fn primary_connection_type(&self) -> Result<Str>;
|
||||
|
||||
#[dbus_proxy(property)]
|
||||
fn wireless_enabled(&self) -> Result<bool>;
|
||||
}
|
||||
|
||||
impl Client {
|
||||
fn new() -> Result<Self> {
|
||||
let client_state = Mutable::new(ClientState::Unknown);
|
||||
let dbus_connection = Connection::system()?;
|
||||
let interface_name = InterfaceName::from_static_str(DBUS_INTERFACE)?;
|
||||
let props_proxy = PropertiesProxy::builder(&dbus_connection)
|
||||
.destination(DBUS_BUS)?
|
||||
.path(DBUS_PATH)?
|
||||
.build()?;
|
||||
|
||||
Ok(Self {
|
||||
client_state,
|
||||
interface_name,
|
||||
dbus_connection,
|
||||
props_proxy,
|
||||
})
|
||||
}
|
||||
|
||||
fn run(&self) -> Result<()> {
|
||||
let proxy = NetworkManagerDbusProxyBlocking::new(&self.dbus_connection)?;
|
||||
|
||||
let mut primary_connection = proxy.primary_connection()?;
|
||||
let mut primary_connection_type = proxy.primary_connection_type()?;
|
||||
let mut wireless_enabled = proxy.wireless_enabled()?;
|
||||
|
||||
self.client_state.set(determine_state(
|
||||
&primary_connection,
|
||||
&primary_connection_type,
|
||||
wireless_enabled,
|
||||
));
|
||||
|
||||
for change in self.props_proxy.receive_properties_changed()? {
|
||||
let args = change.args()?;
|
||||
if args.interface_name != self.interface_name {
|
||||
continue;
|
||||
}
|
||||
|
||||
let changed_props = args.changed_properties;
|
||||
let mut relevant_prop_changed = false;
|
||||
|
||||
if changed_props.contains_key("PrimaryConnection") {
|
||||
primary_connection = proxy.primary_connection()?;
|
||||
relevant_prop_changed = true;
|
||||
}
|
||||
if changed_props.contains_key("PrimaryConnectionType") {
|
||||
primary_connection_type = proxy.primary_connection_type()?;
|
||||
relevant_prop_changed = true;
|
||||
}
|
||||
if changed_props.contains_key("WirelessEnabled") {
|
||||
wireless_enabled = proxy.wireless_enabled()?;
|
||||
relevant_prop_changed = true;
|
||||
}
|
||||
|
||||
if relevant_prop_changed {
|
||||
self.client_state.set(determine_state(
|
||||
&primary_connection,
|
||||
&primary_connection_type,
|
||||
wireless_enabled,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn subscribe(&self) -> MutableSignalCloned<ClientState> {
|
||||
self.client_state.signal_cloned()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_client() -> Result<Arc<Client>> {
|
||||
let client = Arc::new(Client::new()?);
|
||||
{
|
||||
let client = client.clone();
|
||||
spawn_blocking(move || {
|
||||
if let Err(error) = client.run() {
|
||||
error!("{}", error);
|
||||
};
|
||||
});
|
||||
}
|
||||
Ok(client)
|
||||
}
|
||||
|
||||
fn determine_state(
|
||||
primary_connection: &str,
|
||||
primary_connection_type: &str,
|
||||
wireless_enabled: bool,
|
||||
) -> ClientState {
|
||||
if primary_connection == "/" {
|
||||
if wireless_enabled {
|
||||
ClientState::WifiDisconnected
|
||||
} else {
|
||||
ClientState::Offline
|
||||
}
|
||||
} else {
|
||||
match primary_connection_type {
|
||||
"802-3-ethernet" | "adsl" | "pppoe" => ClientState::WiredConnected,
|
||||
"802-11-olpc-mesh" | "802-11-wireless" | "wifi-p2p" => ClientState::WifiConnected,
|
||||
"cdma" | "gsm" | "wimax" => ClientState::CellularConnected,
|
||||
"vpn" | "wireguard" => ClientState::VpnConnected,
|
||||
_ => ClientState::Unknown,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
register_fallible_client!(Client, network_manager);
|
|
@ -10,11 +10,12 @@ use zbus::export::ordered_stream::OrderedStreamExt;
|
|||
use zbus::zvariant::Type;
|
||||
|
||||
#[derive(Debug, Clone, Copy, Type, Deserialize)]
|
||||
#[allow(dead_code)]
|
||||
pub struct Event {
|
||||
pub count: u32,
|
||||
pub dnd: bool,
|
||||
pub cc_open: bool,
|
||||
// pub inhibited: bool,
|
||||
pub inhibited: bool,
|
||||
}
|
||||
|
||||
type GetSubscribeData = (bool, bool, u32, bool);
|
||||
|
@ -22,12 +23,12 @@ type GetSubscribeData = (bool, bool, u32, bool);
|
|||
/// Converts the data returned from
|
||||
/// `get_subscribe_data` into an event for convenience.
|
||||
impl From<GetSubscribeData> for Event {
|
||||
fn from((dnd, cc_open, count, _inhibited): (bool, bool, u32, bool)) -> Self {
|
||||
fn from((dnd, cc_open, count, inhibited): (bool, bool, u32, bool)) -> Self {
|
||||
Self {
|
||||
count,
|
||||
dnd,
|
||||
cc_open,
|
||||
// inhibited,
|
||||
inhibited,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
use super::manager::DataControlDeviceManagerState;
|
||||
use crate::lock;
|
||||
use nix::fcntl::OFlag;
|
||||
use nix::unistd::{close, pipe2};
|
||||
use nix::unistd::pipe2;
|
||||
use smithay_client_toolkit::data_device_manager::data_offer::DataOfferError;
|
||||
use smithay_client_toolkit::data_device_manager::ReadPipe;
|
||||
use std::ops::DerefMut;
|
||||
use std::os::fd::{AsFd, AsRawFd};
|
||||
use std::os::fd::AsFd;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use tracing::{trace, warn};
|
||||
use tracing::trace;
|
||||
use wayland_client::{Connection, Dispatch, Proxy, QueueHandle};
|
||||
use wayland_protocols_wlr::data_control::v1::client::zwlr_data_control_offer_v1::{
|
||||
Event, ZwlrDataControlOfferV1,
|
||||
|
@ -178,9 +178,5 @@ pub unsafe fn receive(
|
|||
|
||||
offer.receive(mime_type, writefd.as_fd());
|
||||
|
||||
if let Err(err) = close(writefd.as_raw_fd()) {
|
||||
warn!("Failed to close write pipe: {}", err);
|
||||
}
|
||||
|
||||
Ok(ReadPipe::from(readfd))
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@ use crate::modules::label::LabelModule;
|
|||
use crate::modules::launcher::LauncherModule;
|
||||
#[cfg(feature = "music")]
|
||||
use crate::modules::music::MusicModule;
|
||||
#[cfg(feature = "network_manager")]
|
||||
use crate::modules::networkmanager::NetworkManagerModule;
|
||||
#[cfg(feature = "notifications")]
|
||||
use crate::modules::notifications::NotificationsModule;
|
||||
use crate::modules::script::ScriptModule;
|
||||
|
@ -60,6 +62,8 @@ pub enum ModuleConfig {
|
|||
Launcher(Box<LauncherModule>),
|
||||
#[cfg(feature = "music")]
|
||||
Music(Box<MusicModule>),
|
||||
#[cfg(feature = "network_manager")]
|
||||
NetworkManager(Box<NetworkManagerModule>),
|
||||
#[cfg(feature = "notifications")]
|
||||
Notifications(Box<NotificationsModule>),
|
||||
Script(Box<ScriptModule>),
|
||||
|
@ -103,6 +107,8 @@ impl ModuleConfig {
|
|||
Self::Launcher(module) => create!(module),
|
||||
#[cfg(feature = "music")]
|
||||
Self::Music(module) => create!(module),
|
||||
#[cfg(feature = "network_manager")]
|
||||
Self::NetworkManager(module) => create!(module),
|
||||
#[cfg(feature = "notifications")]
|
||||
Self::Notifications(module) => create!(module),
|
||||
Self::Script(module) => create!(module),
|
||||
|
|
|
@ -36,6 +36,8 @@ pub mod label;
|
|||
pub mod launcher;
|
||||
#[cfg(feature = "music")]
|
||||
pub mod music;
|
||||
#[cfg(feature = "network_manager")]
|
||||
pub mod networkmanager;
|
||||
#[cfg(feature = "notifications")]
|
||||
pub mod notifications;
|
||||
pub mod script;
|
||||
|
@ -285,6 +287,8 @@ pub trait ModuleFactory {
|
|||
let id = Ironbar::unique_id();
|
||||
let common = module.take_common();
|
||||
|
||||
debug!("adding module {} (id: {})", TModule::name(), id);
|
||||
|
||||
let (ui_tx, ui_rx) = mpsc::channel::<ModuleUpdateEvent<TSend>>(64);
|
||||
let (controller_tx, controller_rx) = mpsc::channel::<TRev>(64);
|
||||
|
||||
|
|
88
src/modules/networkmanager.rs
Normal file
88
src/modules/networkmanager.rs
Normal file
|
@ -0,0 +1,88 @@
|
|||
use color_eyre::Result;
|
||||
use futures_lite::StreamExt;
|
||||
use futures_signals::signal::SignalExt;
|
||||
use gtk::prelude::ContainerExt;
|
||||
use gtk::{Box as GtkBox, Image, Orientation};
|
||||
use serde::Deserialize;
|
||||
use tokio::sync::mpsc::Receiver;
|
||||
|
||||
use crate::clients::networkmanager::{Client, ClientState};
|
||||
use crate::config::CommonConfig;
|
||||
use crate::gtk_helpers::IronbarGtkExt;
|
||||
use crate::image::ImageProvider;
|
||||
use crate::modules::{Module, ModuleInfo, ModuleParts, ModuleUpdateEvent, WidgetContext};
|
||||
use crate::{glib_recv, module_impl, send_async, spawn};
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
|
||||
pub struct NetworkManagerModule {
|
||||
#[serde(default = "default_icon_size")]
|
||||
icon_size: i32,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub common: Option<CommonConfig>,
|
||||
}
|
||||
|
||||
const fn default_icon_size() -> i32 {
|
||||
24
|
||||
}
|
||||
|
||||
impl Module<GtkBox> for NetworkManagerModule {
|
||||
type SendMessage = ClientState;
|
||||
type ReceiveMessage = ();
|
||||
|
||||
module_impl!("network_manager");
|
||||
|
||||
fn spawn_controller(
|
||||
&self,
|
||||
_: &ModuleInfo,
|
||||
context: &WidgetContext<ClientState, ()>,
|
||||
_: Receiver<()>,
|
||||
) -> Result<()> {
|
||||
let client = context.try_client::<Client>()?;
|
||||
let mut client_signal = client.subscribe().to_stream();
|
||||
let widget_transmitter = context.tx.clone();
|
||||
|
||||
spawn(async move {
|
||||
while let Some(state) = client_signal.next().await {
|
||||
send_async!(widget_transmitter, ModuleUpdateEvent::Update(state));
|
||||
}
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn into_widget(
|
||||
self,
|
||||
context: WidgetContext<ClientState, ()>,
|
||||
info: &ModuleInfo,
|
||||
) -> Result<ModuleParts<GtkBox>> {
|
||||
let container = GtkBox::new(Orientation::Horizontal, 0);
|
||||
let icon = Image::new();
|
||||
icon.add_class("icon");
|
||||
container.add(&icon);
|
||||
|
||||
let icon_theme = info.icon_theme.clone();
|
||||
|
||||
let initial_icon_name = "content-loading-symbolic";
|
||||
ImageProvider::parse(initial_icon_name, &icon_theme, false, self.icon_size)
|
||||
.map(|provider| provider.load_into_image(icon.clone()));
|
||||
|
||||
let widget_receiver = context.subscribe();
|
||||
glib_recv!(widget_receiver, state => {
|
||||
let icon_name = match state {
|
||||
ClientState::WiredConnected => "network-wired-symbolic",
|
||||
ClientState::WifiConnected => "network-wireless-symbolic",
|
||||
ClientState::CellularConnected => "network-cellular-symbolic",
|
||||
ClientState::VpnConnected => "network-vpn-symbolic",
|
||||
ClientState::WifiDisconnected => "network-wireless-acquiring-symbolic",
|
||||
ClientState::Offline => "network-wireless-disabled-symbolic",
|
||||
ClientState::Unknown => "dialog-question-symbolic",
|
||||
};
|
||||
ImageProvider::parse(icon_name, &icon_theme, false, self.icon_size)
|
||||
.map(|provider| provider.load_into_image(icon.clone()));
|
||||
});
|
||||
|
||||
Ok(ModuleParts::new(container, None))
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue