From a5ac3020f9ca3707152ed005bb4d47294b6d03de Mon Sep 17 00:00:00 2001 From: LordMZTE Date: Tue, 15 Feb 2022 21:53:09 +0100 Subject: [PATCH] randomwallpaper uses feh --- justfile | 8 ++---- scripts/randomwallpaper | 8 ++++++ scripts/randomwallpaper.zig | 56 ------------------------------------- 3 files changed, 10 insertions(+), 62 deletions(-) create mode 100755 scripts/randomwallpaper delete mode 100644 scripts/randomwallpaper.zig diff --git a/justfile b/justfile index 38416de..156fc98 100644 --- a/justfile +++ b/justfile @@ -8,17 +8,13 @@ yaml-language-server " install-scripts target=(`echo $HOME` + "/.local/bin"): - cd scripts && zig build-exe \ - -lc -lX11 -lXinerama \ - randomwallpaper.zig \ - -femit-bin={{target}}/randomwallpaper - opam install --yes clap cd scripts/playtwitch && dune build + chmod -R +w scripts/playtwitch cp scripts/playtwitch/_build/default/playtwitch.exe {{target}}/playtwitch ln -sf \ - `pwd`/scripts/{start-joshuto,withjava} \ + `pwd`/scripts/{start-joshuto,withjava,randomwallpaper} \ {{target}} install-lsps-paru: diff --git a/scripts/randomwallpaper b/scripts/randomwallpaper new file mode 100755 index 0000000..211135c --- /dev/null +++ b/scripts/randomwallpaper @@ -0,0 +1,8 @@ +#!/bin/sh +mons=$(xrandr --listactivemonitors | wc -l) +mons=$((mons-1)) + +feh --bg-fill $( + fd -L '\.(png|jpg)' /usr/share/backgrounds/ ~/.local/share/backgrounds/ \ + | shuf | head -n 2 +) diff --git a/scripts/randomwallpaper.zig b/scripts/randomwallpaper.zig deleted file mode 100644 index 8d8350e..0000000 --- a/scripts/randomwallpaper.zig +++ /dev/null @@ -1,56 +0,0 @@ -const std = @import("std"); -const mem = std.mem; -const c = @cImport({ - @cInclude("X11/Xlib.h"); - @cInclude("X11/extensions/Xinerama.h"); -}); -const Display = c.struct__XDisplay; - -pub fn main() !void { - var alloc = std.heap.GeneralPurposeAllocator(.{}){}; - if (c.XOpenDisplay(null)) |display| { - defer _ = c.XCloseDisplay(display); - - var dummy1: c_int = undefined; - var dummy2: c_int = undefined; - if (c.XineramaQueryExtension(display, &dummy1, &dummy2) != 0 and c.XineramaIsActive(display) != 0) { - try updateWallpapers(display, alloc.allocator()); - } else { - return error.@"No Xinerama!"; - } - } -} - -fn updateWallpapers(display: *Display, alloc: mem.Allocator) !void { - var heads: c_int = 0; - const info = c.XineramaQueryScreens(display, &heads); - defer _ = c.XFree(info); - - var children = try alloc.alloc(*std.ChildProcess, @intCast(usize, heads)); - defer alloc.free(children); - - var i: usize = 0; - while (i < heads) { - const head = info[i]; - - std.log.info("Setting wallpaper for screen {} with size {}x{}\n", .{ i, head.width, head.height }); - - var buf: [10]u8 = undefined; - - const args = [_][]const u8{ "nitrogen", "--random", "--set-zoom-fill", try std.fmt.bufPrint(&buf, "--head={}", .{i}) }; - var child = try std.ChildProcess.init(&args, alloc); - try child.spawn(); - - children[i] = child; - - i += 1; - } - - for (children) |child| { - _ = try child.wait(); - } - - for (children) |child| { - child.deinit(); - } -}