--- a/WinWorkstation.st Mon Nov 25 12:26:52 2019 +0100
+++ b/WinWorkstation.st Mon Nov 25 12:27:34 2019 +0100
@@ -6350,17 +6350,17 @@
self convertVirtualResolutionPointToCurrentResolutionPoint:2000@500
"
- |centerMonitorInfo centerMonitorScaleFactor
+ |centerMonitorHandle centerMonitorScaleFactor
targetMonitorInfo minScaleFactor
scaledX scaledY|
- centerMonitorInfo := Display monitorInfoForPoint:0@0.
- centerMonitorInfo isNil ifTrue:[
+ centerMonitorHandle := Display monitorHandleForPoint:0@0.
+ centerMonitorHandle isNil ifTrue:[
self halt. "/ should not happen?
^ aPoint
].
- centerMonitorScaleFactor := Screen scaleFactorForMonitorNamed:centerMonitorInfo name.
+ centerMonitorScaleFactor := Display monitorScaleFactorFor:centerMonitorHandle.
targetMonitorInfo := Display monitorInfoForPoint:aPoint.
(targetMonitorInfo isNil
or:[targetMonitorInfo isCenterMonitor]) ifTrue:[
@@ -6393,6 +6393,7 @@
^ scaledX@scaledY
"Created: / 22-11-2019 / 10:09:49 / Stefan Reise"
+ "Modified: / 25-11-2019 / 11:55:52 / Stefan Reise"
! !
!WinWorkstation class methodsFor:'debugging'!
@@ -6784,129 +6785,6 @@
!WinWorkstation class methodsFor:'queries - monitor'!
-currentMonitorResolutionByMonitorDeviceName:aMonitorDeviceName
- "this is the current resolution of the display,
- without any effect of scaling
-
- for e.g.
- real current resolution -> 1080p
- scaling 150%
- virtual resolution -> 720p
-
- real current resolution -> 1080p
- scaling 100%
- virtual resolution -> 1080p"
-
- "
- Screen currentMonitorResolutionByMonitorDeviceName:nil.
- Screen currentMonitorResolutionByMonitorDeviceName:'ereswt'.
- Screen currentMonitorResolutionByMonitorDeviceName:'\\.\DISPLAY1'.
- Screen currentMonitorResolutionByMonitorDeviceName:'\\.\DISPLAY2'.
- "
-
- |currentX currentY|
-
- aMonitorDeviceName isEmptyOrNil ifTrue:[
- "return a default"
- ^ Display extent
- ].
-
-%{
- HDC hdc = CreateDCA(__stringVal(aMonitorDeviceName), NULL, NULL, NULL);
- if (hdc != NULL) {
- currentX = __MKSMALLINT(GetDeviceCaps(hdc, DESKTOPHORZRES));
- currentY = __MKSMALLINT(GetDeviceCaps(hdc, DESKTOPVERTRES));
- DeleteDC(hdc);
- }
-%}.
-
- currentX isNil ifTrue:[
- "return a default"
- ^ Display extent
- ].
-
- ^ currentX@currentY
-
- "Created: / 22-11-2019 / 14:25:10 / Stefan Reise"
- "Modified: / 25-11-2019 / 09:34:50 / Stefan Reise"
-!
-
-currentMonitorResolutionByPoint:aPoint
- "this is the current resolution of the display,
- without any effect of scaling
-
- for e.g.
- real current resolution -> 1080p
- scaling 150%
- virtual resolution -> 720p
-
- real current resolution -> 1080p
- scaling 100%
- virtual resolution -> 1080p"
-
- "
- Screen currentMonitorResolutionByPoint:nil.
- Screen currentMonitorResolutionByPoint:0@0.
- Screen currentMonitorResolutionByPoint:500@0.
- Screen currentMonitorResolutionByPoint:2000@0.
- "
-
- |monitorName|
-
- aPoint isNil ifTrue:[
- "return a default"
- ^ Display extent
- ].
-
- monitorName := self monitorDeviceNameForPoint:aPoint.
- monitorName isNil ifTrue:[
- "return a default"
- ^ Display extent
- ].
-
- ^ self currentMonitorResolutionByMonitorDeviceName:monitorName
-
- "Created: / 22-11-2019 / 14:26:31 / Stefan Reise"
- "Modified (format): / 25-11-2019 / 09:35:18 / Stefan Reise"
-!
-
-currentMonitorResolutionByView:aView
- "this is the current resolution of the display,
- without any effect of scaling
-
- for e.g.
- real current resolution -> 1080p
- scaling 150%
- virtual resolution -> 720p
-
- real current resolution -> 1080p
- scaling 100%
- virtual resolution -> 1080p"
-
- "
- Screen currentMonitorResolutionByView:nil.
- Screen currentMonitorResolutionByView:Transcript topView.
- "
-
- |monitorName|
-
- aView isNil ifTrue:[
- "return a default"
- ^ Display extent
- ].
-
- monitorName := self monitorDeviceNameForView:aView.
- monitorName isNil ifTrue:[
- "return a default"
- ^ Display extent
- ].
-
- ^ self currentMonitorResolutionByMonitorDeviceName:monitorName
-
- "Created: / 22-11-2019 / 14:22:47 / Stefan Reise"
- "Modified (format): / 25-11-2019 / 09:35:22 / Stefan Reise"
-!
-
monitorDeviceNameForPoint:aPoint
"given a point, return its monitor device name or nil if failed"
@@ -6945,83 +6823,92 @@
"Modified (comment): / 21-11-2019 / 12:36:21 / Stefan Reise"
!
-monitorDeviceNameForView:aView
- "given a window ID, return its monitor device name or nil if failed"
-
- "
- Screen monitorDeviceNameForView:Transcript topView
- "
-
- |windowId|
-
- windowId := aView id.
-
-%{
- if (__isExternalAddress(windowId)) {
- HMONITOR hMonitor;
- MONITORINFOEX monitorInfo;
-
- hMonitor = MonitorFromWindow(_HWNDVal(windowId), MONITOR_DEFAULTTOPRIMARY);
- if (hMonitor == 0) {
- RETURN(nil);
- }
-
- monitorInfo.cbSize = sizeof(MONITORINFOEX);
- if (GetMonitorInfo(hMonitor, &monitorInfo) == 0){
- RETURN(nil);
- }
-
- RETURN(__MKSTRING(monitorInfo.szDevice));
- }
-%}
-
- "Created: / 20-11-2019 / 14:52:59 / Stefan Reise"
- "Modified: / 21-11-2019 / 18:04:50 / Stefan Reise"
- "Modified (comment): / 22-11-2019 / 10:22:49 / Stefan Reise"
-!
-
-scaleFactorForMonitorNamed:aMonitorDeviceName
- "ATTENTION: this method always returns the scale factor set by os,
- REGARDLESS if the application (stx, expecco) has a virtual resolution or not
- use #scaleFactorForRootViewTranslationOnMonitorNamed: which is dependent on the
- application's (stx, expecco) high dpi awareness (if the application has a virtual
- resolution or not).
-
- this is the scale factor the user did enter within the windows settings,
- for e.g. the user can choose between 100, 125, 150 etc.
- here we return 1, 1.25 1.5"
-
- "
- self scaleFactorForMonitorNamed:'\\.\DISPLAY1'
- self scaleFactorForMonitorNamed:'\\.\DISPLAY2'
- "
-
- |currentMonitorResolution virtualMonitorResolution|
-
- currentMonitorResolution := self currentMonitorResolutionByMonitorDeviceName:aMonitorDeviceName.
- currentMonitorResolution isNil ifTrue:[
- "may the tool binary is missing"
- ^ super scaleFactorForMonitorNamed:aMonitorDeviceName
- ].
-
- virtualMonitorResolution := self virtualMonitorResolutionByMonitorDeviceName:aMonitorDeviceName.
- virtualMonitorResolution isNil ifTrue:[
- "may the tool binary is missing"
- ^ 1@1
- ].
-
- ^ currentMonitorResolution / virtualMonitorResolution
-
- "Created: / 21-11-2019 / 10:12:00 / Stefan Reise"
- "Modified: / 22-11-2019 / 15:17:05 / Stefan Reise"
- "Modified (comment): / 25-11-2019 / 09:36:06 / Stefan Reise"
+monitorRealResolutionByMonitorDeviceName:aMonitorDeviceName
+ "this is the current resolution of the display,
+ without any effect of scaling
+
+ for e.g.
+ real current resolution -> 1080p
+ scaling 150%
+ virtual resolution -> 720p
+
+ real current resolution -> 1080p
+ scaling 100%
+ virtual resolution -> 1080p"
+
+ "
+ Screen monitorRealResolutionByMonitorDeviceName:nil.
+ Screen monitorRealResolutionByMonitorDeviceName:'ereswt'.
+ Screen monitorRealResolutionByMonitorDeviceName:'\\.\DISPLAY1'.
+ Screen monitorRealResolutionByMonitorDeviceName:'\\.\DISPLAY2'.
+ "
+
+ |currentX currentY|
+
+ aMonitorDeviceName isEmptyOrNil ifTrue:[
+ "return a default"
+ ^ Display extent
+ ].
+
+%{
+ HDC hdc = CreateDCA(__stringVal(aMonitorDeviceName), NULL, NULL, NULL);
+ if (hdc != NULL) {
+ currentX = __MKSMALLINT(GetDeviceCaps(hdc, DESKTOPHORZRES));
+ currentY = __MKSMALLINT(GetDeviceCaps(hdc, DESKTOPVERTRES));
+ DeleteDC(hdc);
+ }
+%}.
+
+ currentX isNil ifTrue:[
+ "return a default"
+ ^ Display extent
+ ].
+
+ ^ currentX@currentY
+
+ "Created: / 25-11-2019 / 12:20:36 / Stefan Reise"
+!
+
+monitorRealResolutionByPoint:aPoint
+ "this is the current resolution of the display,
+ without any effect of scaling
+
+ for e.g.
+ real resolution -> 1080p
+ scaling 150%
+ virtual resolution -> 720p
+
+ real resolution -> 1080p
+ scaling 100%
+ virtual resolution -> 1080p"
+
+ "
+ Screen monitorRealResolutionByPoint:nil.
+ Screen monitorRealResolutionByPoint:0@0.
+ Screen monitorRealResolutionByPoint:500@0.
+ Screen monitorRealResolutionByPoint:2000@0.
+ "
+
+ |monitorName|
+
+ aPoint isNil ifTrue:[
+ "return a default"
+ ^ Display extent
+ ].
+
+ monitorName := self monitorDeviceNameForPoint:aPoint.
+ monitorName isNil ifTrue:[
+ "return a default"
+ ^ Display extent
+ ].
+
+ ^ self monitorRealResolutionByMonitorDeviceName:monitorName
+
+ "Created: / 25-11-2019 / 12:19:40 / Stefan Reise"
!
scaleFactorForRootViewTranslationOnMonitorNamed:aMonitorDeviceName
- "ATTENTION: returns the may wrong default 1@1 if the package or the tool is missing:
- stx:support/win32/displayResolutionTools/bin/cdr.exe
-
- this is the scale factor, we have to use,
+ "this is the scale factor, we have to use,
when we work directly with the root view (desktop)
because we may have a virtual display,
@@ -7030,15 +6917,14 @@
therefor we have to translate from virtual to current resolution"
"
- self scaleFactorForRootViewTranslationOnMonitorNamed:'\\.\DISPLAY1'
- self scaleFactorForRootViewTranslationOnMonitorNamed:'\\.\DISPLAY2'
+ Screen scaleFactorForRootViewTranslationOnMonitorNamed:'\\.\DISPLAY1'.
+ Screen scaleFactorForRootViewTranslationOnMonitorNamed:'\\.\DISPLAY2'.
"
|currentMonitorResolution monitorHandle monitorInfo|
- currentMonitorResolution := Screen currentMonitorResolutionByMonitorDeviceName:aMonitorDeviceName.
+ currentMonitorResolution := Screen monitorRealResolutionByMonitorDeviceName:aMonitorDeviceName.
currentMonitorResolution isNil ifTrue:[
- "may the tool binary is missing"
^ super scaleFactorForRootViewTranslationOnMonitorNamed:aMonitorDeviceName
].
@@ -7059,141 +6945,7 @@
^ currentMonitorResolution / ((monitorInfo screenWidth)@(monitorInfo screenHeight))
"Created: / 21-11-2019 / 12:33:11 / Stefan Reise"
- "Modified: / 22-11-2019 / 15:16:25 / Stefan Reise"
-!
-
-virtualMonitorResolutionByMonitorDeviceName:aMonitorDeviceName
- "ATTENTION: this method always returns the virtual resolution,
- REGARDLESS if the application (stx, expecco) has a virtual resolution or not
-
- this is the resolution of a virtual display,
- this resolution is effected by the scaling
-
- for e.g.
- real current resolution -> 1080p
- scaling 150%
- virtual resolution -> 720p
-
- real current resolution -> 1080p
- scaling 100%
- virtual resolution -> 1080p"
-
- "
- Screen virtualMonitorResolutionByMonitorDeviceName:'\\.\DISPLAY1'.
- Screen virtualMonitorResolutionByMonitorDeviceName:'\\.\DISPLAY2'.
- "
-
- |virtualX virtualY|
-
-
-
-
-
- aMonitorDeviceName isEmptyOrNil ifTrue:[
- "return a default"
- ^ Display extent
- ].
-
-%{
- HDC hdc = CreateDCA(__stringVal(aMonitorDeviceName), NULL, NULL, NULL);
- if (hdc != NULL) {
- virtualX = __MKSMALLINT(GetDeviceCaps(hdc, HORZRES));
- virtualY = __MKSMALLINT(GetDeviceCaps(hdc, VERTRES));
- DeleteDC(hdc);
- }
-%}.
-
- virtualX isNil ifTrue:[
- "return a default"
- ^ Display extent
- ].
-
- ^ virtualX@virtualY
-
- "Created: / 22-11-2019 / 14:28:41 / Stefan Reise"
- "Modified (format): / 25-11-2019 / 09:38:42 / Stefan Reise"
-!
-
-virtualMonitorResolutionByPoint:aPoint
- "ATTENTION: this method always returns the virtual resolution,
- REGARDLESS if the application (stx, expecco) has a virtual resolution or not
-
- this is the resolution of a virtual display,
- this resolution is effected by the scaling
-
- for e.g.
- real current resolution -> 1080p
- scaling 150%
- virtual resolution -> 720p
-
- real current resolution -> 1080p
- scaling 100%
- virtual resolution -> 1080p"
-
- "
- Screen virtualMonitorResolutionByPoint:nil.
- Screen virtualMonitorResolutionByPoint:0@0.
- Screen virtualMonitorResolutionByPoint:500@0.
- Screen virtualMonitorResolutionByPoint:2000@0.
- "
-
- |monitorName|
-
- aPoint isNil ifTrue:[
- "return a default"
- ^ Display extent
- ].
-
- monitorName := self monitorDeviceNameForPoint:aPoint.
- monitorName isNil ifTrue:[
- "return a default"
- ^ Display extent
- ].
-
- ^ self virtualMonitorResolutionByMonitorDeviceName:monitorName
-
- "Created: / 22-11-2019 / 14:28:55 / Stefan Reise"
- "Modified: / 25-11-2019 / 09:37:34 / Stefan Reise"
-!
-
-virtualMonitorResolutionByView:aView
- "ATTENTION: this method always returns the virtual resolution,
- REGARDLESS if the application (stx, expecco) has a virtual resolution or not
-
- this is the resolution of a virtual display,
- this resolution is effected by the scaling
-
- for e.g.
- real current resolution -> 1080p
- scaling 150%
- virtual resolution -> 720p
-
- real current resolution -> 1080p
- scaling 100%
- virtual resolution -> 1080p"
-
- "
- Screen virtualMonitorResolutionByView:nil.
- Screen virtualMonitorResolutionByView:Transcript topView.
- "
-
- |monitorName|
-
- aView isNil ifTrue:[
- "return a default"
- ^ Display extent
- ].
-
- monitorName := self monitorDeviceNameForView:aView.
- monitorName isNil ifTrue:[
- "return a default"
- ^ Display extent
- ].
-
- ^ self virtualMonitorResolutionByMonitorDeviceName:monitorName
-
- "Created: / 22-11-2019 / 14:29:09 / Stefan Reise"
- "Modified: / 25-11-2019 / 09:37:38 / Stefan Reise"
+ "Modified (comment): / 25-11-2019 / 12:22:58 / Stefan Reise"
! !
!WinWorkstation methodsFor:'accessing & queries'!
@@ -8435,11 +8187,23 @@
"Created: / 21-11-2019 / 13:35:22 / Stefan Reise"
!
-monitorScalingFactorFor:aMonitorHandle
- "
- Display monitorScalingFactorFor:(Display monitorHandleForName:'\\.\DISPLAY1').
- Display monitorScalingFactorFor:(Display monitorHandleForName:'\\.\DISPLAY2').
- "
+monitorScaleFactorFor:aMonitorHandle
+ "ATTENTION: this method always returns the scale factor set by os,
+ REGARDLESS if the application (stx, expecco) has a virtual resolution or not
+ use #scaleFactorForRootViewTranslationOnMonitorNamed: which is dependent on the
+ application's (stx, expecco) high dpi awareness (if the application has a virtual
+ resolution or not).
+
+ this is the scale factor the user did enter within the windows settings,
+ for e.g. the user can choose between 100, 125, 150 etc.
+ here we return 1, 1.25 1.5"
+
+ "
+ Display monitorScaleFactorFor:(Display monitorHandleForName:'\\.\DISPLAY1').
+ Display monitorScaleFactorFor:(Display monitorHandleForName:'\\.\DISPLAY2').
+ "
+
+ |scaleFactor|
%{
if (__isExternalAddress(aMonitorHandle)) {
@@ -8447,28 +8211,36 @@
HINSTANCE hShcore = LoadLibrary("Shcore.dll");
if (hShcore) {
- static HRESULT (__stdcall *P_GetDpiForMonitor)(HMONITOR, DWORD, UINT, UINT);
- P_GetDpiForMonitor = (HRESULT (__stdcall *)(HMONITOR, DWORD, UINT, UINT)) GetProcAddress(hShcore, "GetDpiForMonitor");
-
- if (P_GetDpiForMonitor) {
- UINT x;
- UINT y;
-
- if ((*P_GetDpiForMonitor)(hMonitor, 0 /* 0 | 1 | 2 */, &x, &y) == S_OK) {
- printf("%d@%d\n", x, y);
+ static HRESULT (__stdcall *P_GetScaleFactorForMonitor)(HMONITOR, VOID*);
+ P_GetScaleFactorForMonitor = (HRESULT (__stdcall *)(HMONITOR, VOID*))GetProcAddress(hShcore, "GetScaleFactorForMonitor");
+
+ if (P_GetScaleFactorForMonitor) {
+ UINT displayScaleFactor;
+
+ if ((*P_GetScaleFactorForMonitor)(hMonitor, &displayScaleFactor) == S_OK) {
+ scaleFactor = __MKSMALLINT(displayScaleFactor);
} else {
- printf("Call \"GetDpiForMonitor()\" failed\n");
- };
+ printf("Call \"GetScaleFactorForMonitor()\" failed\n");
+ };
} else {
- printf("Loading \"GetDpiForMonitor()\" failed\n");
+ printf("Loading \"GetScaleFactorForMonitor()\" failed\n");
}
} else {
printf("Loading \"Shcore.dll\" failed\n");
}
}
-%}
-
- "Created: / 25-11-2019 / 11:17:48 / Stefan Reise"
+%}.
+
+ scaleFactor isNil ifTrue:[
+ ^ nil
+ ].
+ scaleFactor == 0 ifTrue:[
+ ^ nil
+ ].
+
+ ^ scaleFactor / 100
+
+ "Created: / 25-11-2019 / 11:52:42 / Stefan Reise"
!
numberOfMonitors