From 0a39aca85aea226db55ed152b16e24da07088f01 Mon Sep 17 00:00:00 2001 From: LordMZTE Date: Thu, 30 Dec 2021 15:56:31 +0100 Subject: [PATCH] added random wallpaper --- .config/systemd/user/randomwallpaper.service | 6 +++ .config/systemd/user/randomwallpaper.timer | 10 ++++ scripts/randomwallpaper.c | 52 ++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 .config/systemd/user/randomwallpaper.service create mode 100644 .config/systemd/user/randomwallpaper.timer create mode 100644 scripts/randomwallpaper.c diff --git a/.config/systemd/user/randomwallpaper.service b/.config/systemd/user/randomwallpaper.service new file mode 100644 index 0000000..e73a5fc --- /dev/null +++ b/.config/systemd/user/randomwallpaper.service @@ -0,0 +1,6 @@ +[Unit] +Description=set wallpapers to random ones + +[Service] +Type=oneshot +ExecStart=/bin/bash -c '${HOME}/.local/bin/randomwallpaper' diff --git a/.config/systemd/user/randomwallpaper.timer b/.config/systemd/user/randomwallpaper.timer new file mode 100644 index 0000000..fa2519e --- /dev/null +++ b/.config/systemd/user/randomwallpaper.timer @@ -0,0 +1,10 @@ +[Unit] +Description=Change the wallpaper ever half hour + +[Timer] +OnBootSec=1min +OnUnitActiveSec=30min + +[Install] +WantedBy=timers.target + diff --git a/scripts/randomwallpaper.c b/scripts/randomwallpaper.c new file mode 100644 index 0000000..027f09f --- /dev/null +++ b/scripts/randomwallpaper.c @@ -0,0 +1,52 @@ +// clang -lX11 -lXinerama randomwallpaper.c -o ~/.local/bin/randomwallpaper +// this script updates the desktop wallpapers using the nitrogen tool to random +// wallpapers on all displays. +#include +#include +#include +#include + +void update_wallpapers(Display *d); + +int main(int argc, char *argv[]) { + Display *d = XOpenDisplay(NULL); + + if (d) { + int dummy1, dummy2; + + // check if xinerama is supported and enabled + if (XineramaQueryExtension(d, &dummy1, &dummy2) && XineramaIsActive(d)) { + update_wallpapers(d); + } else { + puts("No Xinerama!\n"); + XCloseDisplay(d); + return 1; + } + + XCloseDisplay(d); + return 0; + } else { + puts("Couldn't open display!\n"); + // I return with 0 here, as I don't really wanna see it as an error if this + // script is run without an X server running. + return 0; + } +} + +void update_wallpapers(Display *d) { + int heads = 0; + XineramaScreenInfo *info = XineramaQueryScreens(d, &heads); + + if (heads > 0) { + for (int i = 0; i < heads; i++) { + // works as long as the user doesn't have over 999 monitors :P + char command[40]; + sprintf(command, "nitrogen --random --set-zoom --head=%d", i); + printf("Setting wallpaper for screen %d with size %dx%d\n", i, + info[i].width, info[i].height); + system(command); + } + } + + XFree(info); +}