code: clean up cursor resize mode

- offset_{x,y} is consistent with delta_{x,y}
- no need to name the type, it's only referenced in one place
This commit is contained in:
Isaac Freund 2020-08-07 21:34:38 +02:00
parent 0c4e3295b1
commit e66c8b0019
No known key found for this signature in database
GPG key ID: 86DED400DDFD7A11

View file

@ -33,18 +33,16 @@ const Seat = @import("Seat.zig");
const View = @import("View.zig"); const View = @import("View.zig");
const ViewStack = @import("view_stack.zig").ViewStack; const ViewStack = @import("view_stack.zig").ViewStack;
const ResizeData = struct {
view: *View,
/// Offset from the lower right corner of the view
x_offset: i32,
y_offset: i32,
};
const Mode = union(enum) { const Mode = union(enum) {
passthrough: void, passthrough: void,
down: *View, down: *View,
move: *View, move: *View,
resize: ResizeData, resize: struct {
view: *View,
/// Offset from the lower right corner of the view
offset_x: i32,
offset_y: i32,
},
/// Enter move or resize mode /// Enter move or resize mode
fn enter(self: *Self, mode: @TagType(Mode), event: *c.wlr_event_pointer_button, view: *View) void { fn enter(self: *Self, mode: @TagType(Mode), event: *c.wlr_event_pointer_button, view: *View) void {
@ -61,8 +59,8 @@ const Mode = union(enum) {
.resize => .{ .resize => .{
.resize = .{ .resize = .{
.view = view, .view = view,
.x_offset = cur_box.x + @intCast(i32, cur_box.width) - @floatToInt(i32, self.wlr_cursor.x), .offset_x = cur_box.x + @intCast(i32, cur_box.width) - @floatToInt(i32, self.wlr_cursor.x),
.y_offset = cur_box.y + @intCast(i32, cur_box.height) - @floatToInt(i32, self.wlr_cursor.y), .offset_y = cur_box.y + @intCast(i32, cur_box.height) - @floatToInt(i32, self.wlr_cursor.y),
}, },
}, },
}; };
@ -171,8 +169,8 @@ const Mode = union(enum) {
c.wlr_cursor_warp_closest( c.wlr_cursor_warp_closest(
self.wlr_cursor, self.wlr_cursor,
device, device,
@intToFloat(f64, box.x + @intCast(i32, box.width) - data.x_offset), @intToFloat(f64, box.x + @intCast(i32, box.width) - data.offset_x),
@intToFloat(f64, box.y + @intCast(i32, box.height) - data.y_offset), @intToFloat(f64, box.y + @intCast(i32, box.height) - data.offset_y),
); );
}, },
} }