styling changes

This commit is contained in:
Peterino2 2026-09-21 09:55:27 -07:00
parent 4c3decfa7f
commit fec5dc297a
3 changed files with 50 additions and 9 deletions

View File

@ -61,18 +61,27 @@ session_drawable: bool = false,
session_first: bool = true, session_first: bool = true,
session_on_demand: bool = false, session_on_demand: bool = false,
startup_timeout_ns: u64 = 10 * std.time.ns_per_s, startup_timeout_ns: u64 = 10 * std.time.ns_per_s,
pub fn create(gpa: std.mem.Allocator, io: std.Io, name: []const u8) !*Application { pub fn create(gpa: std.mem.Allocator, io: std.Io, name: []const u8) !*Application {
const self = try gpa.create(Application); const self = try gpa.create(Application);
errdefer gpa.destroy(self); errdefer gpa.destroy(self);
const owned_name = try gpa.dupe(u8, name); const owned_name = try gpa.dupe(u8, name);
errdefer gpa.free(owned_name); errdefer gpa.free(owned_name);
const scratch = try arenas.BumpArena.init(gpa, io); const scratch = try arenas.BumpArena.init(gpa, io);
self.* = .{ .gpa = gpa, .io = io, .name = owned_name, .scratch = scratch, .epoch = runtime.now(io) }; self.* = .{
.gpa = gpa,
.io = io,
.name = owned_name,
.scratch = scratch,
.epoch = runtime.now(io),
};
return self; return self;
} }
pub fn lock(self: *Application) void { pub fn lock(self: *Application) void {
self.mutex.lockUncancelable(self.io); self.mutex.lockUncancelable(self.io);
} }
pub fn unlock(self: *Application) void { pub fn unlock(self: *Application) void {
self.mutex.unlock(self.io); self.mutex.unlock(self.io);
} }

View File

