Skip to content

Commit

Permalink
hot mess
Browse files Browse the repository at this point in the history
  • Loading branch information
donpdonp committed Jul 8, 2024
1 parent 6b0d3e6 commit bb88115
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 996 deletions.
113 changes: 53 additions & 60 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,73 +1,66 @@
const std = @import("std");
const builtin = @import("builtin");
const Builder = std.build.Builder;

pub fn build(b: *Builder) void {
const gtk4_enabled = b.option(bool, "gtk4", "use GTK4 [default: false]") orelse false;

// Although this function looks imperative, note that its job is to
// declaratively construct a build graph that will be executed by an external
// runner.
pub fn build(b: *std.Build) void {
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
const target = b.standardTargetOptions(.{});
const exe = b.addExecutable(.{
.name = "init-exe",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
});
exe.linkLibC();
exe.addIncludePath(.{ .path = "." });
const cflags = [_][]const u8{};
exe.addCSourceFile(.{ .file = .{ .path = "ragel/lang.c" }, .flags = &cflags });

if (gtk4_enabled) {
// gtk4
// exe.addIncludeDir("/usr/include/gtk-4.0");
// exe.addIncludeDir("/usr/include/graphene-1.0");
// exe.addIncludeDir("/usr/lib/x86_64-linux-gnu/graphene-1.0/include");
exe.linkSystemLibrary("gtk-4");
// exe.addIncludeDir("/usr/include/gdk-pixbuf-2.0");
exe.linkSystemLibrary("gdk"); // does not add extra include path (see below)
} else {
// gtk3
exe.linkSystemLibrary("gtk-3");
exe.linkSystemLibrary("gdk-3.0"); // add include path /usr/include/gtk-3.0
}

// gtk
exe.linkSystemLibrary("glib-2.0");
exe.linkSystemLibrary("gdk_pixbuf-2.0");
exe.linkSystemLibrary("gobject-2.0");
exe.linkSystemLibrary("gmodule-2.0");
exe.linkSystemLibrary("pango-1.0");
exe.linkSystemLibrary("atk-1.0");
exe.linkSystemLibrary("gio-2.0");
// Standard optimization options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
// set a preferred release mode, allowing the user to decide how to optimize.
const optimize = b.standardOptimizeOption(.{});

// html
exe.linkSystemLibrary("gumbo");
const lib = b.addStaticLibrary(.{
.name = "zootdeck",
// In this case the main source file is merely a path, however, in more
// complicated build scripts, this could be a generated file.
.root_source_file = .{ .src_path = .{ .sub_path = "src/root.zig", .owner = b } },
.target = target,
.optimize = optimize,
});

// qt5
//exe.addIncludeDir("/usr/include/x86_64-linux-gnu/qt5");
// This declares intent for the library to be installed into the standard
// location when the user invokes the "install" step (the default step when
// running `zig build`).
b.installArtifact(lib);

// libui (local)
// exe.addIncludeDir("../libui");
// exe.linkSystemLibrary("ui");
// exe.addLibPath("../libui/build/out");
const exe = b.addExecutable(.{
.name = "zootdeck",
.root_source_file = .{ .src_path = .{ .sub_path = "src/main.zig", .owner = b } },
.target = target,
.optimize = optimize,
});

// glfw (local)
// exe.addIncludeDir("../glfw/include");
// exe.addIncludeDir("../glfw/deps");
// exe.addIncludeDir("../nanovg/src");
exe.linkSystemLibrary("glfw3");
exe.addLibraryPath(.{ .path = "../glfw/build/src" });
// This declares intent for the executable to be installed into the
// standard location when the user invokes the "install" step (the default
// step when running `zig build`).
b.installArtifact(exe);

// opengl
//exe.addObjectFile("ext/glad.o"); // build glad.c by hand for now
exe.linkSystemLibrary("dl");
exe.linkSystemLibrary("X11");
exe.linkSystemLibrary("pthread");
// This *creates* a Run step in the build graph, to be executed when another
// step is evaluated that depends on it. The next line below will establish
// such a dependency.
const run_cmd = b.addRunArtifact(exe);

// net
exe.linkSystemLibrary("curl");
// By making the run step depend on the install step, it will be run from the
// installation directory rather than directly from within the cache directory.
// This is not necessary, however, if the application depends on other installed
// files, this ensures they will be present and in the expected location.
run_cmd.step.dependOn(b.getInstallStep());

// lmdb
exe.linkSystemLibrary("lmdb");
// This allows the user to pass arguments to the application in the build
// command itself, like this: `zig build run -- arg1 arg2 etc`
if (b.args) |args| {
run_cmd.addArgs(args);
}

b.installArtifact(exe);
// This creates a build step. It will be visible in the `zig build --help` menu,
// and can be selected like this: `zig build run`
// This will evaluate the `run` step rather than the default, which is "install".
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
}
2 changes: 1 addition & 1 deletion src/config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub const ColumnInfo = struct {
} else {
addon = "_";
}
out = std.fmt.allocPrint(allocator, "{s}@{s}", .{ addon, column.filter.host() }) catch unreachable;
out = "Z"; //std.fmt.allocPrint(allocator, "{s}@{s}", .{ addon, column.filter.host() }) catch unreachable;
}
return out;
}
Expand Down
11 changes: 9 additions & 2 deletions src/db/file.zig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ pub fn init() !void {
}

