hyprwm / Hyprland

Hyprland is an independent, highly customizable, dynamic tiling Wayland compositor that doesn't sacrifice on its looks.
https://hyprland.org
BSD 3-Clause "New" or "Revised" License
21.11k stars 884 forks source link

Mouse cursor escaping League Of Legends Fullscreen with dual monitor setup #1732

Closed MasterKing0806 closed 7 months ago

MasterKing0806 commented 1 year ago

Steps to reproduce: Launch the game League of Legends via Lutris in a dual monitor setup with the following windowrules:

windowrulev2 = float, class:^ (leagueclientux.exe)$,title:^ (League of Legends)$ windowrule = size 1280 720,^ (leagueclientux.exe)$ windowrule = center,^ (leagueclientux.exe)$ windowrulev2 = size 2560 1440,class:^ (league of legends.exe)$ windowrulev2 = fullscreen,class:^ (league of legends.exe)$

Start a game lobby and run it in borderless mode.

Expected outcome: Mouse cursor should not leave the edges of the screen unless the workspace is changed.

Noted outcome: Mouse cursor escapes through the side of the secondary monitor.

Aqa-Ib commented 1 year ago

run it in borderless mode. Maybe running the game in full screen mode instead would fix it ?

MasterKing0806 commented 1 year ago

run it in borderless mode. Maybe running the game in full screen mode instead would fix it ?

I tried that as well. The same issue occurs. Windowed mode doesn't fix it either.

I should have noted as well that the same error does not occur in Sway with the same video settings for the game.

vaxerski commented 1 year ago

Nice, another app that can't use constraints properly.

Maybe that's good though, will force you not to play league of legends.

MasterKing0806 commented 1 year ago

Maybe that's good though, will force you not to play league of legends.

Yeah maybe although I have enjoyed myself playing League so far (I know I know, I must be crazy).

vars1ty commented 1 year ago

Try running it through Gamescope?

Petition to ignore all League-related issues though.

MasterKing0806 commented 1 year ago

Gamescope seems to have problems with Lutris atm. Will give it a try some day.

Fair enough, League in itself isn't the best optimized game in any way.

Makrennel commented 1 year ago

Gamescope seems to have problems with Lutris atm. Will give it a try some day.

Fair enough, League in itself isn't the best optimized game in any way.

Running in Gamescope should work as long as you don't use Lutris's versions of wine, and you may have to manually prefix it in the "Command prefix" to get the correct refresh rate rather than enabling Lutris's option for Gamescope. I can't speak for whether normal wine works with League though, this is just how I got SC2 to work properly.

ArchiMickey commented 1 year ago

This is currently my solution, not a perfect one through. You can set the position of your monitor not equal to resolution / scale to keep your cursor in that monitor(e.g. +100 in x position for the right monitor). The problem is you can't move your cursor to another monitor when you want to. Another thing is that you can edit the keyword monitor using hyprctl. I have a script to toggle this screen edge locking:

#!/bin/bash

# set the expected x position of the monitor by your preference
expect_x=3072
# index 0 is the first monitor in your hyprland.conf
curr_x=$(hyprctl -j monitors | jq '.[0].x') 
echo $curr_x
if [ $curr_x -ne $expect_x ]
then
    echo "Hi"
    hyprctl keyword monitor DP-2, 3840x2160@144, ${expect_x}x0, 1.25
else
    expect_x=$(($expect_x + 100))
    echo "Bye ${expect_x}"
    hyprctl keyword monitor DP-2, 3840x2160@144, ${expect_x}x0, 1.25
fi

You can edit the command with your own monitor's resolution, refresh rate and signal input. Finally you can bind this script in your hyprland.conf. I suggest you to test the script before binding it.

MasterKing0806 commented 1 year ago

This is currently my solution, not a perfect one through. You can set the position of your monitor not equal to resolution / scale to keep your cursor in that monitor(e.g. +100 in x position for the right monitor). The problem is you can't move your cursor to another monitor when you want to. Another thing is that you can edit the keyword monitor using hyprctl. I have a script to toggle this screen edge locking:

