added ipc
This commit is contained in:
parent
65b84198f4
commit
dadd07c4c6
@ -5,6 +5,7 @@ pub enum WallpaperHandler {
|
||||
Feh,
|
||||
Plasma,
|
||||
Gnome,
|
||||
Hyprpaper,
|
||||
Error,
|
||||
}
|
||||
|
||||
@ -14,6 +15,7 @@ impl WallpaperHandler {
|
||||
"feh" => WallpaperHandler::Feh,
|
||||
"plasma" => WallpaperHandler::Plasma,
|
||||
"gnome" => WallpaperHandler::Gnome,
|
||||
"hyprpaper" => WallpaperHandler::Hyprpaper,
|
||||
_ => WallpaperHandler::Error,
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,18 +1,17 @@
|
||||
use std::fmt::Write as _;
|
||||
use crate::lib::ipc;
|
||||
use crate::Wallpapers;
|
||||
|
||||
use std::process::Command;
|
||||
|
||||
pub fn change_wallpapers(wallpapers: &Wallpapers) {
|
||||
let mut command = Command::new("/usr/bin/feh");
|
||||
command.arg("--no-fehbg").arg("--bg-fill");
|
||||
let ipc = ipc::IPC::new(String::from("/run/user/1000/hypr/9958d297641b5c84dcff93f9039d80a5ad37ab00_1751412591_2000702590/.hyprpaper.sock"));
|
||||
|
||||
for monitor in wallpapers.config.monitors.monitors.iter() {
|
||||
command.arg(wallpapers.random_selection(&monitor.ratio).to_string());
|
||||
let mut buf = String::new();
|
||||
let x = wallpapers.random_selection(&monitor.ratio).to_string();
|
||||
write!(&mut buf, "reload ,{}", x).unwrap();
|
||||
ipc.clone().write(buf);
|
||||
// println!("{}", buf);
|
||||
}
|
||||
|
||||
let result = command.output();
|
||||
match result {
|
||||
Ok(_) => {}
|
||||
Err(e) => println!("{}", e),
|
||||
}
|
||||
// println!("{}", ipc.write(String::from("")))
|
||||
}
|
||||
|
||||
28
src/lib/ipc.rs
Normal file
28
src/lib/ipc.rs
Normal file
@ -0,0 +1,28 @@
|
||||
use std::{io::Write, os::unix::net::UnixStream};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct IPC {
|
||||
path: String
|
||||
}
|
||||
|
||||
impl IPC {
|
||||
pub fn new(path: String) -> IPC {
|
||||
IPC{ path: path}
|
||||
}
|
||||
|
||||
pub fn write(self, data: String) -> bool {
|
||||
let mut stream = UnixStream::connect(&self.path).unwrap();
|
||||
let resp = stream.write_all(data.as_bytes());
|
||||
match resp {
|
||||
Ok(_) => return true,
|
||||
Err(_) => return false,
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
pub fn read(self) -> String {
|
||||
// let mut x = String::new();
|
||||
String::from(self.path)
|
||||
}
|
||||
}
|
||||
1
src/lib/mod.rs
Normal file
1
src/lib/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod ipc;
|
||||
@ -5,6 +5,7 @@ mod files;
|
||||
use enums::WallpaperHandler;
|
||||
use files::*;
|
||||
mod handlers;
|
||||
mod lib;
|
||||
|
||||
use untildify::untildify;
|
||||
|
||||
@ -32,6 +33,9 @@ fn main() {
|
||||
WallpaperHandler::Gnome => {
|
||||
handlers::gnome::change_wallpapers(&wallpapers);
|
||||
}
|
||||
WallpaperHandler::Hyprpaper => {
|
||||
handlers::hyprpaper::change_wallpapers(&wallpapers);
|
||||
}
|
||||
_ => {
|
||||
println!("Error: Unknown wallpaper engine");
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user