abg

Animated background for X11
git clone git://git.laack.co/abg.git
Log | Files | Refs | README

commit 8c5395cae232765a859f153b29ff4f32fa04a45d
parent 36d7ad8dc5f922fa3d011475ff048a5bffbcef99
Author: Andrew Laack <andrew@laack.co>
Date:   Tue, 15 Sep 2026 20:20:25 -0500

Removed feh dependence by making the raylib window special in the wm eyes and pushing it to the background

Diffstat:
Mbackground/README | 2+-
Mbackground/headers/background.hpp | 1+
Mbackground/src/background.cpp | 42++++++++++++++++++++++++++++++++++++++++++
Mbackground/src/main.cpp | 35++++++-----------------------------
4 files changed, 50 insertions(+), 30 deletions(-)

diff --git a/background/README b/background/README @@ -4,4 +4,4 @@ background dependencies ============ -X11, feh (on $PATH), raylib, g++ +X11, raylib, g++ diff --git a/background/headers/background.hpp b/background/headers/background.hpp @@ -5,3 +5,4 @@ #include <vector> void setBackground(std::string filePath); std::vector<uint32_t> getScreenSize(); +void sendToBg(std::string name); diff --git a/background/src/background.cpp b/background/src/background.cpp @@ -4,6 +4,8 @@ #include <string> #include <vector> #include <X11/Xlib.h> +#include <X11/Xatom.h> +#include <unistd.h> void setBackground(std::string filePath) { std::string command = "/usr/bin/feh --no-fehbg --bg-scale " + filePath; @@ -22,3 +24,43 @@ std::vector<uint32_t> getScreenSize() { std::vector<uint32_t> res {(uint32_t)screen->width, (uint32_t)screen->height}; return res; } + +void sendToBg(std::string name) +{ + Display* d = XOpenDisplay(nullptr); + Window root = DefaultRootWindow(d), r, p, *kids; + uint32_t n; + + XQueryTree(d, root, &r, &p, &kids, &n); + for (unsigned i = 0; i < n; i++) { + + char* wn = nullptr; + XFetchName(d, kids[i], &wn); + + if (wn == nullptr) { + continue; + } + + bool hit = name == wn; + XFree(wn); + + if (!hit) { + continue; + } + + XSetWindowAttributes a; + + a.override_redirect = True; + XChangeWindowAttributes(d, kids[i], CWOverrideRedirect, &a); + + // have to do unmap / map to make it bg for all tags + XUnmapWindow(d, kids[i]); + XMapWindow(d, kids[i]); + + XLowerWindow(d, kids[i]); + break; + } + + XFree(kids); + XCloseDisplay(d); +} diff --git a/background/src/main.cpp b/background/src/main.cpp @@ -2,33 +2,15 @@ #include "../headers/prim.hpp" #include "../headers/background.hpp" #include <cstdlib> -#include <iostream> #include <unistd.h> #include <raylib.h> #include <ctime> #include <queue> #include <unordered_set> -#include <filesystem> - - -void customTakeScreenshot(char* filePath){ - const char *customParam; - Image screenshot = LoadImageFromScreen(); - ExportImage(screenshot, TextFormat(filePath, customParam)); - UnloadImage(screenshot); -} int main() { - int result = std::system("feh --version > /dev/null"); - - if (result != 0 ) { - std::cout << "Feh not found on $PATH, exiting." << std::endl; - return -1; - } - SetTraceLogLevel(LOG_ERROR); - std::filesystem::create_directory("/dev/shm/bg"); srand(clock()); std::size_t edgeCount = 2000; @@ -39,8 +21,11 @@ int main() { uint32_t xMax = ss[0]; uint32_t yMax = ss[1]; - SetConfigFlags(FLAG_WINDOW_HIDDEN); - InitWindow(xMax, yMax, "Raylib animation window"); + // would be nice to do this all in background.cpp, but raylib and x11 can't both be imported + // by the same file because of some dependency chain thing with Font. + + InitWindow(xMax, yMax, "background-ray"); + sendToBg("background-ray"); while (!WindowShouldClose()) { @@ -57,19 +42,11 @@ int main() { visitedIndices.insert(0); while (!WindowShouldClose() && toVisit.size() != 0) { - sleep(10); BeginDrawing(); ClearBackground(BLACK); g.render(); EndDrawing(); - - // Basically all of the cost happens within these bounds - char path[] = "/dev/shm/bg/out.bmp"; - customTakeScreenshot(path); - // TODO: Can this be done away with? It's not *that* slow... - setBackground(path); - // Above here. - + sleep(5); oneStepPrim(toVisit, visitedIndices, g); }