-
-
Save arjunmenon/c873bb8392480d4d5a76e564a34e14a8 to your computer and use it in GitHub Desktop.
basic animated wallpapers in Xorg https://youtu.be/guchbe-gKis?t=257
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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <dirent.h> | |
#include <X11/Xlib.h> | |
#include <Imlib2.h> | |
#include <unistd.h> | |
int main(int argc, char *argv[]) { | |
if (argc < 4 || argc > 5) { | |
fprintf(stderr, "Usage: %s <image_folder> <frame_delay> <screen_number> [loop]\n", argv[0]); | |
return 1; | |
} | |
char *image_folder = argv[1]; | |
int frame_delay = atoi(argv[2]); | |
int screen_number = atoi(argv[3]); | |
int should_loop = (argc == 5 && atoi(argv[4]) == 1); | |
Display *display = XOpenDisplay(NULL); | |
Window root_window = RootWindow(display, screen_number); | |
imlib_context_set_display(display); | |
DIR *dir = opendir(image_folder); | |
while (should_loop || dir) { | |
rewinddir(dir); | |
struct dirent *entry; | |
while ((entry = readdir(dir))) { | |
if (entry->d_type == DT_REG) { | |
char image_path[256]; | |
snprintf(image_path, sizeof(image_path), "%s%s", image_folder, entry->d_name); | |
imlib_context_set_image(imlib_load_image(image_path)); | |
Pixmap pixmap = XCreatePixmap(display, root_window, imlib_image_get_width(), imlib_image_get_height(), DefaultDepth(display, screen_number)); | |
imlib_context_set_drawable(pixmap); | |
imlib_render_image_on_drawable(0, 0); | |
XSetWindowBackgroundPixmap(display, root_window, pixmap); | |
XClearWindow(display, root_window); | |
XFlush(display); | |
XFreePixmap(display, pixmap); | |
imlib_free_image(); | |
usleep(frame_delay * 1000); | |
} | |
} | |
if (!should_loop) break; | |
} | |
closedir(dir); | |
XCloseDisplay(display); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment