From 45c7e27935497f3702f2278a6514181ef988f6fa Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Tue, 24 Mar 2020 20:39:02 +0100 Subject: [PATCH] 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), );