Skip to content

Commit

Permalink
Make "text only visible on hover" option act more like invisible mode
Browse files Browse the repository at this point in the history
  • Loading branch information
rampaa committed Jun 23, 2022
1 parent 251bdc6 commit 2c33efb
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 48 deletions.
4 changes: 2 additions & 2 deletions JL.Windows/ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ public void ApplyPreferences()
WindowsUtils.Try(() => TextOnlyVisibleOnHover =
bool.Parse(ConfigurationManager.AppSettings.Get("TextOnlyVisibleOnHover")!),
TextOnlyVisibleOnHover, "TextOnlyVisibleOnHover");
mainWindow.MainTextBox.Opacity = TextOnlyVisibleOnHover ? 0 : 1;
mainWindow.MainGrid.Opacity = TextOnlyVisibleOnHover && !mainWindow.IsMouseOver ? 0 : 1;

WindowsUtils.Try(() => ChangeMainWindowBackgroundOpacityOnUnhover =
bool.Parse(ConfigurationManager.AppSettings.Get("ChangeMainWindowBackgroundOpacityOnUnhover")!),
Expand All @@ -480,7 +480,7 @@ public void ApplyPreferences()
int.Parse(ConfigurationManager.AppSettings.Get("MainWindowBackgroundOpacityOnUnhover")!),
MainWindowBackgroundOpacityOnUnhover, "MainWindowBackgroundOpacityOnUnhover");

if (ChangeMainWindowBackgroundOpacityOnUnhover)
if (ChangeMainWindowBackgroundOpacityOnUnhover && !mainWindow.IsMouseOver)
{
mainWindow.Background.Opacity = MainWindowBackgroundOpacityOnUnhover / 100;
}
Expand Down
2 changes: 1 addition & 1 deletion JL.Windows/GUI/AddNameWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
x:Class="JL.Windows.GUI.AddNameWindow"
mc:Ignorable="d"
Title="Add Name" Height="350" Width="400" Topmost="True" SizeToContent="Height" ResizeMode="NoResize"
MaxHeight="600" WindowStyle="SingleBorderWindow" Loaded="Window_Loaded" ShowInTaskbar="False">
MaxHeight="600" WindowStyle="SingleBorderWindow" Loaded="Window_Loaded" ShowInTaskbar="False" Closed="Window_Closed">

<ScrollViewer>
<Grid Background="Black">
Expand Down
19 changes: 19 additions & 0 deletions JL.Windows/GUI/AddNameWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,23 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
{
OtherRadioButton!.IsChecked = true;
}

private void Window_Closed(object sender, EventArgs e)
{
MainWindow mainWindow = MainWindow.Instance;
mainWindow.Focus();

if (!mainWindow.IsMouseOver)
{
if (ConfigManager.TextOnlyVisibleOnHover)
{
mainWindow.MainGrid.Opacity = 0;
}

if (ConfigManager.ChangeMainWindowBackgroundOpacityOnUnhover)
{
mainWindow.Background.Opacity = ConfigManager.MainWindowBackgroundOpacityOnUnhover / 100;
}
}
}
}
2 changes: 1 addition & 1 deletion JL.Windows/GUI/AddWordWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="Add Word" Height="450" ResizeMode="NoResize" Width="457" SizeToContent="Height" MaxHeight="600"
Topmost="True" Loaded="Window_Loaded" ShowInTaskbar="False">
Topmost="True" Loaded="Window_Loaded" ShowInTaskbar="False" Closed="Window_Closed">
<ScrollViewer>
<Grid Background="Black">
<StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" Margin="20,20,20,20">
Expand Down
19 changes: 19 additions & 0 deletions JL.Windows/GUI/AddWordWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,23 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
{
OtherRadioButton!.IsChecked = true;
}

private void Window_Closed(object sender, EventArgs e)
{
MainWindow mainWindow = MainWindow.Instance;
mainWindow.Focus();

if (!mainWindow.IsMouseOver)
{
if (ConfigManager.TextOnlyVisibleOnHover)
{
mainWindow.MainGrid.Opacity = 0;
}

if (ConfigManager.ChangeMainWindowBackgroundOpacityOnUnhover)
{
mainWindow.Background.Opacity = ConfigManager.MainWindowBackgroundOpacityOnUnhover / 100;
}
}
}
}
4 changes: 2 additions & 2 deletions JL.Windows/GUI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
mc:Ignorable="d" Height="269" Width="800" WindowStyle="None" ResizeMode="NoResize" Topmost="True"
Closed="MainWindow_Closed" Closing="MainWindow_Closing" KeyDown="MainWindow_KeyDown"
PreviewKeyDown="MainWindow_PreviewKeyDown" SizeChanged="MainWindow_SizeChanged"
PreviewMouseDown="Window_PreviewMouseDown" DpiChanged="Window_DpiChanged" PreviewMouseLeftButtonDown="Window_PreviewMouseLeftButtonDown" Deactivated="Window_Deactivated" Activated="Window_Activated">
PreviewMouseDown="Window_PreviewMouseDown" DpiChanged="Window_DpiChanged" PreviewMouseLeftButtonDown="Window_PreviewMouseLeftButtonDown" Deactivated="Window_Deactivated" Activated="Window_Activated" MouseLeave="Window_MouseLeave" MouseEnter="Window_MouseEnter">
<Window.Background>
<SolidColorBrush Color="Black" Opacity="0.3" />
</Window.Background>
Expand All @@ -31,7 +31,7 @@
VerticalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="True"
MouseLeave="MainTextBox_MouseLeave" MouseWheel="MainTextBox_MouseWheel" Cursor="Arrow"
FlowDirection="LeftToRight" IsInactiveSelectionHighlightEnabled="True" IsUndoEnabled="False"
PreviewMouseLeftButtonUp="MainTextBox_PreviewMouseLeftButtonUp" MinWidth="100" MinHeight="100" MouseEnter="MainTextBox_MouseEnter" ContextMenuOpening="MainTextBox_ContextMenuOpening">
PreviewMouseLeftButtonUp="MainTextBox_PreviewMouseLeftButtonUp" MinWidth="100" MinHeight="100" ContextMenuOpening="MainTextBox_ContextMenuOpening">

<TextBox.ContextMenu>
<ContextMenu Name="MainTextboxContextMenu">
Expand Down
90 changes: 56 additions & 34 deletions JL.Windows/GUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,24 +300,6 @@ private void Button_MouseEnter(object sender, MouseEventArgs e)

private void MainTextBox_MouseLeave(object sender, MouseEventArgs e)
{
if (ConfigManager.TextOnlyVisibleOnHover
&& !FirstPopupWindow.IsVisible
&& !ManageDictionariesWindow.Instance.IsVisible
&& !ManageFrequenciesWindow.Instance.IsVisible
&& !AddNameWindow.Instance.IsVisible
&& !AddWordWindow.Instance.IsVisible
&& !PreferencesWindow.Instance.IsVisible
&& !StatsWindow.Instance.IsVisible
&& !MainTextboxContextMenu.IsVisible)
{
MainTextBox.Opacity = 0;
}

if (ConfigManager.ChangeMainWindowBackgroundOpacityOnUnhover)
{
Background.Opacity = ConfigManager.MainWindowBackgroundOpacityOnUnhover / 100;
}

if (FirstPopupWindow.MiningMode || ConfigManager.LookupOnSelectOnly || ConfigManager.FixedPopupPositioning || (FirstPopupWindow.UnavoidableMouseEnter && FirstPopupWindow.IsMouseOver))
return;

Expand All @@ -330,19 +312,6 @@ private void MainTextBox_MouseLeave(object sender, MouseEventArgs e)
}
}

private void MainTextBox_MouseEnter(object sender, MouseEventArgs e)
{
if (ConfigManager.TextOnlyVisibleOnHover)
{
MainTextBox.Opacity = 1;
}

if (ConfigManager.ChangeMainWindowBackgroundOpacityOnUnhover)
{
Background.Opacity = OpacitySlider.Value / 100;
}
}

private void Button_MouseLeave(object sender, MouseEventArgs e)
{
((TextBlock)sender).Foreground = Brushes.White;
Expand Down Expand Up @@ -507,12 +476,12 @@ private void MainWindow_KeyDown(object sender, KeyEventArgs e)

if (ConfigManager.TextOnlyVisibleOnHover)
{
MainTextBox.Opacity = MainTextBox.IsMouseOver ? 1 : 0;
MainGrid.Opacity = IsMouseOver ? 1 : 0;
}

else
{
MainTextBox.Opacity = 1;
MainGrid.Opacity = 1;
}
}
}
Expand Down Expand Up @@ -731,6 +700,10 @@ private void Window_PreviewMouseLeftButtonDown(object sender, MouseButtonEventAr

private void Border_OnMouseEnter(object sender, MouseEventArgs e)
{
// For some reason, when DragMove() is used Mouse.GetPosition() returns Point(0, 0)
if (e.GetPosition(this) == new Point(0, 0))
return;

var border = (Border)sender;

switch (border.Name)
Expand Down Expand Up @@ -792,7 +765,19 @@ public bool IsMouseOnTitleBar(int lParam)
int y = lParam >> 16;
Point cursorPoint = PointFromScreen(new Point(x, y));

HitTestResult? hitTestResult = VisualTreeHelper.HitTest(MainGrid!, cursorPoint);
HitTestResult? hitTestResult = VisualTreeHelper.HitTest(this, cursorPoint);

if (hitTestResult != null)
{
return hitTestResult.VisualHit == TitleBar;
}

return false;
}

public bool IsMouseOnTitleBar(Point cursorPoint)
{
HitTestResult? hitTestResult = VisualTreeHelper.HitTest(this, cursorPoint);

if (hitTestResult != null)
{
Expand All @@ -804,6 +789,11 @@ public bool IsMouseOnTitleBar(int lParam)

private void TitleBar_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
DragMove();
}

LeftPositionBeforeResolutionChange = Left;
TopPositionBeforeResolutionChange = Top;
}
Expand Down Expand Up @@ -832,4 +822,36 @@ private void MainTextBox_ContextMenuOpening(object sender, ContextMenuEventArgs
AddNameButton!.IsEnabled = Storage.DictsReady;
AddWordButton!.IsEnabled = Storage.DictsReady;
}

private void Window_MouseLeave(object sender, MouseEventArgs e)
{
if (!FirstPopupWindow.IsVisible
&& !AddNameWindow.Instance.IsVisible
&& !AddWordWindow.Instance.IsVisible
&& !MainTextboxContextMenu.IsVisible)
{
if (ConfigManager.TextOnlyVisibleOnHover)
{
MainGrid.Opacity = 0;
}

if (ConfigManager.ChangeMainWindowBackgroundOpacityOnUnhover)
{
Background.Opacity = ConfigManager.MainWindowBackgroundOpacityOnUnhover / 100;
}
}
}

private void Window_MouseEnter(object sender, MouseEventArgs e)
{
if (ConfigManager.TextOnlyVisibleOnHover)
{
MainGrid.Opacity = 1;
}

if (ConfigManager.ChangeMainWindowBackgroundOpacityOnUnhover)
{
Background.Opacity = OpacitySlider.Value / 100;
}
}
}
15 changes: 7 additions & 8 deletions JL.Windows/WinApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interop;
using JL.Windows.GUI;

namespace JL.Windows;

Expand Down Expand Up @@ -161,13 +160,13 @@ private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref b
handled = true;
return (IntPtr)1;

case NativeMethods.WM_NCHITTEST:
if (MainWindow.Instance.IsMouseOnTitleBar(lParam.ToInt32()))
{
handled = true;
return (IntPtr)2; // HTCAPTION
}
break;
//case NativeMethods.WM_NCHITTEST:
// if (MainWindow.Instance.IsMouseOnTitleBar(lParam.ToInt32()))
// {
// handled = true;
// return (IntPtr)2; // HTCAPTION
// }
// break;
}

return IntPtr.Zero;
Expand Down

0 comments on commit 2c33efb

Please sign in to comment.