update scripts for stage3 zig

This commit is contained in:
LordMZTE 2022-08-21 00:28:34 +02:00
parent 9a54cec127
commit 12f5eb7274
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
4 changed files with 18 additions and 14 deletions

View file

@ -1,6 +1,8 @@
// partially yoinked from https://github.com/Swoogan/ziggtk
const std = @import("std");
pub const c = @cImport({
// fix for a strange behavior in stage2 with self-referential definitions in C
@cDefine("sched_priority", {});
@cInclude("gtk/gtk.h");
});

View file

@ -37,8 +37,8 @@ pub fn activate(app: *c.GtkApplication, state: *GuiState) void {
for (&preset_qualities) |quality| {
c.gtk_combo_box_text_append(
@ptrCast(*c.GtkComboBoxText, quality_box),
quality, // ID
quality, // Text
quality.ptr, // ID
quality.ptr, // Text
);
}
_ = c.gtk_combo_box_set_active_id(@ptrCast(*c.GtkComboBox, quality_box), "best");
@ -81,7 +81,7 @@ pub fn activate(app: *c.GtkApplication, state: *GuiState) void {
ffi.connectSignal(
other_stream_entry,
"activate",
@ptrCast(c.GCallback, onOtherStreamActivate),
@ptrCast(c.GCallback, &onOtherStreamActivate),
other_act_data,
);
@ -113,11 +113,11 @@ pub fn activate(app: *c.GtkApplication, state: *GuiState) void {
.text_buf = dialog_buf,
};
ffi.connectSignal(list, "row-activated", @ptrCast(c.GCallback, onRowActivate), act_data);
ffi.connectSignal(list, "row-activated", @ptrCast(c.GCallback, &onRowActivate), act_data);
channels: {
const channels_data = readChannels() catch |e| {
std.log.err("Failed to read channels: {}", .{e});
std.log.err("Failed to read channels: {!}", .{e});
break :channels;
};
defer c_allocator.free(channels_data);
@ -142,7 +142,7 @@ pub fn activate(app: *c.GtkApplication, state: *GuiState) void {
}
fn readChannels() ![]u8 {
const home = try std.os.getenv("HOME") orelse error.HomeNotSet;
const home = try (std.os.getenv("HOME") orelse error.HomeNotSet);
const fname = try std.fmt.allocPrint(c_allocator, "{s}/.config/playtwitch/channels", .{home});
defer c_allocator.free(fname);
std.log.info("Reading channels from {s}", .{fname});
@ -173,7 +173,7 @@ fn onRowActivate(list: *c.GtkListBox, row: *c.GtkListBoxRow, data: *RowActivateD
.crash_dialog = data.dialog,
.error_text_buf = data.text_buf,
.window = data.win,
}) catch |err| std.log.err("Failed to start children: {}", .{err});
}) catch |err| std.log.err("Failed to start children: {!}", .{err});
c.gtk_widget_hide(@ptrCast(*c.GtkWidget, data.win));
}
@ -202,7 +202,7 @@ fn onOtherStreamActivate(entry: *c.GtkEntry, data: *OtherStreamActivateData) voi
.crash_dialog = data.dialog,
.error_text_buf = data.text_buf,
.window = data.win,
}) catch |err| std.log.err("Failed to start children: {}", .{err});
}) catch |err| std.log.err("Failed to start children: {!}", .{err});
c.gtk_widget_hide(@ptrCast(*c.GtkWidget, data.win));
}
@ -222,7 +222,7 @@ pub fn streamlinkErrorDialog(parent_window: *c.GtkWindow, output: *c.GtkTextBuff
ffi.connectSignal(
dialog,
"response",
@ptrCast(c.GCallback, onErrorDialogResponse),
@ptrCast(c.GCallback, &onErrorDialogResponse),
parent_window,
);
@ -290,7 +290,7 @@ fn start(options: StartOptions) !void {
defer c_allocator.free(url);
const quality_z = try std.cstr.addNullByte(c_allocator, options.quality);
defer c_allocator.free(quality_z);
const streamlink_argv = [_][*c]const u8{ "streamlink", url, quality_z, null };
const streamlink_argv = [_][*c]const u8{ "streamlink", url.ptr, quality_z.ptr, null };
const streamlink_subproc = c.g_subprocess_newv(
&streamlink_argv,
c.G_SUBPROCESS_FLAGS_STDOUT_PIPE,
@ -309,7 +309,7 @@ fn start(options: StartOptions) !void {
streamlink_subproc,
null,
null,
@ptrCast(c.GAsyncReadyCallback, streamlinkCommunicateCb),
@ptrCast(c.GAsyncReadyCallback, &streamlinkCommunicateCb),
communicate_data,
);

View file

@ -18,7 +18,7 @@ pub fn main() !u8 {
const app = c.gtk_application_new("de.mzte.playtwitch", c.G_APPLICATION_FLAGS_NONE);
defer c.g_object_unref(app);
ffi.connectSignal(app, "activate", @ptrCast(c.GCallback, gui.activate), &state);
ffi.connectSignal(app, "activate", @ptrCast(c.GCallback, &gui.activate), &state);
const status = c.g_application_run(
@ptrCast(*c.GApplication, app),

View file

@ -33,7 +33,8 @@ pub fn main() !u8 {
defer alloc.free(feh_argv);
std.mem.copy([]const u8, feh_argv, &feh_baseargs);
const rand = std.rand.DefaultPrng.init(std.crypto.random.int(u64)).random();
var prng = std.rand.DefaultPrng.init(std.crypto.random.int(u64));
const rand = prng.random();
var i: u31 = 0;
while (i < screens) : (i += 1) {
@ -42,7 +43,8 @@ pub fn main() !u8 {
}
std.log.info("feh argv: {s}", .{feh_argv});
const term = try std.ChildProcess.init(feh_argv, alloc).spawnAndWait();
var child = std.ChildProcess.init(feh_argv, alloc);
const term = try child.spawnAndWait();
const exit = switch (term) {
.Exited => |n| n,