pub fn has(namespace: []const u8, key: []const u8, allocator: Allocator) bool {
var keypath = std.fmt.allocPrint(allocator, "{s}/{s}/{s}", .{ cache_dir, namespace, key }) catch unreachable;
_ = cache_dir;
_ = namespace;
_ = key;
_ = allocator;
var keypath = "Z"; //std.fmt.allocPrint(allocator, "{s}/{s}/{s}", .{ cache_dir, namespace, key }) catch unreachable;
var found = false;
if (std.fs.cwd().access(keypath, .{ .mode = .read_only })) {
found = true;
Expand All @@ -23,7 +27,10 @@ pub fn has(namespace: []const u8, key: []const u8, allocator: Allocator) bool {
}

pub fn write(namespace: []const u8, key: []const u8, value: []const u8, allocator: Allocator) !void {
var dirpath = try std.fmt.allocPrint(allocator, "{s}/{s}", .{ cache_dir, namespace });
_ = cache_dir;
_ = namespace;
_ = allocator;
var dirpath = "Z"; //try std.fmt.allocPrint(allocator, "{s}/{s}", .{ cache_dir, namespace });
warn("MKDIR {s}\n", .{dirpath});
var dir = std.fs.Dir.makeOpenPath(std.fs.cwd(), dirpath, .{}) catch unreachable;
defer dir.close();
Expand Down
5 changes: 4 additions & 1 deletion src/db/lmdb.zig
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ pub fn write(namespace: []const u8, key: []const u8, value: []const u8, allocato
ret = c.mdb_dbi_open(txnptr.*, null, c.MDB_CREATE, dbiptr);
if (ret == 0) {
// TODO: seperator issue. perhaps 2 byte invalid utf8 sequence
var fullkey = std.fmt.allocPrint(allocator, "{s}:{s}", .{ namespace, key }) catch unreachable;
var fullkey = "Z";
_ = key;
_ = namespace;
//std.fmt.allocPrint(allocator, "{s}:{s}", .{ namespace, key }) catch unreachable;
var mdb_key = mdbVal(fullkey, allocator);
var mdb_value = mdbVal(value, allocator);
ret = c.mdb_put(txnptr.*, dbiptr.*, mdb_key, mdb_value, 0);
Expand Down
55 changes: 24 additions & 31 deletions src/gui.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ const config = @import("./config.zig");
const toot_lib = @import("./toot.zig");
const thread = @import("./thread.zig");

const guilib = @import("./gui/gtk3.zig");

const GUIError = error{Init};
const Column = guilib.Column;
const Column = u32;
var columns: std.ArrayList(*Column) = undefined;
var allocator: Allocator = undefined;
var settings: *config.Settings = undefined;
Expand All @@ -21,72 +19,67 @@ pub fn init(alloca: Allocator, set: *config.Settings) !void {
settings = set;
allocator = alloca;
columns = std.ArrayList(*Column).init(allocator);
try guilib.init(alloca, set);
}

var myActor: *thread.Actor = undefined;
var stop = false;

pub fn go(data: ?*anyopaque) callconv(.C) ?*anyopaque {
warn("GUI {s} mainloop thread.self()={}\n", .{ guilib.libname(), thread.self() });
warn("GUI {s} mainloop thread.self()={}\n", .{ "none", thread.self() });
myActor = @as(*thread.Actor, @ptrCast(@alignCast(data)));
if (guilib.gui_setup(myActor)) {
// mainloop
var then = std.time.milliTimestamp();
while (!stop) {
stop = guilib.mainloop();
var now = std.time.milliTimestamp();
//warn("{}ms pause gui mainloop\n", .{now - then});
then = now;
}
warn("final mainloop {}\n", .{guilib.mainloop()});
guilib.gui_end();
} else |err| {
warn("gui error {}\n", .{err});
}
return null;
}
pub fn schedule(func: ?*const fn (?*anyopaque) callconv(.C) c_int, param: ?*anyopaque) void {
guilib.schedule(func, param);
_ = func;
_ = param;
}

pub fn show_main_schedule(in: ?*anyopaque) callconv(.C) c_int {
return guilib.show_main_schedule(in);
_ = in;
return 0;
}

pub fn add_column_schedule(in: ?*anyopaque) callconv(.C) c_int {
return guilib.add_column_schedule(in);
_ = in;
return 0;
}

pub fn column_remove_schedule(in: ?*anyopaque) callconv(.C) c_int {
return guilib.column_remove_schedule(in);
_ = in;
return 0;
}

pub fn column_config_oauth_url_schedule(in: ?*anyopaque) callconv(.C) c_int {
return guilib.column_config_oauth_url_schedule(in);
_ = in;
return 0;
}

pub fn update_column_config_oauth_finalize_schedule(in: ?*anyopaque) callconv(.C) c_int {
return guilib.update_column_config_oauth_finalize_schedule(in);
_ = in;
return 0;
}

pub fn update_column_ui_schedule(in: ?*anyopaque) callconv(.C) c_int {
return guilib.update_column_ui_schedule(in);
_ = in;
return 0;
}

pub fn update_column_netstatus_schedule(in: ?*anyopaque) callconv(.C) c_int {
return guilib.update_column_netstatus_schedule(in);
_ = in;
return 0;
}

pub fn update_column_toots_schedule(in: ?*anyopaque) callconv(.C) c_int {
return guilib.update_column_toots_schedule(in);
_ = in;
return 0;
}

pub fn update_author_photo_schedule(in: ?*anyopaque) callconv(.C) c_int {
return guilib.update_author_photo_schedule(in);
_ = in;
return 0;
}

pub const TootPic = guilib.TootPic;
pub fn toot_media_schedule(in: ?*anyopaque) callconv(.C) c_int {
return guilib.toot_media_schedule(in);
_ = in;
return 0;
}
12 changes: 0 additions & 12 deletions src/gui/gtk3.zig
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,6 @@ pub fn update_column_toots(column: *Column) void {
}
const column_footer_count_label = builder_get_widget(column.builder, "column_footer_count");
const tootword = if (column.main.config.img_only) "images" else "toots";
const countStr = std.fmt.allocPrint(allocator, "{} {s}", .{ column.main.toots.count(), tootword }) catch unreachable;
const cCountStr = util.sliceToCstr(allocator, countStr);
c.gtk_label_set_text(@as(*c.GtkLabel, @ptrCast(column_footer_count_label)), cCountStr);
}

pub fn update_netstatus_column(http: *config.HttpInfo, column: *Column) void {
Expand Down Expand Up @@ -440,9 +437,6 @@ pub fn makeTootBox(toot: *toot_lib.Type, column: *Column) *c.GtkBuilder {

fn photo_refresh(acct: []const u8, builder: *c.GtkBuilder) void {
const avatar = builder_get_widget(builder, "toot_author_avatar");
const avatar_path = std.fmt.allocPrint(allocator, "./cache/{s}/photo", .{acct}) catch unreachable;
var pixbuf = c.gdk_pixbuf_new_from_file_at_scale(util.sliceToCstr(allocator, avatar_path), 50, -1, 1, null);
c.gtk_image_set_from_pixbuf(@as(*c.GtkImage, @ptrCast(avatar)), pixbuf);
}

fn toot_media(column: *Column, builder: *c.GtkBuilder, toot: *toot_lib.Type, pic: []const u8) void {
Expand Down Expand Up @@ -521,9 +515,6 @@ fn escapeGtkString(str: []const u8) []const u8 {

pub fn labelBufPrint(label: *c.GtkWidget, comptime fmt: []const u8, args: anytype) void {
const buf = allocator.alloc(u8, 256) catch unreachable;
const str = std.fmt.bufPrint(buf, fmt, args) catch unreachable;
const cStr = util.sliceToCstr(allocator, str);
c.gtk_label_set_text(@as(*c.GtkLabel, @ptrCast(label)), cStr);
}

fn column_config_btn(columnptr: ?*anyopaque) callconv(.C) void {
Expand Down Expand Up @@ -709,9 +700,6 @@ pub fn column_config_oauth_url(colInfo: *config.ColumnInfo) void {
oauth_url_buf.append("&response_type=code") catch unreachable;
oauth_url_buf.append("&redirect_uri=urn:ietf:wg:oauth:2.0:oob") catch unreachable;
var markupBuf = allocator.alloc(u8, 512) catch unreachable;
var markup = std.fmt.bufPrint(markupBuf, "<a href=\"{s}\">{s} oauth</a>", .{ oauth_url_buf.toSliceConst(), column.main.filter.host() }) catch unreachable;
var cLabel = util.sliceToCstr(allocator, markup);
c.gtk_label_set_markup(@as(*c.GtkLabel, @ptrCast(oauth_label)), cLabel);
}

fn column_config_oauth_activate(selfptr: *anyopaque) callconv(.C) void {
Expand Down
Loading

0 comments on commit bb88115

Please sign in to comment.