This commit is contained in:
xzhih 2020-07-20 05:57:32 +08:00
commit 1ee7bccafd
4 changed files with 89 additions and 42 deletions

View file

@ -20,12 +20,14 @@ macOS 的 DPI 机制和 Windows 下不一样,比如 1080p 的屏幕在 Windows
## 使用方法
在终端输入以下命令回车即可
1.远程模式: 在终端输入以下命令回车即可
```bash
bash -c "$(curl -fsSL https://raw.githubusercontent.com/xzhih/one-key-hidpi/dev/hidpi.sh)"
```
2.本地模式: 下载项目解压,双击 `hidpi.command` 运行
![运行](./img/run-zh.jpg)
## 恢复

View file

@ -18,12 +18,14 @@ System Preferences
## Usage
Run this script in Terminal
1.Remote Mode: Run this script in Terminal
```bash
bash -c "$(curl -fsSL https://raw.githubusercontent.com/xzhih/one-key-hidpi/dev/hidpi.sh)"
```
2.Local Mode: Download ZIP, decompressing it, and double click `hidpi.command` to run
![RUN](./img/run.jpg)
## Recovery

6
hidpi.command Executable file
View file

@ -0,0 +1,6 @@
#!/bin/bash
DIR="$( cd "$( dirname "$0" )" && pwd )"
$DIR/hidpi.sh

115
hidpi.sh
View file

