diff options
| -rw-r--r-- | src/GetWindows.cs | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/src/GetWindows.cs b/src/GetWindows.cs index e110760..ee72c39 100644 --- a/src/GetWindows.cs +++ b/src/GetWindows.cs @@ -1,4 +1,4 @@ -namespace hyprwatch.Window +namespace hyprwatch.Window { using System; using System.Diagnostics; @@ -8,20 +8,28 @@ namespace hyprwatch.Window { public static string ActiveWindow() { + string desktopEnv = Environment.GetEnvironmentVariable("XDG_CURRENT_DESKTOP"); string? activeWindow = null; try { - Process process = new Process + Process process = new Process(); + process.StartInfo = new ProcessStartInfo(); + + process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.UseShellExecute = false; + process.StartInfo.CreateNoWindow = true; + + + if(desktopEnv == "Hyprland") { - StartInfo = new ProcessStartInfo - { - FileName = "hyprctl", - Arguments = "activewindow", - RedirectStandardOutput = true, - UseShellExecute = false, - CreateNoWindow = true, - } - }; + process.StartInfo.FileName = "hyprctl"; + process.StartInfo.Arguments = "activewindow"; + } + else if(desktopEnv == "niri") + { + process.StartInfo.FileName = "niri"; + process.StartInfo.Arguments = "msg focused-window"; + } process.Start(); @@ -30,10 +38,25 @@ namespace hyprwatch.Window var classMatch = ClassRegex().Match(output); - if(classMatch.Success) + if(desktopEnv == "niri") + { + var match = Regex.Match(output, "App ID:\\s+\"([^\"]+)\""); + if(match.Success) + { + activeWindow = match.Groups[1].Value.Trim(); + } + } + + + if(desktopEnv == "Hyprland") { - activeWindow = classMatch.Groups[1].Value.Trim(); + if(classMatch.Success) + { + activeWindow = classMatch.Groups[1].Value.Trim(); + } } + + } catch(Exception ex) { |
