Skip to content

Commit

Permalink
fix QT position (#330)
Browse files Browse the repository at this point in the history
* revise QT position from top and not overlap windows task bar

* add taskbar position check on left or right

* revise the position start from bottom, and remove task bar height
  • Loading branch information
joshuatam authored Jul 2, 2024
1 parent df8172a commit 7cae1f2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
5 changes: 3 additions & 2 deletions HandheldCompanion/Views/Windows/OverlayQuickTools.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
xmlns:l="clr-namespace:HandheldCompanion.Localization"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
xmlns:resx="clr-namespace:HandheldCompanion.Properties"
Title="QuickTools"
Width="450"
MinWidth="450"
MaxWidth="960"
MaxHeight="960"
Margin="12"
Margin="0"
ui:ThemeManager.IsThemeAware="True"
ui:TitleBar.ExtendViewIntoTitleBar="True"
ui:WindowHelper.SystemBackdropType="Mica"
Expand All @@ -24,7 +25,7 @@
ResizeMode="NoResize"
ShowActivated="False"
ShowInTaskbar="False"
Topmost="False"
Topmost="True"
WindowStyle="ToolWindow"
mc:Ignorable="d">

Expand Down
24 changes: 13 additions & 11 deletions HandheldCompanion/Views/Windows/OverlayQuickTools.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ private void SystemManager_DisplaySettingsChanged(DesktopScreen desktopScreen, S
UpdateLocation();
}

private const double _MaxWidth = 960;
private const double _Margin = 12;
private const double _MaxHeight = 960;
private const double _MaxWidth = 960;
private const WindowStyle _Style = WindowStyle.ToolWindow;

private void UpdateLocation()
Expand All @@ -170,40 +171,41 @@ private void UpdateLocation()
DesktopScreen friendlyScreen = MultimediaManager.AllScreens.Values.FirstOrDefault(a => a.FriendlyName.Equals(FriendlyName)) ?? MultimediaManager.PrimaryDesktop;

// Find the corresponding Screen object
Screen targerScreen = Screen.AllScreens.FirstOrDefault(screen => screen.DeviceName.Equals(friendlyScreen.screen.DeviceName));
Screen targetScreen = Screen.AllScreens.FirstOrDefault(screen => screen.DeviceName.Equals(friendlyScreen.screen.DeviceName));

// UI thread
Application.Current.Dispatcher.Invoke(() =>
{
// Common settings across cases 0 and 1
MaxWidth = (int)Math.Min(_MaxWidth, targerScreen.WpfBounds.Width);
MaxHeight = _MaxHeight;
MaxWidth = (int)Math.Min(_MaxWidth, targetScreen.WpfBounds.Width);
Width = (int)Math.Max(MinWidth, SettingsManager.GetDouble("QuickToolsWidth"));
MaxHeight = Math.Min(targetScreen.WpfBounds.Height - _Margin * 2, _MaxHeight);
Height = MinHeight = MaxHeight;
WindowStyle = _Style;

switch (QuickToolsLocation)
{
case 0: // Left
this.SetWindowPosition(WindowPositions.BottomLeft, targerScreen);
Left += Margin.Left;
this.SetWindowPosition(WindowPositions.BottomLeft, targetScreen);
Left += _Margin;
break;

case 1: // Right
this.SetWindowPosition(WindowPositions.BottomRight, targerScreen);
Left -= Margin.Right;
this.SetWindowPosition(WindowPositions.BottomRight, targetScreen);
Left -= _Margin;
break;

case 2: // Maximized
Top = 0;
MaxWidth = double.PositiveInfinity;
MaxHeight = double.PositiveInfinity;
WindowStyle = WindowStyle.None;
this.SetWindowPosition(WindowPositions.Maximize, targerScreen);
this.SetWindowPosition(WindowPositions.Maximize, targetScreen);
return; // Early return for case 2
}

// Common operation for case 0 and 1 after switch
Top -= Margin.Top;
Height = MinHeight = Math.Min(MaxHeight, targerScreen.WpfBounds.Height - Margin.Top - Margin.Bottom);
Top = targetScreen.WpfBounds.Bottom - Height - _Margin;
});
}

Expand Down

0 comments on commit 7cae1f2

Please sign in to comment.