@ -5,6 +5,8 @@ systemVersion=($(sw_vers -productVersion | cut -d "." -f 2))
systemLanguage=($(locale | grep LANG | sed s/'LANG='// | tr -d '"' | cut -d "." -f 1))
disableSIP="Need to disable SIP"
langRemoteMode="Remote Mode"
langLocalMode="Local Mode"
langDisplay="Display"
langMonitors="Monitors"
langIndex="Index"
@ -27,6 +29,9 @@ langEnableOp1="(1) Enable HIDPI"
langEnableOp2="(2) Enable HIDPI (with EDID)"
langEnableOp3="(3) Disable HIDPI"
langDisableOpt1="(1) Disable HIDPI on this monitor"
langDisableOpt2="(2) Reset all settings to macOS default"
langChooseRes="resolution config"
langChooseResOp1="(1) 1920x1080 Display"
langChooseResOp2="(2) 1920x1080 Display (use 1424x802, fix underscaled after sleep)"
@ -37,6 +42,8 @@ langChooseResOpCustom="(6) Manual input resolution"
if [[ "${systemLanguage}" == "zh_CN" ]]; then
disableSIP="需要关闭 SIP"
langRemoteMode="远程模式"
langLocalMode="本地模式"
langDisplay="显示器"
langMonitors="显示器"
langIndex="序号"
@ -59,6 +66,9 @@ if [[ "${systemLanguage}" == "zh_CN" ]]; then
langEnableOp2="(2) 开启HIDPI(同时注入EDID)"
langEnableOp3="(3) 关闭HIDPI"
langDisableOpt1="(1) 在此显示器上禁用 HIDPI"
langDisableOpt2="(2) 还原所有设置至 macOS 默认"
langChooseRes="选择分辨率配置"
langChooseResOp1="(1) 1920x1080 显示屏"
langChooseResOp2="(2) 1920x1080 显示屏 (使用 1424x802 分辨率,修复睡眠唤醒后的屏幕缩小问题)"
@ -72,15 +82,20 @@ downloadHost="https://raw.githubusercontent.com/xzhih/one-key-hidpi/master"
# downloadHost="https://raw.githubusercontent.com/xzhih/one-key-hidpi/dev"
# downloadHost="http://127.0.0.1:8080"
if [[ "${sipInfo}" == *"Filesystem Protections: disabled"* ]] || [[ "$(awk '{print $5}' <<< "${sipInfo}")" == "disabled." ]]; then
shellDir="$(cd `dirname -- $0` && pwd)"
if [ -d "${shellDir}/displayIcons" ];then
echo $langLocalMode
downloadHost="file://${shellDir}"
else
echo $langRemoteMode
fi
if [[ "${sipInfo}" == *"Filesystem Protections: disabled"* ]] || [[ "$(awk '{print $5}' <<< "${sipInfo}")" == "disabled." ]] || [[ "$(awk '{print $5}' <<< "${sipInfo}")" == "disabled" ]]; then
:
else
echo "${disableSIP}";
exit 0
fi
if [[ "${systemVersion}" -ge "15" ]]; then
sudo mount -uw / && killall Finder
exit 1
fi
function get_edid()
@ -128,7 +143,7 @@ function get_edid()
# Lower selection (arrays start at zero).
if ((selection < 1 || selection > index)); then
echo "${langEnterError}";
exit 0
exit 1
fi
let selection-=1
gMonitor=${gDisplayInf[$selection]}
@ -136,7 +151,7 @@ function get_edid()
* )
echo "${langEnterError}";
exit 0
exit 1
;;
esac
else
@ -171,23 +186,21 @@ EEF
get_edid
thisDir=$(cd `dirname -- $0` && pwd)
thatDir="/System/Library/Displays/Contents/Resources/Overrides"
Overrides="\/System\/Library\/Displays\/Contents\/Resources\/Overrides"
libDisplaysDir="/Library/Displays"
thatDir="${libDisplaysDir}/Contents/Resources/Overrides"
thatSysDir="/System${thatDir}"
Overrides="\/Library\/Displays\/Contents\/Resources\/Overrides"
sysOverrides="\/System${Overrides}"
DICON="com\.apple\.cinema-display"
imacicon=${Overrides}"\/DisplayVendorID\-610\/DisplayProductID\-a032\.tiff"
mbpicon=${Overrides}"\/DisplayVendorID\-610\/DisplayProductID\-a030\-e1e1df\.tiff"
mbicon=${Overrides}"\/DisplayVendorID\-610\/DisplayProductID\-a028\-9d9da0\.tiff"
lgicon=${Overrides}"\/DisplayVendorID\-1e6d\/DisplayProductID\-5b11\.tiff"
imacicon=${sysOverrides}"\/DisplayVendorID\-610\/DisplayProductID\-a032\.tiff"
mbpicon=${sysOverrides}"\/DisplayVendorID\-610\/DisplayProductID\-a030\-e1e1df\.tiff"
mbicon=${sysOverrides}"\/DisplayVendorID\-610\/DisplayProductID\-a028\-9d9da0\.tiff"
lgicon=${sysOverrides}"\/DisplayVendorID\-1e6d\/DisplayProductID\-5b11\.tiff"
proxdricon=${Overrides}"\/DisplayVendorID\-610\/DisplayProductID\-ae2f\_Landscape\.tiff"
if [[ ! -d ${thatDir}/HIDPI/backup ]]; then
echo "${langBackingUp}"
sudo mkdir -p ${thatDir}/HIDPI/backup
sudo cp ${thatDir}/Icons.plist ${thatDir}/HIDPI/backup/
if [[ -d ${thatDir}/DisplayVendorID-${Vid} ]]; then
sudo cp -r ${thatDir}/DisplayVendorID-${Vid} ${thatDir}/HIDPI/backup/
fi
if [[ ! -d ${thatDir}/HIDPI ]]; then
sudo mkdir -p ${thatDir}/HIDPI
fi
generate_restore_cmd
@ -223,14 +236,14 @@ function get_edid()
[[:digit:]]* )
if ((selection < 1 || selection > index)); then
echo "Enter error, bye";
exit 0
exit 1
fi
let selection-=1
gMonitor=${gDisplayInf[$selection]}
;;
* )
echo "Enter error, bye";
exit 0
exit 1
;;
esac
else
@ -246,13 +259,26 @@ function get_edid()
get_edid
if [[ -d ../DisplayVendorID-${Vid} ]]; then
rm -rf ../DisplayVendorID-${Vid}
fi
rootPath="../../../../../.."
echo ""
echo "(1) Disable HIDPI on this monitor"
echo "(2) Reset all settings to macOS default"
echo ""
read -p "Enter your choice [1~2]: " input
case ${input} in
1) ${rootPath}/usr/libexec/plistbuddy -c "Delete :vendors:${Vid}:products:${Pid}" ../Icons.plist
;;
2) rm -rf ${rootPath}/Library/Displays
;;
*)
echo "Enter error, bye";
exit 1
;;
esac
rm -rf ../Icons.plist
cp -r ./backup/* ../
rm -rf ./disable
echo "HIDPI Disabled"
CCC
@ -299,7 +325,7 @@ case ${logo} in
;;
4) Picon=${lgicon}
RP=("11" "47" "202" "114")
cp ${thatDir}/DisplayVendorID-1e6d/DisplayProductID-5b11.icns ${thisDir}/tmp/DisplayVendorID-${Vid}/DisplayProductID-${Pid}.icns
cp ${thatSysDir}/DisplayVendorID-1e6d/DisplayProductID-5b11.icns ${thisDir}/tmp/DisplayVendorID-${Vid}/DisplayProductID-${Pid}.icns
;;
5) Picon=${proxdricon}
RP=("5" "45" "216" "121")
@ -314,7 +340,7 @@ case ${logo} in
*)
echo "${langEnterError}";
exit 0
exit 1
;;
esac
@ -402,7 +428,7 @@ case ${res} in
;;
*)
echo "${langEnterError}";
exit 0
exit 1
;;
esac
@ -536,13 +562,24 @@ function enable_hidpi_with_patch()
# disable
function disable()
{
if [[ -d ${thatDir}/DisplayVendorID-${Vid} ]]; then
sudo rm -rf ${thatDir}/DisplayVendorID-${Vid}
fi
echo ""
echo "${langDisableOpt1}"
echo "${langDisableOpt2}"
echo ""
read -p "${langInputChoice} [1~2]: " input
case ${input} in
1) sudo /usr/libexec/plistbuddy -c "Delete :vendors:${Vid}:products:${Pid}" ${thatDir}/Icons.plist
;;
2) sudo rm -rf ${libDisplaysDir}
;;
*)
echo "${langEnterError}";
exit 1
;;
esac
sudo rm -rf ${thatDir}/Icons.plist
sudo cp -r ${thatDir}/HIDPI/backup/* ${thatDir}/
sudo rm -rf ${thatDir}/HIDPI/disable
echo "${langDisabled}"
}
@ -568,7 +605,7 @@ case ${input} in
*)
echo "${langEnterError}";
exit 0
exit 1
;;
esac
}