more aggressive formatting changes
This commit is contained in:
parent
fec5dc297a
commit
b55bcb3050
|
|
@ -2,7 +2,10 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const c = @import("native");
|
const c = @import("native");
|
||||||
const abi = @import("abi.zig");
|
const abi = @import("abi.zig");
|
||||||
const Data = struct { ptr: ?*const anyopaque = null, size: u64 = 0 };
|
const Data = struct {
|
||||||
|
ptr: ?*const anyopaque = null,
|
||||||
|
size: u64 = 0,
|
||||||
|
};
|
||||||
|
|
||||||
fn store(comptime T: type, allocator: std.mem.Allocator, value: T) !Data {
|
fn store(comptime T: type, allocator: std.mem.Allocator, value: T) !Data {
|
||||||
const ptr = try allocator.create(T);
|
const ptr = try allocator.create(T);
|
||||||
|
|
@ -25,7 +28,18 @@ fn result(allocator: std.mem.Allocator, source: c.z_request_result) !c.uhdk_requ
|
||||||
c.UHDK_REQUEST_WATCH => try store(c.uhdk_watch_result, allocator, .{ .watch = source.value.watch }),
|
c.UHDK_REQUEST_WATCH => try store(c.uhdk_watch_result, allocator, .{ .watch = source.value.watch }),
|
||||||
else => .{},
|
else => .{},
|
||||||
};
|
};
|
||||||
return .{ .tag = source.tag, .kind = source.kind, .status = source.status, .diagnostic = if (source.status != abi.OK and source.diagnostic.len == 0) abi.statusMessage(source.status) else try abi.copyText(allocator, source.diagnostic), .data = data.ptr, .data_size = data.size };
|
return .{
|
||||||
|
.tag = source.tag,
|
||||||
|
.kind = source.kind,
|
||||||
|
.status = source.status,
|
||||||
|
.diagnostic = if (source.status != abi.OK
|
||||||
|
and source.diagnostic.len == 0)
|
||||||
|
abi.statusMessage(source.status)
|
||||||
|
else
|
||||||
|
try abi.copyText(allocator, source.diagnostic),
|
||||||
|
.data = data.ptr,
|
||||||
|
.data_size = data.size,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pack(allocator: std.mem.Allocator, source: c.z_event) !c.uhdk_event {
|
pub fn pack(allocator: std.mem.Allocator, source: c.z_event) !c.uhdk_event {
|
||||||
|
|
@ -35,7 +49,11 @@ pub fn pack(allocator: std.mem.Allocator, source: c.z_event) !c.uhdk_event {
|
||||||
c.UHDK_EVENT_WINDOW_METRICS => try store(c.uhdk_window_metrics, allocator, source.data.metrics),
|
c.UHDK_EVENT_WINDOW_METRICS => try store(c.uhdk_window_metrics, allocator, source.data.metrics),
|
||||||
c.UHDK_EVENT_PREFERENCES_CHANGED => try store(c.uhdk_preferences, allocator, source.data.preferences),
|
c.UHDK_EVENT_PREFERENCES_CHANGED => try store(c.uhdk_preferences, allocator, source.data.preferences),
|
||||||
c.UHDK_EVENT_KEY => try store(c.uhdk_key_event, allocator, source.data.key),
|
c.UHDK_EVENT_KEY => try store(c.uhdk_key_event, allocator, source.data.key),
|
||||||
c.UHDK_EVENT_POINTER_ENTER, c.UHDK_EVENT_POINTER_LEAVE, c.UHDK_EVENT_POINTER_MOVE, c.UHDK_EVENT_POINTER_BUTTON => try store(c.uhdk_pointer_event, allocator, source.data.pointer),
|
c.UHDK_EVENT_POINTER_ENTER,
|
||||||
|
c.UHDK_EVENT_POINTER_LEAVE,
|
||||||
|
c.UHDK_EVENT_POINTER_MOVE,
|
||||||
|
c.UHDK_EVENT_POINTER_BUTTON,
|
||||||
|
=> try store(c.uhdk_pointer_event, allocator, source.data.pointer),
|
||||||
c.UHDK_EVENT_POINTER_MODE_CHANGED => try store(c.uhdk_pointer_mode_event, allocator, .{ .mode = source.data.pointer_mode }),
|
c.UHDK_EVENT_POINTER_MODE_CHANGED => try store(c.uhdk_pointer_mode_event, allocator, .{ .mode = source.data.pointer_mode }),
|
||||||
c.UHDK_EVENT_SCROLL => try store(c.uhdk_scroll_event, allocator, source.data.scroll),
|
c.UHDK_EVENT_SCROLL => try store(c.uhdk_scroll_event, allocator, source.data.scroll),
|
||||||
c.UHDK_EVENT_TEXT_COMMIT, c.UHDK_EVENT_TEXT_PREEDIT => data: {
|
c.UHDK_EVENT_TEXT_COMMIT, c.UHDK_EVENT_TEXT_PREEDIT => data: {
|
||||||
|
|
@ -55,5 +73,14 @@ pub fn pack(allocator: std.mem.Allocator, source: c.z_event) !c.uhdk_event {
|
||||||
c.UHDK_EVENT_REQUEST_DONE => try store(c.uhdk_request_result, allocator, try result(allocator, source.data.request)),
|
c.UHDK_EVENT_REQUEST_DONE => try store(c.uhdk_request_result, allocator, try result(allocator, source.data.request)),
|
||||||
else => .{},
|
else => .{},
|
||||||
};
|
};
|
||||||
return .{ .struct_size = @sizeOf(c.uhdk_event), .type = source.type, .time_ns = source.time_ns, .input_id = source.input_id, .cycle_id = source.cycle_id, .window = source.window, .data = data.ptr, .data_size = data.size };
|
return .{
|
||||||
|
.struct_size = @sizeOf(c.uhdk_event),
|
||||||
|
.type = source.type,
|
||||||
|
.time_ns = source.time_ns,
|
||||||
|
.input_id = source.input_id,
|
||||||
|
.cycle_id = source.cycle_id,
|
||||||
|
.window = source.window,
|
||||||
|
.data = data.ptr,
|
||||||
|
.data_size = data.size,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,18 +12,21 @@ pub fn queueCreate(
|
||||||
if (handle == null or !abi.validDescriptor(c.z_window_desc, desc)) return abi.INVALID;
|
if (handle == null or !abi.validDescriptor(c.z_window_desc, desc)) return abi.INVALID;
|
||||||
if (out == null) return abi.INVALID;
|
if (out == null) return abi.INVALID;
|
||||||
const d = desc.*;
|
const d = desc.*;
|
||||||
if (!validStyle(&d.style) or
|
if (!validStyle(&d.style)
|
||||||
!abi.validText(d.title, true) or
|
or !abi.validText(d.title, true)
|
||||||
!abi.finiteSize(d.content_size) or
|
or !abi.finiteSize(d.content_size)
|
||||||
d.content_size.width == 0 or
|
or d.content_size.width == 0
|
||||||
d.content_size.height == 0 or
|
or d.content_size.height == 0
|
||||||
!abi.finiteSize(d.min_size) or
|
or !abi.finiteSize(d.min_size)
|
||||||
!abi.finiteSize(d.max_size) or
|
or !abi.finiteSize(d.max_size)
|
||||||
d.flags & ~@as(u32, c.Z_WINDOW_OPENGL) != 0) return abi.INVALID;
|
or d.flags & ~@as(u32, c.Z_WINDOW_OPENGL) != 0) return abi.INVALID;
|
||||||
if ((d.max_size.width != 0 and d.max_size.width < d.min_size.width) or
|
if ((d.max_size.width != 0
|
||||||
(d.max_size.height != 0 and d.max_size.height < d.min_size.height)) return abi.INVALID;
|
and d.max_size.width < d.min_size.width)
|
||||||
if (d.parent != null and (runtime.fromObjectHandle(d.parent).app != runtime.fromAppHandle(handle) or
|
or (d.max_size.height != 0
|
||||||
!runtime.fromObjectHandle(d.parent).alive)) return abi.INVALID;
|
and d.max_size.height < d.min_size.height)) return abi.INVALID;
|
||||||
|
if (d.parent != null
|
||||||
|
and (runtime.fromObjectHandle(d.parent).app != runtime.fromAppHandle(handle)
|
||||||
|
or !runtime.fromObjectHandle(d.parent).alive)) return abi.INVALID;
|
||||||
const command = runtime.createAppCommand(handle, c.Z_WINDOW) catch |err| return runtime.applicationError(err);
|
const command = runtime.createAppCommand(handle, c.Z_WINDOW) catch |err| return runtime.applicationError(err);
|
||||||
const object = runtime.createObject(runtime.fromAppHandle(handle), c.Z_KIND_WINDOW) catch {
|
const object = runtime.createObject(runtime.fromAppHandle(handle), c.Z_KIND_WINDOW) catch {
|
||||||
runtime.abandon(command);
|
runtime.abandon(command);
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,15 @@ fn word(offset: usize) u16 {
|
||||||
}
|
}
|
||||||
const count = word(4);
|
const count = word(4);
|
||||||
const fallback = word(6);
|
const fallback = word(6);
|
||||||
const Glyph = struct { offset: usize, packed_size: usize, width: u8, height: u8, x: i8, y: i8, advance: u8 };
|
const Glyph = struct {
|
||||||
|
offset: usize,
|
||||||
|
packed_size: usize,
|
||||||
|
width: u8,
|
||||||
|
height: u8,
|
||||||
|
x: i8,
|
||||||
|
y: i8,
|
||||||
|
advance: u8,
|
||||||
|
};
|
||||||
fn record(index: usize) Glyph {
|
fn record(index: usize) Glyph {
|
||||||
const offset = 8 + index * 12;
|
const offset = 8 + index * 12;
|
||||||
return .{
|
return .{
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,12 @@ const Offer = struct {
|
||||||
actions: u32 = 0,
|
actions: u32 = 0,
|
||||||
action: u32 = 0,
|
action: u32 = 0,
|
||||||
};
|
};
|
||||||
const Source = struct { next: ?*Source = null, proxy: ?*c.struct_wl_data_source, bytes: []u8, refs: usize = 1 };
|
const Source = struct {
|
||||||
|
next: ?*Source = null,
|
||||||
|
proxy: ?*c.struct_wl_data_source,
|
||||||
|
bytes: []u8,
|
||||||
|
refs: usize = 1,
|
||||||
|
};
|
||||||
const Transfer = struct {
|
const Transfer = struct {
|
||||||
next: ?*Transfer = null,
|
next: ?*Transfer = null,
|
||||||
fd: c_int,
|
fd: c_int,
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,12 @@ const abi = @import("../abi.zig");
|
||||||
const Input = @import("Input.zig");
|
const Input = @import("Input.zig");
|
||||||
const Menu = @import("Menu.zig");
|
const Menu = @import("Menu.zig");
|
||||||
const Bitmap = @import("Bitmap.zig");
|
const Bitmap = @import("Bitmap.zig");
|
||||||
const Buffer = struct { proxy: ?*c.struct_wl_buffer = null, mapping: ?*anyopaque = null, size: usize = 0, busy: bool = false };
|
const Buffer = struct {
|
||||||
|
proxy: ?*c.struct_wl_buffer = null,
|
||||||
|
mapping: ?*anyopaque = null,
|
||||||
|
size: usize = 0,
|
||||||
|
busy: bool = false,
|
||||||
|
};
|
||||||
const Panel = struct {
|
const Panel = struct {
|
||||||
parent: ?*Panel,
|
parent: ?*Panel,
|
||||||
menu: *Resource,
|
menu: *Resource,
|
||||||
|
|
|
||||||
|
|
@ -146,7 +146,10 @@ fn done(_: ?*anyopaque, _: ?*c.struct_zwp_text_input_v3, serial: u32) callconv(.
|
||||||
}
|
}
|
||||||
const listener: c.struct_zwp_text_input_v3_listener = .{ .enter = enter, .leave = leave, .preedit_string = preedit, .commit_string = committed, .delete_surrounding_text = deleted, .done = done };
|
const listener: c.struct_zwp_text_input_v3_listener = .{ .enter = enter, .leave = leave, .preedit_string = preedit, .commit_string = committed, .delete_surrounding_text = deleted, .done = done };
|
||||||
|
|
||||||
pub fn crop(bytes: []const u8, start: usize, length: usize) ?struct { start: usize, end: usize } {
|
pub fn crop(bytes: []const u8, start: usize, length: usize) ?struct {
|
||||||
|
start: usize,
|
||||||
|
end: usize,
|
||||||
|
} {
|
||||||
if (length > 4000 or std.mem.findScalar(u8, bytes, 0) != null) return null;
|
if (length > 4000 or std.mem.findScalar(u8, bytes, 0) != null) return null;
|
||||||
var lo = start -| ((4000 - length) / 2);
|
var lo = start -| ((4000 - length) / 2);
|
||||||
while (lo < start and !abi.boundary(bytes, lo)) lo += 1;
|
while (lo < start and !abi.boundary(bytes, lo)) lo += 1;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue