From 748141d30c536aa441c6090f94cfaa151be7d97c Mon Sep 17 00:00:00 2001 From: Pihkaal Date: Sat, 6 Sep 2025 16:28:38 +0200 Subject: [PATCH] feat: install process --- Makefile | 12 +++++++++++- README.md | 3 +++ src/wallpaper.c | 45 +++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 2bfa826..fc1f710 100644 --- a/Makefile +++ b/Makefile @@ -4,4 +4,14 @@ wallpaper: src/wallpaper.c gcc -O3 -Werror -Wall -Wextra -I./vendor/raylib-5.5_linux_amd64/include/ -o wallpaper src/wallpaper.c -L./vendor/raylib-5.5_linux_amd64/lib -l:libraylib.a -lm distance_field_generator: src/distance_field_generator.c - gcc -Werror -Wall -Wextra -fopenmp -I./vendor/raylib-5.5_linux_amd64/include/ -o distance_field_generator src/distance_field_generator.c -L./vendor/raylib-5.5_linux_amd64/lib -l:libraylib.a -lm \ No newline at end of file + gcc -Werror -Wall -Wextra -fopenmp -I./vendor/raylib-5.5_linux_amd64/include/ -o distance_field_generator src/distance_field_generator.c -L./vendor/raylib-5.5_linux_amd64/lib -l:libraylib.a -lm + +install: wallpaper + sudo install -D -m 755 wallpaper /usr/bin/wallpaper + sudo mkdir -p /usr/share/wallpaper + sudo cp -r resources /usr/share/wallpaper/ + +clean: + rm -f wallpaper distance_field_generator + +.PHONY: all install clean \ No newline at end of file diff --git a/README.md b/README.md index 46bd4bf..f18ab08 100644 --- a/README.md +++ b/README.md @@ -11,4 +11,7 @@ $ ./distance_field_generator ./resources/textures/background_mask.png ./resource # run wallpaper, image paths are customizables $ ./wallpaper + +# install +$ make install ``` diff --git a/src/wallpaper.c b/src/wallpaper.c index 62865f2..389b744 100644 --- a/src/wallpaper.c +++ b/src/wallpaper.c @@ -69,7 +69,21 @@ Vector2 hyprland_get_cursor_position() Texture2D load_texture_from_file(const char *file_path) { - Texture2D texture = LoadTexture(file_path); + Texture2D texture = {0}; + + if (FileExists(file_path)) + { + texture = LoadTexture(file_path); + } + else + { + const char *system_path = TextFormat("/usr/share/wallpaper/%s", file_path); + if (FileExists(system_path)) + { + texture = LoadTexture(system_path); + } + } + if (texture.id == 0) { TraceLog(LOG_ERROR, "Failed to load texture from file: %s", file_path); @@ -77,6 +91,31 @@ Texture2D load_texture_from_file(const char *file_path) return texture; } +Shader load_shader_from_file(const char *vs_path, const char *fs_path) +{ + Shader shader = {0}; + + if (FileExists(vs_path) && FileExists(fs_path)) + { + shader = LoadShader(vs_path, fs_path); + } + else + { + const char *system_vs_path = TextFormat("/usr/share/wallpaper/%s", vs_path); + const char *system_fs_path = TextFormat("/usr/share/wallpaper/%s", fs_path); + if (FileExists(system_vs_path) && FileExists(system_fs_path)) + { + shader = LoadShader(system_vs_path, system_fs_path); + } + } + + if (shader.id == 0) + { + TraceLog(LOG_ERROR, "Failed to load shader from files: %s, %s", vs_path, fs_path); + } + return shader; +} + int main(void) { InitWindow(WIDTH, HEIGHT, "pihkaal-wallpaper"); @@ -92,7 +131,7 @@ int main(void) RenderTexture2D target = LoadRenderTexture(WIDTH, HEIGHT); // initialize shader - Shader shader = LoadShader("resources/shaders/basic.vs", "resources/shaders/distance_field.fs"); + Shader shader = load_shader_from_file("resources/shaders/basic.vs", "resources/shaders/distance_field.fs"); int resolutionLoc = GetShaderLocation(shader, "resolution"); int mousePosLoc = GetShaderLocation(shader, "mousePos"); @@ -142,8 +181,6 @@ int main(void) DrawTextureRec(backgroundTex, (Rectangle){0, 0, screenWidth, screenHeight}, (Vector2){0, 0}, WHITE); - DrawText(TextFormat("Distance Field | x: %.0f, y: %.0f | frame: %.2f ms", mousePos.x, mousePos.y, GetFrameTime() * 1000), 10, 10, 20, WHITE); - EndDrawing(); }