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

commit0d38361556daa59cd98f87fc29ee73710dabe81b
parent143be5bc48
authorIsaac Freund <[email protected]>
date2020-03-24 20:39
Clean up cursor handling code

 src/cursor.zig | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/cursor.zig b/src/cursor.zig
index d403934..6ab2865 100644
--- a/src/cursor.zig
+++ b/src/cursor.zig
@@ -112,8 +112,11 @@ pub const Cursor = struct {
 
     fn process_move(self: *@This(), time: u32) void {
         // Move the grabbed view to the new position.
-        self.grabbed_view.?.x = @floatToInt(c_int, self.wlr_cursor.x - self.grab_x);
-        self.grabbed_view.?.y = @floatToInt(c_int, self.wlr_cursor.y - self.grab_y);
+        // TODO: log on null
+        if (self.grabbed_view) |view| {
+            view.x = @floatToInt(c_int, self.wlr_cursor.x - self.grab_x);
+            view.y = @floatToInt(c_int, self.wlr_cursor.y - self.grab_y);
+        }
     }
 
     fn process_resize(self: *@This(), time: u32) void {
@@ -127,13 +130,13 @@ pub const Cursor = struct {
         // commit any movement that was prepared.
 
         // TODO: Handle null view
-        const view = self.grabbed_view;
+        const view = self.grabbed_view.?;
 
         const dx: f64 = self.wlr_cursor.x - self.grab_x;
         const dy: f64 = self.wlr_cursor.y - self.grab_y;
 
-        var x: f64 = @intToFloat(f64, view.?.x);
-        var y: f64 = @intToFloat(f64, view.?.y);
+        var x: f64 = @intToFloat(f64, view.x);
+        var y: f64 = @intToFloat(f64, view.y);
 
         var width = @intToFloat(f64, self.grab_width);
         var height = @intToFloat(f64, self.grab_height);
@@ -156,10 +159,10 @@ pub const Cursor = struct {
         } else if (self.resize_edges & @intCast(u32, c.WLR_EDGE_RIGHT) != 0) {
             width += dx;
         }
-        view.?.x = @floatToInt(c_int, x);
-        view.?.y = @floatToInt(c_int, y);
+        view.x = @floatToInt(c_int, x);
+        view.y = @floatToInt(c_int, y);
         _ = c.wlr_xdg_toplevel_set_size(
-            view.?.wlr_xdg_surface,
+            view.wlr_xdg_surface,
             @floatToInt(u32, width),
             @floatToInt(u32, height),
         );