feat: add Output, FractionalScale, Viewporter

dev
Louis Pearson 2024-02-17 19:24:52 -07:00
parent 1ba884d7b8
commit 2170bd9649
3 changed files with 269 additions and 2 deletions

View File

@ -618,3 +618,71 @@ pub const Touch = struct {
return .{ .conn = conn, .id = id }; return .{ .conn = conn, .id = id };
} }
}; };
pub const Output = struct {
pub const Request = union(enum) {
release: void,
};
pub const Event = union(enum) {
geometry: struct {
x: i32,
y: i32,
physical_width: i32,
physical_height: i32,
subpixel: Subpixel,
make: []const u8,
model: []const u8,
transform: Transform,
},
mode: struct {
flags: Mode,
width: i32,
height: i32,
refresh: i32,
},
done,
scale: struct {
factor: i32,
},
name: struct {
name: []const u8,
},
description: struct {
description: []const u8,
},
};
const Subpixel = enum(i32) {
unknown,
none,
horizontal_rgb,
horizontal_bgr,
vertical_rgb,
vertical_bgr,
};
const Transform = enum(i32) {
normal,
@"90",
@"180",
@"270",
flipped,
flipped_90,
flipped_180,
flipped_270,
};
const Mode = packed struct(u32) {
current: bool,
preferred: bool,
_1: u30,
};
conn: *Conn,
id: u32,
pub fn init(conn: *Conn, id: u32) Touch {
return .{ .conn = conn, .id = id };
}
};

View File

