Added extra handling for linux screens

This commit is contained in:
Ano-sys
2025-02-14 20:15:21 +01:00
parent 211c6a1768
commit 344b02e097
+15
View File
@@ -1,11 +1,13 @@
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using System.Linq;
using Avalonia; using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using System.Reactive.Linq; using System.Reactive.Linq;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Interactivity; using Avalonia.Interactivity;
using Avalonia.Media; using Avalonia.Media;
using Avalonia.Platform;
namespace SimpleNote; namespace SimpleNote;
@@ -15,7 +17,19 @@ public partial class MainWindow : Window
private PixelRect? screen; private PixelRect? screen;
public MainWindow() public MainWindow()
{ {
if (Screens.Primary == null)
{
Screen max = Screens.All[0];
for (int i = 0; i < Screens.ScreenCount; i++)
{
if (Screens.All[i].Bounds.Width > max.Bounds.Width) max = Screens.All[i];
}
screen = max.WorkingArea;
}
else
screen = Screens.Primary?.WorkingArea; screen = Screens.Primary?.WorkingArea;
if (screen == null) if (screen == null)
{ {
Console.WriteLine("No screen available."); Console.WriteLine("No screen available.");
@@ -80,6 +94,7 @@ public partial class MainWindow : Window
if (width == 55) width -= 5; if (width == 55) width -= 5;
this.Width = width; this.Width = width;
if(!System.OperatingSystem.IsLinux()) // Screenpositionhandling on Hyprland/Wayland/X11 is different
this.Position = new PixelPoint((int)((screen.Value.Width - width) / 2), 10); this.Position = new PixelPoint((int)((screen.Value.Width - width) / 2), 10);
} }