aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2020-10-23 01:23:49 +0200
committerJohn Ankarström <john@ankarstrom.se>2020-10-23 01:23:49 +0200
commite8181cd2509e94052702adba54f8754b84cf43ee (patch)
treead1c5d7294f513824cb3125439ec9f090b7752eb
parent4d3eaa0344e3e64aa1d288dc5f1f32f9fce1489a (diff)
downloaddrm-e8181cd2509e94052702adba54f8754b84cf43ee.tar.gz
release 1.2
-rw-r--r--CHANGELOG.txt12
-rw-r--r--drm.ahk124
-rw-r--r--drm.exebin836608 -> 836608 bytes
3 files changed, 100 insertions, 36 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 74eecb7..353913c 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,9 +1,5 @@
-CHANGELOG ----------------------- 1.1 ---------------------- 2020-04-29
+CHANGELOG ----------------------- 1.2 ---------------------- 2020-04-29
-FIX: Removed exception for 2KCLIENT.EXE (forgot to remove it in origi-
- nal version)
-FIX: Now takes taskbar size into account when calculating window posi-
- tions and sizes, by using MonitorWorkArea instead of absolute
- screen area.
-FIX: Removed unnecessary embedded tray icon. Now it just uses the exe-
- cutable's icon. \ No newline at end of file
+NEW: For programs listed in the Ignore key, window position and size
+ will be ignored; for programs listed in the IgnoreSize key, window
+ size will be ignored, but position retained. \ No newline at end of file
diff --git a/drm.ahk b/drm.ahk
index ed864ab..2207436 100644
--- a/drm.ahk
+++ b/drm.ahk
@@ -2,27 +2,44 @@
#SingleInstance Force
#Persistent
-; Try to retrieve user-set resolutions
+; Retrieve user-set resolutions or fall back on defaults
RegRead, ResolutionsString, HKEY_CURRENT_USER\Software\JohnAJ\DRM, Resolutions
-if (ErrorLevel != 1)
- goto Start
+if (ErrorLevel = 1)
+{
+ ResolutionsString = 1600x1200|1024x768|800x600|640x480 ; 4:3
+ if (A_ScreenWidth/A_ScreenHeight = 1.6)
+ ResolutionsString = 1920x1200|1680x1050|1440x900|1280x800 ; 16:10
+ if (Round(A_ScreenWidth/A_ScreenHeight, 2) = 1.77)
+ ResolutionsString = 1920x1080|1366x768|1280x720|854x480 ; 16:9
+ RegWrite, REG_SZ, HKEY_CURRENT_USER\Software\JohnAJ\DRM, Resolutions, %ResolutionsString%
+}
+
+Resolutions := StrSplit(ResolutionsString, "|")
-; Fall back on default resolutions
+; Retrieve user-set exceptions
-ResolutionsString = 1600x1200|1024x768|800x600|640x480 ; 4:3
-if (A_ScreenWidth/A_ScreenHeight = 1.6)
- ResolutionsString = 1920x1200|1680x1050|1440x900|1280x800 ; 16:10
-if (Round(A_ScreenWidth/A_ScreenHeight, 2) = 1.77)
- ResolutionsString = 1920x1080|1366x768|1280x720|854x480 ; 16:9
+RegRead, IgnoreString, HKEY_CURRENT_USER\Software\JohnAJ\DRM, Ignore
+IgnoreString := "|" IgnoreString ; leading pipe for easy string matching
-RegWrite, REG_SZ, HKEY_CURRENT_USER\Software\JohnAJ\DRM, Resolutions, %ResolutionsString%
+if (ErrorLevel = 1)
+{
+ IgnoreString = ""
+ RegWrite, REG_SZ, HKEY_CURRENT_USER\Software\JohnAJ\DRM, Ignore, % ""
+}
+
+RegRead, IgnoreSizeString, HKEY_CURRENT_USER\Software\JohnAJ\DRM, IgnoreSize
+IgnoreSizeString := "|" IgnoreSizeString ; leading pipe for easy string matching
+
+if (ErrorLevel = 1)
+{
+ IgnoreSizeString = ""
+ RegWrite, REG_SZ, HKEY_CURRENT_USER\Software\JohnAJ\DRM, IgnoreSize, % ""
+}
; Set up tray menu
-Start:
-Resolutions := StrSplit(ResolutionsString, "|")
Menu, Tray, NoStandard
Menu, Tray, Tip, Dynamic Resolution Manager
for k, res in Resolutions
@@ -64,32 +81,56 @@ SwitchToResolutionFrom(WidthNew, HeightNew, WidthOrig, HeightOrig)
Restore(Positions)
}
-; Set screen resolution
-
-SetResolution(Width, Height, ColorDepth := 32)
-{
- VarSetCapacity(DeviceMode, 156, 0)
- NumPut(156, DeviceMode, 36)
- DllCall("EnumDisplaySettingsA", UInt, 0, UInt, -1, UInt, &DeviceMode)
- NumPut(0x5c0000, DeviceMode, 40)
- NumPut(ColorDepth, DeviceMode, 104)
- NumPut(Width, DeviceMode, 108)
- NumPut(Height, DeviceMode, 112)
- DllCall("ChangeDisplaySettingsA", UInt, &DeviceMode, UInt, 0)
-}
-
Save(ByRef Positions)
{
+ global IgnoreString
+ global IgnoreSizeString
+
Positions := {}
WinGet, id, list
SysGet, WorkArea, MonitorWorkArea
Width := WorkAreaRight - WorkAreaLeft
Height := WorkAreaBottom - WorkAreaTop
+
Loop, %id%
{
i := id%A_Index%
WinReallyGetPos(i, x, y, w, h)
- Positions[i] := [x / Width, y / Height, w / Width, h / Height]
+ WinGet, exe, ProcessName, ahk_id %i%
+
+ ; Ignore position and size (2)
+
+ if (InStr(IgnoreString, "|" exe))
+ Positions[i] := [x, y, w, h, 2, 0]
+
+ ; Ignore size, but retain position (1)
+
+ else if (InStr(IgnoreSizeString, "|" exe))
+ {
+ rx := x / Width
+ ry := y / Height
+
+ ; Calculate position relative to right/bottom if necessary
+
+ Align := 1 ; to align right, this should be divisible by 3; bottom, by 5
+ if (x > Width / 2)
+ {
+ Align := Align * 3
+ rx := (Width - (x + w)) / Width
+ }
+ if (y > Height / 2)
+ {
+ Align := Align * 5
+ ry := (Height - (y + h)) / Height
+ }
+
+ Positions[i] := [rx, ry, w, h, 1, Align]
+ }
+
+ ; Retain position and size (0)
+
+ else
+ Positions[i] := [x / Width, y / Height, w / Width, h / Height, 0, 0]
}
}
@@ -104,10 +145,37 @@ Restore(Positions)
y := props[2]
w := props[3]
h := props[4]
- WinReallyMove(i, x * Width, y * Height, w * Width, h * Height)
+ if (props[5] = 2) ; ignore position and size
+ WinReallyMove(i, x, y, w, h)
+ else if (props[5] = 1) ; ignore size, but retain position
+ {
+ rx := x * Width
+ ry := y * Height
+ if (Mod(props[6], 3) = 0) ; align right
+ rx := Width - rx - w
+ if (Mod(props[6], 5) = 0) ; align bottom
+ ry := Height - ry - h
+ WinReallyMove(i, rx, ry, w, h)
+ }
+ else ; retain position and size
+ WinReallyMove(i, x * Width, y * Height, w * Width, h * Height)
}
}
+; Set screen resolution
+
+SetResolution(Width, Height, ColorDepth := 32)
+{
+ VarSetCapacity(DeviceMode, 156, 0)
+ NumPut(156, DeviceMode, 36)
+ DllCall("EnumDisplaySettingsA", UInt, 0, UInt, -1, UInt, &DeviceMode)
+ NumPut(0x5c0000, DeviceMode, 40)
+ NumPut(ColorDepth, DeviceMode, 104)
+ NumPut(Width, DeviceMode, 108)
+ NumPut(Height, DeviceMode, 112)
+ DllCall("ChangeDisplaySettingsA", UInt, &DeviceMode, UInt, 0)
+}
+
; Get position of any window, even a minimized one
WinReallyGetPos(hwnd, ByRef x, ByRef y, ByRef w="", ByRef h="")
diff --git a/drm.exe b/drm.exe
index 84c68cd..aaa3030 100644
--- a/drm.exe
+++ b/drm.exe
Binary files differ