can now move selection

This commit is contained in:
Janis 2022-12-17 17:15:27 +01:00
parent 525ca55a22
commit 07eb3a9177

View file

@ -723,10 +723,18 @@ const Seat = struct {
pointer: ?struct { pointer: ?struct {
pointer: *wl.Pointer, pointer: *wl.Pointer,
current_surface_offset: ?Point = null, current_surface_offset: ?Point = null,
stage: SelectionStage = .Edit,
selection: SelectionState = SelectionState.None(), selection: SelectionState = SelectionState.None(),
} = null, } = null,
// awful naming but thats life innit
// this encodes whether the selection is actively being edited or moved as a whole
const SelectionStage = enum {
Edit,
Move,
};
const SelectionTag = enum { const SelectionTag = enum {
none, none,
pre, pre,
@ -745,8 +753,8 @@ const Seat = struct {
return SelectionState.none; return SelectionState.none;
} }
fn translate(self: SelectionState, delta: Point) void { fn translate(self: *SelectionState, delta: Point) void {
switch (self) { switch (self.*) {
.pre => |*point| { .pre => |*point| {
point.add(delta); point.add(delta);
}, },
@ -757,7 +765,7 @@ const Seat = struct {
.post => |*box| { .post => |*box| {
box.translate(delta); box.translate(delta);
}, },
else => {return null;}, else => {},
} }
} }
@ -817,6 +825,8 @@ const Seat = struct {
if (self.pointer.?.current_surface_offset) |offset| { if (self.pointer.?.current_surface_offset) |offset| {
const point = xy.added(offset); const point = xy.added(offset);
switch (self.pointer.?.stage) {
.Edit => {
switch (self.pointer.?.selection) { switch (self.pointer.?.selection) {
.pre => { .pre => {
self.pointer.?.selection = .{.updating = .{.start = point, .end = point}}; self.pointer.?.selection = .{.updating = .{.start = point, .end = point}};
@ -828,6 +838,27 @@ const Seat = struct {
}, },
else => {}, else => {},
} }
},
.Move => {
const delta = blk: {
switch (self.pointer.?.selection) {
.pre => |end| {
break :blk point.added(end.inverted());
},
.updating => |selection| {
break :blk point.added(selection.end.inverted());
},
else => {break :blk null;},
}
};
if (delta != null) {
self.pointer.?.selection.translate(delta.?);
return self.calculateRedraws();
}
},
}
} }
}, },
.button => |button| { .button => |button| {
@ -933,10 +964,24 @@ const Seat = struct {
} }
}, },
xkb.XKB_KEY_space => {
if (self.pointer) |*ptr| {
ptr.stage = .Move;
}
},
else => {},
}
},
.released => {
switch (keysym) {
xkb.XKB_KEY_space => {
if (self.pointer) |*ptr| {
ptr.stage = .Edit;
}
},
else => {}, else => {},
} }
}, },
.released => {},
else => {}, else => {},
} }
} }