-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Code Quality: Introduced IWindowsWallpaperService #15811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
yaira2
merged 5 commits into
files-community:main
from
0x5bfa:5bfa/CQ-IWindowsWallpaperService
Jul 21, 2024
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
48f3173
Init
0x5bfa efbf042
fix
0x5bfa 406a43e
Update src/Files.App/Data/Contracts/IWindowsWallpaperService.cs
yaira2 71c4191
Update src/Files.App/Actions/Content/Background/SetAsWallpaperBackgro…
0x5bfa 8627d24
Update src/Files.App/Actions/Content/Background/SetAsWallpaperBackgro…
0x5bfa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 use to set as wallpaper.</param> | ||
yaira2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.