git.lucas.co / cce-compositor
Wayland compositor (wlroots)
git clone https://git.lucas.co/cce-compositor.git

commit1daaa7eced42ce34d0ac1b4e26cad6c9846559a0
parent47541cf3ff
authorIsaac Freund <[email protected]>
date2020-04-04 23:26
Take future borders into account for surface size

 src/output.zig | 16 ++++++++--------
 src/root.zig   |  5 +++++
 src/view.zig   |  4 ++--
 3 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/src/output.zig b/src/output.zig
index 0ab7c9d..3106a74 100644
--- a/src/output.zig
+++ b/src/output.zig
@@ -109,10 +109,10 @@ pub const Output = struct {
         // and need to render that buffer until the transaction is complete.
         if (view.stashed_buffer) |buffer| {
             var box = c.wlr_box{
-                .x = view.current_box.x,
-                .y = view.current_box.y,
-                .width = @intCast(c_int, view.current_box.width),
-                .height = @intCast(c_int, view.current_box.height),
+                .x = view.current_box.x + @intCast(i32, view.root.border_width),
+                .y = view.current_box.y + @intCast(i32, view.root.border_width),
+                .width = @intCast(c_int, view.current_box.width - view.root.border_width * 2),
+                .height = @intCast(c_int, view.current_box.height - view.root.border_width * 2),
             };
 
             // Scale the box to the output's current scaling factor
@@ -176,14 +176,14 @@ pub const Output = struct {
         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 + sx);
-        oy += @intToFloat(f64, view.current_box.y + sy);
+        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{
             .x = @floatToInt(c_int, ox),
             .y = @floatToInt(c_int, oy),
-            .width = @intCast(c_int, surface.current.width),
-            .height = @intCast(c_int, surface.current.height),
+            .width = surface.current.width,
+            .height = surface.current.height,
         };
 
         // Scale the box to the output's current scaling factor
diff --git a/src/root.zig b/src/root.zig
index 9700827..bf714b5 100644
--- a/src/root.zig
+++ b/src/root.zig
@@ -34,6 +34,9 @@ pub const Root = struct {
     /// Percentage of the total screen that the master section takes up.
     master_factor: f64,
 
+    /// Width of borders in pixels
+    border_width: u32,
+
     /// Number of pending configures sent in the current transaction.
     /// A value of 0 means there is no current transaction.
     pending_configures: u32,
@@ -63,6 +66,8 @@ pub const Root = struct {
 
         self.master_factor = 0.6;
 
+        self.border_width = 4;
+
         self.pending_configures = 0;
 
         self.transaction_timer = null;
diff --git a/src/view.zig b/src/view.zig
index 40debb0..398d4da 100644
--- a/src/view.zig
+++ b/src/view.zig
@@ -93,8 +93,8 @@ pub const View = struct {
         if (self.pending_box) |pending_box| {
             self.pending_serial = c.wlr_xdg_toplevel_set_size(
                 self.wlr_xdg_surface,
-                pending_box.width,
-                pending_box.height,
+                pending_box.width - self.root.border_width * 2,
+                pending_box.height - self.root.border_width * 2,
             );
         } else {
             // TODO: log warning