Skip to content
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

Improve wallpaper support #51

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions source/SylphyHorn.Core/Serialization/GeneralSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public GeneralSettings(ISerializationProvider provider)

public SerializableProperty<string> Culture => this.Cache(key => new SerializableProperty<string>(key, this._provider));

public SerializableProperty<byte> Position => this.Cache(key => new SerializableProperty<byte>(key, this._provider, 4 /* Fill */));

public SerializableProperty<uint> Placement => this.Cache(key => new SerializableProperty<uint>(key, this._provider, 5 /* Center */));

public SerializableProperty<uint> Display => this.Cache(key => new SerializableProperty<uint>(key, this._provider, 0));
Expand Down
2 changes: 2 additions & 0 deletions source/SylphyHorn/Application.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="http://schemes.grabacr.net/winfx/2015/personal/converters"
xmlns:converters2="clr-namespace:SylphyHorn.UI.Converters"
xmlns:controls="clr-namespace:SylphyHorn.UI.Controls">
<Application.Resources>
<ResourceDictionary>
Expand All @@ -21,6 +22,7 @@
<converters:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
<converters:ReverseBooleanConverter x:Key="ReverseBooleanConverter" />
<converters:EnumToBooleanConverter x:Key="EnumToBooleanConverter" />
<converters2:ArrayToStringConverter x:Key="ArrayToStringConverter" />
<controls:UnlockImageConverter x:Key="UnlockImageConverter" />
</ResourceDictionary>
</Application.Resources>
Expand Down
65 changes: 64 additions & 1 deletion source/SylphyHorn/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 22 additions & 1 deletion source/SylphyHorn/Properties/Resources.ja.resx
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,32 @@
<value>デスクトップの背景</value>
</data>
<data name="Settings_Background_Note1" xml:space="preserve">
<value>サポートされている画像形式: JPG, PNG, BMP</value>
<value>サポートされている画像形式:</value>
</data>
<data name="Settings_Background_Note2" xml:space="preserve">
<value>メモ: 仮想デスクトップ番号をファイル名とした画像ファイルを用意してください (例: "1.png", "2.png", ...)。</value>
</data>
<data name="Settings_Background_Position" xml:space="preserve">
<value>既定の配置方法を選ぶ</value>
</data>
<data name="Settings_Background_Position_Center" xml:space="preserve">
<value>中央に表示</value>
</data>
<data name="Settings_Background_Position_Fill" xml:space="preserve">
<value>画面のサイズに合わせる</value>
</data>
<data name="Settings_Background_Position_Fit" xml:space="preserve">
<value>ページ幅に合わせる</value>
</data>
<data name="Settings_Background_Position_Span" xml:space="preserve">
<value>スパン</value>
</data>
<data name="Settings_Background_Position_Stretch" xml:space="preserve">
<value>拡大して表示</value>
</data>
<data name="Settings_Background_Position_Tile" xml:space="preserve">
<value>並べて表示</value>
</data>
<data name="Settings_Background_SelectionDialog" xml:space="preserve">
<value>背景画像フォルダーを選択</value>
</data>
Expand Down
23 changes: 22 additions & 1 deletion source/SylphyHorn/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,32 @@
<value>Desktop background</value>
</data>
<data name="Settings_Background_Note1" xml:space="preserve">
<value>Supported image formats: JPEG, PNG, BMP</value>
<value>Supported image formats:</value>
</data>
<data name="Settings_Background_Note2" xml:space="preserve">
<value>Note: Please prepare image files with the virtual desktop number as filename (e.g. "1.png", "2.png", ...).</value>
</data>
<data name="Settings_Background_Position" xml:space="preserve">
<value>Choose a default position</value>
</data>
<data name="Settings_Background_Position_Center" xml:space="preserve">
<value>Center</value>
</data>
<data name="Settings_Background_Position_Fill" xml:space="preserve">
<value>Fill</value>
</data>
<data name="Settings_Background_Position_Fit" xml:space="preserve">
<value>Fit</value>
</data>
<data name="Settings_Background_Position_Span" xml:space="preserve">
<value>Span</value>
</data>
<data name="Settings_Background_Position_Stretch" xml:space="preserve">
<value>Stretch</value>
</data>
<data name="Settings_Background_Position_Tile" xml:space="preserve">
<value>Tile</value>
</data>
<data name="Settings_Background_SelectionDialog" xml:space="preserve">
<value>Select Background Images Folder</value>
</data>
Expand Down
49 changes: 49 additions & 0 deletions source/SylphyHorn/Services/ImageFormatSupportDetector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Linq;
using System.Runtime.InteropServices;
using WindowsDesktop.Interop;

