Skip to content

Instantly share code, notes, and snippets.

@jamaluddinrumi
Created May 26, 2017 00:14
Show Gist options
  • Save jamaluddinrumi/288452e621b3ce7acad26bb072e8d2b2 to your computer and use it in GitHub Desktop.
Save jamaluddinrumi/288452e621b3ce7acad26bb072e8d2b2 to your computer and use it in GitHub Desktop.
Keyboard Shortcut - Switch Focus Between Multiple Monitors
#!/usr/bin/env python3
import subprocess
import sys
arg = sys.argv[1]
screeninfo = [
s for s in subprocess.check_output("xrandr").decode("utf-8").split()\
if s.count("+") == 2
]
#print(screeninfo) #ini yg paling penting; cek outputnya dulu
#kalo punya saya, begini: ['1366x768+0+312', '1920x1080+1366+0']
#tinggal dibaca, mana yang akhiran 0 dan mana yang bukan
#kebaca kan?
if arg == "right": #dah beres
match = [s for s in screeninfo if s.endswith("+0")][0]
elif arg == "left":
match = [s for s in screeninfo if not s.endswith("+0")][0]
data = [item.split("x") for item in match.split("+")]
numbers = [int(n) for n in [item for sublist in data for item in sublist]]
coord = [str(int(n)) for n in [(numbers[0]/2)+numbers[2], (numbers[1]/2)+numbers[3]]]
subprocess.Popen(["xdotool", "mousemove", coord[0], coord[1]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment