Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: wpaperctl set MONITOR NEW_WP_PATH #70

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
19 changes: 14 additions & 5 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn main() {
let mut json_resp = false;

let mut conn = UnixStream::connect(socket_path().unwrap()).unwrap();
let msg = match args.subcmd {
let msg: IpcMessage = match args.subcmd {
SubCmd::GetWallpaper { monitor } => IpcMessage::CurrentWallpaper { monitor },
SubCmd::AllWallpapers { json } => {
json_resp = json;
Expand All @@ -29,15 +29,24 @@ fn main() {
SubCmd::ReloadWallpaper { monitors } => IpcMessage::ReloadWallpaper { monitors },
SubCmd::PauseWallpaper { monitors } => IpcMessage::PauseWallpaper { monitors },
SubCmd::ResumeWallpaper { monitors } => IpcMessage::ResumeWallpaper { monitors },
SubCmd::SetWallaper {
wallpaper,
monitors,
} => IpcMessage::SetWallpaper {
wallpaper,
monitors,
},
};

conn.write_all(&serde_json::to_vec(&msg).unwrap()).unwrap();
let mut buf = String::new();
conn.read_to_string(&mut buf).unwrap();
let res: Result<IpcResponse, IpcError> =
serde_json::from_str(&buf).expect("wpaperd to return a valid json");
let res: Result<IpcResponse, IpcError> = serde_json::from_str(&buf)
.unwrap_or_else(|_| panic!("wpaperd to should valid json {}", &buf));

match res {
Ok(resp) => match resp {
IpcResponse::CurrentWallpaper { path } => println!("{}", path.to_string_lossy()),
IpcResponse::CurrentWallpaper { path } => println!("{}", path.display()),
IpcResponse::AllWallpapers { entries: paths } => {
if json_resp {
#[derive(Serialize)]
Expand All @@ -58,7 +67,7 @@ fn main() {
);
} else {
for (monitor, path) in paths {
println!("{monitor}: {}", path.to_string_lossy());
println!("{monitor}: {}", path.display());
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions cli/src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,10 @@ pub enum SubCmd {
PauseWallpaper { monitors: Vec<String> },
#[clap(visible_alias = "resume")]
ResumeWallpaper { monitors: Vec<String> },

#[clap(visible_alias = "set")]
SetWallaper {
wallpaper: std::path::PathBuf,
monitors: Vec<String>,
},
}
13 changes: 12 additions & 1 deletion daemon/src/ipc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn listen_on_ipc_socket(socket_path: &Path) -> Result<SocketSource> {
Ok(socket)
}

fn check_monitors(wpaperd: &Wpaperd, monitors: &Vec<String>) -> Result<(), IpcError> {
fn check_monitors(wpaperd: &Wpaperd, monitors: &[String]) -> Result<(), IpcError> {
for monitor in monitors {
if !wpaperd
.surfaces
Expand Down Expand Up @@ -146,6 +146,17 @@ pub fn handle_message(
}
IpcResponse::Ok
}),

IpcMessage::SetWallpaper {
wallpaper,
monitors,
} => check_monitors(wpaperd, &monitors).map(|_| {
for surf in collect_surfaces(wpaperd, monitors).iter_mut() {
surf.set_new_wallpaper_path(wallpaper.as_path());
surf.queue_draw(&qh);
}
IpcResponse::Ok
}),
};

let mut stream = BufWriter::new(ustream);
Expand Down
6 changes: 5 additions & 1 deletion daemon/src/surface.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{
cell::RefCell,
path::PathBuf,
path::{Path, PathBuf},
rc::Rc,
time::{Duration, Instant},
};
Expand Down Expand Up @@ -402,6 +402,10 @@ impl Surface {
}
}

pub fn set_new_wallpaper_path(&mut self, new_path: &Path) {
self.wallpaper_info.path = new_path.to_path_buf();
}

/// Add a new timer in the event_loop for the current duration
/// Stop if there is already a timer added
pub fn add_timer(
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,22 @@
packages = [
pkg-config
wayland
egl-wayland
glew-egl
mesa
];

shellHook = ''
# Set LD_LIBRARY_PATH to include paths to Mesa libraries
export LD_LIBRARY_PATH="${lib.makeLibraryPath [ wayland glew-egl egl-wayland mesa ]}:$LD_LIBRARY_PATH"
'';
};
});

formatter = eachSystem (system: pkgsFor.${system}.alejandra);
homeManagerModules.default = import ./nix/hm-module.nix self;
};



}
30 changes: 23 additions & 7 deletions ipc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,31 @@ use std::path::PathBuf;
use serde::{Deserialize, Serialize};
use xdg::{BaseDirectories, BaseDirectoriesError};

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
pub enum IpcMessage {
CurrentWallpaper { monitor: String },
NextWallpaper { monitors: Vec<String> },
PreviousWallpaper { monitors: Vec<String> },
PauseWallpaper { monitors: Vec<String> },
ResumeWallpaper { monitors: Vec<String> },
CurrentWallpaper {
monitor: String,
},
NextWallpaper {
monitors: Vec<String>,
},
PreviousWallpaper {
monitors: Vec<String>,
},
PauseWallpaper {
monitors: Vec<String>,
},
ResumeWallpaper {
monitors: Vec<String>,
},
AllWallpapers,
ReloadWallpaper { monitors: Vec<String> },
ReloadWallpaper {
monitors: Vec<String>,
},
SetWallpaper {
wallpaper: PathBuf,
monitors: Vec<String>,
},
}

#[derive(Serialize, Deserialize)]
Expand Down
Loading