namespace SylphyHorn.Services
{
public abstract class ImageFormatSupportDetector
{
private bool? _isSupported = null;

public bool IsSupported
{
get
{
if (!this._isSupported.HasValue)
{
this._isSupported = this.GetValue();
}
return this._isSupported.Value;
}
}

public abstract string[] Extensions { get; }

public abstract string FileType { get; }

public abstract bool GetValue();
}

public abstract class ClsidImageFormatSupportDetector : ImageFormatSupportDetector
{
public abstract Guid CLSID { get; }

public override bool GetValue()
{
try
{
var decoderType = Type.GetTypeFromCLSID(this.CLSID);
var decoder = Activator.CreateInstance(decoderType);
return true;
}
catch (COMException ex) when (ex.Match(HResult.REGDB_E_CLASSNOTREG))
{
return false;
}
}
}
}
163 changes: 163 additions & 0 deletions source/SylphyHorn/Services/ImageFormatSupportDetectors.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
using Microsoft.Win32;
using System;
using System.Collections.ObjectModel;
using System.Linq;

namespace SylphyHorn.Services
{
public sealed class JpegXrSupportDetector : ClsidImageFormatSupportDetector
{
public override string[] Extensions => new string[] { ".wdp", ".jxr" };

public override string FileType => "JPEG XR";

public override Guid CLSID => new Guid(0xa26cec36, 0x234c, 0x4950, 0xae, 0x16, 0xe3, 0x4a, 0xac, 0xe7, 0x1d, 0x0d);
}

public sealed class WebPSupportDetector : ClsidImageFormatSupportDetector
{
public override string[] Extensions => new string[] { ".webp" };

public override string FileType => "WebP";

public override Guid CLSID => new Guid(0x7693e886, 0x51c9, 0x4070, 0x84, 0x19, 0x9f, 0x70, 0x73, 0x8e, 0xc8, 0xfa);
}

public sealed class HEIFSupportDetector : ClsidImageFormatSupportDetector
{
private bool? _isHIFExtensionSupported;

public bool IsHIFExtensionSupported
{
get
{
if (!this._isHIFExtensionSupported.HasValue)
{
if (Environment.OSVersion.Version.Build >= 21301)
{
this._isHIFExtensionSupported = true;
}
else if (Environment.OSVersion.Version.Build >= 19041)
{
const string targetHootfixId = "KB5003214";
const string query = "SELECT HotFixID FROM Win32_QuickFixEngineering";

bool supported = false;
var searcher = new System.Management.ManagementObjectSearcher(query);
foreach (var hotfix in searcher.Get())
{
if (hotfix["HotFixID"].ToString() == targetHootfixId)
{
supported = true;
break;
}
}
this._isHIFExtensionSupported = supported;
}
else
{
this._isHIFExtensionSupported = false;
}
}
return this._isHIFExtensionSupported.Value;
}
}

private bool? _isHEVCSupported;

public bool IsHEVCSupported
{
get
{
if (!this._isHEVCSupported.HasValue)
{
const string targetKeyName = "Microsoft.HEVCVideoExtension_";

this._isHEVCSupported = Registry.ClassesRoot
.OpenSubKey("ActivatableClasses")
.OpenSubKey("Package")
.GetSubKeyNames()
.Any(name => name.StartsWith(targetKeyName));
}
return this._isHEVCSupported.Value;
}
}

private bool? _isAV1Supported;

public bool IsAV1Supported
{
get
{
if (!this._isAV1Supported.HasValue)
{
const string targetKeyName = "Microsoft.AV1VideoExtension_";

this._isAV1Supported = Registry.ClassesRoot
.OpenSubKey("ActivatableClasses")
.OpenSubKey("Package")
.GetSubKeyNames()
.Any(name => name.StartsWith(targetKeyName));
}
return this._isAV1Supported.Value;
}
}

private bool? _isAVIFSupported;

public bool IsAVIFSupported
{
get
{
if (!this._isAVIFSupported.HasValue)
{
this._isAVIFSupported = Environment.OSVersion.Version.Build >= 18305 && this.IsAV1Supported;
}
return this._isAVIFSupported.Value;
}
}

public override string[] Extensions
{
get
{
var extensions = new Collection<string>();
if (this.IsHIFExtensionSupported)
{
extensions.Add(".hif");
}
extensions.Add(".heif");
extensions.Add(".heifs");
extensions.Add(".avci");
extensions.Add(".avcs");
if (this.IsHEVCSupported)
{
extensions.Add(".heic");
extensions.Add(".heics");
}
if (this.IsAVIFSupported)
{
extensions.Add(".avif");
extensions.Add(".avifs");
}
return extensions.ToArray();
}
}

public override string FileType
{
get
{
return this.IsAVIFSupported
? this.IsHEVCSupported
? "HEIF (AVCI, HEIC, AVIF)"
: "HEIF (AVCI, AVIF)"
: this.IsHEVCSupported
? "HEIF (AVCI, HEIC)"
: "HEIF (AVCI)";
}
}

public override Guid CLSID => new Guid(0xe9a4a80a, 0x44fe, 0x4de4, 0x89, 0x71, 0x71, 0x50, 0xb1, 0x0a, 0x51, 0x99);
}
}
Loading