Skip to content

Commit

Permalink
Merge pull request #1019 from dremin/move-openshell-menu
Browse files Browse the repository at this point in the history
Move the Open Shell menu
  • Loading branch information
dremin authored Jan 13, 2025
2 parents 9cbd900 + e5a3553 commit 8ff9adb
Showing 1 changed file with 72 additions and 2 deletions.
74 changes: 72 additions & 2 deletions RetroBar/Utilities/StartMenuMonitor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Threading;
using ManagedShell.AppBar;
using ManagedShell.Common.Helpers;
using ManagedShell.Common.Logging;
using ManagedShell.Common.SupportingClasses;
Expand Down Expand Up @@ -58,6 +60,7 @@ private void poller_Tick(object sender, EventArgs e)
{
// Open Shell Menu
newIsVisible = true;
relocateStartMenuByClass("OpenShell.CMenuContainer");
}

setVisibility(newIsVisible);
Expand Down Expand Up @@ -121,6 +124,73 @@ private bool isVisibleByClass(string className)
return IsWindowVisible(hStartMenu);
}

private void relocateStartMenuByClass(string className)
{
if (_taskbarHwndActivated == IntPtr.Zero)
{
return;
}

// Get current window rects
IntPtr hStartMenu = FindWindowEx(IntPtr.Zero, IntPtr.Zero, className, IntPtr.Zero);
if (hStartMenu == IntPtr.Zero)
{
return;
}
FlowDirection flowDirection = Application.Current.FindResource("flow_direction") as FlowDirection? ?? FlowDirection.LeftToRight;
GetWindowRect(hStartMenu, out ManagedShell.Interop.NativeMethods.Rect startMenuRect);
GetWindowRect(_taskbarHwndActivated, out ManagedShell.Interop.NativeMethods.Rect taskbarRect);

int x = 0, y = 0;
switch (Settings.Instance.Edge)
{
case AppBarEdge.Left:
// Top right of taskbar is menu top left
x = taskbarRect.Right;
y = taskbarRect.Top;
break;
case AppBarEdge.Right:
// Top left of taskbar is menu top right
x = taskbarRect.Left - startMenuRect.Width;
y = taskbarRect.Top;
break;
case AppBarEdge.Top:
if (flowDirection == FlowDirection.LeftToRight)
{
// Bottom left of taskbar is menu top left
x = taskbarRect.Left;
}
else
{
// Bottom right of taskbar is menu top right
x = taskbarRect.Right - startMenuRect.Width;
}
y = taskbarRect.Bottom;
break;
case AppBarEdge.Bottom:
if (flowDirection == FlowDirection.LeftToRight)
{
// Top left of taskbar is menu bottom left
x = taskbarRect.Left;
}
else
{
// Top right of taskbar is menu bottom right
x = taskbarRect.Right - startMenuRect.Width;
}
y = taskbarRect.Top - startMenuRect.Height;
break;
}

if (y == startMenuRect.Top && x == startMenuRect.Left)
{
// Start menu is already in the correct position
return;
}

SetWindowPos(hStartMenu, IntPtr.Zero, x, y, 0, 0, (int)(SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOZORDER));
}

private IImmersiveMonitor GetImmersiveMonitor(ManagedShell.UWPInterop.Interfaces.IServiceProvider shell, IntPtr hWnd)
{
if (shell.QueryService(ref CLSID_ImmersiveMonitorManager, ref IID_ImmersiveMonitorManager, out object monitorManagerObj) != 0)
Expand Down Expand Up @@ -253,9 +323,9 @@ interface IImmersiveMonitor
public int IsConnected(out bool pfConnected);
public int IsPrimary(out bool pfPrimary);
public int GetTrustLevel(out uint level);
public int GetDisplayRect(out Rect prcDisplayRect);
public int GetDisplayRect(out ManagedShell.Interop.NativeMethods.Rect prcDisplayRect);
public int GetOrientation(out uint pdwOrientation);
public int GetWorkArea(out Rect prcWorkArea);
public int GetWorkArea(out ManagedShell.Interop.NativeMethods.Rect prcWorkArea);
public int IsEqual(IImmersiveMonitor pMonitor, out bool pfEqual);
public int GetTrustLevel2(out uint level);
public int GetEffectiveDpi(out uint dpiX, out uint dpiY);
Expand Down

0 comments on commit 8ff9adb

Please sign in to comment.