Skip to content

Commit 9ba6d7a

Browse files
authored
Fix --max-volume not working as expected (#200)
* Vastly simplified the volume change logic Fixes: #90 * Fixed clippy complaints * Removed code to unmute device when volume changes
1 parent 8775be1 commit 9ba6d7a

File tree

6 files changed

+106
-220
lines changed

6 files changed

+106
-220
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "swayosd"
33
version = "0.2.1"
4-
edition = "2021"
4+
edition = "2024"
55

66
[[bin]]
77
name = "swayosd-server"

src/client/main.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,16 @@ fn parse_args(args: &ArgsClient, proxy: &ServerProxyBlocking<'_>) {
129129
actions.push((ArgTypes::ScrollLock, Some(value)));
130130
}
131131
// Output volume
132-
if let Some(value) = args.output_volume.as_deref() {
133-
if let Ok(parsed) = volume_parser(false, value) {
134-
actions.push(parsed);
135-
}
132+
if let Some(value) = args.output_volume.as_deref()
133+
&& let Ok(parsed) = volume_parser(false, value)
134+
{
135+
actions.push(parsed);
136136
}
137137
// Input volume
138-
if let Some(value) = args.input_volume.as_deref() {
139-
if let Ok(parsed) = volume_parser(true, value) {
140-
actions.push(parsed);
141-
}
138+
if let Some(value) = args.input_volume.as_deref()
139+
&& let Ok(parsed) = volume_parser(true, value)
140+
{
141+
actions.push(parsed);
142142
}
143143
// Brightness
144144
if let Some(value) = args.brightness.as_deref() {

src/input-backend/main.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,14 @@ fn event(
129129
continue;
130130
}
131131

132-
if let Some(path) = device.devnode() {
133-
if let Some(path) = path.to_str() {
134-
let event_info = EventInfo {
135-
device_path: path.to_owned(),
136-
ev_key,
137-
};
138-
task::spawn(call(event_info, iface_ref.clone()));
139-
}
132+
if let Some(path) = device.devnode()
133+
&& let Some(path) = path.to_str()
134+
{
135+
let event_info = EventInfo {
136+
device_path: path.to_owned(),
137+
ev_key,
138+
};
139+
task::spawn(call(event_info, iface_ref.clone()));
140140
}
141141
}
142142
}

src/mpris-backend/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ impl Playerctl {
7777
PlayerctlDevice::All(players) => {
7878
for player in players {
7979
let icon_new = self.run_single(player);
80-
if let Ok(icon_new) = icon_new {
81-
if icon.is_err() {
82-
icon = Ok(icon_new);
83-
}
80+
if let Ok(icon_new) = icon_new
81+
&& icon.is_err()
82+
{
83+
icon = Ok(icon_new);
8484
};
8585
if metadata.is_none() {
8686
metadata = self.get_metadata(player);
@@ -141,10 +141,10 @@ impl Playerctl {
141141
fn get_metadata(&self, player: &Player) -> Option<Metadata> {
142142
match self.action {
143143
Next | Prev => {
144-
if let Ok(track_list) = player.get_track_list() {
145-
if let Some(track) = track_list.get(0) {
146-
return player.get_track_metadata(track).ok();
147-
}
144+
if let Ok(track_list) = player.get_track_list()
145+
&& let Some(track) = track_list.get(0)
146+
{
147+
return player.get_track_metadata(track).ok();
148148
}
149149
let metadata = player.get_metadata().ok()?;
150150
let name1 = metadata.url()?;

src/server/application.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ impl SwayOSDApplication {
6363
};
6464

6565
// Apply Server Config
66-
if let Some(margin) = server_config.top_margin {
67-
if (0_f32..1_f32).contains(&margin) {
68-
set_top_margin(margin);
69-
}
66+
if let Some(margin) = server_config.top_margin
67+
&& (0_f32..1_f32).contains(&margin)
68+
{
69+
set_top_margin(margin);
7070
}
7171
if let Some(max_volume) = server_config.max_volume {
7272
set_default_max_volume(max_volume);
@@ -363,10 +363,10 @@ impl SwayOSDApplication {
363363
match get_monitor_name() {
364364
Some(monitor_name) => {
365365
for window in self.windows.borrow().to_owned() {
366-
if let Some(monitor_connector) = window.monitor.connector() {
367-
if monitor_name == monitor_connector {
368-
selected_windows.push(window);
369-
}
366+
if let Some(monitor_connector) = window.monitor.connector()
367+
&& monitor_name == monitor_connector
368+
{
369+
selected_windows.push(window);
370370
}
371371
}
372372
}
@@ -578,11 +578,11 @@ impl SwayOSDApplication {
578578
reset_player();
579579
}
580580
(ArgTypes::KbdBacklight, values) => {
581-
if let Some(values) = values {
582-
if let Ok((value, n_segments)) = segmented_progress_parser(&values) {
583-
for window in self.choose_windows() {
584-
window.changed_kbd_backlight(value, n_segments);
585-
}
581+
if let Some(values) = values
582+
&& let Ok((value, n_segments)) = segmented_progress_parser(&values)
583+
{
584+
for window in self.choose_windows() {
585+
window.changed_kbd_backlight(value, n_segments);
586586
}
587587
}
588588
reset_monitor_name();
@@ -620,16 +620,16 @@ impl SwayOSDApplication {
620620
reset_monitor_name();
621621
}
622622
(ArgTypes::CustomSegmentedProgress, values) => {
623-
if let Some(values) = values {
624-
if let Ok((value, n_segments)) = segmented_progress_parser(&values) {
625-
for window in self.choose_windows() {
626-
window.custom_segmented_progress(
627-
value,
628-
n_segments,
629-
get_progress_text(),
630-
get_icon_name().as_deref(),
631-
);
632-
}
623+
if let Some(values) = values
624+
&& let Ok((value, n_segments)) = segmented_progress_parser(&values)
625+
{
626+
for window in self.choose_windows() {
627+
window.custom_segmented_progress(
628+
value,
629+
n_segments,
630+
get_progress_text(),
631+
get_icon_name().as_deref(),
632+
);
633633
}
634634
}
635635
reset_progress_text();

0 commit comments

Comments
 (0)