aboutsummaryrefslogtreecommitdiff
path: root/src/View.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/View.zig')
-rw-r--r--src/View.zig68
1 files changed, 62 insertions, 6 deletions
diff --git a/src/View.zig b/src/View.zig
index 51e0b98..32924b4 100644
--- a/src/View.zig
+++ b/src/View.zig
@@ -17,6 +17,7 @@
const Self = @This();
+const build_options = @import("build_options");
const std = @import("std");
const c = @import("c.zig");
@@ -27,13 +28,18 @@ const Output = @import("Output.zig");
const Root = @import("Root.zig");
const ViewStack = @import("view_stack.zig").ViewStack;
const XdgToplevel = @import("XdgToplevel.zig");
+const XwaylandView = if (build_options.xwayland)
+ @import("XwaylandView.zig")
+else
+ @import("VoidView.zig");
-const ViewImpl = union(enum) {
+const Impl = union(enum) {
xdg_toplevel: XdgToplevel,
+ xwayland_view: XwaylandView,
};
/// The implementation of this view
-impl: ViewImpl,
+impl: Impl,
/// The output this view is currently associated with
output: *Output,
@@ -63,11 +69,11 @@ pending_serial: ?u32,
// This is what we render while a transaction is in progress
stashed_buffer: ?*c.wlr_buffer,
-pub fn init_xdg_toplevel(
+pub fn init(
self: *Self,
output: *Output,
tags: u32,
- wlr_xdg_surface: *c.wlr_xdg_surface,
+ surface: var,
) void {
self.output = output;
@@ -90,8 +96,13 @@ pub fn init_xdg_toplevel(
self.stashed_buffer = null;
- self.impl = .{ .xdg_toplevel = undefined };
- self.impl.xdg_toplevel.init(self, wlr_xdg_surface);
+ if (@TypeOf(surface) == *c.wlr_xdg_surface) {
+ self.impl = .{ .xdg_toplevel = undefined };
+ self.impl.xdg_toplevel.init(self, surface);
+ } else if (build_options.xwayland and @TypeOf(surface) == *c.wlr_xwayland_surface) {
+ self.impl = .{ .xwayland_view = undefined };
+ self.impl.xwayland_view.init(self, surface);
+ } else unreachable;
}
pub fn deinit(self: *Self) void {
@@ -113,6 +124,7 @@ pub fn configure(self: Self) void {
if (self.pending_box) |pending_box| {
switch (self.impl) {
.xdg_toplevel => |xdg_toplevel| xdg_toplevel.configure(pending_box),
+ .xwayland_view => |xwayland_view| xwayland_view.configure(pending_box),
}
} else {
Log.Error.log("Configure called on a View with no pending box", .{});
@@ -148,6 +160,7 @@ pub fn setFocused(self: *Self, focused: bool) void {
self.focused = focused;
switch (self.impl) {
.xdg_toplevel => |xdg_toplevel| xdg_toplevel.setActivated(focused),
+ .xwayland_view => |xwayland_view| xwayland_view.setActivated(focused),
}
}
@@ -186,6 +199,7 @@ pub fn sendToOutput(self: *Self, destination_output: *Output) void {
pub fn close(self: Self) void {
switch (self.impl) {
.xdg_toplevel => |xdg_toplevel| xdg_toplevel.close(),
+ .xwayland_view => |xwayland_view| xwayland_view.close(),
}
}
@@ -196,5 +210,47 @@ pub fn forEachSurface(
) void {
switch (self.impl) {
.xdg_toplevel => |xdg_toplevel| xdg_toplevel.forEachSurface(iterator, user_data),
+ .xwayland_view => |xwayland_view| xwayland_view.forEachSurface(iterator, user_data),
}
}
+
+/// Return the surface at output coordinates ox, oy and set sx, sy to the
+/// corresponding surface-relative coordinates, if there is a surface.
+pub fn surfaceAt(self: Self, ox: f64, oy: f64, sx: *f64, sy: *f64) ?*c.wlr_surface {
+ return switch (self.impl) {
+ .xdg_toplevel => |xdg_toplevel| xdg_toplevel.surfaceAt(ox, oy, sx, sy),
+ .xwayland_view => |xwayland_view| xwayland_view.surfaceAt(ox, oy, sx, sy),
+ };
+}
+
+/// Called by the impl when the surface is ready to be displayed
+pub fn map(self: *Self) void {
+ const root = self.output.root;
+
+ // Focus the newly mapped view. Note: if a seat is focusing a different output
+ // it will continue to do so.
+ var it = root.server.input_manager.seats.first;
+ while (it) |seat_node| : (it = seat_node.next) {
+ seat_node.data.focus(self);
+ }
+
+ c.wlr_surface_send_enter(self.wlr_surface.?, self.output.wlr_output);
+
+ root.arrange();
+}
+
+/// Called by the impl when the surface will no longer be displayed
+pub fn unmap(self: *Self) void {
+ const root = self.output.root;
+
+ self.wlr_surface = null;
+
+ // Inform all seats that the view has been unmapped so they can handle focus
+ var it = root.server.input_manager.seats.first;
+ while (it) |node| : (it = node.next) {
+ const seat = &node.data;
+ seat.handleViewUnmap(self);
+ }
+
+ root.arrange();
+}