To create a buddy window that follows your mouse in SwiftUI on macOS, you can use an NSPanel as a floating window and track the mouse movements to update its position.
Here is a sample implementation:
main.swift1785 chars51 linesIn this implementation, the ContentView displays some text and sets up mouse tracking with the onHover and onMove modifiers. The isPanelVisible state variable controls the visibility of the BuddyWindow overlay.
The BuddyWindow is an NSViewRepresentable that creates and configures an NSPanel with a yellow layer background. The isVisible and mouseLocation properties are used to show or hide and position the panel based on the current mouse location.
You can customize the panel size, color, and content view as needed.
gistlibby LogSnag