Skip to content

Commit

Permalink
Change the preview taskbar to the actual position.
Browse files Browse the repository at this point in the history
  • Loading branch information
mntone committed Aug 11, 2020
1 parent 1dd0c11 commit fcc0f9c
Show file tree
Hide file tree
Showing 5 changed files with 334 additions and 57 deletions.
5 changes: 4 additions & 1 deletion source/SylphyHorn/Interop/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ public static class NativeMethods
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetMonitorInfo(IntPtr hMonitor, ref MONITORINFOEX lpmi);

[DllImport("user32.dll", SetLastError = true)]
[DllImport("user32.dll", ExactSpelling = true)]
public static extern IntPtr MonitorFromPoint(POINT pt, MonitorDefaultTo dwFlags);

[DllImport("user32.dll", ExactSpelling = true)]
public static extern IntPtr MonitorFromWindow(IntPtr hWnd, MonitorDefaultTo dwFlags);

[DllImport("User32.dll", ExactSpelling = true, CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool SetLayeredWindowAttributes(IntPtr hwnd, int crKey, byte bAlpha, LayeredWindowAttributes dwFlags);

Expand Down
16 changes: 16 additions & 0 deletions source/SylphyHorn/Services/MonitorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,20 @@ internal static class MonitorService

public static Monitor[] GetAreas() => GetMonitorsInternal();

public static Monitor GetPrimaryMonitor() => GetPrimaryMonitorInternal();

public static Monitor GetPrimaryArea() => GetPrimaryMonitorInternal();

public static Monitor GetCurrentMonitor() => GetCurrentMonitorInternal(true);

public static Monitor GetCurrentArea() => GetCurrentMonitorInternal();

public static IntPtr GetPrimaryHMonitor()
{
var hPrimaryMonitor = NativeMethods.MonitorFromWindow(IntPtr.Zero, MonitorDefaultTo.MONITOR_DEFAULTTOPRIMARY);
return hPrimaryMonitor;
}

public static IntPtr GetCurrentHMonitor()
{
POINT pt;
Expand Down Expand Up @@ -65,6 +75,12 @@ private static Monitor[] GetMonitorsInternal(bool additionalRetrive = false)
return list.ToArray();
}

private static Monitor GetPrimaryMonitorInternal(bool additionalRetrive = false)
{
var hPrimaryMonitor = GetPrimaryHMonitor();
return GetMonitorInternal(hPrimaryMonitor, additionalRetrive);
}

private static Monitor GetCurrentMonitorInternal(bool additionalRetrive = false)
{
var hWorkingMonitor = GetCurrentHMonitor();
Expand Down
33 changes: 33 additions & 0 deletions source/SylphyHorn/UI/Bindings/SettingsWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,26 @@ public WallpaperPosition PreviewBackgroundPosition

#endregion

#region PreviewTaskbarPosition notification property

private string _PreviewTaskbarPosition = "Bottom";

public string PreviewTaskbarPosition
{
get => this._PreviewTaskbarPosition;
set
{
if (this._PreviewTaskbarPosition != value)
{
this._PreviewTaskbarPosition = value;

this.RaisePropertyChanged();
}
}
}

#endregion

public Brush NotificationBackground => new SolidColorBrush(WindowsTheme.ColorPrevalence.Current
? ImmersiveColor.GetColorByTypeName(ImmersiveColorNames.SystemAccentDark1)
: ImmersiveColor.GetColorByTypeName(ImmersiveColorNames.DarkChromeMedium))
Expand Down Expand Up @@ -267,6 +287,7 @@ public SettingsWindowViewModel(HookService hookService)
this.PreviewBackgroundBrush = new SolidColorBrush(colAndWall.BackgroundColor);
this.PreviewBackgroundPath = colAndWall.Path;
this.PreviewBackgroundPosition = colAndWall.Position;
this.PreviewTaskbarPosition = GetTaskbarPosition();

this.Logs = ViewModelHelper.CreateReadOnlyDispatcherCollection(
LoggingService.Instance.Logs,
Expand Down Expand Up @@ -316,5 +337,17 @@ public void OpenBackgroundPathDialog()
Settings.General.DesktopBackgroundFolderPath.Value = message.Response;
}
}

private static string GetTaskbarPosition()
{
var workspace = MonitorService.GetPrimaryArea();
var monitorArea = workspace.MonitorArea;
var workArea = workspace.WorkArea;
if (monitorArea.Top < workArea.Top) return "Top";
if (monitorArea.Left < workArea.Left) return "Left";
if (monitorArea.Height > workArea.Height) return "Bottom";
if (monitorArea.Width > workArea.Width) return "Right";
return "AutoHide";
}
}
}
Loading

0 comments on commit fcc0f9c

Please sign in to comment.