#!/bin/bash

# set the expected x position of the monitor by your preference
expect_x=3072
# index 0 is the first monitor in your hyprland.conf
curr_x=$(hyprctl -j monitors | jq '.[0].x') 
echo $curr_x
if [ $curr_x -ne $expect_x ]
then
    echo "Hi"
    hyprctl keyword monitor DP-2, 3840x2160@144, ${expect_x}x0, 1.25
else
    expect_x=$(($expect_x + 100))
    echo "Bye ${expect_x}"
    hyprctl keyword monitor DP-2, 3840x2160@144, ${expect_x}x0, 1.25
fi

You can edit the command with your own monitor's resolution, refresh rate and signal input. Finally you can bind this script in your hyprland.conf. I suggest you to test the script before binding it.

I figured out a similar workaround. Instead of using hyprctl, I use the follwing command in a bash script and edited the config file directly (mind you that I have stacked monitors so the position change is a bit different).

sed -i '13s/.*/monitor=DP-1,2560x1440@165,0x1540,1/' ~/.config/hypr/hyprland.conf

I completely forgot about hyprctl, thanks for pointing this out. It probably is better to use hyprctl because it does not fiddle with the config file.

MasterKing0806 commented 1 year ago

Gamescope seems to have problems with Lutris atm. Will give it a try some day. Fair enough, League in itself isn't the best optimized game in any way.

Running in Gamescope should work as long as you don't use Lutris's versions of wine, and you may have to manually prefix it in the "Command prefix" to get the correct refresh rate rather than enabling Lutris's option for Gamescope. I can't speak for whether normal wine works with League though, this is just how I got SC2 to work properly.

Finally found the time to work out why Lutris and gamescope did not work for me (apparently some problems with Lutris Runtime).

Turns out gamescope is indeed the solution for this problem, enabling gamescope and relative mouse mode (using lutris-0.5.13) and setting output resolution was sufficient. Will mark thread as solved.

EvilBoi123 commented 1 year ago

Hello everyone, apparently i found a workaround that might work on every game, however this will be total cursor lock, even in game or without game. The mouse will be trapped on workspace only. To access another workspace will be entirely depended on keybinding only.

So here's the config:

monitor=HDMI-A-1,1920x1080@60,2000x2000,1
monitor=eDP-1,1920x1080,0x0,1

Consider that eDP-1 is the main monitor, the position value of the main monitor can be at 0x0

Consider that secondary monitor has resolution of 1920x1080, while the main monitor is 1920x1080 we now set the position of second monitor to be far away from the main monitor.

