visualizations

Programmatic visualizations
git clone git://git.laack.co/visualizations.git
Log | Files | Refs | README

commit dc9fa71238ed3bfd784a93bf412f6f456e2bb719
parent e9c21d3b4d42f9d82738b2fe5f3a15184fe3f4cd
Author: Andrew Laack <andrew@laack.co>
Date:   Tue, 15 Sep 2026 12:15:38 -0500

Use X11 to find screen size

Diffstat:
Mbackground/Makefile | 6+++---
Mbackground/headers/background.hpp | 3+++
Mbackground/src/background.cpp | 19+++++++++++++++++++
Mbackground/src/main.cpp | 6++++--
4 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/background/Makefile b/background/Makefile @@ -1,13 +1,13 @@ build: - g++ -Ofast src/main.cpp src/prim.cpp src/graph.cpp src/edge.cpp src/utils.cpp src/vertex.cpp src/background.cpp -lraylib -o background + g++ -Ofast src/main.cpp src/prim.cpp src/graph.cpp src/edge.cpp src/utils.cpp src/vertex.cpp src/background.cpp -lraylib -lX11 -o background install: build cp background /usr/local/bin clean: rm background test: - g++ tests/graph_test.cpp src/prim.cpp src/graph.cpp src/edge.cpp src/utils.cpp src/vertex.cpp src/background.cpp -lCatch2Main -lCatch2 -lraylib -o graph_tests + g++ tests/graph_test.cpp src/prim.cpp src/graph.cpp src/edge.cpp src/utils.cpp src/vertex.cpp src/background.cpp -lCatch2Main -lCatch2 -lraylib -lX11 -o graph_tests ./graph_tests rm graph_tests - g++ tests/algo_test.cpp src/prim.cpp src/graph.cpp src/edge.cpp src/utils.cpp src/vertex.cpp src/background.cpp -lCatch2Main -lCatch2 -lraylib -o algo_tests + g++ tests/algo_test.cpp src/prim.cpp src/graph.cpp src/edge.cpp src/utils.cpp src/vertex.cpp src/background.cpp -lCatch2Main -lCatch2 -lraylib -lX11 -o algo_tests ./algo_tests rm algo_tests diff --git a/background/headers/background.hpp b/background/headers/background.hpp @@ -1,4 +1,7 @@ #pragma once +#include <cstdint> #include <string> +#include <vector> void setBackground(std::string filePath); +std::vector<uint32_t> getScreenSize(); diff --git a/background/src/background.cpp b/background/src/background.cpp @@ -1,6 +1,25 @@ +#include <csignal> +#include <cstddef> +#include <cstdint> +#include <stdexcept> #include <string> +#include <vector> +#include <X11/Xlib.h> void setBackground(std::string filePath) { std::string command = "/usr/bin/feh --no-fehbg --bg-scale " + filePath; system(command.c_str()); } + +std::vector<uint32_t> getScreenSize() { + Display* dpy; + Screen* screen; + dpy = XOpenDisplay(NULL); + int count = ScreenCount(dpy); + if(count == 0) { + throw std::runtime_error{"Unable to find screens."}; + } + screen = ScreenOfDisplay(dpy, 0); + std::vector<uint32_t> res {(uint32_t)screen->width, (uint32_t)screen->height}; + return res; +} diff --git a/background/src/main.cpp b/background/src/main.cpp @@ -34,8 +34,10 @@ int main() { std::size_t edgeCount = 2000; std::size_t vertCount = 100; - uint32_t xMax = 5120; - uint32_t yMax = 1440; + auto ss = getScreenSize(); + + uint32_t xMax = ss[0]; + uint32_t yMax = ss[1]; SetConfigFlags(FLAG_WINDOW_HIDDEN); InitWindow(xMax, yMax, "Raylib animation window");