Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root = true

[*.rs]
charset = utf-8
end_of_line = lf
indent_size = tab
indent_style = tab
insert_final_newline = true
max_line_length = 100
tab_width = 4
5 changes: 5 additions & 0 deletions data/config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ min_brightness = 5
## Available values:
## artist, albumArtist, title, album, trackNumber, discNumber, autoRating

# If SwayOSD should automatically display the OSD when the keyboard backlight changes or not.
# Note: Only displays the OSD if the hardware changed the keyboard brightness itself
# (automatically or through a firmware-handled hotkey being pressed)
keyboard_backlight = true

[client]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 13 additions & 3 deletions data/style/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,32 @@ window#osd {
opacity: 0.5;
}

progressbar {
progressbar,
segmentedprogress {
min-height: 6px;
border-radius: 999px;
background: transparent;
border: none;
}
trough {
trough,
segment {
min-height: inherit;
border-radius: inherit;
border: none;
background: #{"alpha(@theme_fg_color, 0.5)"};
}
progress {
progress,
segment.active {
min-height: inherit;
border-radius: inherit;
border: none;
background: #{"@theme_fg_color"};
}

segment {
margin-left: 8px;
&:first-child {
margin-left: 0;
}
}
}
4 changes: 4 additions & 0 deletions data/swayosd.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,9 @@
<file>icons/scalable/status/playlist-consecutive-symbolic.svg</file>
<file>icons/scalable/status/playlist-shuffle-symbolic.svg</file>
<file>icons/scalable/status/stop-large-symbolic.svg</file>

<file>icons/scalable/status/keyboard-brightness-high-symbolic.svg</file>
<file>icons/scalable/status/keyboard-brightness-medium-symbolic.svg</file>
<file>icons/scalable/status/keyboard-brightness-off-symbolic.svg</file>
</gresource>
</gresources>
6 changes: 6 additions & 0 deletions src/argtypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub enum ArgTypes {
CustomMessage = 13,
Playerctl = 14,
CustomProgress = 15,
CustomSegmentedProgress = 16,
KbdBacklight = 17,
}

impl fmt::Display for ArgTypes {
Expand Down Expand Up @@ -56,8 +58,10 @@ impl fmt::Display for ArgTypes {
ArgTypes::Player => "PLAYER",
ArgTypes::MonitorName => "MONITOR-NAME",
ArgTypes::CustomProgress => "CUSTOM-PROGRESS",
ArgTypes::CustomSegmentedProgress => "CUSTOM-SEGMENTED-PROGRESS",
ArgTypes::CustomProgressText => "CUSTOM-PROGRESS-TEXT",
ArgTypes::MinBrightness => "MIN-BRIGHTNESS",
ArgTypes::KbdBacklight => "KBD-BACKLIGHT",
};
write!(f, "{}", string)
}
Expand Down Expand Up @@ -89,8 +93,10 @@ impl str::FromStr for ArgTypes {
"PLAYER" => ArgTypes::Player,
"MONITOR-NAME" => ArgTypes::MonitorName,
"CUSTOM-PROGRESS" => ArgTypes::CustomProgress,
"CUSTOM-SEGMENTED-PROGRESS" => ArgTypes::CustomSegmentedProgress,
"CUSTOM-PROGRESS-TEXT" => ArgTypes::CustomProgressText,
"MIN-BRIGHTNESS" => ArgTypes::MinBrightness,
"KBD-BACKLIGHT" => ArgTypes::KbdBacklight,
other_type => return Err(other_type.to_owned()),
};
Ok(result)
Expand Down
9 changes: 9 additions & 0 deletions src/client/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,15 @@ fn main() -> Result<(), glib::Error> {
Some("Progress from 0.0 to 1.0"),
);

app.add_main_option(
"custom-segmented-progress",
glib::Char::from(0),
OptionFlags::NONE,
OptionArg::String,
"Segmented progress to display (value:num-segments). Ex: 2:4",
Some("Progress from 0 to num-segments"),
);

app.add_main_option(
"custom-progress-text",
glib::Char::from(0),
Expand Down
1 change: 1 addition & 0 deletions src/config/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct ServerConfig {
pub show_percentage: Option<bool>,
pub playerctl_format: Option<String>,
pub min_brightness: Option<u32>,
pub keyboard_backlight: Option<bool>,
}

#[derive(Deserialize, Default, Debug)]
Expand Down
33 changes: 33 additions & 0 deletions src/global_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,20 @@ pub(crate) fn handle_application_args(
}
}
}
"custom-segmented-progress" => {
let value = child.value().str().unwrap_or("").trim();
let parsed = segmented_progress_parser(value);
match parsed {
Ok((value, n_segments)) => (
ArgTypes::CustomSegmentedProgress,
Some(format!("{}:{}", value, n_segments)),
),
Err(msg) => {
eprintln!("{}", msg);
return (HandleLocalStatus::FAILURE, actions);
}
}
}
"custom-progress-text" => {
let value = match child.value().str() {
Some(v) => v.to_string(),
Expand Down Expand Up @@ -273,6 +287,25 @@ fn volume_parser(is_sink: bool, value: &str) -> Result<(ArgTypes, Option<String>
Ok(v)
}

pub fn segmented_progress_parser(ref_value: &str) -> Result<(u32, u32), String> {
let (value, n_segments) = match ref_value.split_once(":") {
Some(v) => v,
None => {
return Err(format!(
"Value {} not valid for segmented_progress",
ref_value
));
}
};
match (value.parse::<u32>(), n_segments.parse::<u32>()) {
(Ok(value), Ok(max)) => Ok((value, max)),
_ => Err(format!(
"Value {} not valid for segmented_progress. Must contain positive integers",
ref_value
)),
}
}

pub fn div_round_u32(a: u32, b: u32) -> u32 {
(a + b / 2) / b
}
Loading