Draw borders around views

This commit is contained in:
Isaac Freund 2020-04-05 14:26:22 +02:00
parent 5be50921d4
commit 89d2a86851
No known key found for this signature in database
GPG key ID: 86DED400DDFD7A11

View file

@ -11,6 +11,8 @@ const RenderData = struct {
renderer: *c.wlr_renderer, renderer: *c.wlr_renderer,
view: *View, view: *View,
when: *c.struct_timespec, when: *c.struct_timespec,
ox: f64,
oy: f64,
}; };
pub const Output = struct { pub const Output = struct {
@ -80,6 +82,19 @@ pub const Output = struct {
const color = [_]f32{ 0.3, 0.3, 0.3, 1.0 }; const color = [_]f32{ 0.3, 0.3, 0.3, 1.0 };
c.wlr_renderer_clear(renderer, &color); c.wlr_renderer_clear(renderer, &color);
// The view has a position in layout coordinates. If you have two displays,
// one next to the other, both 1080p, a view on the rightmost display might
// have layout coordinates of 2000,100. We need to translate that to
// output-local coordinates, or (2000 - 1920).
var ox: f64 = 0.0;
var oy: f64 = 0.0;
c.wlr_output_layout_output_coords(
output.root.wlr_output_layout,
output.wlr_output,
&ox,
&oy,
);
// The first view in the list is "on top" so iterate in reverse. // The first view in the list is "on top" so iterate in reverse.
var it = ViewStack.reverseIterator( var it = ViewStack.reverseIterator(
output.root.views.last, output.root.views.last,
@ -91,7 +106,8 @@ pub const Output = struct {
if (view.current_box.width == 0 or view.current_box.height == 0) { if (view.current_box.width == 0 or view.current_box.height == 0) {
continue; continue;
} }
output.renderView(view, &now); output.renderView(view, &now, ox, oy);
output.renderBorders(view, &now, ox, oy);
} }
// Hardware cursors are rendered by the GPU on a separate plane, and can be // Hardware cursors are rendered by the GPU on a separate plane, and can be
@ -109,7 +125,7 @@ pub const Output = struct {
_ = c.wlr_output_commit(output.wlr_output); _ = c.wlr_output_commit(output.wlr_output);
} }
fn renderView(self: Self, view: *View, now: *c.struct_timespec) void { fn renderView(self: Self, view: *View, now: *c.struct_timespec, ox: f64, oy: f64) 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| {
@ -148,6 +164,8 @@ pub const Output = struct {
.view = view, .view = view,
.renderer = self.root.server.wlr_renderer, .renderer = self.root.server.wlr_renderer,
.when = now, .when = now,
.ox = ox,
.oy = oy,
}; };
// This calls our render_surface function for each surface among the // This calls our render_surface function for each surface among the
@ -174,19 +192,11 @@ pub const Output = struct {
return; return;
} }
// The view has a position in layout coordinates. If you have two displays,
// one next to the other, both 1080p, a view on the rightmost display might
// have layout coordinates of 2000,100. We need to translate that to
// output-local coordinates, or (2000 - 1920).
var ox: f64 = 0.0;
var oy: f64 = 0.0;
c.wlr_output_layout_output_coords(view.root.wlr_output_layout, output, &ox, &oy);
ox += @intToFloat(f64, view.current_box.x + @intCast(i32, view.root.border_width) + sx);
oy += @intToFloat(f64, view.current_box.y + @intCast(i32, view.root.border_width) + sy);
var box = c.wlr_box{ var box = c.wlr_box{
.x = @floatToInt(c_int, ox), .x = @floatToInt(c_int, rdata.ox) + view.current_box.x + sx +
.y = @floatToInt(c_int, oy), @intCast(c_int, view.root.border_width),
.y = @floatToInt(c_int, rdata.oy) + view.current_box.y + sy +
@intCast(c_int, view.root.border_width),
.width = surface.current.width, .width = surface.current.width,
.height = surface.current.height, .height = surface.current.height,
}; };
@ -210,6 +220,68 @@ pub const Output = struct {
// prepare another one now if it likes. // prepare another one now if it likes.
c.wlr_surface_send_frame_done(surface, rdata.when); c.wlr_surface_send_frame_done(surface, rdata.when);
} }
fn renderBorders(self: Self, view: *View, now: *c.struct_timespec, ox: f64, oy: f64) void {
var border: c.wlr_box = undefined;
const color = [_]f32{ 0.34509804, 0.43137255, 0.45882353, 1.0 }; // Solarized base01
const border_width = self.root.border_width;
// left border
border.x = @floatToInt(c_int, ox) + view.current_box.x;
border.y = @floatToInt(c_int, oy) + view.current_box.y;
border.width = @intCast(c_int, border_width);
border.height = @intCast(c_int, view.current_box.height);
scaleBox(&border, self.wlr_output.scale);
c.wlr_render_rect(
self.root.server.wlr_renderer,
&border,
&color,
&self.wlr_output.transform_matrix,
);
// right border
border.x = @floatToInt(c_int, ox) + view.current_box.x +
@intCast(c_int, view.current_box.width - border_width);
border.y = @floatToInt(c_int, oy) + view.current_box.y;
border.width = @intCast(c_int, border_width);
border.height = @intCast(c_int, view.current_box.height);
scaleBox(&border, self.wlr_output.scale);
c.wlr_render_rect(
self.root.server.wlr_renderer,
&border,
&color,
&self.wlr_output.transform_matrix,
);
// top border
border.x = @floatToInt(c_int, ox) + view.current_box.x +
@intCast(c_int, border_width);
border.y = @floatToInt(c_int, oy) + view.current_box.y;
border.width = @intCast(c_int, view.current_box.width);
border.height = @intCast(c_int, border_width);
scaleBox(&border, self.wlr_output.scale);
c.wlr_render_rect(
self.root.server.wlr_renderer,
&border,
&color,
&self.wlr_output.transform_matrix,
);
// bottom border
border.x = @floatToInt(c_int, ox) + view.current_box.x +
@intCast(c_int, border_width);
border.y = @floatToInt(c_int, oy) + view.current_box.y +
@intCast(c_int, view.current_box.height - border_width);
border.width = @intCast(c_int, view.current_box.width);
border.height = @intCast(c_int, border_width);
scaleBox(&border, self.wlr_output.scale);
c.wlr_render_rect(
self.root.server.wlr_renderer,
&border,
&color,
&self.wlr_output.transform_matrix,
);
}
}; };
/// Scale a wlr_box, taking the possibility of fractional scaling into account. /// Scale a wlr_box, taking the possibility of fractional scaling into account.