Last active
January 28, 2021 16:19
-
-
Save rzymek/52a8509cc7f919fc868e2b7267568b47 to your computer and use it in GitHub Desktop.
multiple pointers/keyboards on xserver for pair programming
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
#!/bin/bash | |
set -eu | |
function getPairIds { | |
xinput test-xi2 --root | awk ' | |
BEGIN{FS="[()]"} | |
/EVENT.*KeyPress[)]/ {key=1} | |
/EVENT.*ButtonPress[)]/ {mouse=1} | |
key && /device: / {kId=$2;key=0} | |
mouse && /device: / {mId=$2;mouse=0} | |
kId && mId { print kId "," mId; exit } | |
' | |
} | |
function getMasterId { | |
xinput list "$1" | awk 'match($0,/id=([0-9]*)/,g) {print g[1];exit}' | |
} | |
echo "Press button on keyboard and mouse pair: " | |
ids=$(getPairIds) | |
xinput create-master pair | |
pairKeyboard=$(getMasterId "pair keyboard") | |
pairPointer=$(getMasterId "pair pointer") | |
keyId=$(echo $ids|cut -d, -f1) | |
mouseId=$(echo $ids|cut -d, -f2) | |
xinput reattach $keyId $pairKeyboard | |
xinput reattach $mouseId $pairPointer | |
echo "Unpair with: " | |
echo "xinput reattach $keyId $(getMasterId 'Virtual core keyboard'); xinput reattach $mouseId $(getMasterId 'Virtual core pointer'); xinput remove-master $(getMasterId 'pair pointer')" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment