View: eliminate "self" naming convention
This commit is contained in:
parent
d8f041c96f
commit
99a99b72e7
@ -14,7 +14,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
const Self = @This();
|
const View = @This();
|
||||||
|
|
||||||
const build_options = @import("build_options");
|
const build_options = @import("build_options");
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
@ -177,10 +177,10 @@ foreign_toplevel_handle: ForeignToplevelHandle = .{},
|
|||||||
/// Connector name of the output this view occupied before an evacuation.
|
/// Connector name of the output this view occupied before an evacuation.
|
||||||
output_before_evac: ?[]const u8 = null,
|
output_before_evac: ?[]const u8 = null,
|
||||||
|
|
||||||
pub fn create(impl: Impl) error{OutOfMemory}!*Self {
|
pub fn create(impl: Impl) error{OutOfMemory}!*View {
|
||||||
assert(impl != .none);
|
assert(impl != .none);
|
||||||
|
|
||||||
const view = try util.gpa.create(Self);
|
const view = try util.gpa.create(View);
|
||||||
errdefer util.gpa.destroy(view);
|
errdefer util.gpa.destroy(view);
|
||||||
|
|
||||||
const tree = try server.root.hidden.tree.createSceneTree();
|
const tree = try server.root.hidden.tree.createSceneTree();
|
||||||
@ -228,7 +228,7 @@ pub fn create(impl: Impl) error{OutOfMemory}!*Self {
|
|||||||
/// If saved buffers of the view are currently in use by a transaction,
|
/// If saved buffers of the view are currently in use by a transaction,
|
||||||
/// mark this view for destruction when the transaction completes. Otherwise
|
/// mark this view for destruction when the transaction completes. Otherwise
|
||||||
/// destroy immediately.
|
/// destroy immediately.
|
||||||
pub fn destroy(view: *Self) void {
|
pub fn destroy(view: *View) void {
|
||||||
assert(view.impl == .none);
|
assert(view.impl == .none);
|
||||||
|
|
||||||
view.destroying = true;
|
view.destroying = true;
|
||||||
@ -256,7 +256,7 @@ pub fn destroy(view: *Self) void {
|
|||||||
/// until the size of the buffer actually committed is known. Clients are permitted
|
/// until the size of the buffer actually committed is known. Clients are permitted
|
||||||
/// by the protocol to take a size smaller than that requested by the compositor in
|
/// by the protocol to take a size smaller than that requested by the compositor in
|
||||||
/// order to maintain an aspect ratio or similar (mpv does this for example).
|
/// order to maintain an aspect ratio or similar (mpv does this for example).
|
||||||
pub fn resizeUpdatePosition(view: *Self, width: i32, height: i32) void {
|
pub fn resizeUpdatePosition(view: *View, width: i32, height: i32) void {
|
||||||
assert(view.inflight.resizing);
|
assert(view.inflight.resizing);
|
||||||
|
|
||||||
const data = blk: {
|
const data = blk: {
|
||||||
@ -284,7 +284,7 @@ pub fn resizeUpdatePosition(view: *Self, width: i32, height: i32) void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn commitTransaction(view: *Self) void {
|
pub fn commitTransaction(view: *View) void {
|
||||||
assert(view.inflight_transaction);
|
assert(view.inflight_transaction);
|
||||||
view.inflight_transaction = false;
|
view.inflight_transaction = false;
|
||||||
|
|
||||||
@ -356,7 +356,7 @@ pub fn commitTransaction(view: *Self) void {
|
|||||||
view.updateSceneState();
|
view.updateSceneState();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn updateSceneState(view: *Self) void {
|
pub fn updateSceneState(view: *View) void {
|
||||||
const box = &view.current.box;
|
const box = &view.current.box;
|
||||||
view.tree.node.setPosition(box.x, box.y);
|
view.tree.node.setPosition(box.x, box.y);
|
||||||
view.popup_tree.node.setPosition(box.x, box.y);
|
view.popup_tree.node.setPosition(box.x, box.y);
|
||||||
@ -440,49 +440,49 @@ pub fn updateSceneState(view: *Self) void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the configure should be waited for by the transaction system.
|
/// Returns true if the configure should be waited for by the transaction system.
|
||||||
pub fn configure(self: *Self) bool {
|
pub fn configure(view: *View) bool {
|
||||||
assert(self.mapped and !self.destroying);
|
assert(view.mapped and !view.destroying);
|
||||||
switch (self.impl) {
|
switch (view.impl) {
|
||||||
.xdg_toplevel => |*xdg_toplevel| return xdg_toplevel.configure(),
|
.xdg_toplevel => |*xdg_toplevel| return xdg_toplevel.configure(),
|
||||||
.xwayland_view => |*xwayland_view| return xwayland_view.configure(),
|
.xwayland_view => |*xwayland_view| return xwayland_view.configure(),
|
||||||
.none => unreachable,
|
.none => unreachable,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rootSurface(self: Self) *wlr.Surface {
|
pub fn rootSurface(view: View) *wlr.Surface {
|
||||||
assert(self.mapped and !self.destroying);
|
assert(view.mapped and !view.destroying);
|
||||||
return switch (self.impl) {
|
return switch (view.impl) {
|
||||||
.xdg_toplevel => |xdg_toplevel| xdg_toplevel.rootSurface(),
|
.xdg_toplevel => |xdg_toplevel| xdg_toplevel.rootSurface(),
|
||||||
.xwayland_view => |xwayland_view| xwayland_view.rootSurface(),
|
.xwayland_view => |xwayland_view| xwayland_view.rootSurface(),
|
||||||
.none => unreachable,
|
.none => unreachable,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sendFrameDone(self: Self) void {
|
pub fn sendFrameDone(view: View) void {
|
||||||
assert(self.mapped and !self.destroying);
|
assert(view.mapped and !view.destroying);
|
||||||
var now: os.timespec = undefined;
|
var now: os.timespec = undefined;
|
||||||
os.clock_gettime(os.CLOCK.MONOTONIC, &now) catch @panic("CLOCK_MONOTONIC not supported");
|
os.clock_gettime(os.CLOCK.MONOTONIC, &now) catch @panic("CLOCK_MONOTONIC not supported");
|
||||||
self.rootSurface().sendFrameDone(&now);
|
view.rootSurface().sendFrameDone(&now);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dropSavedSurfaceTree(self: *Self) void {
|
pub fn dropSavedSurfaceTree(view: *View) void {
|
||||||
if (!self.saved_surface_tree.node.enabled) return;
|
if (!view.saved_surface_tree.node.enabled) return;
|
||||||
|
|
||||||
var it = self.saved_surface_tree.children.safeIterator(.forward);
|
var it = view.saved_surface_tree.children.safeIterator(.forward);
|
||||||
while (it.next()) |node| node.destroy();
|
while (it.next()) |node| node.destroy();
|
||||||
|
|
||||||
self.saved_surface_tree.node.setEnabled(false);
|
view.saved_surface_tree.node.setEnabled(false);
|
||||||
self.surface_tree.node.setEnabled(true);
|
view.surface_tree.node.setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn saveSurfaceTree(self: *Self) void {
|
pub fn saveSurfaceTree(view: *View) void {
|
||||||
assert(!self.saved_surface_tree.node.enabled);
|
assert(!view.saved_surface_tree.node.enabled);
|
||||||
assert(self.saved_surface_tree.children.empty());
|
assert(view.saved_surface_tree.children.empty());
|
||||||
|
|
||||||
self.surface_tree.node.forEachBuffer(*wlr.SceneTree, saveSurfaceTreeIter, self.saved_surface_tree);
|
view.surface_tree.node.forEachBuffer(*wlr.SceneTree, saveSurfaceTreeIter, view.saved_surface_tree);
|
||||||
|
|
||||||
self.surface_tree.node.setEnabled(false);
|
view.surface_tree.node.setEnabled(false);
|
||||||
self.saved_surface_tree.node.setEnabled(true);
|
view.saved_surface_tree.node.setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn saveSurfaceTreeIter(
|
fn saveSurfaceTreeIter(
|
||||||
@ -501,7 +501,7 @@ fn saveSurfaceTreeIter(
|
|||||||
saved.setTransform(buffer.transform);
|
saved.setTransform(buffer.transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setPendingOutput(view: *Self, output: *Output) void {
|
pub fn setPendingOutput(view: *View, output: *Output) void {
|
||||||
view.pending.output = output;
|
view.pending.output = output;
|
||||||
view.pending_wm_stack_link.remove();
|
view.pending_wm_stack_link.remove();
|
||||||
view.pending_focus_stack_link.remove();
|
view.pending_focus_stack_link.remove();
|
||||||
@ -523,18 +523,18 @@ pub fn setPendingOutput(view: *Self, output: *Output) void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn close(self: Self) void {
|
pub fn close(view: View) void {
|
||||||
assert(!self.destroying);
|
assert(!view.destroying);
|
||||||
switch (self.impl) {
|
switch (view.impl) {
|
||||||
.xdg_toplevel => |xdg_toplevel| xdg_toplevel.close(),
|
.xdg_toplevel => |xdg_toplevel| xdg_toplevel.close(),
|
||||||
.xwayland_view => |xwayland_view| xwayland_view.close(),
|
.xwayland_view => |xwayland_view| xwayland_view.close(),
|
||||||
.none => unreachable,
|
.none => unreachable,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroyPopups(self: Self) void {
|
pub fn destroyPopups(view: View) void {
|
||||||
assert(!self.destroying);
|
assert(!view.destroying);
|
||||||
switch (self.impl) {
|
switch (view.impl) {
|
||||||
.xdg_toplevel => |xdg_toplevel| xdg_toplevel.destroyPopups(),
|
.xdg_toplevel => |xdg_toplevel| xdg_toplevel.destroyPopups(),
|
||||||
.xwayland_view => {},
|
.xwayland_view => {},
|
||||||
.none => unreachable,
|
.none => unreachable,
|
||||||
@ -542,9 +542,9 @@ pub fn destroyPopups(self: Self) void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Return the current title of the view if any.
|
/// Return the current title of the view if any.
|
||||||
pub fn getTitle(self: Self) ?[*:0]const u8 {
|
pub fn getTitle(view: View) ?[*:0]const u8 {
|
||||||
assert(!self.destroying);
|
assert(!view.destroying);
|
||||||
return switch (self.impl) {
|
return switch (view.impl) {
|
||||||
.xdg_toplevel => |xdg_toplevel| xdg_toplevel.getTitle(),
|
.xdg_toplevel => |xdg_toplevel| xdg_toplevel.getTitle(),
|
||||||
.xwayland_view => |xwayland_view| xwayland_view.getTitle(),
|
.xwayland_view => |xwayland_view| xwayland_view.getTitle(),
|
||||||
.none => unreachable,
|
.none => unreachable,
|
||||||
@ -552,9 +552,9 @@ pub fn getTitle(self: Self) ?[*:0]const u8 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Return the current app_id of the view if any.
|
/// Return the current app_id of the view if any.
|
||||||
pub fn getAppId(self: Self) ?[*:0]const u8 {
|
pub fn getAppId(view: View) ?[*:0]const u8 {
|
||||||
assert(!self.destroying);
|
assert(!view.destroying);
|
||||||
return switch (self.impl) {
|
return switch (view.impl) {
|
||||||
.xdg_toplevel => |xdg_toplevel| xdg_toplevel.getAppId(),
|
.xdg_toplevel => |xdg_toplevel| xdg_toplevel.getAppId(),
|
||||||
.xwayland_view => |xwayland_view| xwayland_view.getAppId(),
|
.xwayland_view => |xwayland_view| xwayland_view.getAppId(),
|
||||||
.none => unreachable,
|
.none => unreachable,
|
||||||
@ -562,13 +562,13 @@ pub fn getAppId(self: Self) ?[*:0]const u8 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Clamp the width/height of the box to the constraints of the view
|
/// Clamp the width/height of the box to the constraints of the view
|
||||||
pub fn applyConstraints(self: *Self, box: *wlr.Box) void {
|
pub fn applyConstraints(view: *View, box: *wlr.Box) void {
|
||||||
box.width = math.clamp(box.width, self.constraints.min_width, self.constraints.max_width);
|
box.width = math.clamp(box.width, view.constraints.min_width, view.constraints.max_width);
|
||||||
box.height = math.clamp(box.height, self.constraints.min_height, self.constraints.max_height);
|
box.height = math.clamp(box.height, view.constraints.min_height, view.constraints.max_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Attach after n visible, not-floating views in the pending wm_stack
|
/// Attach after n visible, not-floating views in the pending wm_stack
|
||||||
pub fn attachAfter(view: *Self, output_pending: *Output.PendingState, n: usize) void {
|
pub fn attachAfter(view: *View, output_pending: *Output.PendingState, n: usize) void {
|
||||||
var visible: u32 = 0;
|
var visible: u32 = 0;
|
||||||
var it = output_pending.wm_stack.iterator(.forward);
|
var it = output_pending.wm_stack.iterator(.forward);
|
||||||
|
|
||||||
@ -583,7 +583,7 @@ pub fn attachAfter(view: *Self, output_pending: *Output.PendingState, n: usize)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Attach above or below the currently focused view
|
/// Attach above or below the currently focused view
|
||||||
pub fn attachRelative(view: *Self, output_pending: *Output.PendingState, mode: AttachRelativeMode) void {
|
pub fn attachRelative(view: *View, output_pending: *Output.PendingState, mode: AttachRelativeMode) void {
|
||||||
var focus_stack_it = output_pending.focus_stack.iterator(.forward);
|
var focus_stack_it = output_pending.focus_stack.iterator(.forward);
|
||||||
|
|
||||||
const focus_stack_head = focus_stack_it.next() orelse {
|
const focus_stack_head = focus_stack_it.next() orelse {
|
||||||
@ -613,7 +613,7 @@ pub fn attachRelative(view: *Self, output_pending: *Output.PendingState, mode: A
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Called by the impl when the surface is ready to be displayed
|
/// Called by the impl when the surface is ready to be displayed
|
||||||
pub fn map(view: *Self) !void {
|
pub fn map(view: *View) !void {
|
||||||
log.debug("view '{?s}' mapped", .{view.getTitle()});
|
log.debug("view '{?s}' mapped", .{view.getTitle()});
|
||||||
|
|
||||||
assert(!view.mapped and !view.destroying);
|
assert(!view.mapped and !view.destroying);
|
||||||
@ -688,7 +688,7 @@ pub fn map(view: *Self) !void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Called by the impl when the surface will no longer be displayed
|
/// Called by the impl when the surface will no longer be displayed
|
||||||
pub fn unmap(view: *Self) void {
|
pub fn unmap(view: *View) void {
|
||||||
log.debug("view '{?s}' unmapped", .{view.getTitle()});
|
log.debug("view '{?s}' unmapped", .{view.getTitle()});
|
||||||
|
|
||||||
if (!view.saved_surface_tree.node.enabled) view.saveSurfaceTree();
|
if (!view.saved_surface_tree.node.enabled) view.saveSurfaceTree();
|
||||||
@ -709,7 +709,7 @@ pub fn unmap(view: *Self) void {
|
|||||||
server.root.applyPending();
|
server.root.applyPending();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn notifyTitle(view: *const Self) void {
|
pub fn notifyTitle(view: *const View) void {
|
||||||
if (view.foreign_toplevel_handle.wlr_handle) |wlr_handle| {
|
if (view.foreign_toplevel_handle.wlr_handle) |wlr_handle| {
|
||||||
if (view.getTitle()) |title| wlr_handle.setTitle(title);
|
if (view.getTitle()) |title| wlr_handle.setTitle(title);
|
||||||
}
|
}
|
||||||
@ -725,7 +725,7 @@ pub fn notifyTitle(view: *const Self) void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn notifyAppId(view: Self) void {
|
pub fn notifyAppId(view: View) void {
|
||||||
if (view.foreign_toplevel_handle.wlr_handle) |wlr_handle| {
|
if (view.foreign_toplevel_handle.wlr_handle) |wlr_handle| {
|
||||||
if (view.getAppId()) |app_id| wlr_handle.setAppId(app_id);
|
if (view.getAppId()) |app_id| wlr_handle.setAppId(app_id);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user