Skip to content

Commit

Permalink
Fixed issue with positioning on monitors that are scaled
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Brogden committed Feb 26, 2022
1 parent 249d101 commit b3c5cb8
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 28 deletions.
13 changes: 13 additions & 0 deletions QuickVSOpen/Commands/GoToMethodCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Threading.Tasks;
using System.Linq;
using Task = System.Threading.Tasks.Task;
using System.Windows;

namespace QuickVSOpen
{
Expand Down Expand Up @@ -147,6 +148,18 @@ private void Execute(object sender, EventArgs e)

if (found != null)
{
if(m_openDialog != null)
{
var source = PresentationSource.FromVisual(m_openDialog.Owner);
var dpi = source?.CompositionTarget?.TransformFromDevice.M11 ?? 1.0;
if(dpi != m_openDialog.ClosedDpi)
{
m_openDialog.AllowCloseClose = true;
m_openDialog.Close();
m_openDialog = null;
}
}

if (m_openDialog == null)
{
m_openDialog = new OpenDialog(found, true, true, true);
Expand Down
13 changes: 13 additions & 0 deletions QuickVSOpen/Commands/OpenSolutionFileCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Threading.Tasks;
using System.Linq;
using Task = System.Threading.Tasks.Task;
using System.Windows;

namespace QuickVSOpen
{
Expand Down Expand Up @@ -141,6 +142,18 @@ private void Execute(object sender, EventArgs e)
}
}

if (m_openDialog != null)
{
var source = PresentationSource.FromVisual(m_openDialog.Owner);
var dpi = source?.CompositionTarget?.TransformFromDevice.M11 ?? 1.0;
if (dpi != m_openDialog.ClosedDpi)
{
m_openDialog.AllowCloseClose = true;
m_openDialog.Close();
m_openDialog = null;
}
}

if (m_openDialog == null)
{
m_openDialog = new OpenDialog(m_files, true, false, true);
Expand Down
55 changes: 28 additions & 27 deletions QuickVSOpen/OpenDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public partial class OpenDialog : Window
public string SelectedSearchString { get; set; }
bool m_handleTextChanged = true;

public double ClosedDpi { get; set; }
public bool AllowCloseClose { get; set; } = false;

public OpenDialog(ISearchable files, bool multiSelect, bool showSecondColumn, bool showFileTooltip)
{
InitializeComponent();
Expand Down Expand Up @@ -163,32 +166,23 @@ public void Init()
m_resultsListView.SelectedIndex = 0;
}));


Result = false;

this.ShowInTaskbar = false;
var source = PresentationSource.FromVisual(this.Owner);
var dpi = source?.CompositionTarget?.TransformFromDevice.M11 ?? 1.0;

if (System.Windows.Application.Current.MainWindow.WindowState == System.Windows.WindowState.Maximized)
{
POINT lpPoint;
GetCursorPos(out lpPoint);
var p = this.Owner.PointToScreen(new Point(this.Owner.Width / 2, this.Owner.Height / 2));

var screen = ScreenFromPoint1(lpPoint);
POINT lpPoint;
lpPoint.X = (int)p.X;
lpPoint.Y = (int)p.Y;

var left = screen.Bounds.Left + (screen.Bounds.Width / 2) - (this.Width / 2);
this.Left = left;
var screen = ScreenFromPoint1(lpPoint);

var top = screen.Bounds.Top + (screen.Bounds.Height / 2) - (this.Height / 2);
this.Top = top;
}
else
{
var left = (System.Windows.Application.Current.MainWindow.Left + (System.Windows.Application.Current.MainWindow.ActualWidth / 2)) - (this.Width / 2);
this.Left = left;
this.Left = screen.Bounds.Left + ((screen.Bounds.Width * dpi) / 2) - (this.Width / 2);
this.Top = screen.Bounds.Top + ((screen.Bounds.Height * dpi) / 2) - (this.Height / 2);

var top = (System.Windows.Application.Current.MainWindow.Top + (System.Windows.Application.Current.MainWindow.ActualHeight / 2)) - (this.Height / 2);
this.Top = top;
}
this.ShowInTaskbar = false;
}

private void Window_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
Expand Down Expand Up @@ -316,15 +310,22 @@ private void m_searchTextBox_KeyDown(object sender, KeyEventArgs e)
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
SelectedSearchString = m_searchTextBox.Text;
e.Cancel = true;

Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (DispatcherOperationCallback)(arg =>

if (this.AllowCloseClose == false)
{
this.Left = -1000;
this.Hide();

return null;
}), null);
e.Cancel = true;

//keep track of this, not sure why but i was having problems (window would disapear) with closing the window and opening on a different dpi screen
//this lets us close the window on open if they are on different dpi and that works then
var s = PresentationSource.FromVisual(this);
this.ClosedDpi = s?.CompositionTarget?.TransformFromDevice.M11 ?? 1.0;

Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (DispatcherOperationCallback)(arg =>
{
this.Hide();
return null;
}), null);
}
}
}
}
2 changes: 1 addition & 1 deletion QuickVSOpen/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="QuickVSOpen2022.40b2ce6b-418f-4384-aa14-ee01bd357aa5" Version="1.1.2.0" Language="en-US" Publisher="Scott Brogden" />
<Identity Id="QuickVSOpen2022.40b2ce6b-418f-4384-aa14-ee01bd357aa5" Version="1.1.3.0" Language="en-US" Publisher="Scott Brogden" />
<DisplayName>QuickVSOpen2022</DisplayName>
<Description xml:space="preserve">Quickly open solution files or go to file members</Description>
</Metadata>
Expand Down

0 comments on commit b3c5cb8

Please sign in to comment.