-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
122 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#[cfg(any(target_os = "linux", target_os = "netbsd"))] | ||
pub mod unix; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use crate::util::{arguments::Cli, config::ConfigFile}; | ||
use color_eyre::{eyre::Result, Report}; | ||
|
||
use std::process::Command; | ||
|
||
use crate::SchemesEnum; | ||
|
||
#[cfg(any(target_os = "linux", target_os = "netbsd"))] | ||
pub fn reload(args: &Cli, config: &ConfigFile) -> Result<(), Report> { | ||
if config.config.reload_apps_list.is_none() { | ||
warn!("<d>The option <yellow><u>config.reload_apps<b></><d> is set to <u><green>TRUE</>, but <yellow><u>config.reload_apps_list</><d> is <u><red>EMPTY</>. Not restarting any apps...</>"); | ||
return Ok(()); | ||
} | ||
|
||
let reload_apps_list = &config.config.reload_apps_list.as_ref().unwrap(); | ||
|
||
if reload_apps_list.waybar == Some(true) || reload_apps_list.waybar.is_none() { | ||
reload_app("waybar", "SIGUSR2")?; | ||
} | ||
|
||
if reload_apps_list.kitty == Some(true) || reload_apps_list.waybar.is_none() { | ||
reload_app("kitty", "SIGUSR1")?; | ||
} | ||
|
||
if reload_apps_list.dunst == Some(true) || reload_apps_list.waybar.is_none() { | ||
reload_app("dunst", "SIGUSR2")?; | ||
} | ||
|
||
if reload_apps_list.gtk_theme == Some(true) || reload_apps_list.waybar.is_none() { | ||
reload_gtk_theme(args)?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
#[cfg(any(target_os = "linux", target_os = "netbsd"))] | ||
pub fn reload_app(name: &str, signal: &str) -> Result<(), Report> { | ||
info!("Restarting {}", name); | ||
let mut kill = Command::new("pkill"); | ||
kill.arg(format!("-{}", signal)); | ||
kill.arg(name); | ||
|
||
kill.spawn()?; | ||
Ok(()) | ||
} | ||
|
||
#[cfg(any(target_os = "linux", target_os = "netbsd"))] | ||
fn reload_gtk_theme(args: &Cli) -> Result<(), Report> { | ||
let mode = match args.mode { | ||
Some(SchemesEnum::Light) => "light", | ||
Some(SchemesEnum::Dark) => "dark", | ||
Some(SchemesEnum::Amoled) => "dark", | ||
None => "dark", | ||
}; | ||
|
||
info!("Setting gtk theme to adw-gtk3-{}", mode); | ||
|
||
set_theme("")?; | ||
set_theme(format!("adw-gtk3-{}", mode).as_str())?; | ||
Ok(()) | ||
} | ||
|
||
#[cfg(any(target_os = "linux", target_os = "netbsd"))] | ||
fn set_theme(theme: &str) -> Result<(), Report> { | ||
Command::new("gsettings") | ||
.args(["set", "org.gnome.desktop.interface", "gtk-theme", theme]) | ||
.spawn()?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,3 @@ pub mod config; | |
pub mod image; | ||
pub mod reload; | ||
pub mod template; | ||
pub mod wallpaper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#[cfg(any(target_os = "linux", target_os = "netbsd"))] | ||
pub mod unix; | ||
|
||
#[cfg(target_os = "windows")] | ||
pub mod windows; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use color_eyre::Report; | ||
|
||
#[cfg(target_os = "windows")] | ||
use std::ffi::OsStr; | ||
use std::io; | ||
use std::iter; | ||
use std::mem; | ||
use std::os::windows::ffi::OsStrExt; | ||
use winapi::ctypes::c_void; | ||
use winapi::um::winuser::SystemParametersInfoW; | ||
use winapi::um::winuser::SPIF_SENDCHANGE; | ||
use winapi::um::winuser::SPIF_UPDATEINIFILE; | ||
use winapi::um::winuser::SPI_SETDESKWALLPAPER; | ||
|
||
#[cfg(target_os = "windows")] | ||
pub fn set(path: &String) -> Result<(), Report> { | ||
unsafe { | ||
let path = OsStr::new(path) | ||
.encode_wide() | ||
// append null byte | ||
.chain(iter::once(0)) | ||
.collect::<Vec<u16>>(); | ||
let successful = SystemParametersInfoW( | ||
SPI_SETDESKWALLPAPER, | ||
0, | ||
path.as_ptr() as *mut c_void, | ||
SPIF_UPDATEINIFILE | SPIF_SENDCHANGE, | ||
) == 1; | ||
|
||
if successful { | ||
Ok(()) | ||
} else { | ||
Err(io::Error::last_os_error().into()) | ||
} | ||
} | ||
} |