Greatly simplify view offset handling
Fixes https://github.com/ifreund/river/issues/9
This commit is contained in:
parent
21c3969c5f
commit
550bd493cd
6 changed files with 82 additions and 80 deletions
23
src/box.zig
23
src/box.zig
|
@ -1,6 +1,17 @@
|
||||||
pub const Box = struct {
|
const Self = @This();
|
||||||
x: i32,
|
|
||||||
y: i32,
|
const c = @import("c.zig");
|
||||||
width: u32,
|
|
||||||
height: u32,
|
x: i32,
|
||||||
};
|
y: i32,
|
||||||
|
width: u32,
|
||||||
|
height: u32,
|
||||||
|
|
||||||
|
pub fn toWlrBox(self: Self) c.wlr_box {
|
||||||
|
return c.wlr_box{
|
||||||
|
.x = @intCast(c_int, self.x),
|
||||||
|
.y = @intCast(c_int, self.y),
|
||||||
|
.width = @intCast(c_int, self.width),
|
||||||
|
.height = @intCast(c_int, self.height),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const c = @import("c.zig");
|
const c = @import("c.zig");
|
||||||
|
|
||||||
const Box = @import("box.zig").Box;
|
const Box = @import("box.zig");
|
||||||
const Log = @import("log.zig").Log;
|
const Log = @import("log.zig").Log;
|
||||||
const Output = @import("output.zig").Output;
|
const Output = @import("output.zig").Output;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ const std = @import("std");
|
||||||
const c = @import("c.zig");
|
const c = @import("c.zig");
|
||||||
const render = @import("render.zig");
|
const render = @import("render.zig");
|
||||||
|
|
||||||
const Box = @import("box.zig").Box;
|
const Box = @import("box.zig");
|
||||||
const LayerSurface = @import("layer_surface.zig").LayerSurface;
|
const LayerSurface = @import("layer_surface.zig").LayerSurface;
|
||||||
const Log = @import("log.zig").Log;
|
const Log = @import("log.zig").Log;
|
||||||
const Root = @import("root.zig").Root;
|
const Root = @import("root.zig").Root;
|
||||||
|
@ -160,6 +160,8 @@ pub const Output = struct {
|
||||||
const master_count = std.math.min(self.master_count, visible_count);
|
const master_count = std.math.min(self.master_count, visible_count);
|
||||||
const slave_count = if (master_count >= visible_count) 0 else visible_count - master_count;
|
const slave_count = if (master_count >= visible_count) 0 else visible_count - master_count;
|
||||||
|
|
||||||
|
const border_width = self.root.server.config.border_width;
|
||||||
|
const view_padding = self.root.server.config.view_padding;
|
||||||
const outer_padding = self.root.server.config.outer_padding;
|
const outer_padding = self.root.server.config.outer_padding;
|
||||||
|
|
||||||
const layout_width = @intCast(u32, self.usable_box.width) - outer_padding * 2;
|
const layout_width = @intCast(u32, self.usable_box.width) - outer_padding * 2;
|
||||||
|
@ -183,30 +185,34 @@ pub const Output = struct {
|
||||||
var it = ViewStack(View).pendingIterator(self.views.first, output_tags);
|
var it = ViewStack(View).pendingIterator(self.views.first, output_tags);
|
||||||
while (it.next()) |node| {
|
while (it.next()) |node| {
|
||||||
const view = &node.view;
|
const view = &node.view;
|
||||||
|
|
||||||
if (view.floating) {
|
if (view.floating) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var new_box: Box = undefined;
|
||||||
|
|
||||||
|
// Add the remainder to the first master/slave to ensure every
|
||||||
|
// pixel of height is used
|
||||||
if (i < master_count) {
|
if (i < master_count) {
|
||||||
// Add the remainder to the first master to ensure every pixel of height is used
|
|
||||||
const master_height = @divTrunc(layout_height, master_count);
|
const master_height = @divTrunc(layout_height, master_count);
|
||||||
const master_height_rem = layout_height % master_count;
|
const master_height_rem = layout_height % master_count;
|
||||||
|
|
||||||
view.pending_box = Box{
|
new_box = .{
|
||||||
.x = @intCast(i32, outer_padding),
|
.x = 0,
|
||||||
.y = @intCast(i32, outer_padding + i * master_height +
|
.y = @intCast(i32, i * master_height +
|
||||||
if (i > 0) master_height_rem else 0),
|
if (i > 0) master_height_rem else 0),
|
||||||
|
|
||||||
.width = master_column_width,
|
.width = master_column_width,
|
||||||
.height = master_height + if (i == 0) master_height_rem else 0,
|
.height = master_height + if (i == 0) master_height_rem else 0,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
// Add the remainder to the first slave to ensure every pixel of height is used
|
|
||||||
const slave_height = @divTrunc(layout_height, slave_count);
|
const slave_height = @divTrunc(layout_height, slave_count);
|
||||||
const slave_height_rem = layout_height % slave_count;
|
const slave_height_rem = layout_height % slave_count;
|
||||||
|
|
||||||
view.pending_box = Box{
|
new_box = .{
|
||||||
.x = @intCast(i32, outer_padding + master_column_width),
|
.x = @intCast(i32, master_column_width),
|
||||||
.y = @intCast(i32, outer_padding + (i - master_count) * slave_height +
|
.y = @intCast(i32, (i - master_count) * slave_height +
|
||||||
if (i > master_count) slave_height_rem else 0),
|
if (i > master_count) slave_height_rem else 0),
|
||||||
|
|
||||||
.width = slave_column_width,
|
.width = slave_column_width,
|
||||||
|
@ -215,6 +221,16 @@ pub const Output = struct {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply offsets from borders and padding
|
||||||
|
new_box.x += @intCast(i32, border_width + outer_padding + view_padding);
|
||||||
|
new_box.y += @intCast(i32, border_width + outer_padding + view_padding);
|
||||||
|
|
||||||
|
new_box.width -= (border_width + view_padding) * 2;
|
||||||
|
new_box.height -= (border_width + view_padding) * 2;
|
||||||
|
|
||||||
|
// Set the view's pending box to the new dimensions
|
||||||
|
view.pending_box = new_box;
|
||||||
|
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const c = @import("c.zig");
|
const c = @import("c.zig");
|
||||||
|
|
||||||
|
const Box = @import("box.zig");
|
||||||
const LayerSurface = @import("layer_surface.zig").LayerSurface;
|
const LayerSurface = @import("layer_surface.zig").LayerSurface;
|
||||||
const Output = @import("output.zig").Output;
|
const Output = @import("output.zig").Output;
|
||||||
const Server = @import("server.zig").Server;
|
const Server = @import("server.zig").Server;
|
||||||
|
@ -168,13 +169,11 @@ fn renderView(output: Output, view: *View, now: *c.timespec) void {
|
||||||
// If we have a stashed buffer, we are in the middle of a transaction
|
// If we have a stashed buffer, we are in the middle of a transaction
|
||||||
// and need to render that buffer until the transaction is complete.
|
// and need to render that buffer until the transaction is complete.
|
||||||
if (view.stashed_buffer) |buffer| {
|
if (view.stashed_buffer) |buffer| {
|
||||||
const border_width = view.output.root.server.config.border_width;
|
|
||||||
const view_padding = view.output.root.server.config.view_padding;
|
|
||||||
var box = c.wlr_box{
|
var box = c.wlr_box{
|
||||||
.x = view.current_box.x + @intCast(i32, border_width + view_padding),
|
.x = view.current_box.x,
|
||||||
.y = view.current_box.y + @intCast(i32, border_width + view_padding),
|
.y = view.current_box.y,
|
||||||
.width = @intCast(c_int, view.current_box.width - border_width * 2 - view_padding * 2),
|
.width = @intCast(c_int, view.current_box.width),
|
||||||
.height = @intCast(c_int, view.current_box.height - border_width * 2 - view_padding * 2),
|
.height = @intCast(c_int, view.current_box.height),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Scale the box to the output's current scaling factor
|
// Scale the box to the output's current scaling factor
|
||||||
|
@ -229,11 +228,9 @@ fn renderSurface(_surface: ?*c.wlr_surface, sx: c_int, sy: c_int, data: ?*c_void
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const border_width = view.output.root.server.config.border_width;
|
|
||||||
const view_padding = view.output.root.server.config.view_padding;
|
|
||||||
var box = c.wlr_box{
|
var box = c.wlr_box{
|
||||||
.x = view.current_box.x + sx + @intCast(c_int, border_width + view_padding),
|
.x = view.current_box.x + sx,
|
||||||
.y = view.current_box.y + sy + @intCast(c_int, border_width + view_padding),
|
.y = view.current_box.y + sy,
|
||||||
.width = surface.current.width,
|
.width = surface.current.width,
|
||||||
.height = surface.current.height,
|
.height = surface.current.height,
|
||||||
};
|
};
|
||||||
|
@ -259,66 +256,46 @@ fn renderSurface(_surface: ?*c.wlr_surface, sx: c_int, sy: c_int, data: ?*c_void
|
||||||
}
|
}
|
||||||
|
|
||||||
fn renderBorders(output: Output, view: *View, now: *c.timespec) void {
|
fn renderBorders(output: Output, view: *View, now: *c.timespec) void {
|
||||||
var border: c.wlr_box = undefined;
|
var border: Box = undefined;
|
||||||
const color = if (view.focused)
|
const color = if (view.focused)
|
||||||
[_]f32{ 0.57647059, 0.63137255, 0.63137255, 1.0 } // Solarized base1
|
[_]f32{ 0.57647059, 0.63137255, 0.63137255, 1.0 } // Solarized base1
|
||||||
else
|
else
|
||||||
[_]f32{ 0.34509804, 0.43137255, 0.45882353, 1.0 }; // Solarized base01
|
[_]f32{ 0.34509804, 0.43137255, 0.45882353, 1.0 }; // Solarized base01
|
||||||
const border_width = output.root.server.config.border_width;
|
const border_width = output.root.server.config.border_width;
|
||||||
const view_padding = output.root.server.config.view_padding;
|
|
||||||
|
|
||||||
// left border
|
// left and right, covering the corners as well
|
||||||
border.x = view.current_box.x + @intCast(c_int, view_padding);
|
border.y = view.current_box.y - @intCast(i32, border_width);
|
||||||
border.y = view.current_box.y + @intCast(c_int, view_padding);
|
border.width = border_width;
|
||||||
border.width = @intCast(c_int, border_width);
|
border.height = view.current_box.height + border_width * 2;
|
||||||
border.height = @intCast(c_int, view.current_box.height - view_padding * 2);
|
|
||||||
scaleBox(&border, output.wlr_output.scale);
|
|
||||||
c.wlr_render_rect(
|
|
||||||
output.root.server.wlr_renderer,
|
|
||||||
&border,
|
|
||||||
&color,
|
|
||||||
&output.wlr_output.transform_matrix,
|
|
||||||
);
|
|
||||||
|
|
||||||
// right border
|
// left
|
||||||
border.x = view.current_box.x +
|
border.x = view.current_box.x - @intCast(i32, border_width);
|
||||||
@intCast(c_int, view.current_box.width - border_width - view_padding);
|
renderRect(output, border, color);
|
||||||
border.y = view.current_box.y + @intCast(c_int, view_padding);
|
|
||||||
border.width = @intCast(c_int, border_width);
|
|
||||||
border.height = @intCast(c_int, view.current_box.height - view_padding * 2);
|
|
||||||
scaleBox(&border, output.wlr_output.scale);
|
|
||||||
c.wlr_render_rect(
|
|
||||||
output.root.server.wlr_renderer,
|
|
||||||
&border,
|
|
||||||
&color,
|
|
||||||
&output.wlr_output.transform_matrix,
|
|
||||||
);
|
|
||||||
|
|
||||||
// top border
|
// right
|
||||||
border.x = view.current_box.x + @intCast(c_int, border_width + view_padding);
|
border.x = view.current_box.x + @intCast(i32, view.current_box.width);
|
||||||
border.y = view.current_box.y + @intCast(c_int, view_padding);
|
renderRect(output, border, color);
|
||||||
border.width = @intCast(c_int, view.current_box.width -
|
|
||||||
border_width * 2 - view_padding * 2);
|
// top and bottom
|
||||||
border.height = @intCast(c_int, border_width);
|
border.x = view.current_box.x;
|
||||||
scaleBox(&border, output.wlr_output.scale);
|
border.width = view.current_box.width;
|
||||||
c.wlr_render_rect(
|
border.height = border_width;
|
||||||
output.root.server.wlr_renderer,
|
|
||||||
&border,
|
// top
|
||||||
&color,
|
border.y = view.current_box.y - @intCast(i32, border_width);
|
||||||
&output.wlr_output.transform_matrix,
|
renderRect(output, border, color);
|
||||||
);
|
|
||||||
|
|
||||||
// bottom border
|
// bottom border
|
||||||
border.x = view.current_box.x + @intCast(c_int, border_width + view_padding);
|
border.y = view.current_box.y + @intCast(i32, view.current_box.height);
|
||||||
border.y = view.current_box.y +
|
renderRect(output, border, color);
|
||||||
@intCast(c_int, view.current_box.height - border_width - view_padding);
|
}
|
||||||
border.width = @intCast(c_int, view.current_box.width -
|
|
||||||
border_width * 2 - view_padding * 2);
|
fn renderRect(output: Output, box: Box, color: [4]f32) void {
|
||||||
border.height = @intCast(c_int, border_width);
|
var wlr_box = box.toWlrBox();
|
||||||
scaleBox(&border, output.wlr_output.scale);
|
scaleBox(&wlr_box, output.wlr_output.scale);
|
||||||
c.wlr_render_rect(
|
c.wlr_render_rect(
|
||||||
output.root.server.wlr_renderer,
|
output.root.server.wlr_renderer,
|
||||||
&border,
|
&wlr_box,
|
||||||
&color,
|
&color,
|
||||||
&output.wlr_output.transform_matrix,
|
&output.wlr_output.transform_matrix,
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const c = @import("c.zig");
|
const c = @import("c.zig");
|
||||||
|
|
||||||
const Box = @import("box.zig").Box;
|
const Box = @import("box.zig");
|
||||||
const Log = @import("log.zig").Log;
|
const Log = @import("log.zig").Log;
|
||||||
const Output = @import("output.zig").Output;
|
const Output = @import("output.zig").Output;
|
||||||
const Root = @import("root.zig").Root;
|
const Root = @import("root.zig").Root;
|
||||||
|
|
|
@ -3,7 +3,7 @@ const Self = @This();
|
||||||
const c = @import("c.zig");
|
const c = @import("c.zig");
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const Box = @import("box.zig").Box;
|
const Box = @import("box.zig");
|
||||||
const Log = @import("log.zig").Log;
|
const Log = @import("log.zig").Log;
|
||||||
const View = @import("view.zig").View;
|
const View = @import("view.zig").View;
|
||||||
const ViewStack = @import("view_stack.zig").ViewStack;
|
const ViewStack = @import("view_stack.zig").ViewStack;
|
||||||
|
@ -44,12 +44,10 @@ pub fn init(self: *Self, view: *View, wlr_xdg_surface: *c.wlr_xdg_surface) void
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn configure(self: Self, pending_box: Box) void {
|
pub fn configure(self: Self, pending_box: Box) void {
|
||||||
const border_width = self.view.output.root.server.config.border_width;
|
|
||||||
const view_padding = self.view.output.root.server.config.view_padding;
|
|
||||||
self.view.pending_serial = c.wlr_xdg_toplevel_set_size(
|
self.view.pending_serial = c.wlr_xdg_toplevel_set_size(
|
||||||
self.wlr_xdg_surface,
|
self.wlr_xdg_surface,
|
||||||
pending_box.width - border_width * 2 - view_padding * 2,
|
pending_box.width,
|
||||||
pending_box.height - border_width * 2 - view_padding * 2,
|
pending_box.height,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue