mirror of
https://github.com/MezzalunaWM/Mezzaluna.git
synced 2026-03-07 19:49:53 -05:00
borders now correctly outline a view and ensure that the view is clipped...
down to the correct size even when it doesn't want to be
This commit is contained in:
parent
6a5afe20e3
commit
b24c16b34e
1 changed files with 23 additions and 22 deletions
45
src/View.zig
45
src/View.zig
|
|
@ -23,11 +23,11 @@ output: ?*Output,
|
||||||
xdg_toplevel: *wlr.XdgToplevel,
|
xdg_toplevel: *wlr.XdgToplevel,
|
||||||
xdg_toplevel_decoration: ?*wlr.XdgToplevelDecorationV1,
|
xdg_toplevel_decoration: ?*wlr.XdgToplevelDecorationV1,
|
||||||
scene_tree: *wlr.SceneTree,
|
scene_tree: *wlr.SceneTree,
|
||||||
test_node: *wlr.SceneNode,
|
surface_tree: *wlr.SceneTree,
|
||||||
scene_node_data: SceneNodeData,
|
scene_node_data: SceneNodeData,
|
||||||
borders: [4]*wlr.SceneRect,
|
borders: [4]*wlr.SceneRect,
|
||||||
border_width: i32, // TODO: move this to some config controlled by lua
|
border_width: i32, // TODO: move this to some config controlled by lua
|
||||||
geometry: wlr.Box,
|
geometry: wlr.Box, // The total geometry including borders
|
||||||
|
|
||||||
// Surface Listeners
|
// Surface Listeners
|
||||||
map: wl.Listener(void) = .init(handleMap),
|
map: wl.Listener(void) = .init(handleMap),
|
||||||
|
|
@ -71,7 +71,7 @@ pub fn init(xdg_toplevel: *wlr.XdgToplevel) *View {
|
||||||
|
|
||||||
.xdg_toplevel = xdg_toplevel,
|
.xdg_toplevel = xdg_toplevel,
|
||||||
.scene_tree = undefined,
|
.scene_tree = undefined,
|
||||||
.test_node = undefined,
|
.surface_tree = undefined,
|
||||||
.xdg_toplevel_decoration = null,
|
.xdg_toplevel_decoration = null,
|
||||||
.borders = undefined,
|
.borders = undefined,
|
||||||
.border_width = 10,
|
.border_width = 10,
|
||||||
|
|
@ -81,7 +81,8 @@ pub fn init(xdg_toplevel: *wlr.XdgToplevel) *View {
|
||||||
|
|
||||||
// Add new Toplevel to root of the tree
|
// Add new Toplevel to root of the tree
|
||||||
if(server.seat.focused_output) |output| {
|
if(server.seat.focused_output) |output| {
|
||||||
self.scene_tree = try output.layers.content.createSceneXdgSurface(xdg_toplevel.base);
|
self.scene_tree = try output.layers.content.createSceneTree();
|
||||||
|
self.surface_tree = try self.scene_tree.createSceneXdgSurface(xdg_toplevel.base);
|
||||||
self.output = output;
|
self.output = output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -95,8 +96,6 @@ pub fn init(xdg_toplevel: *wlr.XdgToplevel) *View {
|
||||||
self.xdg_toplevel.base.events.new_popup.add(&self.new_popup);
|
self.xdg_toplevel.base.events.new_popup.add(&self.new_popup);
|
||||||
self.xdg_toplevel.base.events.ack_configure.add(&self.ack_configure);
|
self.xdg_toplevel.base.events.ack_configure.add(&self.ack_configure);
|
||||||
|
|
||||||
self.test_node = self.scene_tree.children.first().?;
|
|
||||||
|
|
||||||
for (self.borders, 0..) |_, i| {
|
for (self.borders, 0..) |_, i| {
|
||||||
const color: [4]f32 = .{ 1, 0, 0, 1 };
|
const color: [4]f32 = .{ 1, 0, 0, 1 };
|
||||||
self.borders[i] = try wlr.SceneTree.createSceneRect(self.scene_tree, 0, 0, &color);
|
self.borders[i] = try wlr.SceneTree.createSceneRect(self.scene_tree, 0, 0, &color);
|
||||||
|
|
@ -148,17 +147,22 @@ pub fn setSize(self: *View, width: i32, height: i32) void {
|
||||||
if (self.output == null or !self.xdg_toplevel.base.surface.mapped) return;
|
if (self.output == null or !self.xdg_toplevel.base.surface.mapped) return;
|
||||||
|
|
||||||
// at the very least the client must be big enough to have borders
|
// at the very least the client must be big enough to have borders
|
||||||
self.geometry.width = @max(
|
self.geometry.width = @max(1 + 2 * self.border_width, width);
|
||||||
1 + 2 * self.border_width,
|
self.geometry.height = @max(1 + 2 * self.border_width, height);
|
||||||
width - 2 * self.border_width,
|
|
||||||
);
|
|
||||||
self.geometry.height = @max(
|
|
||||||
1 + 2 * self.border_width,
|
|
||||||
height - 2 * self.border_width,
|
|
||||||
);
|
|
||||||
|
|
||||||
// This returns a configure serial for verifying the configure
|
// This returns a configure serial for verifying the configure
|
||||||
_ = self.xdg_toplevel.setSize(self.geometry.width, self.geometry.height);
|
_ = self.xdg_toplevel.setSize(
|
||||||
|
self.geometry.width - 2 * self.border_width,
|
||||||
|
self.geometry.height - 2 * self.border_width,
|
||||||
|
);
|
||||||
|
|
||||||
|
// clip the surface tree to the size of the view
|
||||||
|
self.surface_tree.node.subsurfaceTreeSetClip(&wlr.Box{
|
||||||
|
.x = 0,
|
||||||
|
.y = 0,
|
||||||
|
.width = self.geometry.width,
|
||||||
|
.height = self.geometry.height,
|
||||||
|
});
|
||||||
|
|
||||||
self.resizeBorders();
|
self.resizeBorders();
|
||||||
}
|
}
|
||||||
|
|
@ -167,17 +171,14 @@ pub fn setSize(self: *View, width: i32, height: i32) void {
|
||||||
/// should be called after something in the size or position is changed
|
/// should be called after something in the size or position is changed
|
||||||
fn resizeBorders(self: *View) void {
|
fn resizeBorders(self: *View) void {
|
||||||
// set the position of the surface to not clip with the borders
|
// set the position of the surface to not clip with the borders
|
||||||
self.test_node.setPosition(self.border_width, self.border_width);
|
self.surface_tree.node.setPosition(self.border_width, self.border_width);
|
||||||
// FIXME: the surface needs to be resized to not clip on the bottom and right
|
|
||||||
// sides
|
|
||||||
|
|
||||||
self.borders[0].setSize(self.geometry.width, self.border_width);
|
self.borders[0].setSize(self.geometry.width, self.border_width);
|
||||||
self.borders[1].setSize(self.geometry.width, self.border_width);
|
self.borders[1].setSize(self.geometry.width, self.border_width);
|
||||||
self.borders[2].setSize(self.border_width, self.geometry.height - 2 * self.border_width);
|
self.borders[2].setSize(self.border_width, self.geometry.height);
|
||||||
self.borders[3].setSize(self.border_width, self.geometry.height - 2 * self.border_width);
|
self.borders[3].setSize(self.border_width, self.geometry.height);
|
||||||
self.borders[1].node.setPosition(0, self.geometry.height - self.border_width);
|
self.borders[1].node.setPosition(0, self.geometry.height - self.border_width);
|
||||||
self.borders[2].node.setPosition(0, self.border_width);
|
self.borders[2].node.setPosition(self.geometry.width - self.border_width, 0);
|
||||||
self.borders[3].node.setPosition(self.geometry.width - self.border_width, self.border_width);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------- XdgTopLevel event handlers ---------
|
// --------- XdgTopLevel event handlers ---------
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue