Skip to content

Commit

Permalink
Update ViewerWindow.xaml.cs
Browse files Browse the repository at this point in the history
Keep window non-focusable. Feature added on this commit:
QL-Win@a7115f6
But removed for some issue discussed here:
QL-Win#644
  • Loading branch information
simioni authored May 22, 2020
1 parent a7115f6 commit 0cd354f
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion QuickLook/ViewerWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Animation;
using QuickLook.Common.ExtensionMethods;
using QuickLook.Common.Helpers;
Expand Down Expand Up @@ -54,6 +56,12 @@ internal ViewerWindow()
SizeChanged += SaveWindowSizeOnSizeChanged;

StateChanged += (sender, e) => _ignoreNextWindowSizeChange = true;

// bring the window to top when users click in the client area.
// the non-client area is handled by the WndProc inside OnSourceInitialized().
// This is buggy for Windows 7 and 8: https://github.com/QL-Win/QuickLook/issues/644#issuecomment-628921704
if (App.IsWin10)
PreviewMouseDown += (sender, e) => this.BringToFront(false);

windowFrameContainer.PreviewMouseMove += ShowWindowCaptionContainer;

Expand Down Expand Up @@ -97,6 +105,32 @@ internal ViewerWindow()
buttonShare.Click += (sender, e) => ShareHelper.Share(_path, this);
buttonOpenWith.Click += (sender, e) => ShareHelper.Share(_path, this, true);
}

// bring the window to top when users click in the non-client area.
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);

// The non-focusable trick is buggy for Windows 7 and 8
// https://github.com/QL-Win/QuickLook/issues/644#issuecomment-628921704
if (App.IsWin10)
{
this.SetNoactivate();

HwndSource.FromHwnd(new WindowInteropHelper(this).Handle)?.AddHook(
(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) =>
{
switch (msg)
{
case 0x0112: // WM_SYSCOMMAND
this.BringToFront(false);
break;
}

return IntPtr.Zero;
});
}
}

public override void OnApplyTemplate()
{
Expand Down Expand Up @@ -148,4 +182,4 @@ private void AutoHideCaptionContainer(object sender, EventArgs e)
hide.Begin();
}
}
}
}

0 comments on commit 0cd354f

Please # to comment.