網頁

2020年2月1日 星期六

Scale for menu and title bars

參考下列設定
udev匹配規則的編寫
How to automatically mirror screens when an HDMI cable is plugged in
How to reload udev rules without reboot?

Run script on screen lock/unlock


因為4K的解析度太高,導致字形按鈕等物件太小,可以直接修改下列設定
System Settings/Displays/Scale for menu and title bars
但是開關螢幕和結束螢幕保護時,會自動恢復設定

nvidia@nvidia-desktop:~$ udevadm monitor --environment --udev
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing

拔起 HDMI, 出現
UDEV  [38201.950691] change   /devices/virtual/switch/hdmi (switch)
ACTION=change
DEVPATH=/devices/virtual/switch/hdmi
SEQNUM=6034
SUBSYSTEM=switch
SWITCH_NAME=hdmi
SWITCH_STATE=0
USEC_INITIALIZED=14008647
net.ifnames=0

插入 HDMI, 出現
UDEV  [38204.241016] change   /devices/virtual/switch/hdmi (switch)
ACTION=change
DEVPATH=/devices/virtual/switch/hdmi
SEQNUM=6039
SUBSYSTEM=switch
SWITCH_NAME=hdmi
SWITCH_STATE=1
USEC_INITIALIZED=14008647
net.ifnames=0

nvidia@nvidia-desktop:~$ udevadm info -a -p /devices/virtual/switch/hdmi

Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

  looking at device '/devices/virtual/switch/hdmi':
    KERNEL=="hdmi"
    SUBSYSTEM=="switch"
    DRIVER==""
    ATTR{name}=="hdmi"
    ATTR{state}=="1"
    ATTR{uevent_in_suspend}=="Y"


HDMI 接頭插入時執行
nvidia@nvidia-desktop:~$ cat /etc/udev/rules.d/95-hdmi-hotplug.rules
SUBSYSTEM!="switch", GOTO="hdmi_end"
KERNEL!="hdmi", GOTO="hdmi_end"

ATTRS{state}=="1", RUN+="/bin/bash /home/nvidia/hdmi_on.sh"
ATTRS{state}=="0", RUN+="/bin/bash /home/nvidia/hdmi_off.sh"

LABEL="hdmi_end"
nvidia@nvidia-desktop:~$ cat /home/nvidia/hdmi_on.sh
sleep 1
# 需要切換不同身份執行
su -c '/home/nvidia/scale_factor.sh' - nvidia
nvidia@nvidia-desktop:~$ cat /home/nvidia/hdmi_off.sh
#echo "`date` off">>/home/nvidia/hdmi.log
nvidia@nvidia-desktop:~$ cat scale_factor.sh
/usr/bin/gsettings set com.ubuntu.user-interface scale-factor "{'HDMI-0': 16}"
nvidia@nvidia-desktop:~$

編寫完成 udev rule 時, 要重新載入
nvidia@nvidia-desktop:~$ sudo udevadm control --reload-rules && udevadm trigger
[sudo] password for nvidia:
nvidia@nvidia-desktop:~$


螢幕解鎖時執行
nvidia@nvidia-desktop:~$ cat screen_unlock.sh 
dbus-monitor --session "type='signal',interface='org.gnome.ScreenSaver'" |
while read x; do
case "$x" in
*"boolean false"*)
/bin/bash /home/nvidia/scale_factor.sh
;;
esac
done
nvidia@nvidia-desktop:~$ 

沒有留言:

張貼留言