-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindowManagerDetector.cs
More file actions
62 lines (54 loc) · 1.56 KB
/
Copy pathWindowManagerDetector.cs
File metadata and controls
62 lines (54 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Runtime.InteropServices;
namespace Winithm.Native;
/// <summary>
/// Supported windowing environments and OS versions.
/// </summary>
public enum WindowManagerType
{
Unknown,
Windows10,
Windows11,
MacOS,
X11,
Wayland
}
/// <summary>
/// Detects the current window manager or desktop environment session type.
/// </summary>
public static class WindowManagerDetector
{
/// <summary>
/// Identifies the active WM/OS based on runtime info and environment variables.
/// </summary>
public static WindowManagerType Detect()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// Windows 11 starts at build 22000
var version = Environment.OSVersion.Version;
return version.Build >= 22000 ? WindowManagerType.Windows11 : WindowManagerType.Windows10;
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return WindowManagerType.MacOS;
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
// Check standard session type first
var sessionType = Environment.GetEnvironmentVariable("XDG_SESSION_TYPE");
if (string.Equals(sessionType, "wayland", StringComparison.OrdinalIgnoreCase))
{
return WindowManagerType.Wayland;
}
// Fallback to Wayland display socket
var waylandDisplay = Environment.GetEnvironmentVariable("WAYLAND_DISPLAY");
if (!string.IsNullOrEmpty(waylandDisplay))
{
return WindowManagerType.Wayland;
}
return WindowManagerType.X11;
}
return WindowManagerType.Unknown;
}
}