Skip to content

Commit

Permalink
Merge pull request #136 from Hofknecht/feature/taskbar_orientation
Browse files Browse the repository at this point in the history
Feature/taskbar orientation
  • Loading branch information
Hofknecht authored Sep 25, 2020
2 parents bec1b3f + 684babe commit cbdef12
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 156 deletions.
92 changes: 60 additions & 32 deletions Business/Menus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ internal class Menus : IDisposable
private readonly BackgroundWorker workerMainMenu = new BackgroundWorker();
private readonly List<BackgroundWorker> workersSubMenu = new List<BackgroundWorker>();

private readonly int screenHeight = Screen.PrimaryScreen.Bounds.Height;
private readonly int screenWidth = Screen.PrimaryScreen.Bounds.Width;
private readonly int screenRight = Screen.PrimaryScreen.Bounds.Right;
private readonly int taskbarHeight = new WindowsTaskbar().Size.Height;

private readonly DgvMouseRow dgvMouseRow = new DgvMouseRow();
private readonly WaitToLoadMenu waitToOpenMenu = new WaitToLoadMenu();
private readonly KeyboardInput keyboardInput = null;
Expand All @@ -41,6 +36,7 @@ internal class Menus : IDisposable
private OpenCloseState openCloseState = OpenCloseState.Default;
private RowData loadingRowData = null;
private bool showingMessageBox = false;
private TaskbarPosition taskbarPosition = new WindowsTaskbar().Position;

public Menus()
{
Expand Down Expand Up @@ -513,7 +509,7 @@ internal void MainPreload()
menus[0] = Create(
GetData(workerMainMenu, Config.Path, 0),
Path.GetFileName(Config.Path));
menus[0].AdjustSizeAndLocation(screenHeight, screenRight, taskbarHeight);
AdjustMenusSizeAndLocation();
DisposeMenu(menus[0]);
}

Expand Down Expand Up @@ -859,34 +855,66 @@ private void MenusFadeOut()

