Você deve conseguir fazer isso combinando xrandr
e xwininfo
.
-
Obtenha as telas, suas resoluções e offsets:
$ xrandr | grep -w connected | awk -F'[ \+]' '{print $1,$3,$4}' VGA-0 1440x900 1600 DP-3 1600x900 0
-
Obtenha a posição da janela atual
$ xwininfo -id $(xdotool getactivewindow) | grep Absolute Absolute upper-left X: 1927 Absolute upper-left Y: 70
Então, combinando os dois, você deve conseguir a resolução da tela atual:
#!/usr/bin/env bash
## Get screen info
screen1=($(xrandr | grep -w connected | awk -F'[ +]' '{print $1,$3,$4}' |
head -n 1))
screen2=($(xrandr | grep -w connected | awk -F'[ +]' '{print $1,$3,$4}' |
tail -n 1))
## Figure out which screen is to the right of which
if [ ${screen1[2]} -eq 0 ]
then
right=(${screen2[@]});
left=(${screen1[@]});
else
right=(${screen1[@]});
left=(${screen2[@]});
fi
## Get window position
pos=$(xwininfo -id $(xdotool getactivewindow) | grep "Absolute upper-left X" |
awk '{print $NF}')
## Which screen is this window displayed in? If $pos
## is greater than the offset of the rightmost screen,
## then the window is on the right hand one
if [ "$pos" -gt "${right[2]}" ]
then
echo "${right[0]} : ${right[1]}"
else
echo "${left[0]} : ${left[1]}"
fi
O script imprimirá o nome e a resolução da tela atual.