i hope cursor lock will be implemented soon cause i do not like this workaround i do sure like to change my window to another monitor via dragging windows tho :(

Makrennel commented 1 year ago

Hello everyone, apparently i found a workaround that might work on every game, however this will be total cursor lock, even in game or without game. The mouse will be trapped on workspace only. To access another workspace will be entirely depended on keybinding only.

So here's the config:

monitor=HDMI-A-1,1920x1080@60,2000x2000,1
monitor=eDP-1,1920x1080,0x0,1

Consider that eDP-1 is the main monitor, the position value of the main monitor can be at 0x0

Consider that secondary monitor has resolution of 1920x1080, while the main monitor is 1920x1080 we now set the position of second monitor to be far away from the main monitor.

i hope cursor lock will be implemented soon cause i do not like this workaround i do sure like to change my window to another monitor via dragging windows tho :(

This can be improved. Instead of setting it in the monitor conf directly, you can use a script with wlr-randr and set a bind to execute it so that you can toggle this on and off pretty easily.

Here's mine

#!/bin/zsh

state="${XDG_STATE_HOME}/togglemonitorlock"
booleanvalue="false"

if [[ -f ${state} ]]; then
     booleanvalue=$(cat ${state})
fi

if [[ ${booleanvalue} == "true" ]]; then
     wlr-randr --output DP-2 --pos 2560,0
     echo "false" > ${state}
else
     wlr-randr --output DP-2 --pos 2000,2000
     echo "true" > ${state}
fi

Edit: I now realize this is similar to the workarounds the others have offered lol

SkyLeite commented 1 year ago

The issue here is that this line of code doesn't do anything for some reason. The mouse is never warped

https://github.com/hyprwm/Hyprland/blob/main/src/managers/input/InputManager.cpp#L146C1-L146C114

Changing it to mouseCoords.x - 1 and mouseCoords.y - 1 makes the cursor warp as expected, but warping it to the positions in mouseCoords means the cursor isn't warped at all and is thus free to move around. This causes the same issue to occur in Dota 2, so I don't think this is about games misbehaving.

SkyLeite commented 1 year ago

For reference, here's how sway handles this: https://github.com/swaywm/sway/blob/master/sway/input/cursor.c#L901-L913

Worth noting that it doesn't just warp to the current position (which doesn't make any sense) and, most importantly, actually works.

Mikilio commented 1 year ago

Can you submit a PR if it works? 🙏

SkyLeite commented 1 year ago

I couldn't actually get Hyprland to behave properly unfortunately, and I'm not knowledgeable enough on wlroots to properly copy what Sway is doing. It should be relatively simple for someone familiar with the protocol though.

vaxerski commented 1 year ago

@SkyLeite if thats the case, how about this? patch.txt

Mikilio commented 1 year ago

I will sacrifice myself to test this on league of legends

EDIT: It didn't work.

Mikilio commented 1 year ago

I can debug this and see if the constraint is even active though I'm pretty convinced it's not. I saw some TODOs in the code indicating an intention to fix this anyways then there is also wayland on wine just waiting to be merged. A workaround has also been shown here. So, I don't see any urgency to push this issue any further. XWayland isn't going to be good even if this is fixed after all.

SkyLeite commented 1 year ago

From my testing the constraint does indeed exist, Hyprland just fails to warp the cursor back to the area when it leaves.

mikigal commented 1 year ago

I had the same issue (3 displays setup, game launched with leagueoflegends-git). I decided to create simple tool in Go to make "gaps" between displays - it disallow cursor to go outside of the game. When you start tool automatically apply fix, when you close - it reverts displays' layout to default

Repository: https://github.com/mikigal/LeagueFixHyprland Please let me know does it fix this issue for you!

Bui-Christopher commented 1 year ago

I just recently switched from xorg/i3 to wayland/hyprland. I'm able to get DotA to run; however, I'm also getting the dual monitor issue as I'm screen panning. If I screen pan toward the direction of my second monitor, the mouse exits the game and moves onto the second monitor, the other workspace. I've tried these steam launch options gamescope -W 3840 -H 1600 -r 60 -e -f -- %command%. I believe a temporary workaround would be to add a gap between my monitors. Is there any other way I could handle screen panning alongside two monitors?

Unbreathable commented 8 months ago

I was just able to replicate this with Minecraft, similar to #2376, and thought I would post this here since I also have a dual monitor setup. I feel like there is a wrong multiplication in the way constraints are enforced when using fractional scaling on one monitor. I've made a little screen recording looking into it a little bit to show what I mean since this is really hard to explain using text: https://www.youtube.com/watch?v=VWr7cwtFKq4. It's a little on the long side, but I hope it helps!

Edit: This would also explain why the work-around with putting the second monitor to 0x0 works. Think about it, if the scale origin is in the top right of the screen and you just move your other monitor to the left of the screen, it will also fix the issue because the wrong boundary isn't scaling to the left, but only to the right (looking at it from the origin point).

vaxerski commented 7 months ago

please check #4889

rurigk commented 7 months ago

I have been playing league for some time now and this issue was very uncommon to trigger At first I fixed it by just switching focus to other windows then only right clicking was enough

I also dont have any window rule for league

Im gonna test this MR some more time to see if i can trigger it again but for now its not happening anymore

StoicaTielemans commented 3 months ago

I found this script someone made https://git.mgoder.com/mg/hyprlock (Its not the hyprlock lockscreen thingy)

Its works perfectly for me, just bind it to a key like is stated in the README and it locks your mouse to the screen your on.