can now move selection
This commit is contained in:
parent
525ca55a22
commit
07eb3a9177
69
main.zig
69
main.zig
|
@ -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,17 +825,40 @@ 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.?.selection) {
|
switch (self.pointer.?.stage) {
|
||||||
.pre => {
|
.Edit => {
|
||||||
self.pointer.?.selection = .{.updating = .{.start = point, .end = point}};
|
switch (self.pointer.?.selection) {
|
||||||
return self.calculateRedraws();
|
.pre => {
|
||||||
|
self.pointer.?.selection = .{.updating = .{.start = point, .end = point}};
|
||||||
|
return self.calculateRedraws();
|
||||||
|
},
|
||||||
|
.updating => |*selection| {
|
||||||
|
selection.end = point;
|
||||||
|
return self.calculateRedraws();
|
||||||
|
},
|
||||||
|
else => {},
|
||||||
|
}
|
||||||
},
|
},
|
||||||
.updating => |*selection| {
|
.Move => {
|
||||||
selection.end = point;
|
const delta = blk: {
|
||||||
return self.calculateRedraws();
|
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();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
else => {},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.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 => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue