Skip to content

Commit 506753d

Browse files
committed
Add AsClone to Enable-Display
1 parent d0a392f commit 506753d

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

Docs/Enable-Display.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ If the display is already active, but is used for display cloning then this will
1414
## SYNTAX
1515

1616
```
17-
Enable-Display [-DisplayId] <UInt32[]> [<CommonParameters>]
17+
Enable-Display [-DisplayId] <UInt32[]> [-AsClone] [<CommonParameters>]
1818
```
1919

2020
## DESCRIPTION
@@ -51,6 +51,23 @@ Accept pipeline input: False
5151
Accept wildcard characters: False
5252
```
5353
54+
### -AsClone
55+
When specified, the specified displays are put into one clone group.
56+
This allows you to turn on displays and add them to a clone group in one go.
57+
You can use this over Copy-DisplaySource when you want to let Windows determine the best mode, rather than copying it from an existing display.
58+
59+
```yaml
60+
Type: SwitchParameter
61+
Parameter Sets: (All)
62+
Aliases:
63+
64+
Required: False
65+
Position: Named
66+
Default value: None
67+
Accept pipeline input: False
68+
Accept wildcard characters: False
69+
```
70+
5471
### CommonParameters
5572
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
5673

Release notes.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
Removed the "ApplyNow" parameter as it is no longer needed. If the DisplayConfig parameter is not specified, it will apply the changes immediately.
99
The "Position" parameter set is now the default and "XPosition" and "YPosition" are no longer mandatory, allowing adjustment of one without the other.
1010
Fix index out of bounds error when cloning a display while another display is disabled.
11+
Add new switch parameter "AsClone" to "Enable-Display". When this is set, the specified displays are enabled as needed and put into one clone group.
12+
This allows Windows to determine the best clone source instead of manually specifying it with "Copy-DisplaySource" and it works with disabled displays.
1113
Update the displayId completer list item text and tooltip to include the connection type.
1214
Update "Use-DisplayConfig" so the "UpdateAdapterIds" parameter defaults to true for imported configs.
1315
2.0:

src/DisplayConfig/Commands/EnableDisplayCommand.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ public sealed class EnableDisplayCommand : Cmdlet
1515
[ArgumentCompleter(typeof(DisplayIdCompleter))]
1616
public uint[] DisplayId { get; set; }
1717

18+
[Parameter()]
19+
public SwitchParameter AsClone { get; set; }
20+
1821
protected override void EndProcessing()
1922
{
2023
var config = API.DisplayConfig.GetConfig();
@@ -35,8 +38,10 @@ protected override void EndProcessing()
3538
// This is done by invalidating all the mode indexes and setting a clone group for each display that should be active.
3639
// Displays with the same desktop position are considered cloned.
3740
// We keep track of the existing display clones so we don't accidentally stop cloning a display while enabling another.
41+
// If the AsClone switch is set, we add all the specified displays to Clone group 0.
42+
// This puts them in one clone group regardless if they are disabled or already in a different clone group.
3843
var cloneGroupTable = new Dictionary<POINTL, uint>();
39-
uint cloneGroup = 0;
44+
uint cloneGroup = AsClone ? (uint)1 : 0;
4045
foreach (int index in config.AvailablePathIndexes)
4146
{
4247
config.PathArray[index].targetInfo.modeInfoIdx = API.DisplayConfig.DISPLAYCONFIG_PATH_MODE_IDX_INVALID;
@@ -45,8 +50,8 @@ protected override void EndProcessing()
4550
{
4651
if (displaysToEnable.Contains(index))
4752
{
48-
config.PathArray[index].sourceInfo.ResetModeAndSetCloneGroup(cloneGroup);
49-
cloneGroup++;
53+
uint cloneGroupToSet = AsClone ? 0 : cloneGroup++;
54+
config.PathArray[index].sourceInfo.ResetModeAndSetCloneGroup(cloneGroupToSet);
5055
}
5156
else
5257
{
@@ -65,9 +70,9 @@ protected override void EndProcessing()
6570
}
6671
else if (displaysToEnable.Contains(index))
6772
{
68-
config.PathArray[index].sourceInfo.CloneGroupId = cloneGroup;
73+
uint cloneGroupToSet = AsClone ? 0 : cloneGroup++;
74+
config.PathArray[index].sourceInfo.CloneGroupId = cloneGroupToSet;
6975
config.PathArray[index].flags |= PathInfoFlags.DISPLAYCONFIG_PATH_ACTIVE;
70-
cloneGroup++;
7176
}
7277
}
7378

0 commit comments

Comments
 (0)