mirror of
https://mzte.de/git/LordMZTE/dotfiles.git
synced 2024-12-13 04:52:56 +01:00
randomwallpaper: rewrite to use libxcb
This commit is contained in:
parent
34cdd162c3
commit
c8d9cc82d9
4 changed files with 19 additions and 17 deletions
|
@ -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;
|
||||||
|
|
||||||
|
|
|
@ -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");
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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);
|
||||||
|
if (is_active_reply.*.state == 0) return error.XineramaInactive;
|
||||||
|
|
||||||
var screens: c_int = 0;
|
const query_screens_cookie = c.xcb_xinerama_query_screens(connection);
|
||||||
const info = c.XineramaQueryScreens(display, &screens) orelse return error.XineramaError;
|
const query_screens_reply = c.xcb_xinerama_query_screens_reply(connection, query_screens_cookie, &err);
|
||||||
defer _ = c.XFree(info);
|
if (err) |_| return error.FailedToQueryXinerama;
|
||||||
|
defer std.c.free(query_screens_reply);
|
||||||
|
|
||||||
return screens;
|
return query_screens_reply.*.number;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue