Created
June 9, 2021 16:48
-
-
Save voronaam/452fdbdcbff0aa42fc6989cd30fb7ac0 to your computer and use it in GitHub Desktop.
Python script to warp the mouse comfortable around adges of a vertical display
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from Xlib import display | |
from time import sleep | |
from os import system | |
# My screen setup has a vertical display with a large dead zone: | |
# | |
# +----------------+ | |
# | | | |
# DEAD | | | |
# ZONE | | | |
# | | | |
# | | | |
# | | | |
# | | | |
# +----------+| | | |
# | || DisplayPort-1 | | |
# | eDP || | | |
# +----------++----------------+ | |
# | |
# So I use this script to warp mouse pointer around. | |
# The only dependency I had to install was "python3-xlib" | |
system('xrandr --output eDP --primary --mode 1920x1080 --pos 0x1480 --rotate normal --output DisplayPort-1 --mode 2560x1440 --pos 1920x0 --rotate left --output DP-1-1 --off --output HDMI-1-1 --off') | |
fps=50.0 | |
delay=1.0/fps | |
d=display.Display() | |
while True: | |
sleep(delay) | |
data = d.screen().root.query_pointer()._data | |
x = data["root_x"] | |
y = data["root_y"] | |
# Warp in the middle | |
if x == 1920 and y < 1480: | |
d.screen().root.warp_pointer(1919,1580) | |
# Warp on the right edge | |
if x == 3359: | |
d.screen().root.warp_pointer(1,int(2560 - 1080*(2560-y)/2560)) | |
# Warp on the left edge | |
if x == 0: | |
d.screen().root.warp_pointer(3358,int(2560*(y-1480)/1080)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment