Skip to content

Commit

Permalink
Fix "Always on top" option not taking effect correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
rampaa committed Dec 30, 2022
1 parent cc6f29e commit c39dad8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions JL.Windows/ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ public void ApplyPreferences()
Precaching = GetValueFromConfig(Precaching, nameof(Precaching), bool.TryParse);
CheckForJLUpdatesOnStartUp = GetValueFromConfig(CheckForJLUpdatesOnStartUp, nameof(CheckForJLUpdatesOnStartUp), bool.TryParse);
AlwaysOnTop = GetValueFromConfig(AlwaysOnTop, nameof(AlwaysOnTop), bool.TryParse);
mainWindow.Topmost = AlwaysOnTop;

RequireLookupKeyPress = GetValueFromConfig(RequireLookupKeyPress, nameof(RequireLookupKeyPress), bool.TryParse);
DisableHotkeys = GetValueFromConfig(DisableHotkeys, nameof(DisableHotkeys), bool.TryParse);
Focusable = GetValueFromConfig(Focusable, nameof(Focusable), bool.TryParse);
Expand All @@ -193,8 +195,6 @@ public void ApplyPreferences()
DisableLookupsForNonJapaneseCharsInMainWindow = GetValueFromConfig(DisableLookupsForNonJapaneseCharsInMainWindow, nameof(DisableLookupsForNonJapaneseCharsInMainWindow), bool.TryParse);
MainWindowDynamicHeight = GetValueFromConfig(MainWindowDynamicHeight, nameof(MainWindowDynamicHeight), bool.TryParse);
MainWindowDynamicWidth = GetValueFromConfig(MainWindowDynamicWidth, nameof(MainWindowDynamicWidth), bool.TryParse);
TextBoxIsReadOnly = GetValueFromConfig(TextBoxIsReadOnly, nameof(TextBoxIsReadOnly), bool.TryParse);
TextBoxIsReadOnly = GetValueFromConfig(TextBoxIsReadOnly, nameof(TextBoxIsReadOnly), bool.TryParse);
PopupDynamicHeight = GetValueFromConfig(PopupDynamicHeight, nameof(PopupDynamicHeight), bool.TryParse);
PopupDynamicWidth = GetValueFromConfig(PopupDynamicWidth, nameof(PopupDynamicWidth), bool.TryParse);

Expand Down Expand Up @@ -611,10 +611,21 @@ public void LoadPreferences(PreferencesWindow preferenceWindow)
preferenceWindow.MainWindowFontComboBox.SelectedIndex = s_japaneseFonts.FindIndex(f =>
f.Content.ToString() == mainWindow.MainTextBox.FontFamily.Source);

if (preferenceWindow.MainWindowFontComboBox.SelectedIndex == -1)
{
preferenceWindow.MainWindowFontComboBox.SelectedIndex = 0;
}


preferenceWindow.PopupFontComboBox.ItemsSource = s_popupJapaneseFonts;
preferenceWindow.PopupFontComboBox.SelectedIndex =
s_popupJapaneseFonts.FindIndex(f => f.Content.ToString() == PopupFont.Source);

if (preferenceWindow.PopupFontComboBox.SelectedIndex == -1)
{
preferenceWindow.PopupFontComboBox.SelectedIndex = 0;
}

preferenceWindow.PopupMaxHeightNumericUpDown.Maximum = WindowsUtils.ActiveScreen.Bounds.Height;
preferenceWindow.PopupMaxWidthNumericUpDown.Maximum = WindowsUtils.ActiveScreen.Bounds.Width;

Expand Down
2 changes: 1 addition & 1 deletion JL.Windows/GUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ private void DisplaySettingsChanged(object? sender, EventArgs? e)
private void Window_DpiChanged(object sender, DpiChangedEventArgs e)
{
WindowsUtils.Dpi = e.NewDpi;
WindowsUtils.ActiveScreen = System.Windows.Forms.Screen.FromHandle(new WindowInteropHelper(this).Handle);
WindowsUtils.ActiveScreen = System.Windows.Forms.Screen.FromHandle(WindowHandle);
WindowsUtils.DpiAwareWorkAreaWidth = WindowsUtils.ActiveScreen.Bounds.Width / e.NewDpi.DpiScaleX;
WindowsUtils.DpiAwareWorkAreaHeight = WindowsUtils.ActiveScreen.Bounds.Height / e.NewDpi.DpiScaleY;
WindowsUtils.DpiAwareXOffset = ConfigManager.PopupXOffset / e.NewDpi.DpiScaleX;
Expand Down

0 comments on commit c39dad8

Please sign in to comment.