Fix two crashes
One was where WM was assuming that a seat existed during first manage, but that's not always true, so we have to check that before running the initialization code. I also split that off into its own function like in Window. The other crash was when trying to calculate the layout with the output's width and/or height equal to zero, it would crash subtracting the border width. I discovered both of these when try to restart beansprout without restarting River.
This commit is contained in:
parent
6f68850a70
commit
08be768d99
2 changed files with 76 additions and 56 deletions
|
|
@ -576,8 +576,11 @@ pub fn manage(output: *Output) void {
|
|||
}
|
||||
}
|
||||
|
||||
// Calculate layout before managing windows
|
||||
output.calculateLayout();
|
||||
// Calculate layout before managing windows, but only if output dimensions are initialized
|
||||
if (output.usable_geometry.width > 0 and output.usable_geometry.height > 0) {
|
||||
output.calculateLayout();
|
||||
}
|
||||
|
||||
var it = output.windows.iterator(.forward);
|
||||
while (it.next()) |window| {
|
||||
window.manage();
|
||||
|
|
@ -612,6 +615,8 @@ pub fn render(output: *Output) void {
|
|||
/// - Single window: maximized
|
||||
/// - Multiple windows: stack (45% left, vertically tiled), primary (55% right)
|
||||
fn calculateLayout(output: *Output) void {
|
||||
// Shouldn't be called if height/width are not positive
|
||||
assert(output.geometry.width > 0 and output.geometry.height > 0);
|
||||
// Get a list of active windows
|
||||
var active_list: DoublyLinkedList = .{};
|
||||
var active_count: u31 = 0;
|
||||
|
|
@ -714,8 +719,14 @@ fn calculateLayout(output: *Output) void {
|
|||
}
|
||||
|
||||
// Make space for borders
|
||||
window.pending_manage.dimensions.?.height -= 2 * border_width;
|
||||
window.pending_manage.dimensions.?.width -= 2 * border_width;
|
||||
if (window.pending_manage.dimensions.?.height > 2 * border_width and
|
||||
window.pending_manage.dimensions.?.width > 2 * border_width)
|
||||
{
|
||||
window.pending_manage.dimensions.?.height -= 2 * border_width;
|
||||
window.pending_manage.dimensions.?.width -= 2 * border_width;
|
||||
} else {
|
||||
log.warn("Can't add borders to some window; {s}'s dimensions are too small.", .{output.name orelse "some output"});
|
||||
}
|
||||
window.pending_render.position.?.x += border_width;
|
||||
window.pending_render.position.?.y += border_width;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue