~mil/fbp

ref: 5f7f62b5ad4a15a191c4d94f026cd4449d20aa04 fbp/src/types.zig -rw-r--r-- 1.6 KiB
5f7f62b5Miles Alan s/pending_touch/touch_pending/g 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
pub const Pixel = packed struct {
    b: u8,
    g: u8,
    r: u8,
    alpha: u8 = 0,
    pub fn from_u24(val: u24) @This() {
        return .{
            .r = @intCast(u8, val >> 16),
            .g = @intCast(u8, val >> 8 & 0xff),
            .b = @intCast(u8, val & 0xff),
        };
    }
};

pub const Key = enum(u2) { Up, Down, Select };

pub const Keybinding = packed struct {
    key: Key,
    // TODO: below should be in packed union, but currently zig fails with
    //       msg that says bit packing union unimplemented
    HoldRepeat: bool = false, // E.g. ideally void in union
    HoldStart: bool = false, // E.g. ideally void in union

    MultiTap: u3 = 0,
};

pub const Mode = enum { Normal, Lock };
pub const SubmodeNormal = enum { Keyboard, Strings };
pub const SubmodeLock = enum { ScreenOn, ScreenOff };

pub const HandlerArgTag = enum {
    Number,
};

pub const HandlerArg = union(HandlerArgTag) { Number: i32 };

pub const KeybindingAction = struct {
    mode: Mode,
    submode: ?union(Mode) { Normal: SubmodeNormal, Lock: SubmodeLock } = null,
    keybinding: Keybinding,
    handler: fn (runtime: *@import("./Runtime.zig"), arg: ?HandlerArg) void,
    arg: ?HandlerArg = null,
};

pub const GridItem = struct {
    t: []const u8, // E.g. string to display (and type if v not provided)
    v: ?c_ushort = null, // E.g. v is actual key vaue which overrides t[] if provided

    set_normalsubmode: ?SubmodeNormal = null,
    set_offset: ?usize = null,

    sticky: bool = false,
    span: u8 = 1,

    touched: bool = false,
    selected: bool = false,
    stickied: bool = false,
};