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,
|
.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 {
|
const Size = struct {
|
||||||
|
@ -288,8 +299,7 @@ const Box = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn translate(self: *Self, delta: Point) void {
|
fn translate(self: *Self, delta: Point) void {
|
||||||
self.position.x += delta.x;
|
self.position.add(delta);
|
||||||
self.position.y += delta.y;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn translated(self: Self, delta: Point) Self {
|
fn translated(self: Self, delta: Point) Self {
|
||||||
|
@ -712,7 +722,7 @@ const Seat = struct {
|
||||||
|
|
||||||
pointer: ?struct {
|
pointer: ?struct {
|
||||||
pointer: *wl.Pointer,
|
pointer: *wl.Pointer,
|
||||||
button_state: ?wl.Pointer.ButtonState = null,
|
current_surface_offset: ?Point = null,
|
||||||
selection: SelectionState = SelectionState.None(),
|
selection: SelectionState = SelectionState.None(),
|
||||||
} = null,
|
} = null,
|
||||||
|
|
||||||
|
@ -735,6 +745,22 @@ const Seat = struct {
|
||||||
return SelectionState.none;
|
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 {
|
fn getSelectionBox(self: SelectionState) ?Box {
|
||||||
switch (self) {
|
switch (self) {
|
||||||
.updating => |selection| {
|
.updating => |selection| {
|
||||||
|
@ -773,24 +799,35 @@ const Seat = struct {
|
||||||
_ = pointer;
|
_ = pointer;
|
||||||
|
|
||||||
switch (event) {
|
switch (event) {
|
||||||
.enter => {},
|
.enter => |enter| {
|
||||||
.leave => {},
|
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| {
|
.motion => |motion| {
|
||||||
const x = motion.surface_x.toInt();
|
const x = motion.surface_x.toInt();
|
||||||
const y = motion.surface_y.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) {
|
switch (self.pointer.?.selection) {
|
||||||
.pre => {
|
.pre => {
|
||||||
self.pointer.?.selection = .{.updating = .{.start = end, .end = end}};
|
self.pointer.?.selection = .{.updating = .{.start = point, .end = point}};
|
||||||
return self.calculateRedraws();
|
return self.calculateRedraws();
|
||||||
},
|
},
|
||||||
.updating => |*selection| {
|
.updating => |*selection| {
|
||||||
selection.end = end;
|
selection.end = point;
|
||||||
return self.calculateRedraws();
|
return self.calculateRedraws();
|
||||||
},
|
},
|
||||||
else => {},
|
else => {},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.button => |button| {
|
.button => |button| {
|
||||||
|
@ -1210,6 +1247,18 @@ const State = struct {
|
||||||
self.ally.destroy(link);
|
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 {
|
fn deinit(self: *Self) void {
|
||||||
defer self.ally.destroy(self);
|
defer self.ally.destroy(self);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue