Created
May 26, 2017 00:14
-
-
Save jamaluddinrumi/288452e621b3ce7acad26bb072e8d2b2 to your computer and use it in GitHub Desktop.
Keyboard Shortcut - Switch Focus Between Multiple Monitors
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 | |
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