Merge pull request #140 from williambj1/master

Support macOS Big Sur
This commit is contained in:
ZeRo° Xu 2020-07-06 04:52:23 -05:00 committed by GitHub
commit fcdcb21c4b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 89 additions and 42 deletions

View file

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

View file

@ -18,12 +18,14 @@ System Preferences
## Usage ## Usage
Run this script in Terminal 1.Remote Mode: Run this script in Terminal
```bash ```bash
bash -c "$(curl -fsSL https://raw.githubusercontent.com/xzhih/one-key-hidpi/dev/hidpi.sh)" 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) ![RUN](./img/run.jpg)
## Recovery ## Recovery

6
hidpi.command Executable file
View file

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

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