lib/windowing/src/unsupported.zig
daab053ee43316e1809a84551d573ddd1e5bf3d2
1 const std = @import("std");
2 const sys = @import("sys");
3 const clipboard = @import("clipboard.zig");
4 const CursorShape = @import("cursor.zig").CursorShape;
5 const EventIterator = @import("event.zig").EventIterator;
6 const WindowConfig = @import("config.zig").WindowConfig;
7 const CreateError = @import("window.zig").CreateError;
8 const PollError = @import("window.zig").PollError;
9 const PresentError = @import("window.zig").PresentError;
10 const PresentRegion = @import("window.zig").PresentRegion;
11 const Scale = @import("window.zig").Scale;
12 const Size = @import("window.zig").Size;
13 const gamepad = @import("gamepad.zig");
14 const input = @import("input.zig");
15 const Modifier = @import("modifier.zig").Modifier;
16 const surface = @import("surface.zig");
17 const PresentationOutcome = @import("presentation.zig").Outcome;
18 const PresentationStatus = @import("presentation.zig").Status;
19 const PresentationStorageStatus = @import("presentation.zig").StorageStatus;
20 const WaylandStorageStatus = @import("wayland").runtime.StorageStatus;
21
22 pub const UnsupportedBackend = struct {
23 width: u32 = 1,
24 height: u32 = 1,
25 should_close: bool = true,
26 input: input.State = undefined,
27 gamepads: gamepad.State = undefined,
28
29 pub fn init(_: *UnsupportedBackend, _: std.mem.Allocator, config: WindowConfig) CreateError!void {
30 _ = config;
31 return error.UnsupportedPlatform;
32 }
33
34 pub fn deinit(_: *UnsupportedBackend) void {}
35
36 pub fn pollEvents(_: *UnsupportedBackend) PollError!EventIterator {
37 return .{ .events = &.{} };
38 }
39
40 pub fn droppedEventCount(_: *const UnsupportedBackend) u64 {
41 return 0;
42 }
43
44 pub fn shouldClose(self: *const UnsupportedBackend) bool {
45 return self.should_close;
46 }
47
48 pub fn eventSource(_: *const UnsupportedBackend) ?@import("window.zig").EventSource {
49 return null;
50 }
51
52 pub fn getSize(self: *const UnsupportedBackend) Size {
53 return .{ .width = self.width, .height = self.height };
54 }
55
56 pub fn inputState(self: *const UnsupportedBackend) *const input.State {
57 return &self.input;
58 }
59
60 pub fn inputStateMut(self: *UnsupportedBackend) *input.State {
61 return &self.input;
62 }
63
64 pub fn modifiers(self: *const UnsupportedBackend) Modifier {
65 return self.input.modifiers();
66 }
67
68 pub fn gamepadState(self: *const UnsupportedBackend) *const gamepad.State {
69 return &self.gamepads;
70 }
71
72 pub fn setTitle(_: *UnsupportedBackend, _: [:0]const u8) void {}
73
74 pub fn getFramebufferSize(self: *const UnsupportedBackend) Size {
75 return .{ .width = self.width, .height = self.height };
76 }
77
78 pub fn nativeSurface(self: *UnsupportedBackend) surface.Surface {
79 return .{ .unsupported = .{ .extent = surface.extentFromSizes(
80 self.width,
81 self.height,
82 self.width,
83 self.height,
84 1,
85 1,
86 ) } };
87 }
88
89 pub fn presentRgba8(
90 _: *UnsupportedBackend,
91 _: []const u8,
92 _: u32,
93 _: u32,
94 ) PresentError!void {
95 return error.UnsupportedPlatform;
96 }
97
98 pub fn presentRgba8Region(
99 _: *UnsupportedBackend,
100 _: []const u8,
101 _: u32,
102 _: u32,
103 _: PresentRegion,
104 ) PresentError!void {
105 return error.UnsupportedPlatform;
106 }
107
108 pub fn getContentScale(_: *const UnsupportedBackend) Scale {
109 return .{ .x = 1, .y = 1 };
110 }
111
112 pub fn setMinSize(_: *UnsupportedBackend, _: u32, _: u32) void {}
113
114 pub fn setCursor(_: *UnsupportedBackend, _: CursorShape) void {}
115
116 pub fn isCursorOnScreen(_: *const UnsupportedBackend) bool {
117 return false;
118 }
119
120 pub fn minimize(_: *UnsupportedBackend) void {}
121
122 pub fn maximize(_: *UnsupportedBackend) void {}
123
124 pub fn restore(_: *UnsupportedBackend) void {}
125
126 pub fn isMaximized(_: *const UnsupportedBackend) bool {
127 return false;
128 }
129
130 pub fn getClipboardTextAlloc(_: *UnsupportedBackend, _: std.mem.Allocator) !?[]u8 {
131 return null;
132 }
133
134 pub fn setClipboardText(_: *UnsupportedBackend, _: []const u8) clipboard.PublishError!void {
135 return error.Unavailable;
136 }
137
138 pub fn clipboardStatus(_: *const UnsupportedBackend) clipboard.Status {
139 return .{};
140 }
141
142 pub fn x11StorageStatus(_: *const UnsupportedBackend) sys.x11.Status {
143 return .{};
144 }
145
146 pub fn waylandDmabuf(_: *UnsupportedBackend) ?@import("wayland/root.zig").DmabufSurface {
147 return null;
148 }
149
150 pub fn waylandStorageStatus(_: *const UnsupportedBackend) WaylandStorageStatus {
151 return .{};
152 }
153
154 pub fn nextPresentationOutcome(_: *UnsupportedBackend) ?PresentationOutcome {
155 return null;
156 }
157
158 pub fn presentationStatus(_: *const UnsupportedBackend) PresentationStatus {
159 return .unavailable;
160 }
161
162 pub fn presentationStorageStatus(_: *const UnsupportedBackend) PresentationStorageStatus {
163 return .{};
164 }
165 };
166
167 test "unsupported backend rejects clipboard publication explicitly" {
168 var backend = UnsupportedBackend{};
169 try std.testing.expectError(
170 error.Unavailable,
171 backend.setClipboardText("unavailable"),
172 );
173 }