Skip to content

Commit

Permalink
[Workspaces] add monitor detection
Browse files Browse the repository at this point in the history
  • Loading branch information
donlaci committed Sep 23, 2024
1 parent cf470a6 commit f0712f9
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/modules/Workspaces/WorkspacesEditor/Models/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,37 @@ public MonitorSetup MonitorSetup
if (_monitorSetup == null)
{
_monitorSetup = Parent.Monitors.Where(x => x.MonitorNumber == MonitorNumber).FirstOrDefault();
if (_monitorSetup == null)
{
// monitors changed: try to determine monitor id based on middle point
int middleX = Position.X + (Position.Width / 2);
int middleY = Position.Y + (Position.Height / 2);
var monitorCandidate = Parent.Monitors.Where(x =>
(x.MonitorDpiUnawareBounds.Left < middleX) &&
(x.MonitorDpiUnawareBounds.Right > middleX) &&
(x.MonitorDpiUnawareBounds.Top < middleY) &&
(x.MonitorDpiUnawareBounds.Bottom > middleY)).FirstOrDefault();
if (monitorCandidate != null)
{
_monitorSetup = monitorCandidate;
MonitorNumber = monitorCandidate.MonitorNumber;
}
else
{
// monitors and even the app's area unknown, set the main monitor (which is closer to (0,0)) as the app's monitor
monitorCandidate = Parent.Monitors.OrderBy(x => Math.Abs(x.MonitorDpiUnawareBounds.Left) + Math.Abs(x.MonitorDpiUnawareBounds.Top)).FirstOrDefault();
if (monitorCandidate != null)
{
_monitorSetup = monitorCandidate;
MonitorNumber = monitorCandidate.MonitorNumber;
}
else
{
// no monitors defined at all.
Logger.LogError($"Wrong workspace setup. No monitors defined for the workspace: {Parent.Name}.");
}
}
}
}

return _monitorSetup;
Expand Down

0 comments on commit f0712f9

Please sign in to comment.