Clean up cursor handling code

This commit is contained in:
Isaac Freund 2020-03-24 20:39:02 +01:00
parent b3bad0ca93
commit 45c7e27935
No known key found for this signature in database
GPG Key ID: 86DED400DDFD7A11

View File

@ -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),
);