Skip to content

Commit

Permalink
Add blured-fit functionality to UI and core
Browse files Browse the repository at this point in the history
  • Loading branch information
goodtrailer committed Apr 29, 2021
1 parent 910a454 commit 03a67af
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 19 deletions.
58 changes: 52 additions & 6 deletions DailyDesktop.Core/DailyDesktopCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ public class DailyDesktopCore
private const string TASK_NAME_PREFIX = "Daily Desktop";
private const string TASK_EXECUTABLE = "DailyDesktop.Task.exe";
private const string DEFAULT_UPDATE_TIME = "12:00 AM";
private const int DEFAULT_BLUR_STRENGTH = 40;

private readonly ProviderStore store;
private readonly Task task;

private bool enabled;
private bool doBlurredFit;
private int blurStrength;
private IProvider currentProvider;
private DateTime updateTime;

Expand All @@ -40,6 +43,26 @@ public bool Enabled
}
}

public bool DoBlurredFit
{
get => doBlurredFit;
set
{
doBlurredFit = value;
updateTask();
}
}

public int BlurStrength
{
get => blurStrength;
set
{
blurStrength = value;
updateTask();
}
}

public IProvider CurrentProvider
{
get => currentProvider;
Expand Down Expand Up @@ -105,6 +128,17 @@ private ExecAction execAction
}
}

private string[] execArguments
{
get => execAction.Arguments?.Split(" ");
set
{
execAction.Arguments = string.Join(" ", value);
}
}

private int execArgumentsCount => execArguments?.Length ?? 0;

//-----------------------------------------------------------------METHODS

public DailyDesktopCore()
Expand Down Expand Up @@ -144,24 +178,34 @@ public DailyDesktopCore()
};
taskDefinition.Actions.Add(newExecAction);

#if (!DEBUG)
taskDefinition.Settings.Hidden = true;
#endif

task = TaskService.Instance.RootFolder.RegisterTaskDefinition(taskName, taskDefinition);
currentProvider = null;
}
else
{
string key = execAction.Arguments;
string key = (execArgumentsCount < 1) ? null : execArguments[0];

if (key != null && store.Providers.ContainsKey(key))
store.Providers.TryGetValue(key, out currentProvider);
else
currentProvider = null;

execAction.Path = taskExecutablePath;
task.RegisterChanges();
}

updateTime = dailyTrigger.StartBoundary;
enabled = dailyTrigger.Enabled;
updateTime = dailyTrigger.StartBoundary;

if (execArgumentsCount >= 2 && int.TryParse(execArguments[1], out blurStrength))
{
doBlurredFit = true;
} else
{
doBlurredFit = false;
blurStrength = DEFAULT_BLUR_STRENGTH;
}
}

public void UpdateWallpaper()
Expand All @@ -172,7 +216,9 @@ public void UpdateWallpaper()
private void updateTask()
{
dailyTrigger.StartBoundary = updateTime;
execAction.Arguments = currentProvider?.Key ?? string.Empty;
string key = currentProvider?.Key ?? string.Empty;
string blur = doBlurredFit ? blurStrength.ToString() : string.Empty;
execArguments = new string[] { key, blur };
dailyTrigger.Enabled = enabled;
logonTrigger.Enabled = enabled;
task.RegisterChanges();
Expand Down
14 changes: 6 additions & 8 deletions DailyDesktop.Desktop/MainForm.Designer.cs

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

12 changes: 12 additions & 0 deletions DailyDesktop.Desktop/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ private void MainForm_Load(object sender, EventArgs e)

enabledCheckBox.Checked = core.Enabled;
updateTimePicker.Value = core.UpdateTime;
updateTimePicker.Enabled = enabledCheckBox.Checked;
blurredFitCheckBox.Checked = core.DoBlurredFit;
blurStrengthTrackBar.Value = core.BlurStrength;
blurStrengthTrackBar.Enabled = blurredFitCheckBox.Checked;
updateBlurStrengthToolTip();
}

Expand Down Expand Up @@ -72,6 +76,7 @@ private void updateTimePicker_ValueChanged(object sender, EventArgs e)
private void enabledCheckBox_CheckedChanged(object sender, EventArgs e)
{
core.Enabled = enabledCheckBox.Checked;
updateTimePicker.Enabled = enabledCheckBox.Checked;
}

private void updateWallpaperButton_Click(object sender, EventArgs e)
Expand All @@ -96,6 +101,7 @@ private void okButton_Click(object sender, EventArgs e)

private void blurStrengthTrackBar_Scroll(object sender, EventArgs e)
{
core.BlurStrength = blurStrengthTrackBar.Value;
updateBlurStrengthToolTip();
}

Expand All @@ -104,5 +110,11 @@ private void updateBlurStrengthToolTip()
string strength = (blurStrengthTrackBar.Value / 100f).ToString("0.00");
mainToolTip.SetToolTip(blurStrengthTrackBar, strength);
}

private void blurredFitCheckBox_CheckedChanged(object sender, EventArgs e)
{
core.DoBlurredFit = blurredFitCheckBox.Checked;
blurStrengthTrackBar.Enabled = blurredFitCheckBox.Checked;
}
}
}
12 changes: 12 additions & 0 deletions DailyDesktop.Desktop/MainForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="blurredFitCheckBox.ToolTip" xml:space="preserve">
<value>Sizes wallpaper to fit within the display's dimensions,
but the leftover background is filled with an enlarged
and blurred portion of the picture instead of a solid color.
This effect is only noticeable if the wallpaper's aspect
ratio is different from the primary display's aspect ratio.

If you want to change the official fit mode, the option
is in the Personalization settings in Windows, the same
as normal.
</value>
</data>
<assembly alias="System.Drawing.Common" name="System.Drawing.Common, Version=4.0.2.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" />
<data name="bannerPicture.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing.Common" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
Expand Down
10 changes: 5 additions & 5 deletions DailyDesktop.Task/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"profiles": {
"DailyDesktop.Task": {
"commandName": "Project"
}
"profiles": {
"DailyDesktop.Task": {
"commandName": "Project"
}
}
}
}

0 comments on commit 03a67af

Please sign in to comment.