aboutsummaryrefslogtreecommitdiff
path: root/src/main.zig
blob: 561745080b00a22e023082779789051e1ecdd3b3 (plain) (blame)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
const c = @cImport({
    @cDefine("WLR_USE_UNSTABLE", {});
    @cInclude("wayland-server-core.h");
    @cInclude("wlr/backend.h");
    @cInclude("wlr/util/log.h");
    @cInclude("wlr/types/wlr_xdg_shell.h>");
});
const std = @import("std");

const CursorMode = enum {
    Passthrough,
    Move,
    Resize,
};

fn create_list() c.wl_list {
    return c.wl_list{
        .prev = null,
        .next = null,
    };
}

fn create_listener() c.wl_listener {
    return c.wl_listener{
        .link = create_list(),
        .notify = null,
    };
}

const Server = struct {
    wl_display: ?*c.wl_display,
    backend: ?*c.wlr_backend,
    renderer: ?*c.wlr_renderer,

    xdg_shell: ?*c.wlr_xdg_shell,
    new_xdg_surface: c.wl_listener,
    views: c.wl_list,

    cursor: ?*c.wlr_cursor,
    cursor_mgr: ?*c.wlr_xcursor_manager,
    cursor_motion: c.wl_listener,
    cursor_motion_absolute: c.wl_listener,
    cursor_button: c.wl_listener,
    cursor_axis: c.wl_listener,
    cursor_frame: c.wl_listener,

    seat: ?*c.wlr_seat,
    new_input: c.wl_listener,
    request_cursor: c.wl_listener,
    keyboards: c.wl_list,
    cursor_mode: CursorMode,
    grabbed_view: ?*c.tinywl_view,
    grab_x: f64,
    grab_y: f64,
    grab_width: c_int,
    grab_height: c_int,
    resize_edges: u32,

    output_layout: ?*c.wlr_output_layout,
    outputs: c.wl_list,
    new_output: c.wl_listener,
};

pub fn main() !void {
    std.debug.warn("Starting up.\n", .{});

    c.wlr_log_init(c.enum_wlr_log_importance.WLR_DEBUG, null);

    var server = Server{
        .wl_display = null,
        .backend = null,
        .renderer = null,

        .xdg_shell = null,
        .new_xdg_surface = create_listener(),
        .views = c.wl_list,

        .cursor = null,
        .cursor_mgr = null,
        .cursor_motion = create_listener(),
        .cursor_motion_absolute = create_listener(),
        .cursor_button = create_listener(),
        .cursor_axis = create_listener(),
        .cursor_frame = create_listener(),

        .seat = null,
        .new_input = create_listener(),
        .request_cursor = create_listener(),
        .keyboards = c.wl_list,
        .cursor_mode = CursorMode.Passthrough,
        .grabbed_view = null,
        .grab_x = 0.0,
        .grab_y = 0.0,
        .grab_width = 0,
        .grab_height = 0,
        .resize_edges = 0,

        .output_layout = null,
        .outputs = c.wl_list{ .prev = null, .next = null },
        .new_output = create_listener(){},
    };
}