private void AdjustMenusSizeAndLocation()
{
Menu menuPredecessor = menus[0];
int widthPredecessors = -1; // -1 padding
bool directionToRight = false;

menus[0].AdjustSizeAndLocation(screenHeight, screenRight, taskbarHeight);

foreach (Menu menu in AsEnumerable.Where(m => m.Level > 0))
{
int newWith = menu.Width - menu.Padding.Horizontal + menuPredecessor.Width;
if (directionToRight)
{
if (widthPredecessors - menus[0].Width - menu.Width < 0)
{
directionToRight = false;
}
else
{
widthPredecessors -= newWith;
}
}
else if (screenWidth < widthPredecessors + menus[0].Width + menu.Width)
{
directionToRight = true;
widthPredecessors -= newWith;
WindowsTaskbar taskbar = new WindowsTaskbar();
Menu menuPredecessor = null;
List<Menu> list = AsList;
Menu menu;
Rectangle screenBounds = Screen.PrimaryScreen.Bounds;
Menu.StartLocation startLocation;

// Only apply taskbar position change when no menu is currently open
if (list.Count == 1)
{
taskbarPosition = taskbar.Position;
}

// Shrink the usable space depending on taskbar location
switch (taskbarPosition)
{
case TaskbarPosition.Left:
screenBounds.X += taskbar.Size.Width;
screenBounds.Width -= taskbar.Size.Width;
startLocation = Menu.StartLocation.BottomLeft;
break;
case TaskbarPosition.Right:
screenBounds.Width -= taskbar.Size.Width;
startLocation = Menu.StartLocation.BottomRight;
break;
case TaskbarPosition.Top:
screenBounds.Y += taskbar.Size.Height;
screenBounds.Height -= taskbar.Size.Height;
startLocation = Menu.StartLocation.TopRight;
break;
case TaskbarPosition.Bottom:
default:
screenBounds.Height -= taskbar.Size.Height;
startLocation = Menu.StartLocation.BottomRight;
break;
}

for (int i = 0; i < list.Count; i++)
{
menu = list[i];

// Only last one has to be updated as all previous one were already updated in the past
if (list.Count - 1 == i)
{
menu.AdjustSizeAndLocation(screenBounds, menuPredecessor, startLocation);
}

if (i == 0)
{
const int overlapTolerance = 4;

// Remember width of the initial menu as we don't want to overlap with it
if (taskbarPosition == TaskbarPosition.Left)
{
screenBounds.X += menu.Width - overlapTolerance;
}

screenBounds.Width -= menu.Width - overlapTolerance;
}

menu.AdjustSizeAndLocation(screenHeight, screenRight, taskbarHeight, menuPredecessor, directionToRight);
widthPredecessors += menu.Width - menu.Padding.Left;
menuPredecessor = menu;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,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("1.0.15.1")]
[assembly: AssemblyFileVersion("1.0.15.1")]
[assembly: AssemblyVersion("1.0.16.0")]
[assembly: AssemblyFileVersion("1.0.16.0")]
36 changes: 18 additions & 18 deletions Properties/CustomSettingsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,24 @@ public override void SetPropertyValues(SettingsContext context, SettingsProperty
SaveValuesToFile();
}

/// <summary>
/// Creates an empty user.config file...looks like the one MS creates.
/// This could be overkill a simple key/value pairing would probably do.
/// </summary>
private static void CreateEmptyConfig()
{
var doc = new XDocument();
var declaration = new XDeclaration("1.0", "utf-8", "true");
var config = new XElement(Config);
var userSettings = new XElement(UserSettings);
var group = new XElement(typeof(Properties.Settings).FullName);
userSettings.Add(group);
config.Add(userSettings);
doc.Add(config);
doc.Declaration = declaration;
doc.Save(UserConfigPath);
}

/// <summary>
/// Loads the values of the file into memory.
/// </summary>
Expand Down Expand Up @@ -185,24 +203,6 @@ private void LoadValuesFromFile()
}
}

/// <summary>
/// Creates an empty user.config file...looks like the one MS creates.
/// This could be overkill a simple key/value pairing would probably do.
/// </summary>
private void CreateEmptyConfig()
{
var doc = new XDocument();
var declaration = new XDeclaration("1.0", "utf-8", "true");
var config = new XElement(Config);
var userSettings = new XElement(UserSettings);
var group = new XElement(typeof(Properties.Settings).FullName);
userSettings.Add(group);
config.Add(userSettings);
doc.Add(config);
doc.Declaration = declaration;
doc.Save(UserConfigPath);
}

/// <summary>
/// Saves the in memory dictionary to the user config file.
/// </summary>
Expand Down
16 changes: 8 additions & 8 deletions UserInterface/AppContextMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ static void About_Click(object sender, EventArgs e)
AppMoreInfo = versionInfo.LegalCopyright,
};
ab.AppMoreInfo += Environment.NewLine;
ab.AppMoreInfo += "Markus Hofknecht (mailto:Markus@Hofknecht.eu)";
ab.AppMoreInfo += Environment.NewLine;
ab.AppMoreInfo += "Tanja Kauth (mailto:Tanja@Hofknecht.eu)";
ab.AppMoreInfo += Environment.NewLine;
ab.AppMoreInfo += "http://www.hofknecht.eu/systemtraymenu/";
ab.AppMoreInfo += Environment.NewLine;
ab.AppMoreInfo += "https://github.com/Hofknecht/SystemTrayMenu";
ab.AppMoreInfo += Environment.NewLine;
ab.AppMoreInfo += "Markus Hofknecht (mailto:Markus@Hofknecht.eu)" + Environment.NewLine;
ab.AppMoreInfo += "Tanja Kauth (mailto:Tanja@Hofknecht.eu)" + Environment.NewLine;

// Thanks for letting me being part of this project and that I am allowed to be listed here :-)
ab.AppMoreInfo += "Peter Kirmeier (mai" + "lto:top" + "ete" + "rk@f" + "reen" + "et." + "de)" + Environment.NewLine;

ab.AppMoreInfo += "http://www.hofknecht.eu/systemtraymenu/" + Environment.NewLine;
ab.AppMoreInfo += "https://github.com/Hofknecht/SystemTrayMenu" + Environment.NewLine;
ab.AppMoreInfo += Environment.NewLine;
ab.AppMoreInfo += "GNU GENERAL PUBLIC LICENSE" + Environment.NewLine;
ab.AppMoreInfo += "(Version 3, 29 June 2007)" + Environment.NewLine;
Expand Down
Loading

0 comments on commit cbdef12

Please sign in to comment.