diff --git a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 index 9bed77e1..f95e8830 100644 --- a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 +++ b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 @@ -28,10 +28,27 @@ enum PointerSize { ExtraLarge } +enum BinarySettingState { + KeepCurrentValue + Enabled + Disabled +} + +enum AnimationEffectsSettings { + SmoothScrollListBoxes + SlideOpenComboBoxes + FadeOrSlideMenusIntoView + ShowShadowsUnderMousePointer + FadeOrSlideToolTipsIntoView + FadeOutMenuItemsAfterClicking + ShowShadowsUnderWindows +} + if ([string]::IsNullOrEmpty($env:TestRegistryPath)) { $global:AccessibilityRegistryPath = 'HKCU:\Software\Microsoft\Accessibility\' $global:MagnifierRegistryPath = 'HKCU:\Software\Microsoft\ScreenMagnifier\' $global:PointerRegistryPath = 'HKCU:\Control Panel\Cursors\' + $global:AnimationEffectsRegistryPath = 'HKCU:\Control Panel\Desktop\' } else { $global:AccessibilityRegistryPath = $global:MagnifierRegistryPath = $global:PointerRegistryPath = $env:TestRegistryPath @@ -200,7 +217,7 @@ class MousePointer { else { $currentState.PointerSizeValue = (Get-ItemProperty -Path $global:PointerRegistryPath -Name $this.PointerSizeProperty).CursorBaseSize $currentSize = switch ($currentState.PointerSizeValue) { - '32' { [PointerSize]::Normal } + '32' { [PointerSize]::Normal } '96' { [PointerSize]::Medium } '144' { [PointerSize]::Large } '256' { [PointerSize]::ExtraLarge } @@ -241,7 +258,142 @@ class MousePointer { } } +[DSCResource()] +class AnimationEffects { + #Need to verify the Animation Effects setting toggle on the Accessibility page changes when these are updated, or find the setting to update that also. + [DscProperty(Key)] [BinarySettingState] $SmoothScrollListBoxes = [BinarySettingState]::KeepCurrentValue + [DscProperty()] [BinarySettingState] $SlideOpenComboBoxes = [BinarySettingState]::KeepCurrentValue + [DscProperty()] [BinarySettingState] $FadeOrSlideMenusIntoView = [BinarySettingState]::KeepCurrentValue + [DscProperty()] [BinarySettingState] $ShowShadowsUnderMousePointer = [BinarySettingState]::KeepCurrentValue + [DscProperty()] [BinarySettingState] $FadeOrSlideToolTipsIntoView = [BinarySettingState]::KeepCurrentValue + [DscProperty()] [BinarySettingState] $FadeOutMenuItemsAfterClicking = [BinarySettingState]::KeepCurrentValue + [DscProperty()] [BinarySettingState] $ShowShadowsUnderWindows = [BinarySettingState]::KeepCurrentValue + [DscProperty(NotConfigurable)] [AnimationEffects] $currentState + + [AnimationEffects] Get() { + $this.currentState = [AnimationEffects]::new() + + $this.currentState = [BinarySettingState]::Disabled + + foreach ($enum in [AnimationEffectsSettings].GetEnumNames()) { + $thisState = Get-AnimationState $enum + if ($thisState -eq [BinarySettingState]::Enabled) { + $this.currentState = [BinarySettingState]::Enabled + } + } + + return $this.currentState + } + + [bool] Test() { + $this.currentState = $this.Get() + if ($this.SmoothScrollListBoxes -ne [BinarySettingState]::KeepCurrentValue) { + + return $false + } + + elseif ($this.SmoothScrollListBoxes -ne $this.currentState.SmoothScrollListBoxes) { + + return $false + } + + elseif ($this.SlideOpenComboBoxes -ne [BinarySettingState]::KeepCurrentValue) { + + return $false + } + + elseif ($this.SlideOpenComboBoxes -ne $this.currentState.SlideOpenComboBoxes) { + + return $false + } + + elseif ($this.FadeOrSlideMenusIntoView -ne [BinarySettingState]::KeepCurrentValue) { + + return $false + } + + elseif ($this.FadeOrSlideMenusIntoView -ne $this.currentState.FadeOrSlideMenusIntoView) { + + return $false + } + + elseif ($this.ShowShadowsUnderMousePointer -ne [BinarySettingState]::KeepCurrentValue) { + + return $false + } + + elseif ($this.ShowShadowsUnderMousePointer -ne $this.currentState.ShowShadowsUnderMousePointer) { + + return $false + } + + elseif ($this.ShowShadowsUnderMousePointer -ne [BinarySettingState]::KeepCurrentValue) { + + return $false + } + + elseif ($this.ShowShadowsUnderMousePointer -ne $this.currentState.ShowShadowsUnderMousePointer) { + + return $false + } + + elseif ($this.FadeOrSlideToolTipsIntoView -ne [BinarySettingState]::KeepCurrentValue) { + + return $false + } + + elseif ($this.FadeOrSlideToolTipsIntoView -ne $this.currentState.FadeOrSlideToolTipsIntoView) { + + return $false + } + + elseif ($this.FadeOutMenuItemsAfterClicking -ne [BinarySettingState]::KeepCurrentValue) { + + return $false + } + + elseif ($this.FadeOutMenuItemsAfterClicking -ne $this.currentState.FadeOutMenuItemsAfterClicking) { + + return $false + } + + elseif ($this.ShowShadowsUnderWindows -ne [BinarySettingState]::KeepCurrentValue) { + + return $false + } + + elseif ($this.ShowShadowsUnderWindows -ne $this.currentState.ShowShadowsUnderWindows) { + + return $false + }else { + + return $true + } + } + + [void] Set() { + if ($this.Test() -eq $false) { + + $this.currentState = GetAnimationEffectsStateHexValue # -SmoothScrollListBoxesDesiredValue $SmoothScrollListBoxes + # -SlideOpenComboBoxesDesiredValue $SlideOpenComboBoxes ` + # -FadeOrSlideMenusIntoViewDesiredValue $FadeOrSlideMenusIntoView ` + # -ShowShadowsUnderMousePointerDesiredValue $ShowShadowsUnderMousePointer ` + # -FadeOrSlideToolTipsIntoViewDesiredValue $FadeOrSlideToolTipsIntoView ` + # -FadeOutMenuItemsAfterClickingDesiredValue $FadeOutMenuItemsAfterClicking ` + # -ShowShadowsUnderWindowsDesiredValue $ShowShadowsUnderWindows + + if (-not (Test-Path -Path $global:AnimationEffectsRegistryPath)) { + New-Item -Path $global:AnimationEffectsRegistryPath -Force | Out-Null + } + + Set-ItemProperty -Path $global:AnimationEffectsRegistryPath -Name $this.AnimationEffectsProperty -Value $this.currentState + } + } +} + #region Functions +[string] $AnimationEffectsProperty = 'UserPreferencesMask' + function DoesRegistryKeyPropertyExist { param ( [Parameter(Mandatory)] @@ -255,4 +407,90 @@ function DoesRegistryKeyPropertyExist { $itemProperty = Get-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue return $null -ne $itemProperty } + +function GetAnimationEffectsStateHexValue { + param( + [Parameter(Mandatory)] + [BinarySettingState]$SmoothScrollListBoxesDesiredValue, + + [Parameter(Mandatory)] + [BinarySettingState]$SlideOpenComboBoxesDesiredValue, + + [Parameter(Mandatory)] + [BinarySettingState]$FadeOrSlideMenusIntoViewDesiredValue, + + [Parameter(Mandatory)] + [BinarySettingState]$ShowShadowsUnderMousePointerDesiredValue, + + [Parameter(Mandatory)] + [BinarySettingState]$FadeOrSlideToolTipsIntoViewDesiredValue, + + [Parameter(Mandatory)] + [BinarySettingState]$FadeOutMenuItemsAfterClickingDesiredValue, + + [Parameter(Mandatory)] + [BinarySettingState]$ShowShadowsUnderWindowsDesiredValue + ) + + [array]$OverallState = (Get-ItemPropertyValue -Path $global:AnimationEffectsRegistryPath -Name $AnimationEffectsProperty) | %{[System.Convert]::ToString($_,2).PadLeft(8,'0')}#Registry converts from hex to int, so this converts from int to binary. + + + foreach ($enum in [AnimationEffectsSettings].GetEnumNames()) { + $StateValue = switch ([AnimationEffectsSettings]$enum) { + SmoothScrollListBoxes {$OverallState[0][4]} + SlideOpenComboBoxes {$OverallState[0][5]} + FadeOrSlideMenusIntoView {$OverallState[0][6]} + ShowShadowsUnderMousePointer {$OverallState[1][2]} + FadeOrSlideToolTipsIntoView {$OverallState[1][4]} + FadeOutMenuItemsAfterClicking {$OverallState[1][5]} + ShowShadowsUnderWindows {$OverallState[2][5]} + } + if ($StateValue -eq 1) { + $OutputValue = [BinarySettingState]::Enabled + }else { + $OutputValue = [BinarySettingState]::Disabled + } + switch ([AnimationEffectsSettings]$enum) { + SmoothScrollListBoxes {$SmoothScrollListBoxesDesiredValue = $OutputValue} + SlideOpenComboBoxes {$SlideOpenComboBoxesDesiredValue = $OutputValue} + FadeOrSlideMenusIntoView {$FadeOrSlideMenusIntoViewDesiredValue = $OutputValue} + ShowShadowsUnderMousePointer {$ShowShadowsUnderMousePointerDesiredValue = $OutputValue} + FadeOrSlideToolTipsIntoView {$FadeOrSlideToolTipsIntoViewDesiredValue = $OutputValue} + FadeOutMenuItemsAfterClicking {$FadeOutMenuItemsAfterClickingDesiredValue = $OutputValue} + ShowShadowsUnderWindows {$ShowShadowsUnderWindowsDesiredValue = $OutputValue} + } + } + + + $OverallState = $OverallState | %{[convert]::ToInt32($_,2).ToString("X").PadLeft(2,'0')}#Converts from binary back to hex. + return $OverallState +} + + +Function Get-AnimationState { + param( + [Parameter(Mandatory)] + [AnimationEffectsSettings]$enum + ) + + $OverallState = (Get-ItemPropertyValue -Path $global:AnimationEffectsRegistryPath -Name $AnimationEffectsProperty) | %{[System.Convert]::ToString($_,2).PadLeft(8,'0')}#Registry converts from hex to int, so this converts from int to binary. + + $IndividualState = switch ([AnimationEffectsSettings]$enum) { + SmoothScrollListBoxes {$OverallState[0][4]} + SlideOpenComboBoxes {$OverallState[0][5]} + FadeOrSlideMenusIntoView {$OverallState[0][6]} + ShowShadowsUnderMousePointer {$OverallState[1][2]} + FadeOrSlideToolTipsIntoView {$OverallState[1][4]} + FadeOutMenuItemsAfterClicking {$OverallState[1][5]} + ShowShadowsUnderWindows {$OverallState[2][5]} + } + + if ($IndividualState -eq [BinarySettingState]::Disabled) { + $currentState = [BinarySettingState]::Disabled + }else { + $currentState = [BinarySettingState]::Enabled + } + + return $currentState +} #endregion Functions \ No newline at end of file diff --git a/tests/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.Tests.ps1 b/tests/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.Tests.ps1 index a99398fd..2d68d910 100644 --- a/tests/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.Tests.ps1 +++ b/tests/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.Tests.ps1 @@ -114,6 +114,42 @@ Describe 'MousePointer' { } } +Describe 'Animation'{ + It 'Keeps current value.'{ + $initialState = Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} + + $parameters = @{ AnimationBehavior = 'KeepCurrentValue' } + + $testResult = Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters + $testResult.InDesiredState | Should -Be $true + + # Invoking set should not change these values. + Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $parameters + $finalState = Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} + $finalState.AnimationBehavior | Should -Be $initialState.AnimationBehavior + } + + It 'Sets desired value.'{ + # Randomly generate desired state. Minimum is set to 1 to avoid using KeepCurrentValue + $desiredAnimationBehavior = [AnimationBehavior](Get-Random -Maximum 2 -Minimum 1) + + $desiredState = @{ AnimationBehavior = $desiredAnimationBehavior } + + Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $desiredState + + $finalState = Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} + $finalState.AnimationBehavior | Should -Be $desiredAnimationBehavior + $finalState.SmoothScrollListBoxes | Should -Be $desiredAnimationBehavior + $finalState.SlideOpenComboBoxes | Should -Be $desiredAnimationBehavior + $finalState.FadeOrSlideMenusIntoView | Should -Be $desiredAnimationBehavior + $finalState.ShowShadowsUnderMousePointer | Should -Be $desiredAnimationBehavior + $finalState.FadeOrSlideToolTipsIntoView | Should -Be $desiredAnimationBehavior + $finalState.FadeOrSlideToolTipsIntoView | Should -Be $desiredAnimationBehavior + $finalState.ShowShadowsUnderWindows | Should -Be $desiredAnimationBehavior + + } +} + AfterAll { $env:TestRegistryPath = "" } \ No newline at end of file