If I have to move the mouse from the left screen all the way to the right screen, the distance is quite big.

Is there a way to virtually connect the sides of the screen as if they were arranged in a circle? I could then move from the left screen to the right screen, by simply moving the cursor to the left.


Script to connect screens "circular"

The script below will do as you describe; if the mouse touches the right edge of the right (-most) screen, the mouse re- appears on the left (-most) screen. If it touches the left side of the left screen, it re- appears on the right side of the right screen.

Built- in precautions

The script assumes the screens are arranged in a non- overlapping configuration, x-wise, but it has a built- in correction in case the screens are not top- aligned, or of a different y- resolution. Although you wouldn't run into problems in most cases, in the situation below you would, unless the script takes into account the possible differences in y- resolution and /or (un-) alignment of the screens:

enter image description here

If the top of the left screen is below the top of the right screen, the cursor moves from top- right to the top of the left screen. Possibly un- aligned bottom idem ditto

The script

#!/usr/bin/env python3
import subprocess
import time

def get_screendata():
    data = [s.split("+") for s in subprocess.check_output(["xrandr"]).decode("utf-8").split() \
            if s.count("+") == 2]
    # calculate total x-size of spanning screens
    x_span = sum([int(item[0].split("x")[0]) for item in data])
    # sort screens to find first/last screen (also for 2+ screens)
    data.sort(key=lambda x: x[1])
    # find (possible) screen offset of first/last screen and vertical area
    scr_first = data[0]; shiftl = int(scr_first[2])
    areal = [shiftl, shiftl+int(scr_first[0].split("x")[1])] 
    scr_last = data[-1]; shiftr = int(scr_last[2])
    arear = [shiftr, shiftr+int(scr_last[0].split("x")[1])]   
    return (x_span, areal, arear)

screendata = get_screendata()
x_span = screendata[0]; areal = screendata[1]; arear = screendata[2]
new_coords = []

while True:
    new_coords = []
    # read the current mouse position
    pos = [int(s.split(":")[-1]) for s in \
           subprocess.check_output(["xdotool", "getmouselocation"]).decode("utf-8").split()\
           if any(["x" in s, "y" in s])]
    # if the mouse is on the left of the first screen
    if pos[0] == 0:
        if pos[1] <=  arear[0]:
        elif pos[1] >= arear[1]:
    # if the mouse is on the right of the last screen
    elif pos[0] > x_span-2:
        if pos[1] <=  areal[0]:
        elif pos[1] >= areal[1]:
    # move the mouse
    if new_coords:
        subprocess.Popen(["xdotool", "mousemove", str(new_coords[0]), str(new_coords[1])])

How to use

  1. The script needs xdotool

    sudo apt-get install xdotool
  2. Copy the script into an empty file, save it as circular_mouse.py
  3. Test- run the script by running in a terminal:

    python3 /path/to/circular_mouse.py

    You should be able to make an infinite mouse movement to either right or left, circulation through your screens.

  4. If all works fine, add it to startup applications: Dash > Startup Applications > Add the command:

    /bin/bash -c "sleep 15 &&  python3 /path/to/circular_mouse.py" 
  • So there is no built-in method. Thanks – ubuntico Nov 2 '15 at 16:18
  • @ubuntico I am quite sure indeed there isn't. – Jacob Vlijm Nov 2 '15 at 16:21

You could try using Taralli. You would need to edit map_beef.c for your own monitor setup.

Alternatively, @ohayden posted a bash script here that could be customized to do what you're wanting to. To use it, you would need to install xdotool by running

sudo apt-get install xdotool

I'm afaid I only have one monitor, so I've not been able to try out either of these possible solutions.

  • I will test this soon. Just a general rule of thumb, if quoting external sources always add relevant parts of the link to your own answer in case the link goes dead. – k0pernikus Nov 27 '15 at 19:42
  • Hi Gsxr1k, both scripts raise cpu usage from 5% to 65% on my system. Much too much for a background script. – Jacob Vlijm Nov 28 '15 at 4:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.