added random wallpaper

This commit is contained in:
LordMZTE 2021-12-30 15:56:31 +01:00
parent 781e4e28b2
commit 0a39aca85a
3 changed files with 68 additions and 0 deletions

View file

@ -0,0 +1,6 @@
[Unit]
Description=set wallpapers to random ones
[Service]
Type=oneshot
ExecStart=/bin/bash -c '${HOME}/.local/bin/randomwallpaper'

View file

@ -0,0 +1,10 @@
[Unit]
Description=Change the wallpaper ever half hour
[Timer]
OnBootSec=1min
OnUnitActiveSec=30min
[Install]
WantedBy=timers.target

52
scripts/randomwallpaper.c Normal file
View file

@ -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 <X11/Xlib.h>
#include <X11/extensions/Xinerama.h>
#include <stdio.h>
#include <stdlib.h>
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);
}