--- a/WinWorkstation.st Mon Nov 25 14:28:48 2019 +0100
+++ b/WinWorkstation.st Mon Nov 25 14:29:25 2019 +0100
@@ -6345,29 +6345,32 @@
!WinWorkstation class methodsFor:'converting'!
convertVirtualResolutionPointToCurrentResolutionPoint:aPoint
+ "this is required when you want to access the root display coordinates correctly,
+ because may the os did scale the application (when the app is not high DPI aware),
+ and if the os do scale the application, the application gets a virtual display
+ with a diffrent resolution"
+
"
self convertVirtualResolutionPointToCurrentResolutionPoint:2000@400
self convertVirtualResolutionPointToCurrentResolutionPoint:2000@500
"
- |centerMonitorHandle centerMonitorScaleFactor
- targetMonitorInfo minScaleFactor
+ |centerMonitorDeviceName targetMonitorInfo minScaleFactor
scaledX scaledY|
- centerMonitorHandle := Display monitorHandleForPoint:0@0.
- centerMonitorHandle isNil ifTrue:[
+ centerMonitorDeviceName := Screen monitorDeviceNameForPoint:0@0.
+ centerMonitorDeviceName isNil ifTrue:[
self halt. "/ should not happen?
^ aPoint
- ].
-
- centerMonitorScaleFactor := Display monitorScaleFactorFor:centerMonitorHandle.
+ ].
+
targetMonitorInfo := Display monitorInfoForPoint:aPoint.
(targetMonitorInfo isNil
or:[targetMonitorInfo isCenterMonitor]) ifTrue:[
"the point is not inside any monitor
or is inside the center monitor
use the center monitor scale factor"
- ^ (aPoint * centerMonitorScaleFactor) rounded
+ ^ (aPoint * (Screen scaleFactorForRootViewTranslationOnMonitorNamed:centerMonitorDeviceName)) rounded
].
minScaleFactor := (Display monitorInfos
@@ -6379,21 +6382,19 @@
scaledX := self
convertTargetValue:aPoint x
targetMonitorInfo:targetMonitorInfo
- minScaleFactor:minScaleFactor x
- pointValueFetch:[:eachPoint | eachPoint x]
+ minScaleFactor:minScaleFactor
monitorInfoTopOrLeftFetch:[:monitorInfo | monitorInfo screenX].
scaledY := self
convertTargetValue:aPoint y
targetMonitorInfo:targetMonitorInfo
- minScaleFactor:minScaleFactor y
- pointValueFetch:[:eachPoint | eachPoint y]
+ minScaleFactor:minScaleFactor
monitorInfoTopOrLeftFetch:[:monitorInfo | monitorInfo screenY].
^ scaledX@scaledY
"Created: / 22-11-2019 / 10:09:49 / Stefan Reise"
- "Modified: / 25-11-2019 / 11:55:52 / Stefan Reise"
+ "Modified (comment): / 25-11-2019 / 14:23:47 / Stefan Reise"
! !
!WinWorkstation class methodsFor:'debugging'!
@@ -6708,16 +6709,17 @@
convertTargetValue:targetValue
targetMonitorInfo:targetMonitorInfo
minScaleFactor:minScaleFactor
- pointValueFetch:pointValueFetch
monitorInfoTopOrLeftFetch:monitorInfoTopOrLeftFetch
+ "helper function,
+ take a look at the caller"
+
|scaleFactorInTargetMonitor targetMonitorVirtualTopOrLeft
targetMonitorRealTopOrLeft remainingVirtual remainingReal
returnValue|
- scaleFactorInTargetMonitor := pointValueFetch
- value:(Screen
- scaleFactorForRootViewTranslationOnMonitorNamed:targetMonitorInfo name).
+ scaleFactorInTargetMonitor := Screen
+ scaleFactorForRootViewTranslationOnMonitorNamed:targetMonitorInfo name.
"check if target moinitor is the center monitor"
targetMonitorVirtualTopOrLeft := monitorInfoTopOrLeftFetch value:targetMonitorInfo.
@@ -6735,26 +6737,43 @@
^ targetMonitorRealTopOrLeft + remainingReal
- "Created: / 22-11-2019 / 10:37:55 / Stefan Reise"
+ "Created: / 25-11-2019 / 13:56:58 / Stefan Reise"
+!
+
+scaleFactorForRootViewTranslationOnMonitorNamed:aMonitorDeviceName
+ "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,
+ but the screen (from which we take a screenshot for e.g.)
+ does always have the current resoltion,
+ therefor we have to translate from virtual to current resolution"
+
+ "
+ Screen scaleFactorForRootViewTranslationOnMonitorNamed:'\\.\DISPLAY1'.
+ Screen scaleFactorForRootViewTranslationOnMonitorNamed:'\\.\DISPLAY2'.
+ "
+
+ |currentMonitorResolution thisAppVirtualResolution|
+
+ currentMonitorResolution := Screen monitorRealResolutionByMonitorDeviceName:aMonitorDeviceName.
+ currentMonitorResolution isNil ifTrue:[
+ ^ 1
+ ].
+
+ thisAppVirtualResolution := self thisAppVirtualResolutionByMonitorDeviceName:aMonitorDeviceName.
+ thisAppVirtualResolution isNil ifTrue:[
+ ^ 1
+ ].
+
+ ^ currentMonitorResolution x / thisAppVirtualResolution x
+
+ "Created: / 21-11-2019 / 12:33:11 / Stefan Reise"
+ "Modified: / 25-11-2019 / 14:18:09 / Stefan Reise"
! !
!WinWorkstation class methodsFor:'queries'!
-isApplicationHighDpiAware
- "just the query if stx/expecco is high dpi aware,
- if not: windows does scale expecco"
-
- "
- self isApplicationHighDpiAware
- "
-
- ^ (self registryKeyForHighDpiAware
- valueNamed:OperatingSystem pathOfSTXExecutable)
- = self registryValueForHighDpiAware
-
- "Created: / 25-11-2019 / 09:55:34 / Stefan Reise"
-!
-
isWindowsPlatform
"return true, if this device is a windows screen"
@@ -6824,16 +6843,16 @@
!
monitorRealResolutionByMonitorDeviceName:aMonitorDeviceName
- "this is the current resolution of the display,
- without any effect of scaling
+ "this is the real resolution of the display,
+ without any effect of os scaling
for e.g.
- real current resolution -> 1080p
- scaling 150%
+ real resolution -> 1080p
+ os scaling 150%
virtual resolution -> 720p
- real current resolution -> 1080p
- scaling 100%
+ real resolution -> 1080p
+ os scaling 100%
virtual resolution -> 1080p"
"
@@ -6846,8 +6865,7 @@
|currentX currentY|
aMonitorDeviceName isEmptyOrNil ifTrue:[
- "return a default"
- ^ Display extent
+ ^ super monitorRealResolutionByMonitorDeviceName:aMonitorDeviceName
].
%{
@@ -6860,26 +6878,26 @@
%}.
currentX isNil ifTrue:[
- "return a default"
- ^ Display extent
+ ^ super monitorRealResolutionByMonitorDeviceName:aMonitorDeviceName
].
^ currentX@currentY
"Created: / 25-11-2019 / 12:20:36 / Stefan Reise"
+ "Modified (format): / 25-11-2019 / 14:25:31 / Stefan Reise"
!
monitorRealResolutionByPoint:aPoint
- "this is the current resolution of the display,
- without any effect of scaling
+ "this is the real resolution of the display,
+ without any effect of os scaling
for e.g.
real resolution -> 1080p
- scaling 150%
+ os scaling 150%
virtual resolution -> 720p
real resolution -> 1080p
- scaling 100%
+ os scaling 100%
virtual resolution -> 1080p"
"
@@ -6892,60 +6910,109 @@
|monitorName|
aPoint isNil ifTrue:[
- "return a default"
- ^ Display extent
+ ^ super monitorRealResolutionByPoint:aPoint
].
monitorName := self monitorDeviceNameForPoint:aPoint.
monitorName isNil ifTrue:[
- "return a default"
- ^ Display extent
+ ^ super monitorRealResolutionByPoint:aPoint
].
^ self monitorRealResolutionByMonitorDeviceName:monitorName
"Created: / 25-11-2019 / 12:19:40 / Stefan Reise"
-!
-
-scaleFactorForRootViewTranslationOnMonitorNamed:aMonitorDeviceName
- "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,
- but the screen (from which we take a screenshot for e.g.)
- does always have the current resoltion,
- therefor we have to translate from virtual to current resolution"
-
- "
- Screen scaleFactorForRootViewTranslationOnMonitorNamed:'\\.\DISPLAY1'.
- Screen scaleFactorForRootViewTranslationOnMonitorNamed:'\\.\DISPLAY2'.
- "
-
- |currentMonitorResolution monitorHandle monitorInfo|
-
- currentMonitorResolution := Screen monitorRealResolutionByMonitorDeviceName:aMonitorDeviceName.
- currentMonitorResolution isNil ifTrue:[
- ^ super scaleFactorForRootViewTranslationOnMonitorNamed:aMonitorDeviceName
- ].
+ "Modified (comment): / 25-11-2019 / 14:25:43 / Stefan Reise"
+!
+
+monitorScaleFactorFor:aMonitorHandle
+ "this method always returns the os scale factor,
+ regardless if the app is high dpi aware or not.
+
+ this is the scale factor the user did enter in the os settings,
+ for e.g. the user can choose between 100, 125, 150 etc.
+ here we return 1, 1.25 1.5"
+
+ "
+ Screen monitorScaleFactorFor:(Display monitorHandleForName:'\\.\DISPLAY1').
+ Screen monitorScaleFactorFor:(Display monitorHandleForName:'\\.\DISPLAY2').
+ "
+
+ |scaleFactor|
+
+%{
+ if (__isExternalAddress(aMonitorHandle)) {
+ HMONITOR hMonitor = (HMONITOR)(_HWNDVal(aMonitorHandle));
+ HINSTANCE hShcore = LoadLibrary("Shcore.dll");
+
+ if (hShcore) {
+ 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 \"GetScaleFactorForMonitor()\" failed\n");
+ };
+ } else {
+ printf("Loading \"GetScaleFactorForMonitor()\" failed\n");
+ }
+ } else {
+ printf("Loading \"Shcore.dll\" failed\n");
+ }
+ }
+%}.
+
+ scaleFactor isNil ifTrue:[
+ ^ super monitorScaleFactorFor:aMonitorHandle
+ ].
+ scaleFactor == 0 ifTrue:[
+ ^ super monitorScaleFactorFor:aMonitorHandle
+ ].
+
+ ^ scaleFactor / 100
+
+ "Created: / 25-11-2019 / 11:52:42 / Stefan Reise"
+ "Modified (comment): / 25-11-2019 / 14:26:07 / Stefan Reise"
+!
+
+thisAppVirtualResolutionByMonitorDeviceName:aMonitorDeviceName
+ "this is the virtual resolution of the display for this app,
+ may (when a os scaling is defined and this app is not high dpi aware) effected by os scaling
+
+ for e.g.
+ real current resolution -> 1080p
+ scaling 150%
+ virtual resolution -> 720p
+
+ real current resolution -> 1080p
+ scaling 100%
+ virtual resolution -> 1080p"
+
+ "
+ Screen thisAppVirtualResolutionByMonitorDeviceName:nil.
+ Screen thisAppVirtualResolutionByMonitorDeviceName:'ereswt'.
+ Screen thisAppVirtualResolutionByMonitorDeviceName:'\\.\DISPLAY1'.
+ Screen thisAppVirtualResolutionByMonitorDeviceName:'\\.\DISPLAY2'.
+ "
+
+ |monitorHandle monitorInfo|
monitorHandle := Display monitorHandleForName:aMonitorDeviceName.
monitorHandle isNil ifTrue:[
- ^ super scaleFactorForRootViewTranslationOnMonitorNamed:aMonitorDeviceName
+ ^ super thisAppVirtualResolutionByMonitorDeviceName:aMonitorDeviceName
].
monitorInfo := Display monitorInfoFor:monitorHandle.
- monitorInfo isNil ifTrue:[
- "something wrong with the monitor name?"
- ^ super scaleFactorForRootViewTranslationOnMonitorNamed:aMonitorDeviceName
+ monitorInfo isNil ifTrue:[
+ ^ super thisAppVirtualResolutionByMonitorDeviceName:aMonitorDeviceName
].
- "the #monitorInfo contains the virtual resolution,
- if the application is not high dpi aware.
- otherwise the current resolution"
- ^ currentMonitorResolution / ((monitorInfo screenWidth)@(monitorInfo screenHeight))
-
- "Created: / 21-11-2019 / 12:33:11 / Stefan Reise"
- "Modified (comment): / 25-11-2019 / 12:22:58 / Stefan Reise"
+ ^ (monitorInfo screenWidth)@(monitorInfo screenHeight)
+
+ "Created: / 25-11-2019 / 14:17:05 / Stefan Reise"
! !
!WinWorkstation methodsFor:'accessing & queries'!
@@ -8096,12 +8163,29 @@
"
!
-monitorHandleForView:aWindowId
+monitorHandleForView:aViewOrViewId
"given a window ID, return a handle to the monitor"
-%{
- if (__isExternalAddress(aWindowId)) {
- HWND hWnd = _HWNDVal(aWindowId);
+ "
+ Display monitorHandleForView:Transcript topView.
+ Display monitorHandleForView:Transcript topView id.
+ "
+
+ |windowId|
+
+ aViewOrViewId isNil ifTrue:[
+ ^ nil
+ ].
+
+ aViewOrViewId isExternalAddress ifTrue:[
+ windowId := aViewOrViewId.
+ ] ifFalse:[
+ windowId := aViewOrViewId id.
+ ].
+
+%{
+ if (__isExternalAddress(windowId)) {
+ HWND hWnd = _HWNDVal(windowId);
HMONITOR hMonitor;
#if 0
/* the following is only needed when we want
@@ -8127,11 +8211,16 @@
}
RETURN ( __MKEXTERNALADDRESS(hMonitor) );
}
-%}
+%}.
+
+ ^ nil
+
"
Screen current monitorHandleForView:(Transcript topView id)
Screen current monitorHandleForPoint:(0@0)
"
+
+ "Modified (comment): / 25-11-2019 / 14:10:10 / Stefan Reise"
!
monitorHandles
@@ -8187,62 +8276,6 @@
"Created: / 21-11-2019 / 13:35:22 / Stefan Reise"
!
-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)) {
- HMONITOR hMonitor = (HMONITOR)(_HWNDVal(aMonitorHandle));
- HINSTANCE hShcore = LoadLibrary("Shcore.dll");
-
- if (hShcore) {
- 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 \"GetScaleFactorForMonitor()\" failed\n");
- };
- } else {
- printf("Loading \"GetScaleFactorForMonitor()\" failed\n");
- }
- } else {
- printf("Loading \"Shcore.dll\" failed\n");
- }
- }
-%}.
-
- scaleFactor isNil ifTrue:[
- ^ nil
- ].
- scaleFactor == 0 ifTrue:[
- ^ nil
- ].
-
- ^ scaleFactor / 100
-
- "Created: / 25-11-2019 / 11:52:42 / Stefan Reise"
-!
-
numberOfMonitors
^ self getSystemMetrics:#SM_CMONITORS