@ -91,6 +91,7 @@ pub fn main() !void {
defer app.deinit(); defer app.deinit();
try app.callbacks.put(seat.id, seatInitHandler); try app.callbacks.put(seat.id, seatInitHandler);
try app.callbacks.put(surface.id, surfaceHandler);
try app.callbacks.put(xdg_toplevel.id, toplevelInitHandler); try app.callbacks.put(xdg_toplevel.id, toplevelInitHandler);
try app.callbacks.put(xdg_surface.id, surfaceInitHandler); try app.callbacks.put(xdg_surface.id, surfaceInitHandler);
try app.callbacks.put(display.id, displayHandler); try app.callbacks.put(display.id, displayHandler);
@ -241,7 +242,8 @@ const App = struct {
} }; } };
try app.callbacks.put(app.state.run.keyboard.id, keyboardHandler); try app.callbacks.put(app.state.run.keyboard.id, keyboardHandler);
try app.callbacks.put(app.xdg_surface.id, surfaceDesktopHandler); try app.callbacks.put(app.surface.id, surfaceHandler);
try app.callbacks.put(app.xdg_surface.id, xdgSurfaceHandler);
try app.callbacks.put(app.xdg_wmbase.id, wmbaseHandler); try app.callbacks.put(app.xdg_wmbase.id, wmbaseHandler);
try app.callbacks.put(app.xdg_toplevel.id, toplevelHandler); try app.callbacks.put(app.xdg_toplevel.id, toplevelHandler);
@ -563,7 +565,26 @@ fn toplevelHandler(app: *App, header: wayland.Header, body: []const u32) !void {
} }
} }
fn surfaceDesktopHandler(app: *App, header: wayland.Header, body: []const u32) !void { fn surfaceHandler(app: *App, header: wayland.Header, body: []const u32) !void {
const event = try wayland.deserialize(wayland.core.Surface.Event, header, body);
_ = app;
switch (event) {
.leave => |leave| {
std.log.info("Output left: {}", .{leave});
},
.enter => |enter| {
std.log.info("Output entered: {}", .{enter});
},
.preferred_buffer_scale => |scale| {
std.log.info("Surface preferred buffer scale: {}", .{scale});
},
.preferred_buffer_transform => |transform| {
std.log.info("Surface preferred buffer transform: {}", .{transform});
},
}
}
fn xdgSurfaceHandler(app: *App, header: wayland.Header, body: []const u32) !void {
const event = try wayland.deserialize(wayland.xdg.Surface.Event, header, body); const event = try wayland.deserialize(wayland.xdg.Surface.Event, header, body);
switch (event) { switch (event) {
.configure => |conf| { .configure => |conf| {

178
src/wp.zig Normal file
View File

@ -0,0 +1,178 @@
const core = @import("core.zig");
const Conn = @import("root.zig").Conn;
pub const Viewporter = struct {
pub const INTERFACE = "wp_viewporter";
pub const VERSION = 1;
pub const Request = union(Request.Tag) {
destroy: void,
get_viewport: struct {
id: u32,
surface: u32,
},
pub const Tag = enum(u16) {
destroy,
get_viewport,
};
};
pub const Error = enum(u32) {
viewport_exists,
};
conn: *Conn,
id: u32,
pub fn init(conn: *Conn, id: u32) Viewporter {
return .{ .conn = conn, .id = id };
}
pub fn get_viewport(viewporter: Viewporter, surface: core.Surface) !Viewport {
const new_id = viewporter.conn.id_pool.create();
try viewporter.conn.send(
Request,
viewporter.id,
.{ .get_viewport = .{
.id = new_id,
.surface = surface.id,
} },
);
return Viewport.init(viewporter.conn, new_id);
}
};
pub const Viewport = struct {
pub const INTERFACE = "wp_viewport";
pub const VERSION = 1;
pub const Request = union(Request.Tag) {
destroy: void,
set_source: struct {
x: i32,
y: i32,
width: i32,
height: i32,
},
set_destination: struct {
width: i32,
height: i32,
},
pub const Tag = enum(u16) {
destroy,
set_source,
set_destination,
};
};
pub const Error = enum(u32) {
bad_value,
bad_size,
out_of_buffer,
no_surface,
};
conn: *Conn,
id: u32,
pub fn init(conn: *Conn, id: u32) Viewport {
return .{ .conn = conn, .id = id };
}
pub fn set_source(viewport: Viewport, x: i32, y: i32, width: i32, height: i32) !void {
try viewport.conn.send(
Request,
viewport.id,
.{ .set_source = .{
.x = x,
.y = y,
.width = width,
.height = height,
} },
);
}
pub fn set_destination(viewport: Viewport, width: i32, height: i32) !void {
try viewport.conn.send(
Request,
viewport.id,
.{ .set_destination = .{
.width = width,
.height = height,
} },
);
}
};
pub const FractionalScaleManagerV1 = struct {
pub const INTERFACE = "wp_fractional_scale_manager_v1";
pub const VERSION = 1;
pub const Request = union(Request.Tag) {
destroy: void,
get_fractional_scale: struct {
id: u32,
surface: u32,
},
pub const Tag = enum(u16) {
destroy,
get_fractional_scale,
};
};
pub const Error = enum(u32) {
fractional_scale_exists,
};
conn: *Conn,
id: u32,
pub fn init(conn: *Conn, id: u32) FractionalScaleManagerV1 {
return .{ .conn = conn, .id = id };
}
pub fn get_viewport(viewporter: Viewporter, surface: core.Surface) !Viewport {
const new_id = viewporter.conn.id_pool.create();
try viewporter.conn.send(
Request,
viewporter.id,
.{ .get_viewport = .{
.id = new_id,
.surface = surface.id,
} },
);
return Viewport.init(viewporter.conn, new_id);
}
};
pub const FractionalScaleV1 = struct {
pub const INTERFACE = "wp_fractional_scale_v1";
pub const VERSION = 1;
pub const Request = union(Request.Tag) {
destroy: void,
pub const Tag = enum(u16) {
destroy,
};
};
pub const Event = union(Tag) {
preferred_scale: struct {
scale: u32,
},
pub const Tag = enum(u16) {
preferred_scale,
};
};
conn: *Conn,
id: u32,
pub fn init(conn: *Conn, id: u32) Viewporter {
return .{ .conn = conn, .id = id };
}
};