diff --git a/src/Seat.zig b/src/Seat.zig index 7a5447b..77b95fe 100644 --- a/src/Seat.zig +++ b/src/Seat.zig @@ -15,6 +15,7 @@ layer_focus: LayerFocus = .focus_none, pointer_op: PointerOp = .none, +pointer_pos: utils.Pos = .{}, /// State consumed in manage phase, reset at end of manage(). pending_manage: PendingManage = .{}, @@ -107,6 +108,11 @@ fn seatListener(river_seat_v1: *river.SeatV1, event: river.SeatV1.Event, seat: * .op_release => { seat.pending_manage.op_released = true; }, + .pointer_position => |ev| { + seat.pointer_pos.x = ev.x; + seat.pointer_pos.y = ev.y; + }, + else => |ev| { log.debug("unhandled event: {s}", .{@tagName(ev)}); }, @@ -308,8 +314,23 @@ pub fn manage(seat: *Seat) void { switch (seat.pointer_op) { .none => {}, .move => { + const window = seat.focused_window orelse return; seat.river_seat_v1.opEnd(); seat.pointer_op = .none; + // Iterate over every display and check if the curser is inside it + var it = seat.context.wm.outputs.iterator(.forward); + while (it.next()) |output| { + if (utils.isPosInRect(seat.pointer_pos, output.geometry)) { + window.pending_manage.pending_output = .{ .output = output }; + // We have to remove window from current output's windows list first + window.link.remove(); + output.windows.append(window); + + seat.pending_manage.output = .{ .output = output }; + window.pending_manage.pending_output = .{ .output = output }; + break; + } + } }, .resize => |op| { op.window.river_window_v1.informResizeEnd(); diff --git a/src/utils.zig b/src/utils.zig index 0243443..80a60d4 100644 --- a/src/utils.zig +++ b/src/utils.zig @@ -19,6 +19,15 @@ pub const Rect = struct { y: i32 = 0, }; +pub const Pos = struct { + x: i32 = 0, + y: i32 = 0, +}; + +pub fn isPosInRect(pos: Pos, rect: Rect) bool { + return (pos.x > rect.x and pos.x < rect.x + rect.width) and (pos.y > rect.y and pos.y < rect.y + rect.height); +} + /// Parse a color in the format 0xRRGGBB or 0xRRGGBBAA and convert it to /// 32-bit color values (used by Window.set_borders in rwm). pub fn parseRgba(s: []const u8) !RiverColor {