mirror of
https://mzte.de/git/LordMZTE/dotfiles.git
synced 2024-12-12 21:42:58 +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.linkSystemLibrary("x11");
|
||||
exe.linkSystemLibrary("xinerama");
|
||||
exe.linkSystemLibrary("xcb");
|
||||
exe.linkSystemLibrary("xcb-xinerama");
|
||||
|
||||
exe.strip = mode != .Debug;
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
pub const c = @cImport({
|
||||
@cInclude("stdlib.h");
|
||||
@cInclude("X11/Xlib.h");
|
||||
@cInclude("X11/extensions/Xinerama.h");
|
||||
@cInclude("xcb/xcb.h");
|
||||
@cInclude("xcb/xinerama.h");
|
||||
});
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
const std = @import("std");
|
||||
const xinerama = @import("xinerama.zig");
|
||||
const Walker = @import("Walker.zig");
|
||||
const c = @import("ffi.zig").c;
|
||||
|
||||
pub const std_options = struct {
|
||||
pub const log_level = .debug;
|
||||
|
|
|
@ -1,19 +1,23 @@
|
|||
const std = @import("std");
|
||||
const c = @import("ffi.zig").c;
|
||||
|
||||
pub fn getHeadCount() !i32 {
|
||||
const display_name = c.getenv("DISPLAY") orelse return error.DisplayNotSet;
|
||||
const display = c.XOpenDisplay(display_name) orelse return error.CouldntOpenDisplay;
|
||||
pub fn getHeadCount() !u32 {
|
||||
const connection = c.xcb_connect(null, null).?;
|
||||
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) {
|
||||
return error.XineramaError;
|
||||
}
|
||||
const is_active_cookie = c.xcb_xinerama_is_active(connection);
|
||||
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 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);
|
||||
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