Skip to content

Commit 9888e9c

Browse files
committed
修复多显示器以及不同DPI问题
修复多显示器下窗口位置显示错位的问题 修复不同DPI下显示宽度不同的问题 编译新版
1 parent 4ee84ab commit 9888e9c

File tree

3 files changed

+76
-21
lines changed

3 files changed

+76
-21
lines changed

README.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@
2424
2525
## 使用
2626

27-
1. 请先安装 [AutoHotKeyV2](http://www.autohotkey.com/)
27+
### 方法一
2828

29-
2. 下载所有`.ahk`文件
30-
3. 运行 `winautohidev2.ahk`
31-
4. 使用`Ctrl+Left`将窗口屏幕隐藏到左侧,最大化窗口不可隐藏
29+
1. 请先安装 [AutoHotKeyV2](http://www.autohotkey.com/)
3230

31+
2. 下载所有`.ahk`文件。
32+
3. 运行 `winautohidev2.ahk`
33+
4. 使用`Ctrl+Left`将窗口屏幕隐藏到左侧,最大化窗口不可隐藏。
34+
35+
### 方法二
36+
37+
1. 前往 [Release](https://github.com/windwhim/winautohidev2/release) 下载最新版。

README_en.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,14 @@ The following is partially quoted from [winautohide](https://github.com/scavin/w
2525
2626
## Usage
2727

28-
1. Please install [AutoHotKeyV2] (http://www.autohotkey.com/)
28+
### One
2929

30-
2. Download all `.ahk` files or clone this repo
31-
3. Run `winautohidev2.ahk`
32-
4. Use `Ctrl + Left` to hide the window screen to the left, the maximized window cannot be hidden.
30+
1. Please install [AutoHotKeyV2](http://www.autohotkey.com/).
31+
32+
2. Download all `.ahk` files or clone this repo.
33+
3. Run `winautohidev2.ahk`.
34+
4. Use `Ctrl + Left` to hide the window screen to the left, the maximized window cannot be hidden.
35+
36+
### Two
37+
38+
1. Go to [Release](https://github.com/windwhim/winautohidev2/release) and download the latest version.

winautohidev2.ahk

+57-13
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#Requires AutoHotkey v2.0
22
#include Array.ahk
33
#include DPI.ahk
4-
5-
;author windwhim https://github.com/windwhim
64
; 实现窗口平滑移动,越小越平滑,最小为-1
75
SetWinDelay(5)
86

@@ -25,6 +23,26 @@ global suspendWindowIds
2523

2624
maxHeight := 1000
2725

26+
; 加入右键菜单
27+
myMenu := A_TrayMenu
28+
myMenu.Add()
29+
myMenu.Add("Reset all hidden windows", Reset)
30+
31+
32+
Reset(*){
33+
; 多显示器支持
34+
MonitorGet 1, &leftEdge,&topEdge
35+
monitorHandles := DPI.GetMonitorHandles()
36+
dpiValue := DPI.GetForMonitor(monitorHandles.Get(1))
37+
dpiValue := dpiValue / 120 * 125 / 100
38+
global leftEdge
39+
global dpiValue
40+
global topEdge
41+
for i,v in hiddenWindowIds{
42+
WinMove(showMargin+leftEdge,showMargin+topEdge,,,"ahk_id" v)
43+
}
44+
}
45+
2846

2947

3048
SetTimer WatchCursor, 200
@@ -36,7 +54,6 @@ WatchCursor(){
3654
DPI.MouseGetPos , , &id, &control
3755
; 判断是否为中间态,是则不需要移动
3856
isSuspend := suspendWindowIds.Find((v) => (v =id))
39-
4057
if isSuspend > 0{
4158
;拖动窗口去除隐藏
4259
if (isWindowMove(id)=1){
@@ -50,33 +67,56 @@ WatchCursor(){
5067
}
5168
}
5269
else{
53-
; 不为中间态时,判断是否为隐藏的窗口
70+
; 不为中间态时,则若为其他隐藏窗口则不隐藏,接着判断是否为隐藏的窗口
5471
isHidden := hiddenWindowIds.Find((v) => (v =id))
5572
; 隐藏窗口则显示
5673
if isHidden>0 {
5774
showWindow(id)
5875
}
5976
else{
60-
; 切换到其他窗口继续隐藏
77+
;按顺序隐藏
6178
if suspendWindowIds.Length > 0{
62-
suspendId := suspendWindowIds.Get(1)
63-
suspendWindowIds.RemoveAt(1)
79+
suspendId := suspendWindowIds.Get(suspendWindowIds.Length)
80+
suspendWindowIds.RemoveAt(suspendWindowIds.Length)
6481
hideWindow(suspendId)
65-
}
66-
82+
}
6783
}
6884
}
85+
; else{
86+
; ; 不为中间态时,则直接隐藏,接着判断是否为隐藏的窗口
87+
; isHidden := hiddenWindowIds.Find((v) => (v =id))
88+
; ; 切换到其他窗口继续隐藏
89+
; if suspendWindowIds.Length > 0{
90+
; suspendId := suspendWindowIds.Get(1)
91+
; suspendWindowIds.RemoveAt(1)
92+
; hideWindow(suspendId)
93+
; }
94+
; ; 隐藏窗口则显示
95+
; if isHidden>0 {
96+
; showWindow(id)
97+
; }
98+
; }
6999
}
70100
}
71101

72102

73103

74104
^Left::{
105+
MonitorGet 1, &leftEdge,&topEdge
106+
monitorHandles := DPI.GetMonitorHandles()
107+
dpiValue := DPI.GetForMonitor(monitorHandles.Get(1))
108+
dpiValue := dpiValue / 120 * 125 / 100
109+
global leftEdge
110+
global dpiValue
111+
global topEdge
112+
75113
id := WinGetID("A")
76114
hideWindow(id)
77115
}
78116
F4::{
79117
; getWinPos
118+
; 多显示器支持
119+
80120
id := WinGetID("A")
81121
window := "ahk_id" id
82122

@@ -92,13 +132,15 @@ hideWindow(id){
92132
;最大化窗口不可隐藏
93133
if WinExist(window) and WinGetMinMax(window) != 1{
94134
DPI.WinGetPos(&X, &Y, &W, &H,window)
95-
; 乘以1.25 使用DPI缩放
96-
NewX := -Round(W*1.25)+margin
135+
; 乘以dpi 使用DPI缩放
136+
NewX := -Round(W*dpiValue)+leftEdge+margin
97137
; WinMove(NewX, Y,,,window)
138+
Y :=Max(Y,topEdge)
98139
if H>maxHeight{
99-
WinMove(,,,H,window)
140+
WinMove(,Y,,H,window)
100141
}
101142
winSmoothMove(newX,Y,window)
143+
WinSetExStyle "-0x80", window
102144
WinSetAlwaysOnTop(1, window)
103145
pushTo(hiddenWindowIds,id)
104146
}
@@ -107,9 +149,10 @@ hideWindow(id){
107149
showWindow(id){
108150
window := "ahk_id" id
109151
DPI.WinGetPos(&X, &Y, &W, &H,window)
110-
NewX := showMargin
152+
NewX := showMargin+leftEdge
111153
; WinMove(NewX, Y,,,window)
112154
winSmoothMove(newX,Y,window)
155+
WinSetExStyle "+0x80", window
113156
pushTo(suspendWindowIds,id)
114157
}
115158
isWindowMove(id){
@@ -150,3 +193,4 @@ winSmoothMove(newX,newY,window){
150193
WinMove(v,newY,,,window)
151194
}
152195
}
196+

0 commit comments

Comments
 (0)