hopefully sound selection rectangle and surface offset logic
This commit is contained in:
parent
a9a64d2f18
commit
fd9dfc613a
81
main.zig
81
main.zig
|
@ -27,6 +27,17 @@ const Point = struct {
|
|||
.y = self.y * -1,
|
||||
};
|
||||
}
|
||||
|
||||
fn add(self: *Self, other: Self) void {
|
||||
self.x += other.x;
|
||||
self.y += other.x;
|
||||
}
|
||||
|
||||
fn added(self: *const Self, other: Self) Self {
|
||||
var new = self.*;
|
||||
new.add(other);
|
||||
return new;
|
||||
}
|
||||
};
|
||||
|
||||
const Size = struct {
|
||||
|
@ -288,8 +299,7 @@ const Box = struct {
|
|||
}
|
||||
|
||||
fn translate(self: *Self, delta: Point) void {
|
||||
self.position.x += delta.x;
|
||||
self.position.y += delta.y;
|
||||
self.position.add(delta);
|
||||
}
|
||||
|
||||
fn translated(self: Self, delta: Point) Self {
|
||||
|
@ -712,7 +722,7 @@ const Seat = struct {
|
|||
|
||||
pointer: ?struct {
|
||||
pointer: *wl.Pointer,
|
||||
button_state: ?wl.Pointer.ButtonState = null,
|
||||
current_surface_offset: ?Point = null,
|
||||
selection: SelectionState = SelectionState.None(),
|
||||
} = null,
|
||||
|
||||
|
@ -735,6 +745,22 @@ const Seat = struct {
|
|||
return SelectionState.none;
|
||||
}
|
||||
|
||||
fn translate(self: SelectionState, delta: Point) void {
|
||||
switch (self) {
|
||||
.pre => |*point| {
|
||||
point.add(delta);
|
||||
},
|
||||
.updating => |*selection| {
|
||||
selection.start.add(delta);
|
||||
selection.end.add(delta);
|
||||
},
|
||||
.post => |*box| {
|
||||
box.translate(delta);
|
||||
},
|
||||
else => {return null;},
|
||||
}
|
||||
}
|
||||
|
||||
fn getSelectionBox(self: SelectionState) ?Box {
|
||||
switch (self) {
|
||||
.updating => |selection| {
|
||||
|
@ -773,24 +799,35 @@ const Seat = struct {
|
|||
_ = pointer;
|
||||
|
||||
switch (event) {
|
||||
.enter => {},
|
||||
.leave => {},
|
||||
.enter => |enter| {
|
||||
if (self.state.getOutputForSurface(enter.surface.?)) |output| {
|
||||
self.pointer.?.current_surface_offset = output.logical_geometry.position;
|
||||
}
|
||||
|
||||
std.debug.print("surface offset: {?}\n", .{self.pointer.?.current_surface_offset});
|
||||
},
|
||||
.leave => {
|
||||
self.pointer.?.current_surface_offset = null;
|
||||
},
|
||||
.motion => |motion| {
|
||||
const x = motion.surface_x.toInt();
|
||||
const y = motion.surface_y.toInt();
|
||||
const xy = Point{.x = x, .y = y,};
|
||||
|
||||
const end = Point{.x = x, .y = y,};
|
||||
if (self.pointer.?.current_surface_offset) |offset| {
|
||||
const point = xy.added(offset);
|
||||
|
||||
switch (self.pointer.?.selection) {
|
||||
.pre => {
|
||||
self.pointer.?.selection = .{.updating = .{.start = end, .end = end}};
|
||||
return self.calculateRedraws();
|
||||
},
|
||||
.updating => |*selection| {
|
||||
selection.end = end;
|
||||
return self.calculateRedraws();
|
||||
},
|
||||
else => {},
|
||||
switch (self.pointer.?.selection) {
|
||||
.pre => {
|
||||
self.pointer.?.selection = .{.updating = .{.start = point, .end = point}};
|
||||
return self.calculateRedraws();
|
||||
},
|
||||
.updating => |*selection| {
|
||||
selection.end = point;
|
||||
return self.calculateRedraws();
|
||||
},
|
||||
else => {},
|
||||
}
|
||||
}
|
||||
},
|
||||
.button => |button| {
|
||||
|
@ -1210,6 +1247,18 @@ const State = struct {
|
|||
self.ally.destroy(link);
|
||||
}
|
||||
|
||||
fn getOutputForSurface(self: *Self, surface: *wl.Surface) ?*Output {
|
||||
var output_iter = self.outputs.iterator(.forward);
|
||||
while (output_iter.next()) |next| {
|
||||
const output = next.get();
|
||||
if (output.surface == surface) {
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
fn deinit(self: *Self) void {
|
||||
defer self.ally.destroy(self);
|
||||
|
||||
|
|
Loading…
Reference in a new issue