view: clean up initialization

This commit is contained in:
Isaac Freund 2020-08-21 16:43:12 +02:00
parent 7274761069
commit 283f3f8061
No known key found for this signature in database
GPG key ID: 86DED400DDFD7A11

View file

@ -55,16 +55,16 @@ const State = struct {
/// The output-relative coordinates and dimensions of the view. The /// The output-relative coordinates and dimensions of the view. The
/// surface itself may have other dimensions which are stored in the /// surface itself may have other dimensions which are stored in the
/// surface_box member. /// surface_box member.
box: Box, box: Box = Box{ .x = 0, .y = 0, .width = 0, .height = 0 },
/// The tags of the view, as a bitmask /// The tags of the view, as a bitmask
tags: u32, tags: u32,
/// Number of seats currently focusing the view /// Number of seats currently focusing the view
focus: u32, focus: u32 = 0,
float: bool, float: bool = false,
fullscreen: bool, fullscreen: bool = false,
}; };
const SavedBuffer = struct { const SavedBuffer = struct {
@ -74,68 +74,50 @@ const SavedBuffer = struct {
}; };
/// The implementation of this view /// The implementation of this view
impl: Impl, impl: Impl = undefined,
/// The output this view is currently associated with /// The output this view is currently associated with
output: *Output, output: *Output,
/// This is from the point where the view is mapped until the surface /// This is from the point where the view is mapped until the surface
/// is destroyed by wlroots. /// is destroyed by wlroots.
wlr_surface: ?*c.wlr_surface, wlr_surface: ?*c.wlr_surface = null,
/// This View struct outlasts the wlroots object it wraps. This bool is set to /// This View struct outlasts the wlroots object it wraps. This bool is set to
/// true when the backing wlr_xdg_toplevel or equivalent has been destroyed. /// true when the backing wlr_xdg_toplevel or equivalent has been destroyed.
destroying: bool, destroying: bool = false,
/// The double-buffered state of the view /// The double-buffered state of the view
current: State, current: State,
pending: State, pending: State,
/// The serial sent with the currently pending configure event /// The serial sent with the currently pending configure event
pending_serial: ?u32, pending_serial: ?u32 = null,
/// The currently commited geometry of the surface. The x/y may be negative if /// The currently commited geometry of the surface. The x/y may be negative if
/// for example the client has decided to draw CSD shadows a la GTK. /// for example the client has decided to draw CSD shadows a la GTK.
surface_box: Box, surface_box: Box = undefined,
/// The geometry the view's surface had when the transaction started and /// The geometry the view's surface had when the transaction started and
/// buffers were saved. /// buffers were saved.
saved_surface_box: Box, saved_surface_box: Box = undefined,
/// These are what we render while a transaction is in progress /// These are what we render while a transaction is in progress
saved_buffers: std.ArrayList(SavedBuffer), saved_buffers: std.ArrayList(SavedBuffer),
/// The floating dimensions the view, saved so that they can be restored if the /// The floating dimensions the view, saved so that they can be restored if the
/// view returns to floating mode. /// view returns to floating mode.
float_box: Box, float_box: Box = undefined,
draw_borders: bool, draw_borders: bool = true,
pub fn init(self: *Self, output: *Output, tags: u32, surface: var) void { pub fn init(self: *Self, output: *Output, tags: u32, surface: var) void {
self.output = output; self.* = .{
.output = output,
self.wlr_surface = null; .current = .{ .tags = tags },
self.destroying = false; .pending = .{ .tags = tags },
.saved_buffers = std.ArrayList(SavedBuffer).init(util.gpa),
self.current = .{
.box = .{
.x = 0,
.y = 0,
.height = 0,
.width = 0,
},
.tags = tags,
.focus = 0,
.float = false,
.fullscreen = false,
}; };
self.pending = self.current;
self.pending_serial = null;
self.saved_buffers = std.ArrayList(SavedBuffer).init(util.gpa);
self.draw_borders = true;
if (@TypeOf(surface) == *c.wlr_xdg_surface) { if (@TypeOf(surface) == *c.wlr_xdg_surface) {
self.impl = .{ .xdg_toplevel = undefined }; self.impl = .{ .xdg_toplevel = undefined };