Clippy
This commit is contained in:
@@ -136,34 +136,31 @@ impl ActionCentre {
|
||||
glib::timeout_add_local(Duration::from_millis(100), move || {
|
||||
while let Ok(message) = net_rx.try_recv() {
|
||||
match message {
|
||||
NetworkState::ChangeNetwork(info) => match info {
|
||||
Some(info) => {
|
||||
for (name, widget) in wifi_networks_clone.borrow().iter() {
|
||||
if name.eq(&info.name) {
|
||||
widget.add_css_class("connected");
|
||||
} else {
|
||||
widget.remove_css_class("connected");
|
||||
}
|
||||
NetworkState::ChangeNetwork(Some(info)) => {
|
||||
for (name, widget) in wifi_networks_clone.borrow().iter() {
|
||||
if name.eq(&info.name) {
|
||||
widget.add_css_class("connected");
|
||||
} else {
|
||||
widget.remove_css_class("connected");
|
||||
}
|
||||
}
|
||||
None => {}
|
||||
},
|
||||
}
|
||||
NetworkState::Networks(networks) => {
|
||||
for network in &networks {
|
||||
let borrowed_wifi_networks_clone = wifi_networks_clone.borrow_mut();
|
||||
let widget = borrowed_wifi_networks_clone.get(&network.name);
|
||||
if widget.is_none() {
|
||||
if let Some(widget) = widget {
|
||||
let idx = ((network.signal as f32 / 100.0)
|
||||
* (WIFI_ICONS.len() - 1) as f32
|
||||
+ 0.5) as usize;
|
||||
widget.set_wifi_icon_from_name(WIFI_ICONS[idx]);
|
||||
} else {
|
||||
let widget = Self::create_wifi_widget(
|
||||
&channels,
|
||||
network,
|
||||
borrowed_wifi_networks_clone,
|
||||
);
|
||||
content.append(&widget);
|
||||
} else {
|
||||
let idx = ((network.signal as f32 / 100.0)
|
||||
* (WIFI_ICONS.len() - 1) as f32
|
||||
+ 0.5) as usize;
|
||||
widget.unwrap().set_wifi_icon_from_name(WIFI_ICONS[idx]);
|
||||
}
|
||||
}
|
||||
let mut removal: Vec<String> = Vec::new();
|
||||
@@ -179,7 +176,7 @@ impl ActionCentre {
|
||||
}
|
||||
}
|
||||
NetworkState::Auth(ssid, auth) => {
|
||||
if let Some(widget) = Self::find_focused_widget((&window_clone).as_ref()) {
|
||||
if let Some(widget) = Self::find_focused_widget(window_clone.as_ref()) {
|
||||
match auth {
|
||||
AuthType::Password => {
|
||||
if widget.ssid().eq(&ssid) {
|
||||
@@ -268,7 +265,7 @@ impl ActionCentre {
|
||||
wifi_networks: &Rc<RefCell<HashMap<String, WifiWidget>>>,
|
||||
window: &ApplicationWindow,
|
||||
) {
|
||||
for (_, widget) in wifi_networks.clone().borrow().iter() {
|
||||
for widget in wifi_networks.clone().borrow().values() {
|
||||
let focused_inside = window.focus().is_some_and(|mut focus| {
|
||||
loop {
|
||||
if focus == *widget {
|
||||
@@ -329,8 +326,6 @@ impl ActionCentre {
|
||||
if !window.is_visible() {
|
||||
self.animate_margin(-window.width() - 20, 20, ANIMATION_DURATION, || {});
|
||||
window.present();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,22 +17,21 @@ pub fn build() -> Button {
|
||||
title.set_visible(false);
|
||||
title.add_css_class("title");
|
||||
title.connect_clicked(|button| {
|
||||
if button.has_css_class("media") {
|
||||
if let Ok(player_finder) = PlayerFinder::new() {
|
||||
if let Ok(player) = player_finder.find_active() {
|
||||
let _ = player.play_pause();
|
||||
}
|
||||
}
|
||||
if button.has_css_class("media")
|
||||
&& let Ok(player_finder) = PlayerFinder::new()
|
||||
&& let Ok(player) = player_finder.find_active()
|
||||
{
|
||||
let _ = player.play_pause();
|
||||
}
|
||||
});
|
||||
|
||||
let right_click = GestureClick::new();
|
||||
right_click.set_button(3);
|
||||
right_click.connect_pressed(|_gesture, _n_press, _, _| {
|
||||
if let Ok(player_finder) = PlayerFinder::new() {
|
||||
if let Ok(player) = player_finder.find_active() {
|
||||
let _ = player.stop();
|
||||
}
|
||||
if let Ok(player_finder) = PlayerFinder::new()
|
||||
&& let Ok(player) = player_finder.find_active()
|
||||
{
|
||||
let _ = player.stop();
|
||||
}
|
||||
});
|
||||
title.add_controller(right_click);
|
||||
@@ -41,35 +40,35 @@ pub fn build() -> Button {
|
||||
|
||||
pub fn manage_title(button_opt: &Option<Button>, player_opt: &Option<Player>) {
|
||||
let mut handled = false;
|
||||
if let Some(button) = button_opt {
|
||||
if let Some(player) = player_opt {
|
||||
if let Ok(status) = player.get_playback_status() {
|
||||
if let Ok(metadata) = player.get_metadata() {
|
||||
match status {
|
||||
PlaybackStatus::Playing => {
|
||||
button.set_visible(true);
|
||||
button.child()
|
||||
.and_downcast::<Label>()
|
||||
.unwrap()
|
||||
.set_label(&format!(" {}", metadata.title().unwrap_or("")));
|
||||
button.add_css_class("media");
|
||||
button.add_css_class("playing");
|
||||
handled = true;
|
||||
}
|
||||
PlaybackStatus::Paused => {
|
||||
button.set_visible(true);
|
||||
button.child()
|
||||
.and_downcast::<Label>()
|
||||
.unwrap()
|
||||
.set_label(&format!(" {}", metadata.title().unwrap_or("")));
|
||||
button.add_css_class("media");
|
||||
button.remove_css_class("playing");
|
||||
handled = true;
|
||||
}
|
||||
PlaybackStatus::Stopped => {},
|
||||
}
|
||||
}
|
||||
if let Some(button) = button_opt
|
||||
&& let Some(player) = player_opt
|
||||
&& let Ok(status) = player.get_playback_status()
|
||||
&& let Ok(metadata) = player.get_metadata()
|
||||
{
|
||||
match status {
|
||||
PlaybackStatus::Playing => {
|
||||
button.set_visible(true);
|
||||
button
|
||||
.child()
|
||||
.and_downcast::<Label>()
|
||||
.unwrap()
|
||||
.set_label(&format!(" {}", metadata.title().unwrap_or("")));
|
||||
button.add_css_class("media");
|
||||
button.add_css_class("playing");
|
||||
handled = true;
|
||||
}
|
||||
PlaybackStatus::Paused => {
|
||||
button.set_visible(true);
|
||||
button
|
||||
.child()
|
||||
.and_downcast::<Label>()
|
||||
.unwrap()
|
||||
.set_label(&format!(" {}", metadata.title().unwrap_or("")));
|
||||
button.add_css_class("media");
|
||||
button.remove_css_class("playing");
|
||||
handled = true;
|
||||
}
|
||||
PlaybackStatus::Stopped => {}
|
||||
}
|
||||
if !handled {
|
||||
button.set_visible(true);
|
||||
@@ -87,9 +86,10 @@ pub fn set_title(title: &str, title_button: &Option<Button>) {
|
||||
} else {
|
||||
button.set_visible(true);
|
||||
}
|
||||
button.child()
|
||||
button
|
||||
.child()
|
||||
.and_downcast::<Label>()
|
||||
.unwrap()
|
||||
.set_label(&HyprlandComms::get_current_title());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ pub fn build(
|
||||
button.remove_css_class("on")
|
||||
}
|
||||
} else {
|
||||
if let Ok(_) = child.as_mut().unwrap().kill() {
|
||||
if child.as_mut().unwrap().kill().is_ok() {
|
||||
let _ = child.take();
|
||||
button.add_css_class("on");
|
||||
}
|
||||
@@ -316,10 +316,9 @@ pub fn build(
|
||||
|
||||
glib::timeout_add_local(Duration::from_millis(1000), move || {
|
||||
let timestamp = time_format::now().unwrap();
|
||||
let time_str = time_format::strftime_local("%H:%M", timestamp).unwrap_or(String::new());
|
||||
let time_str = time_format::strftime_local("%H:%M", timestamp).unwrap_or_default();
|
||||
time.set_title(&time_str);
|
||||
let time_sec =
|
||||
time_format::strftime_local(":%S %Y-%m-%d", timestamp).unwrap_or(String::new());
|
||||
let time_sec = time_format::strftime_local(":%S %Y-%m-%d", timestamp).unwrap_or_default();
|
||||
time_hidden.set_label(&time_sec);
|
||||
ControlFlow::Continue
|
||||
});
|
||||
@@ -332,46 +331,40 @@ pub fn build(
|
||||
let hypridle = channels.hypridle();
|
||||
glib::timeout_add_local(Duration::from_millis(100), move || {
|
||||
while let Ok(command) = media_rx.try_recv() {
|
||||
match command {
|
||||
MediaCommand::Cmd(vol, mute, bt) => {
|
||||
changed_progr.set(true);
|
||||
volume.set_value(vol as f64);
|
||||
changed_progr.set(false);
|
||||
volume.show_scale(!mute);
|
||||
volume.imp().button.set_active(mute);
|
||||
if mute {
|
||||
volume.imp().button.add_css_class("muted");
|
||||
volume.imp().second_icon.add_child_css_class("muted");
|
||||
volume
|
||||
.imp()
|
||||
.main_icon
|
||||
.set_icon_path("icons/volume-mute.svg");
|
||||
} else {
|
||||
volume.imp().button.remove_css_class("muted");
|
||||
volume.imp().second_icon.remove_child_css_class("muted");
|
||||
let idx = ((volume.value() / 100.0) * (VOLUME_ICON_PATHS.len() - 1) as f64
|
||||
+ 0.5) as usize;
|
||||
volume.imp().main_icon.set_icon_path(VOLUME_ICON_PATHS[idx]);
|
||||
}
|
||||
volume.imp().second_icon.set_visible(bt);
|
||||
if let MediaCommand::Cmd(vol, mute, bt) = command {
|
||||
changed_progr.set(true);
|
||||
volume.set_value(vol as f64);
|
||||
changed_progr.set(false);
|
||||
volume.show_scale(!mute);
|
||||
volume.imp().button.set_active(mute);
|
||||
if mute {
|
||||
volume.imp().button.add_css_class("muted");
|
||||
volume.imp().second_icon.add_child_css_class("muted");
|
||||
volume
|
||||
.imp()
|
||||
.main_icon
|
||||
.set_icon_path("icons/volume-mute.svg");
|
||||
} else {
|
||||
volume.imp().button.remove_css_class("muted");
|
||||
volume.imp().second_icon.remove_child_css_class("muted");
|
||||
let idx = ((volume.value() / 100.0) * (VOLUME_ICON_PATHS.len() - 1) as f64
|
||||
+ 0.5) as usize;
|
||||
volume.imp().main_icon.set_icon_path(VOLUME_ICON_PATHS[idx]);
|
||||
}
|
||||
_ => {}
|
||||
volume.imp().second_icon.set_visible(bt);
|
||||
}
|
||||
}
|
||||
while let Ok(message) = br_rx.try_recv() {
|
||||
match message {
|
||||
BrightnessMessage::Value(mon, value) => {
|
||||
if monitor.eq(&mon) {
|
||||
brightness.set_value(value as f64);
|
||||
let idx = ((value as f32 / 100.0) * (BRIGHTNESS_ICONS.len() - 1) as f32
|
||||
+ 0.5) as usize;
|
||||
brightness
|
||||
.imp()
|
||||
.main_icon
|
||||
.set_font_icon(BRIGHTNESS_ICONS[idx]);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
if let BrightnessMessage::Value(mon, value) = message
|
||||
&& monitor.eq(&mon)
|
||||
{
|
||||
brightness.set_value(value as f64);
|
||||
let idx =
|
||||
((value as f32 / 100.0) * (BRIGHTNESS_ICONS.len() - 1) as f32 + 0.5) as usize;
|
||||
brightness
|
||||
.imp()
|
||||
.main_icon
|
||||
.set_font_icon(BRIGHTNESS_ICONS[idx]);
|
||||
}
|
||||
}
|
||||
if let Ok(mut hypridle) = hypridle.try_lock() {
|
||||
@@ -416,16 +409,13 @@ pub fn build(
|
||||
}
|
||||
}
|
||||
}
|
||||
NetworkState::VpnState { connected, profile } => match profile.as_str() {
|
||||
"wg" => {
|
||||
if connected {
|
||||
wg_button.add_css_class("on");
|
||||
} else {
|
||||
wg_button.remove_css_class("on");
|
||||
}
|
||||
NetworkState::VpnState { connected, profile } if profile.as_str() == "wg" => {
|
||||
if connected {
|
||||
wg_button.add_css_class("on");
|
||||
} else {
|
||||
wg_button.remove_css_class("on");
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@@ -468,9 +458,8 @@ pub fn build(
|
||||
}
|
||||
}
|
||||
|
||||
for gpu in stats.gpus {
|
||||
if let Some(gpu) = stats.gpus.into_iter().next() {
|
||||
gpu_label.set_label(&format!("{}%", gpu.1));
|
||||
break;
|
||||
}
|
||||
|
||||
set_battery_css_classes(&battery_widget, stats.battery_state, stats.battery_charge);
|
||||
|
||||
@@ -7,7 +7,10 @@ use hyprland::prelude::HyprDataActive;
|
||||
use jmb_logger_rs::*;
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub(crate) fn build(buttons: &mut HashMap<i32, Button>, monitor: Option<u32>) -> (gtk::Box, Button) {
|
||||
pub(crate) fn build(
|
||||
buttons: &mut HashMap<i32, Button>,
|
||||
monitor: Option<u32>,
|
||||
) -> (gtk::Box, Button) {
|
||||
let workspaces = gtk::Box::new(Orientation::Horizontal, 0);
|
||||
workspaces.set_halign(Align::Start);
|
||||
workspaces.set_valign(Align::Center);
|
||||
@@ -24,13 +27,12 @@ pub(crate) fn build(buttons: &mut HashMap<i32, Button>, monitor: Option<u32>) ->
|
||||
|
||||
let initial_workspace = Workspace::get_active()
|
||||
.ok()
|
||||
.map(|workspace| workspace.id().unwrap_or(1) as i32)
|
||||
.map(|workspace| workspace.id().unwrap_or(1))
|
||||
.unwrap_or(1);
|
||||
|
||||
let is_active_ws_on_current_monitor = Workspace::get_active()
|
||||
.ok()
|
||||
.map(|ws| ws.monitor_id)
|
||||
.flatten()
|
||||
.and_then(|ws| ws.monitor_id)
|
||||
.is_some_and(|id| monitor.is_some_and(|other_id| id == other_id as i128));
|
||||
|
||||
if workspace == initial_workspace && is_active_ws_on_current_monitor {
|
||||
@@ -41,8 +43,14 @@ pub(crate) fn build(buttons: &mut HashMap<i32, Button>, monitor: Option<u32>) ->
|
||||
button.set_visible(true);
|
||||
}
|
||||
button.connect_clicked(move |_button| {
|
||||
if let Err(err) = HyprlandComms::dispatch(&format!("hl.dsp.focus({{ workspace = {workspace} }})")) {
|
||||
warn!(&LOGGER, "Couldn't change workspace focus {}", err.to_string());
|
||||
if let Err(err) =
|
||||
HyprlandComms::dispatch(&format!("hl.dsp.focus({{ workspace = {workspace} }})"))
|
||||
{
|
||||
warn!(
|
||||
&LOGGER,
|
||||
"Couldn't change workspace focus {}",
|
||||
err.to_string()
|
||||
);
|
||||
}
|
||||
});
|
||||
workspaces.append(&button);
|
||||
@@ -59,4 +67,4 @@ pub(crate) fn build(buttons: &mut HashMap<i32, Button>, monitor: Option<u32>) ->
|
||||
workspaces.append(&submap_button);
|
||||
|
||||
(workspaces, submap_button)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user