wlbg: save cursor positions for all outputs

This commit is contained in:
LordMZTE 2023-10-31 13:30:23 +01:00
parent 70e60a3b95
commit ad019a7331
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
3 changed files with 28 additions and 35 deletions

View file

@ -156,15 +156,14 @@ pub fn preDraw(
self: *Gfx, self: *Gfx,
dt: i64, dt: i64,
pointer_state: *PointerState, pointer_state: *PointerState,
outputs: []const OutputWindow,
infos: []const OutputInfo, infos: []const OutputInfo,
dth: *DrawTimerHandler, dth: *DrawTimerHandler,
) !void { ) !void {
for (self.cursor_positions, infos, outputs, 0..) |*pos, inf, outp, i| { for (self.cursor_positions, infos, 0..) |*pos, inf, i| {
const lerp_amt = std.math.clamp(@as(f32, @floatFromInt(std.math.clamp(dt, 0, 10))) / 150.0, 0.0, 1.0); const lerp_amt = std.math.clamp(@as(f32, @floatFromInt(std.math.clamp(dt, 0, 10))) / 150.0, 0.0, 1.0);
const target = if (pointer_state.surface == outp.surface) const target = if (pointer_state.active_surface_idx == i)
.{ pointer_state.x, pointer_state.y } pointer_state.surface_positions[i]
else else
.{ @divTrunc(inf.width, 2), @divTrunc(inf.height, 2) }; .{ @divTrunc(inf.width, 2), @divTrunc(inf.height, 2) };
@ -235,7 +234,7 @@ pub fn draw(
); );
c.glUniform1f( c.glUniform1f(
c.glGetUniformLocation(self.main_shader_program, "hasCursor"), c.glGetUniformLocation(self.main_shader_program, "hasCursor"),
if (outputs[output_idx].surface == pointer_state.surface) 1.0 else 0.0, if (pointer_state.active_surface_idx == output_idx) 1.0 else 0.0,
); );
//c.glUniform1f( //c.glUniform1f(
// c.glGetUniformLocation(self.main_shader_program, "time"), // c.glGetUniformLocation(self.main_shader_program, "time"),

View file

@ -1,5 +1,4 @@
const wl = @import("wayland").client.wl; const wl = @import("wayland").client.wl;
surface: ?*wl.Surface, active_surface_idx: ?usize,
x: c_int, surface_positions: [][2]c_int,
y: c_int,

View file

@ -144,10 +144,11 @@ pub fn main() !void {
@memset(dth.should_redraw, true); @memset(dth.should_redraw, true);
var pointer_state = PointerState{ var pointer_state = PointerState{
.surface = null, .active_surface_idx = null,
.x = 0, .surface_positions = try std.heap.c_allocator.alloc([2]c_int, output_info.len),
.y = 0,
}; };
defer std.heap.c_allocator.free(pointer_state.surface_positions);
@memset(pointer_state.surface_positions, .{ 0, 0 });
var pointer_listener_data = PointerListenerData{ var pointer_listener_data = PointerListenerData{
.pstate = &pointer_state, .pstate = &pointer_state,
@ -265,7 +266,6 @@ fn renderCb(
data.?.gfx.preDraw( data.?.gfx.preDraw(
delta_time, delta_time,
data.?.pointer_state, data.?.pointer_state,
data.?.outputs,
data.?.output_info, data.?.output_info,
data.?.dth, data.?.dth,
) catch |e| { ) catch |e| {
@ -387,38 +387,33 @@ const PointerListenerData = struct {
pstate: *PointerState, pstate: *PointerState,
outputs: []const OutputWindow, outputs: []const OutputWindow,
dth: *DrawTimerHandler, dth: *DrawTimerHandler,
fn damageCurrentWindow(self: *PointerListenerData) !void {
if (self.pstate.surface) |ps| {
for (self.outputs, 0..) |o, i| {
if (ps == o.surface) {
self.dth.damage(i);
}
}
}
}
}; };
fn pointerListener(_: *wl.Pointer, ev: wl.Pointer.Event, d: *PointerListenerData) void { fn pointerListener(_: *wl.Pointer, ev: wl.Pointer.Event, d: *PointerListenerData) void {
switch (ev) { switch (ev) {
.motion => |motion| { .motion => |motion| {
d.pstate.x = motion.surface_x.toInt(); if (d.pstate.active_surface_idx) |i| {
d.pstate.y = motion.surface_y.toInt(); d.pstate.surface_positions[i] = .{
d.damageCurrentWindow() catch |e| { motion.surface_x.toInt(),
std.log.err("unable to damage window: {}", .{e}); motion.surface_y.toInt(),
}; };
d.dth.damage(i);
}
}, },
.enter => |enter| { .enter => |enter| {
d.pstate.surface = enter.surface; for (d.outputs, 0..) |out, i| {
d.damageCurrentWindow() catch |e| { if (out.surface == enter.surface) {
std.log.err("unable to damage window: {}", .{e}); d.dth.damage(i);
}; d.pstate.active_surface_idx = i;
break;
}
}
}, },
.leave => { .leave => {
d.damageCurrentWindow() catch |e| { if (d.pstate.active_surface_idx) |i| {
std.log.err("unable to damage window: {}", .{e}); d.dth.damage(i);
}; d.pstate.active_surface_idx = null;
d.pstate.surface = null; }
}, },
else => {}, else => {},
} }