srctree

Gregory Mullen parent 41e794f9 d42c77dd
wireup message framework into plugin

src/gui.zig added: 55, removed: 6, total 49
@@ -1,3 +1,5 @@
const std = @import("std");
 
pub const obs = @cImport({
@cInclude("obs/util/base.h");
@cInclude("obs/obs-module.h");
@@ -9,6 +11,30 @@ pub const obs = @cImport({
const obs_frontend_cb = *const fn (?*anyopaque) callconv(.C) void;
extern "obs-frontend-api" fn obs_frontend_add_tools_menu_item(name: [*:0]const u8, cb: obs_frontend_cb, ?*anyopaque) void;
 
extern "obs-frontend-api" fn obs_frontend_get_current_scene() ?*obs.obs_source_t;
extern "obs-frontend-api" fn obs_frontend_set_current_scene(*obs.obs_source_t) callconv(.C) void;
extern "obs-frontend-api" fn obs_frontend_get_scene_names() callconv(.C) [*:null]?[*c]u8;
 
pub fn currentScene() ?[:0]const u8 {
_ = obs_frontend_get_current_scene() orelse return null;
 
//const t = @as(?*obs.obs_source_info, @ptrCast(scene));
 
//if (t.?.get_name) |_gn| {
// const name: ?[*c]const u8 = _gn(scene);
// if (name) |n| return std.mem.span(n);
//}
return null;
}
 
pub fn setCurrentScene(scene: ?*obs.obs_source_t) void {
obs_frontend_set_current_scene(scene);
}
 
pub fn getSceneNames() [:null]?[*c]const u8 {
return std.mem.span(obs_frontend_get_scene_names());
}
 
pub fn init() void {
propertiesInit();
//obs.obs_register_service(&focus_service);
 
src/root.zig added: 55, removed: 6, total 49
@@ -69,10 +69,20 @@ fn thread(_: ?*anyopaque) void {
log("unexpected read error");
unreachable;
};
const text = alloc.dupeZ(u8, msg.data) catch unreachable;
defer alloc.free(text);
log(text);
 
if (gui.currentScene()) |name| {
logFmt("name {s}\n", .{name});
}
std.time.sleep(10_000_000);
switch (msg.toStruct(alloc) catch {
log("unable to build struct");
continue;
}) {
.window => |w| logFmt("marks {s}", .{w.container.marks}),
}
}
for (gui.getSceneNames()) |name| {
logFmt("scene name: {s}", .{std.mem.span(name.?)});
}
}
 
 
src/sway-ipc.zig added: 55, removed: 6, total 49
@@ -69,6 +69,14 @@ pub const Message = struct {
try w.writeInt(u32, @intFromEnum(m.header.payload_type), .little);
try w.writeAll(m.data);
}
 
/// Leaks if you don't use an gc'd allocator
pub fn toStruct(m: Message, a: Allocator) !SwayMessages.MsgKind {
const thing = try std.json.parseFromSlice(SwayMessages.WindowChange, a, m.data, .{ .ignore_unknown_fields = true });
return .{
.window = thing.value,
};
}
};
 
pub fn getSockPath(a: Allocator) ![]const u8 {
@@ -173,6 +181,11 @@ test "waiting" {
std.debug.print("msg {s}\n", .{msg.data});
continue;
};
//std.debug.print("value {}\n", .{thing.value});
//std.debug.print("marks {s}\n", .{thing.value.container.marks});
if (thing.value.container.marks.len > 0) {
try std.testing.expectEqualStrings("test", thing.value.container.marks[0]);
}
defer thing.deinit();
}
}