-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Code Quality: Introduced IWindowsWallpaperService (#15811)
- Loading branch information
Showing
9 changed files
with
170 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) 2024 Files Community | ||
// Licensed under the MIT License. See the LICENSE. | ||
|
||
namespace Files.App.Data.Contracts | ||
{ | ||
/// <summary> | ||
/// Provides service for manipulating shell wallpapers on Windows. | ||
/// </summary> | ||
public interface IWindowsWallpaperService | ||
{ | ||
/// <summary> | ||
/// Sets desktop wallpaper using the specified image path. | ||
/// </summary> | ||
/// <param name="szPath">The image path to assign as the desktop wallpaper.</param> | ||
void SetDesktopWallpaper(string szPath); | ||
|
||
/// <summary> | ||
/// Sets desktop slideshow using the specified image paths. | ||
/// </summary> | ||
/// <param name="aszPaths">The image paths to use to set as slideshow.</param> | ||
void SetDesktopSlideshow(string[] aszPaths); | ||
|
||
/// <summary> | ||
/// Gets lock screen wallpaper using the specified image path. | ||
/// </summary> | ||
/// <param name="szPath">The image path to use to set as lock screen wallpaper.</param> | ||
Task SetLockScreenWallpaper(string szPath); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright (c) 2024 Files Community | ||
// Licensed under the MIT License. See the LICENSE. | ||
|
||
using Windows.Storage; | ||
using Windows.System.UserProfile; | ||
using Windows.Win32; | ||
using Windows.Win32.Foundation; | ||
using Windows.Win32.System.Com; | ||
using Windows.Win32.UI.Shell; | ||
using Windows.Win32.UI.Shell.Common; | ||
|
||
namespace Files.App.Services | ||
{ | ||
/// <inheritdoc cref="IWindowsWallpaperService"/> | ||
public sealed class WindowsWallpaperService : IWindowsWallpaperService | ||
{ | ||
/// <inheritdoc/> | ||
public unsafe void SetDesktopWallpaper(string szPath) | ||
{ | ||
PInvoke.CoCreateInstance( | ||
new Guid("{C2CF3110-460E-4fc1-B9D0-8A1C0C9CC4BD}"), | ||
null, | ||
CLSCTX.CLSCTX_LOCAL_SERVER, | ||
out IDesktopWallpaper desktopWallpaper) | ||
.ThrowOnFailure(); | ||
|
||
desktopWallpaper.GetMonitorDevicePathCount(out var dwMonitorCount); | ||
|
||
fixed (char* pszPath = szPath) | ||
{ | ||
var pwszPath = new PWSTR(pszPath); | ||
|
||
for (uint dwIndex = 0; dwIndex < dwMonitorCount; dwIndex++) | ||
{ | ||
desktopWallpaper.GetMonitorDevicePathAt(dwIndex, out var pMonitorID); | ||
desktopWallpaper.SetWallpaper(pMonitorID, pwszPath); | ||
} | ||
} | ||
} | ||
|
||
/// <inheritdoc/> | ||
public unsafe void SetDesktopSlideshow(string[] aszPaths) | ||
{ | ||
PInvoke.CoCreateInstance( | ||
new Guid("{C2CF3110-460E-4fc1-B9D0-8A1C0C9CC4BD}"), | ||
null, | ||
CLSCTX.CLSCTX_LOCAL_SERVER, | ||
out IDesktopWallpaper desktopWallpaper) | ||
.ThrowOnFailure(); | ||
|
||
var dwCount = (uint)aszPaths.Length; | ||
|
||
fixed (ITEMIDLIST** idList = new ITEMIDLIST*[dwCount]) | ||
{ | ||
for (uint dwIndex = 0u; dwIndex < dwCount; dwIndex++) | ||
{ | ||
var id = PInvoke.ILCreateFromPath(aszPaths[dwIndex]); | ||
idList[dwIndex] = id; | ||
} | ||
|
||
// Get shell item array from images to use for slideshow | ||
PInvoke.SHCreateShellItemArrayFromIDLists(dwCount, idList, out var shellItemArray); | ||
|
||
// Set slideshow | ||
desktopWallpaper.SetSlideshow(shellItemArray); | ||
} | ||
|
||
// Set wallpaper to fill desktop. | ||
desktopWallpaper.SetPosition(DESKTOP_WALLPAPER_POSITION.DWPOS_FILL); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public async Task SetLockScreenWallpaper(string szPath) | ||
{ | ||
IStorageFile sourceFile = await StorageFile.GetFileFromPathAsync(szPath); | ||
await LockScreen.SetImageFileAsync(sourceFile); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.