diff options
| author | Isaac Freund <ifreund@ifreund.xyz> | 2020-03-24 20:39:02 +0100 |
|---|---|---|
| committer | Isaac Freund <ifreund@ifreund.xyz> | 2020-03-24 20:39:02 +0100 |
| commit | 45c7e27935497f3702f2278a6514181ef988f6fa (patch) | |
| tree | f89316be83e66059933d30c6f26da98b38f8cc37 | |
| parent | b3bad0ca9372d4dee1baca634591d82aefa5cb5c (diff) | |
| download | river-45c7e27935497f3702f2278a6514181ef988f6fa.tar.gz river-45c7e27935497f3702f2278a6514181ef988f6fa.tar.xz | |
Clean up cursor handling code
| -rw-r--r-- | src/cursor.zig | 19 |
1 files 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), ); |