@ -27,7 +27,9 @@ pub fn textBytes(text: c.uhdk_text) []const u8 {
} }
pub fn validText(t: c.uhdk_text, no_nul: bool) bool { pub fn validText(t: c.uhdk_text, no_nul: bool) bool {
return validSpan(t.ptr, t.len) and std.unicode.utf8ValidateSlice(textBytes(t)) and (!no_nul or std.mem.findScalar(u8, textBytes(t), 0) == null); return validSpan(t.ptr, t.len) and
std.unicode.utf8ValidateSlice(textBytes(t)) and
(!no_nul or std.mem.findScalar(u8, textBytes(t), 0) == null);
} }
pub fn textSpan(s: []const u8) c.uhdk_text { pub fn textSpan(s: []const u8) c.uhdk_text {
@ -55,7 +57,10 @@ pub fn writeOutput(comptime T: type, dest: [*c]T, value: T) Status {
} }
pub fn finiteSize(s: c.uhdk_size) bool { pub fn finiteSize(s: c.uhdk_size) bool {
return std.math.isFinite(s.width) and std.math.isFinite(s.height) and s.width >= 0 and s.height >= 0 and s.width <= 65536 and s.height <= 65536; return std.math.isFinite(s.width) and
std.math.isFinite(s.height) and
s.width >= 0 and s.height >= 0 and
s.width <= 65536 and s.height <= 65536;
} }
pub fn boundary(s: []const u8, offset: u64) bool { pub fn boundary(s: []const u8, offset: u64) bool {

View File

@ -7,8 +7,19 @@ const native = @import("native.zig");
const Input = @import("Input.zig"); const Input = @import("Input.zig");
const runtime = @import("../runtime.zig"); const runtime = @import("../runtime.zig");
const abi = @import("../abi.zig"); const abi = @import("../abi.zig");
const Activation = struct { next: ?*Activation = null, id: u64, window: *native.Window, token: ?*c.struct_xdg_activation_token_v1, deadline: u64 }; const Activation = struct {
const Icon = struct { proxy: ?*c.struct_xdg_toplevel_icon_v1, buffer: ?*c.struct_wl_buffer, mapping: *anyopaque, size: usize }; next: ?*Activation = null,
id: u64,
window: *native.Window,
token: ?*c.struct_xdg_activation_token_v1,
deadline: u64,
};
const Icon = struct {
proxy: ?*c.struct_xdg_toplevel_icon_v1,
buffer: ?*c.struct_wl_buffer,
mapping: *anyopaque,
size: usize,
};
pub const State = struct { pub const State = struct {
activation: ?*c.struct_xdg_activation_v1 = null, activation: ?*c.struct_xdg_activation_v1 = null,
manager: ?*c.struct_xdg_toplevel_icon_manager_v1 = null, manager: ?*c.struct_xdg_toplevel_icon_manager_v1 = null,
@ -54,13 +65,21 @@ pub fn focus(w: *native.Window, id: u64) u32 {
return abi.OK; return abi.OK;
} }
const input = Input.state(); const input = Input.state();
if (input.serial == 0 or input.key_focus == null or runtime.now(backend().app.io) -| input.serial_time > 5 * std.time.ns_per_s) return abi.UNAVAILABLE; if (input.serial == 0 or input.key_focus == null or
runtime.now(backend().app.io) -| input.serial_time > 5 * std.time.ns_per_s)
return abi.UNAVAILABLE;
const p = backend().app.gpa.create(Activation) catch return abi.OOM; const p = backend().app.gpa.create(Activation) catch return abi.OOM;
const token = c.xdg_activation_v1_get_activation_token(desktopState().activation) orelse { const token = c.xdg_activation_v1_get_activation_token(desktopState().activation) orelse {
backend().app.gpa.destroy(p); backend().app.gpa.destroy(p);
return abi.OOM; return abi.OOM;
}; };
p.* = .{ .next = desktopState().pending, .id = id, .window = w, .token = token, .deadline = runtime.now(backend().app.io) + 5 * std.time.ns_per_s }; p.* = .{
.next = desktopState().pending,
.id = id,
.window = w,
.token = token,
.deadline = runtime.now(backend().app.io) + 5 * std.time.ns_per_s,
};
desktopState().pending = p; desktopState().pending = p;
_ = c.xdg_activation_token_v1_add_listener(token, &activation_listener, p); _ = c.xdg_activation_token_v1_add_listener(token, &activation_listener, p);
c.xdg_activation_token_v1_set_serial(token, input.serial, input.seat); c.xdg_activation_token_v1_set_serial(token, input.serial, input.seat);
@ -112,7 +131,8 @@ pub fn forget(w: *native.Window) void {
} }
} }
pub fn applyIcon(w: *native.Window) void { pub fn applyIcon(w: *native.Window) void {
if (desktopState().icon) |icon| c.xdg_toplevel_icon_manager_v1_set_icon(desktopState().manager, w.top, icon.proxy); if (desktopState().icon) |icon|
c.xdg_toplevel_icon_manager_v1_set_icon(desktopState().manager, w.top, icon.proxy);
} }
/// Public pixels are straight RGBA; wl_shm ARGB8888 uses native-endian, /// Public pixels are straight RGBA; wl_shm ARGB8888 uses native-endian,
/// premultiplied channels. Pad rectangular images to a transparent square. /// premultiplied channels. Pad rectangular images to a transparent square.
@ -148,7 +168,14 @@ pub fn setIcon(image: n.uhdk_image) u32 {
pixels(words[0 .. size / 4], side, image); pixels(words[0 .. size / 4], side, image);
const pool = c.wl_shm_create_pool(desktopState().shm, fd, @intCast(size)) orelse return abi.OOM; const pool = c.wl_shm_create_pool(desktopState().shm, fd, @intCast(size)) orelse return abi.OOM;
defer c.wl_shm_pool_destroy(pool); defer c.wl_shm_pool_destroy(pool);
const buffer = c.wl_shm_pool_create_buffer(pool, 0, @intCast(side), @intCast(side), @intCast(side * 4), c.WL_SHM_FORMAT_ARGB8888) orelse return abi.OOM; const buffer = c.wl_shm_pool_create_buffer(
pool,
0,
@intCast(side),
@intCast(side),
@intCast(side * 4),
c.WL_SHM_FORMAT_ARGB8888,
) orelse return abi.OOM;
const proxy = c.xdg_toplevel_icon_manager_v1_create_icon(desktopState().manager) orelse { const proxy = c.xdg_toplevel_icon_manager_v1_create_icon(desktopState().manager) orelse {
c.wl_buffer_destroy(buffer); c.wl_buffer_destroy(buffer);
return abi.OOM; return abi.OOM;