randomwallpaper: rewrite to use libxcb

This commit is contained in:
LordMZTE 2023-08-12 22:06:23 +02:00
parent 34cdd162c3
commit c8d9cc82d9
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
4 changed files with 19 additions and 17 deletions

View file

@ -12,8 +12,8 @@ pub fn build(b: *std.build.Builder) void {
}); });
exe.linkLibC(); exe.linkLibC();
exe.linkSystemLibrary("x11"); exe.linkSystemLibrary("xcb");
exe.linkSystemLibrary("xinerama"); exe.linkSystemLibrary("xcb-xinerama");
exe.strip = mode != .Debug; exe.strip = mode != .Debug;

View file

@ -1,5 +1,4 @@
pub const c = @cImport({ pub const c = @cImport({
@cInclude("stdlib.h"); @cInclude("xcb/xcb.h");
@cInclude("X11/Xlib.h"); @cInclude("xcb/xinerama.h");
@cInclude("X11/extensions/Xinerama.h");
}); });

View file

@ -1,7 +1,6 @@
const std = @import("std"); const std = @import("std");
const xinerama = @import("xinerama.zig"); const xinerama = @import("xinerama.zig");
const Walker = @import("Walker.zig"); const Walker = @import("Walker.zig");
const c = @import("ffi.zig").c;
pub const std_options = struct { pub const std_options = struct {
pub const log_level = .debug; pub const log_level = .debug;

View file

@ -1,19 +1,23 @@
const std = @import("std"); const std = @import("std");
const c = @import("ffi.zig").c; const c = @import("ffi.zig").c;
pub fn getHeadCount() !i32 { pub fn getHeadCount() !u32 {
const display_name = c.getenv("DISPLAY") orelse return error.DisplayNotSet; const connection = c.xcb_connect(null, null).?;
const display = c.XOpenDisplay(display_name) orelse return error.CouldntOpenDisplay; if (c.xcb_connection_has_error(connection) > 0) return error.ConnectionFailed;
defer c.xcb_disconnect(connection);
defer _ = c.XCloseDisplay(display); var err: ?*c.xcb_generic_error_t = null;
if (c.XineramaIsActive(display) == 0) { const is_active_cookie = c.xcb_xinerama_is_active(connection);
return error.XineramaError; const is_active_reply = c.xcb_xinerama_is_active_reply(connection, is_active_cookie, &err);
} if (err) |_| return error.FailedToQueryXinerama;
defer std.c.free(is_active_reply);
var screens: c_int = 0; if (is_active_reply.*.state == 0) return error.XineramaInactive;
const info = c.XineramaQueryScreens(display, &screens) orelse return error.XineramaError;
defer _ = c.XFree(info); const query_screens_cookie = c.xcb_xinerama_query_screens(connection);
const query_screens_reply = c.xcb_xinerama_query_screens_reply(connection, query_screens_cookie, &err);
return screens; if (err) |_| return error.FailedToQueryXinerama;
defer std.c.free(query_screens_reply);
return query_screens_reply.*.number;
} }