diff --git a/bin/cli_modes.rs b/bin/cli_modes.rs index 8577bbba510b954a54ae013c866d37a560f4eac6..827741c6bd63e8e13ea43e51a32a6d4d1ebac5a5 100644 --- a/bin/cli_modes.rs +++ b/bin/cli_modes.rs @@ -13,7 +13,7 @@ pub fn start_listen() -> MBGResult<()> { let connection = setup_connection()?; loop { - connection.process(Duration::from_millis(500)).unwrap(); + connection.process(Duration::from_millis(100)).unwrap(); } } diff --git a/example_configs/example1.toml b/example_configs/example1.toml new file mode 100644 index 0000000000000000000000000000000000000000..e511c4bda188f6c92c3082bfe0a6c61ed74c9c41 --- /dev/null +++ b/example_configs/example1.toml @@ -0,0 +1,25 @@ +blender = [0, 2] +reset_command = 'nitrogen --restore' + +[logger] +level = "info" +time_format = '[%Y-%m-%d][%H:%M:%S]' + +[[processors]] +effect = 'Scale' +strength = 1.0 +layer = 0 + +[[processors]] +effect = { Crop = { fit = true } } +layer = 0 + +[[processors]] +effect = 'Blur' +strength = 6.2 +layer = 0 + +[[processors]] +effect = {Border = {circle=false, color = "0E0B7C", width = 1}} +strength = 1.0 +layer = 2 diff --git a/example_configs/example1_res.png b/example_configs/example1_res.png new file mode 100644 index 0000000000000000000000000000000000000000..0033e0b8c9426be48080083881494c9a54fec0b8 Binary files /dev/null and b/example_configs/example1_res.png differ diff --git a/example_confiigs/example1.toml b/example_confiigs/example1.toml deleted file mode 100644 index 50a9da7281b5cdf6acae56d3a0f4d26dcfb06b72..0000000000000000000000000000000000000000 --- a/example_confiigs/example1.toml +++ /dev/null @@ -1,39 +0,0 @@ -blender = [0, 1, 2] - -[logger] -level = "debug" -time_format = '[%Y-%m-%d][%H:%M:%S]' - -[[processors]] -effect = 'Scale' -strength = 1.0 -layer = 0 - -[[processors]] -effect = { Crop = { fit = true } } -layer = 0 - -[[processors]] -effect = 'Blur' -strength = 6.2 -layer = 0 - -[[processors]] -effect = 'Scale' -strength = 0.29 -layer = 1 - -[[processors]] -effect = 'Blur' -strength = 3.2 -layer = 1 - -[[processors]] -effect = {Border = {circle=true, color = "96b7e8"}} -strength = 1.0 -layer = 1 - -[[processors]] -effect = {Border = {circle=false, color = "0E0B7C", width = 7}} -strength = 1.0 -layer = 2 diff --git a/example_confiigs/example1_res.png b/example_confiigs/example1_res.png deleted file mode 100644 index 25bae01690e102d2328054adc963de2160daa89d..0000000000000000000000000000000000000000 Binary files a/example_confiigs/example1_res.png and /dev/null differ diff --git a/lib/background.rs b/lib/background.rs index f67152ab6c5a0aa93c24132fa4f4dd4ada4fac2e..c476c6e1fb7bb36e5282917dfde434b0d07011d3 100644 --- a/lib/background.rs +++ b/lib/background.rs @@ -11,13 +11,13 @@ pub fn reset_background_handler(_: (), _: &Connection, message: &Message) -> boo let member_name = message.read1::<String>(); if let Ok(name) = member_name { if name.starts_with("org.mpris.MediaPlayer2.") { - nitrogen_restore(); + reset_bg(); } } true } -pub fn nitrogen_restore() { +pub fn reset_bg() { info!("Reset BG"); let config = Config::get_props(); let out = Command::new("sh") @@ -33,7 +33,7 @@ pub fn process_image_url(image_url: String) -> MBGResult<()> { let resp = attohttpc::get(image_url.as_str()).send()?; let bytes_vec = resp.bytes()?; let res = process_image(bytes_vec)?; - let img_path = "/dev/shm/test.png"; + let img_path = "/tmp/music_bg.png"; res.save(img_path)?; set_wallpaper(img_path); Ok(()) diff --git a/lib/config/mod.rs b/lib/config/mod.rs index 4ee97c8396b197294e735351b0a2d99f6a81f4fe..9ac464a71118b39da1722fac03c91e840b3041b6 100644 --- a/lib/config/mod.rs +++ b/lib/config/mod.rs @@ -29,11 +29,13 @@ pub fn reset_command_default() -> String { } pub fn set_command_default() -> String { - String::from(r#"nitrogen --set-auto "{}""#) + String::from(r#"feh --bg-fill "{}""#) } pub fn screen_resolution_command_default() -> String { - String::from("xrandr | grep '*' | cut -d' ' -f4") + String::from( + "xrandr | grep '*' | cut -d' ' -f4 | sort --human-numeric-sort --reverse | head -n 1", + ) } impl Config { diff --git a/lib/dbus_interface/player_dbus.rs b/lib/dbus_interface/player_dbus.rs index 911d6e72b4f85755586f11c2a802422768faff20..f89e14107d9616082b011bc7835524f8f53ed46f 100644 --- a/lib/dbus_interface/player_dbus.rs +++ b/lib/dbus_interface/player_dbus.rs @@ -6,7 +6,7 @@ use dbus::blocking::Connection; use dbus::message::{MatchRule, SignalArgs}; use dbus::{arg, Message}; -use crate::background::{nitrogen_restore, process_image_url, reset_background_handler}; +use crate::background::{reset_bg, process_image_url, reset_background_handler}; use crate::dbus_interface::main_dbus::DBusNameOwnerChanged; use crate::dbus_interface::media_player::OrgMprisMediaPlayer2Player; use crate::dbus_interface::statuses::PlayerStatus; @@ -76,8 +76,8 @@ pub fn player_state_router(_: (), connection: &Connection, message: &Message) -> return true; } } - PlayerStatus::Paused => nitrogen_restore(), - PlayerStatus::Stopped => nitrogen_restore(), + PlayerStatus::Paused => reset_bg(), + PlayerStatus::Stopped => reset_bg(), PlayerStatus::Unknown => {} } true diff --git a/lib/display.rs b/lib/display.rs index f1a3847fcf83c79dba9992dab070bdc59a1ae197..44062e9dc29f532ea223866b52a2b03cc51655d1 100644 --- a/lib/display.rs +++ b/lib/display.rs @@ -1,6 +1,7 @@ use std::process::Command; use crate::config::Config; +use crate::result::MBGError; use crate::result::MBGResult; pub fn get_max_resolution() -> MBGResult<(i32, i32)> { @@ -18,6 +19,8 @@ pub fn get_max_resolution() -> MBGResult<(i32, i32)> { .split('x') .map(|slice| slice.parse()) .collect::<Result<Vec<_>, _>>()?; - + if splitted.len() != 2 { + return Err(MBGError::ResolutionFormatErr(String::from(out))); + } Ok((splitted[0], splitted[1])) } diff --git a/lib/result.rs b/lib/result.rs index 581df0cc782eac044846c480b3ed056d424153fb..e7c4a3a15cc9891e4fdc108425a5cd6712f91a73 100644 --- a/lib/result.rs +++ b/lib/result.rs @@ -8,6 +8,8 @@ pub enum MBGError { DBusErr(String), #[fail(display = "Configuration file parsing error: {}", _0)] ConfigErr(String), + #[fail(display = "Invalid screen resolution string: {}", _0)] + ResolutionFormatErr(String), #[fail(display = "Error while processing metadata from D-BUS: {}", _0)] MetadataError(String), #[fail(display = "Error while fetching image: {}", _0)]