Skip to content

Commit

Permalink
more support for 4K.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArcadeRenegade committed Feb 1, 2016
1 parent 0718dfa commit 694c55f
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 42 deletions.
15 changes: 9 additions & 6 deletions SidebarDiagnostics/AppBar.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,19 @@ private void InitWindow()

private void InitAppBar()
{
WorkArea _workArea = Windows.Monitor.GetWorkArea(this);
WorkArea _windowWA;
WorkArea _appbarWA;

Left = _workArea.Left;
Top = _workArea.Top;
Width = _workArea.Width;
Height = _workArea.Height;
Windows.Monitor.GetWorkArea(this, out _windowWA, out _appbarWA);

Left = _windowWA.Left;
Top = _windowWA.Top;
Width = _windowWA.Width;
Height = _windowWA.Height;

if (Properties.Settings.Default.UseAppBar)
{
SetAppBar(Properties.Settings.Default.DockEdge, _workArea);
SetAppBar(Properties.Settings.Default.DockEdge, _windowWA, _appbarWA);
}
}

Expand Down
4 changes: 2 additions & 2 deletions SidebarDiagnostics/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.3.1.0")]
[assembly: AssemblyFileVersion("2.3.1.0")]
[assembly: AssemblyVersion("2.3.2.0")]
[assembly: AssemblyFileVersion("2.3.2.0")]
100 changes: 66 additions & 34 deletions SidebarDiagnostics/Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ public static MonitorInfo GetMonitorFromIndex(int index)
return _monitors.Where(s => s.IsPrimary).Single();
}

public static WorkArea GetWorkArea(AppBarWindow window)
public static void GetWorkArea(AppBarWindow window, out WorkArea windowWA, out WorkArea appbarWA)
{
MonitorInfo _screen = GetMonitorFromIndex(Properties.Settings.Default.ScreenIndex);

Expand All @@ -611,7 +611,7 @@ public static WorkArea GetWorkArea(AppBarWindow window)
window.UpdateScale(_screen.ScaleX, _screen.ScaleY, false);
}

WorkArea _workArea = new WorkArea()
windowWA = new WorkArea()
{
Left = _screen.WorkArea.Left,
Top = _screen.WorkArea.Top,
Expand All @@ -621,10 +621,10 @@ public static WorkArea GetWorkArea(AppBarWindow window)

if (Properties.Settings.Default.Enabled4K)
{
_workArea.Left *= _inverseX;
_workArea.Top *= _inverseY;
_workArea.Right *= _inverseX;
_workArea.Bottom *= _inverseY;
windowWA.Left *= _inverseX;
windowWA.Top *= _inverseY;
windowWA.Right *= _inverseX;
windowWA.Bottom *= _inverseY;
}

double _windowWidth = Properties.Settings.Default.SidebarWidth * _screenX;
Expand All @@ -639,25 +639,49 @@ public static WorkArea GetWorkArea(AppBarWindow window)
switch (Properties.Settings.Default.DockEdge)
{
case DockEdge.Left:
_workArea.Right = _workArea.Left + _windowWidth - _modifyX;
_workArea.Left -= _modifyX;
windowWA.Right = windowWA.Left + _windowWidth - _modifyX;
windowWA.Left -= _modifyX;
break;

case DockEdge.Right:
_workArea.Left = _workArea.Right - _windowWidth + _modifyX;
_workArea.Right += _modifyX;
windowWA.Left = windowWA.Right - _windowWidth + _modifyX;
windowWA.Right += _modifyX;
break;
}

int _offsetX = Properties.Settings.Default.XOffset;
int _offsetY = Properties.Settings.Default.YOffset;

_workArea.Left += _offsetX;
_workArea.Top += _offsetY;
_workArea.Right += _offsetX;
_workArea.Bottom += _offsetY;
windowWA.Left += _offsetX;
windowWA.Top += _offsetY;
windowWA.Right += _offsetX;
windowWA.Bottom += _offsetY;

return _workArea;
appbarWA = new WorkArea()
{
Left = windowWA.Left,
Top = windowWA.Top,
Right = windowWA.Right,
Bottom = windowWA.Bottom
};

if (Properties.Settings.Default.Enabled4K)
{
double _oldWidth = appbarWA.Width;
double _newWidth = _oldWidth * _screenX;
double _delta = _newWidth - _oldWidth;

switch (Properties.Settings.Default.DockEdge)
{
case DockEdge.Left:
appbarWA.Right += _delta;
break;

case DockEdge.Right:
appbarWA.Left -= _delta;
break;
}
}
}
}

Expand Down Expand Up @@ -859,7 +883,7 @@ public void SetBottom()
);
}

public void SetAppBar(DockEdge edge, WorkArea workArea)
public void SetAppBar(DockEdge edge, WorkArea windowWA, WorkArea appbarWA)
{
if (edge == DockEdge.None)
{
Expand All @@ -878,7 +902,7 @@ public void SetAppBar(DockEdge edge, WorkArea workArea)
NativeMethods.SHAppBarMessage(APPBARMSG.ABM_NEW, ref _data);
}

DockAppBar(edge, workArea);
DockAppBar(edge, windowWA, appbarWA);
}

public void ClearAppBar()
Expand All @@ -902,9 +926,12 @@ public void AppBarShow()
{
if (Properties.Settings.Default.UseAppBar)
{
WorkArea _workArea = Monitor.GetWorkArea(this);
WorkArea _windowWA;
WorkArea _appbarWA;

SetAppBar(DockEdge, _workArea);
Monitor.GetWorkArea(this, out _windowWA, out _appbarWA);

SetAppBar(DockEdge, _windowWA, _appbarWA);
}

Show();
Expand All @@ -930,37 +957,37 @@ private APPBARDATA NewData()
return _data;
}

private void DockAppBar(DockEdge edge, WorkArea workArea)
private void DockAppBar(DockEdge edge, WorkArea windowWA, WorkArea appbarWA)
{
APPBARDATA _data = NewData();
_data.uEdge = (int)edge;
_data.rc = new RECT()
{
Left = (int)Math.Round(workArea.Left),
Top = (int)Math.Round(workArea.Top),
Right = (int)Math.Round(workArea.Right),
Bottom = (int)Math.Round(workArea.Bottom)
Left = (int)Math.Round(appbarWA.Left),
Top = (int)Math.Round(appbarWA.Top),
Right = (int)Math.Round(appbarWA.Right),
Bottom = (int)Math.Round(appbarWA.Bottom)
};

NativeMethods.SHAppBarMessage(APPBARMSG.ABM_QUERYPOS, ref _data);

NativeMethods.SHAppBarMessage(APPBARMSG.ABM_SETPOS, ref _data);

workArea.Left = _data.rc.Left;
workArea.Top = _data.rc.Top;
workArea.Right = _data.rc.Right;
workArea.Bottom = _data.rc.Bottom;
appbarWA.Left = _data.rc.Left;
appbarWA.Top = _data.rc.Top;
appbarWA.Right = _data.rc.Right;
appbarWA.Bottom = _data.rc.Bottom;

AppBarWidth = workArea.Width;
AppBarWidth = appbarWA.Width;

_source = HwndSource.FromHwnd(_data.hWnd);

Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
{
Top = workArea.Top;
Left = workArea.Left;
Width = workArea.Width;
Height = workArea.Height;
Top = windowWA.Top;
Left = windowWA.Left;
Width = windowWA.Width;
Height = windowWA.Height;

_source.AddHook(AppBarHook);
}));
Expand Down Expand Up @@ -989,7 +1016,12 @@ private IntPtr AppBarHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, re

Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
{
DockAppBar(DockEdge, Monitor.GetWorkArea(this));
WorkArea _windowWA;
WorkArea _appbarWA;

Monitor.GetWorkArea(this, out _windowWA, out _appbarWA);

SetAppBar(DockEdge, _windowWA, _appbarWA);
}));

_cancelReposition = null;
Expand Down

0 comments on commit 694c55f

Please sign in to comment.