Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Region + follow mouse = magnifier #35

Closed
Vladimir-csp opened this issue May 14, 2024 · 6 comments
Closed

Region + follow mouse = magnifier #35

Vladimir-csp opened this issue May 14, 2024 · 6 comments
Labels
enhancement New feature or request help wanted Extra attention is needed scripts Issues that relate to example scripts and not the wl-mirror binary itself

Comments

@Vladimir-csp
Copy link
Contributor

If it is possible to make a region follow mouse, wl-mirror could act as screen magnifier.

@Ferdi265
Copy link
Owner

There is no way to get the mouse position in wayland if the mouse is not currently over your own window, so this would require extra compositor support.

some compositors (e.g. sway, hyprland) might have ways to get the current mouse position via IPC, wo you could script that outside wl-mirror in a similar way to what wl-present does.

@Ferdi265
Copy link
Owner

if this is easily scriptable on a compositor, I would very gladly accept a PR for an example script that implements a magnifier, since it's a really cool demo.

@Ferdi265 Ferdi265 added enhancement New feature or request scripts Issues that relate to example scripts and not the wl-mirror binary itself labels May 14, 2024
@Ferdi265 Ferdi265 added the help wanted Extra attention is needed label Jun 13, 2024
@Ferdi265
Copy link
Owner

It seems like there is no feature to get the current mouse coordinates on sway, but there is an IPC command for it on hyprland (hyprctl cursorpos). The latter can be scripted, but doesn't provide for a great experience since there is no way to be notified of any cursor changes, so you have to constantly poll it.

Here's a very hacky proof-of-concept script for hyprland that demonstrates the possibility:

#!/bin/bash
# usage: ./magnify.sh eDP-1
# usage: ./magnify.sh eDP-1 200 

DEFAULT_SIZE=100

magnify-region() {
    SIZE=${1:-$DEFAULT_SIZE}
    POS=$(hyprctl cursorpos)
    IFS=',' read -r X Y <<< "$POS"
    echo "$((X-SIZE/2)),$((Y-SIZE/2)) $((SIZE))x$((SIZE))"
}

magnify() {
    SIZE=${1:-$DEFAULT_SIZE}
    while sleep .1; do
        wl-present set-region "$(magnify-region "$SIZE")"
    done
}

wl-present mirror "${1:-eDP-1}" &
magnify "${2:-$DEFAULT_SIZE}"
trap 'killall wl-mirror' EXIT

This doesn't provide a great experience, but shows that if at some point compositors provide better ways to get the cursor position, this could be implementable.

@Ferdi265
Copy link
Owner

Of note: IIRC it's possible for compositors to provide the cursor image as a separate layer in the XDG Portals / Pipewire screen capture protocol (see #16). Technically wl-mirror could also extract mouse coordinates from there once that protocol is implemented, and that would be a much more consistent source of the cursor position for magnification. This would still be a hack though, since it's not guaranteed that a compositor provides the cursor as a separate layer or displays it at all.

@Ferdi265
Copy link
Owner

Since there isn't a good way to get the cursor position in Wayland right now I might either close this issue or mark this as an "upstream bug" since there isn't much we can do as a regular Wayland client that would solve this in a satisfactory fashion.

@Vladimir-csp
Copy link
Contributor Author

Well, till something comes up in the protocols...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed scripts Issues that relate to example scripts and not the wl-mirror binary itself
Projects
None yet
Development

No branches or pull requests

2 participants